00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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