lib/SYMBOL.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "SYMBOL.h"
00023 #include "DbPlugin.h"
00024 #include "Config.h"
00025 #include "DBIndex.h"
00026 #include "PrefDialog.h"
00027 #include <qdatetime.h>
00028 #include <qdict.h>
00029 #include <qobject.h>
00030 
00031 SYMBOL::SYMBOL ()
00032 {
00033   pluginName = "SYMBOL";
00034   formatList.append(FormatString);
00035   helpFile = "symbol.html";
00036 }
00037 
00038 SYMBOL::~SYMBOL ()
00039 {
00040 }
00041 
00042 PlotLine * SYMBOL::getSYMBOL ()
00043 {
00044   QString s;
00045   Config config;
00046   config.getData(Config::IndexPath, s);
00047   DBIndex index;
00048   index.open(s);
00049 
00050   PlotLine *line = new PlotLine();
00051 
00052   DbPlugin db;
00053   if (db.open(symbol, &index))
00054   {
00055     db.close();
00056     index.close();
00057     return line;
00058   }
00059   
00060   QDateTime date;
00061   data->getDate(0, date);
00062 
00063   QString ts;
00064   config.getData(Config::BarLength, ts);
00065   db.setBarLength((BarData::BarLength) ts.toInt());
00066   config.getData(Config::Bars, ts);
00067   db.setBarRange(ts.toInt());
00068   BarData *recordList = new BarData(symbol);
00069   QDateTime dt = QDateTime::currentDateTime();
00070   db.getHistory(recordList, dt);
00071 
00072   QDict<Setting> dict;
00073   dict.setAutoDelete(TRUE);
00074   
00075   int loop;
00076   ts = "Close";
00077   QString ts2;
00078   for (loop = 0; loop < (int) recordList->count(); loop++)
00079   {
00080     Setting *r = new Setting;
00081     ts2 = QString::number(recordList->getClose(loop));
00082     r->setData(ts, ts2);
00083     recordList->getDate(loop, dt);
00084     QString s = dt.toString("yyyyMMddhhmmss");
00085     dict.insert(s, r);
00086   }
00087 
00088   double val = 0;
00089 
00090   for (loop = 0; loop < (int) data->count(); loop++)
00091   {
00092     data->getDate(loop, dt);
00093     QString s = dt.toString("yyyyMMddhhmmss");
00094     Setting *r2 = dict[s];
00095     if (r2)
00096     {
00097       val = r2->getDouble(ts);
00098       line->append(val);
00099     }
00100   }
00101 
00102   delete recordList;
00103   db.close();
00104   index.close();
00105 
00106   line->setScaleFlag(TRUE);
00107   return line;
00108 }
00109 
00110 PlotLine * SYMBOL::calculateCustom (QString &p, QPtrList<PlotLine> &d)
00111 {
00112   // format1: SYMBOL
00113 
00114   if (checkFormat(p, d, 1, 1))
00115     return 0;
00116 
00117   symbol = formatStringList[0];
00118 
00119   return getSYMBOL();
00120 }
00121 
00122 void SYMBOL::formatDialog (QStringList &, QString &rv, QString &rs)
00123 {
00124   rs.truncate(0);
00125   rv.truncate(0);
00126   QString pl = QObject::tr("Parms");
00127   QString vnl = QObject::tr("Variable Name");
00128   QString sl = QObject::tr("Symbol");
00129   PrefDialog *dialog = new PrefDialog(0);
00130   dialog->setCaption(QObject::tr("SYMBOL Format"));
00131   dialog->createPage (pl);
00132   dialog->setHelpFile(helpFile);
00133 
00134   QString s;
00135   Config config;
00136   dialog->addTextItem(vnl, pl, s);
00137   config.getData(Config::DataPath, s);
00138   dialog->addSymbolItem(sl, pl, s, symbol);
00139 
00140   int rc = dialog->exec();
00141   
00142   if (rc == QDialog::Accepted)
00143   {
00144     dialog->getText(vnl, rv);
00145     dialog->getSymbol(sl, rs);
00146   }
00147 
00148   delete dialog;
00149 }
00150