[Qtstalker-cvs-commits] qtstalker/plugins/ROC ROCObject.cpp, NONE, 1.1 ROCObject.h, NONE, 1.1 ROC.c
Brought to you by:
sstratos
Update of /cvsroot/qtstalker/qtstalker/plugins/ROC In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv9477/qtstalker/plugins/ROC Modified Files: ROC.cpp ROC.h ROC.pro ROCDialog.cpp ROCDialog.h ROCType.h Added Files: ROCObject.cpp ROCObject.h Log Message: Index: ROCDialog.h =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROCDialog.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROCDialog.h 25 Jun 2012 22:28:02 -0000 1.1 --- ROCDialog.h 15 Feb 2013 04:37:09 -0000 1.2 *************** *** 23,78 **** #define PLUGIN_ROC_DIALOG_HPP ! #include <QDialog> ! #include <QPushButton> ! #include <QDialogButtonBox> ! #include <QStringList> ! #include <QTabWidget> ! #include <QComboBox> ! #include <QLineEdit> ! #include <QSpinBox> ! #include <QCheckBox> ! #include "Entity.h" ! #include "ColorButton.h" ! class ROCDialog : public QDialog { Q_OBJECT ! public: ! ROCDialog (QWidget *); ! void setGUI (Entity *); ! public slots: void done (); - void cancel (); - void help (); void loadSettings (); void saveSettings (); ! void modified (); ! void save (); ! protected: - Entity *_settings; - QTabWidget *_tabs; - QDialogButtonBox *_buttonBox; - QPushButton *_okButton; - QPushButton *_cancelButton; - QString _helpFile; - int _modified; - - ColorButton *_upColor; - ColorButton *_downColor; - QSpinBox *_period; - QComboBox *_input; QComboBox *_method; ! QCheckBox *_rocShow; ! ! QSpinBox *_maWidth; ! ColorButton *_maColor; ! QSpinBox *_maPeriod; ! QComboBox *_maStyle; ! QComboBox *_maType; ! QCheckBox *_maShow; }; --- 23,51 ---- #define PLUGIN_ROC_DIALOG_HPP ! #include <QtGui> ! #include "Dialog.h" ! #include "InputObjectWidget.h" ! class ROCDialog : public Dialog { Q_OBJECT ! public: ! ROCDialog (QHash<QString, void *> objects, QString name); ! ~ROCDialog (); ! void createTab (QHash<QString, void *>); ! void setSettings(QString i, QString ik, QString m, int p); ! void settings(QString &i, QString &ik, QString &m, int &p); ! public slots: void done (); void loadSettings (); void saveSettings (); ! protected: QComboBox *_method; ! InputObjectWidget *_input; ! QSpinBox *_period; }; Index: ROC.pro =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROC.pro,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROC.pro 25 Jun 2012 22:28:02 -0000 1.1 --- ROC.pro 15 Feb 2013 04:37:09 -0000 1.2 *************** *** 1,21 **** TEMPLATE = lib CONFIG += plugin - INCLUDEPATH += ../../lib - LIBS += -L../../lib -lOTA MOC_DIR += build OBJECTS_DIR += build HEADERS += ROC.h SOURCES += ROC.cpp HEADERS += ROCDialog.h SOURCES += ROCDialog.cpp HEADERS += ROCType.h SOURCES += ROCType.cpp ! target.path = /usr/local/lib/OTA/plugins INSTALLS += target QT += core QT += gui - QT += sql - QT += network --- 1,35 ---- TEMPLATE = lib CONFIG += plugin MOC_DIR += build OBJECTS_DIR += build + INCLUDEPATH += ../../src + HEADERS += ROC.h SOURCES += ROC.cpp + HEADERS += ROCObject.h + SOURCES += ROCObject.cpp HEADERS += ROCDialog.h SOURCES += ROCDialog.cpp HEADERS += ROCType.h SOURCES += ROCType.cpp + HEADERS += ../../src/Object.h + SOURCES += ../../src/Object.cpp + HEADERS += ../../src/Util.h + SOURCES += ../../src/Util.cpp + HEADERS += ../../src/Plugin.h + HEADERS += ../../src/PluginCommand.h + HEADERS += ../../src/ObjectCommand.h + SOURCES += ../../src/ObjectCommand.cpp + SOURCES += ../../src/Dialog.cpp + HEADERS += ../../src/Dialog.h + SOURCES += ../../src/InputObjectWidget.cpp + HEADERS += ../../src/InputObjectWidget.h ! ! HOME=$$system(echo $HOME) ! target.path = $${HOME}/OTA/lib INSTALLS += target QT += core QT += gui Index: ROC.cpp =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROC.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROC.cpp 25 Jun 2012 22:28:02 -0000 1.1 --- ROC.cpp 15 Feb 2013 04:37:08 -0000 1.2 *************** *** 20,57 **** */ - #include <QtGui> - #include "ta_libc.h" #include "ROC.h" ! #include "MAType.h" ! #include "BarType.h" ! #include "CurveLineType.h" ! #include "CurveHistogramType.h" ! #include "Global.h" ! #include "ROCDialog.h" ! #include "ROCType.h" int ! ROC::command (PluginData *pd) { int rc = 0; ! QStringList cl; ! cl << "type" << "dialog" << "runIndicator" << "settings"; ! ! switch (cl.indexOf(pd->command)) { case 0: // type ! pd->type = QString("indicator"); rc = 1; break; ! case 1: // dialog ! rc = dialog(pd); ! break; ! case 2: // runIndicator ! rc = run(pd); ! break; ! case 3: // settings ! rc = settings(pd); break; default: --- 20,47 ---- */ #include "ROC.h" ! #include "ROCObject.h" ! + ROC::ROC () + { + _commandList << QString("type"); + _commandList << QString("object"); + } int ! ROC::command (PluginCommand *pc) { int rc = 0; ! switch (_commandList.indexOf(pc->command)) { case 0: // type ! pc->type = QString("indicator"); rc = 1; break; ! case 1: // object ! pc->object = new ROCObject(pc->profile, pc->name); ! rc = 1; break; default: *************** *** 62,372 **** } - int - ROC::dialog (PluginData *pd) - { - if (! pd->dialogParent) - { - qDebug() << "ROC::dialog: invalid parent"; - return 0; - } - - if (! pd->settings) - { - qDebug() << "ROC::dialog: invalid settings"; - return 0; - } - - ROCDialog *dialog = new ROCDialog(pd->dialogParent); - dialog->setGUI(pd->settings); - pd->dialog = dialog; - - return 1; - } - - int - ROC::run (PluginData *pd) - { - if (! g_symbol) - return 0; - - QVariant *input = pd->settings->get(QString("input")); - if (! input) - return 0; - - QVariant *var = pd->settings->get(QString("method")); - if (! var) - return 0; - ROCType rt; - int method = rt.stringToIndex(var->toString()); - if (method == -1) - return 0; - - QVariant *period = pd->settings->get(QString("period")); - if (! period) - return 0; - - QVariant *label = pd->settings->get(QString("label")); - if (! label) - return 0; - - if (! getROC(input->toString(), method, period->toInt(), label->toString())) - return 0; - - // roc - QVariant *show = pd->settings->get(QString("rocShow")); - if (! show) - return 0; - - if (show->toBool()) - { - QVariant *var = pd->settings->get(QString("upColor")); - if (! var) - return 0; - QColor uc(var->toString()); - - var = pd->settings->get(QString("downColor")); - if (! var) - return 0; - QColor dc(var->toString()); - - Curve *hl = new Curve(QString("CurveHistogram")); - hl->setColor(uc); - hl->setLabel(label->toString()); - hl->setStyle(CurveHistogramType::_BAR); - hl->fill(label->toString(), QString(), QString(), QString(), uc); - pd->curves << hl; - - // color down bars - QList<int> keys = g_symbol->keys(); - - for (int pos = 0; pos < keys.size(); pos++) - { - Bar *bar = hl->bar(keys.at(pos)); - if (! bar) - continue; - - if (bar->value() < bar->base()) - bar->setColor(dc); - } - } - - // ma - show = pd->settings->get(QString("maShow")); - if (! show) - return 0; - - if (show->toBool()) - { - Curve *ma = getMA(pd->settings); - if (ma) - pd->curves << ma; - } - - return 1; - } - - Curve * - ROC::getMA (Entity *settings) - { - QVariant *type = settings->get(QString("maType")); - if (! type) - return 0; - - QVariant *period = settings->get(QString("maPeriod")); - if (! period) - return 0; - - QVariant *var = settings->get(QString("maColor")); - if (! var) - return 0; - QColor color(var->toString()); - - QVariant *label = settings->get(QString("maLabel")); - if (! label) - return 0; - - QVariant *style = settings->get(QString("maStyle")); - if (! style) - return 0; - - QVariant *width = settings->get(QString("maWidth")); - if (! width) - return 0; - - QVariant *momLabel = settings->get(QString("label")); - if (! momLabel) - return 0; - - if (! getMA(momLabel->toString(), label->toString(), type->toInt(), period->toInt())) - return 0; - - CurveLineType clt; - Curve *curve = new Curve(QString("CurveLine")); - curve->setLabel(label->toString()); - curve->setStyle(clt.stringToIndex(style->toString())); - curve->setPen(width->toInt()); - curve->setColor(color); - curve->fill(label->toString(), QString(), QString(), QString(), color); - - return curve; - } - - int - ROC::getROC (QString ikey, int method, int period, QString okey) - { - if (! g_symbol) - return 0; - - TA_RetCode rc = TA_Initialize(); - if (rc != TA_SUCCESS) - qDebug() << "ROC::ROC: error on TA_Initialize"; - - QList<int> keys = g_symbol->keys(); - - int size = keys.size(); - TA_Real input[size]; - TA_Real out[size]; - TA_Integer outBeg; - TA_Integer outNb; - - int dpos = 0; - for (int kpos = 0; kpos < keys.size(); kpos++) - { - CBar *bar = g_symbol->bar(keys.at(kpos)); - - double v; - if (! bar->get(ikey, v)) - continue; - - input[dpos++] = (TA_Real) v; - } - - switch ((ROCType::Key) method) - { - case ROCType::_ROC: - rc = TA_ROC (0, dpos - 1, &input[0], period, &outBeg, &outNb, &out[0]); - break; - case ROCType::_ROCP: - rc = TA_ROCP (0, dpos - 1, &input[0], period, &outBeg, &outNb, &out[0]); - break; - case ROCType::_ROCR: - rc = TA_ROCR (0, dpos - 1, &input[0], period, &outBeg, &outNb, &out[0]); - break; - case ROCType::_ROCR100: - rc = TA_ROCR100 (0, dpos - 1, &input[0], period, &outBeg, &outNb, &out[0]); - break; - default: - break; - } - - if (rc != TA_SUCCESS) - { - qDebug() << "ROC::getROC: TA-Lib error" << rc; - return 0; - } - - int keyLoop = keys.size() - 1; - int outLoop = outNb - 1; - while (keyLoop > -1 && outLoop > -1) - { - CBar *bar = g_symbol->bar(keys.at(keyLoop)); - bar->set(okey, out[outLoop]); - keyLoop--; - outLoop--; - } - - return 1; - } - - int - ROC::getMA (QString inKey, QString outKey, int type, int period) - { - if (! g_symbol) - return 0; - - TA_RetCode rc = TA_Initialize(); - if (rc != TA_SUCCESS) - qDebug() << "ROC::getMA: error on TA_Initialize"; - - QList<int> keys = g_symbol->keys(); - - int size = keys.size(); - TA_Real input[size]; - TA_Real out[size]; - TA_Integer outBeg; - TA_Integer outNb; - - int dpos = 0; - for (int kpos = 0; kpos < keys.size(); kpos++) - { - CBar *bar = g_symbol->bar(keys.at(kpos)); - - double v; - if (! bar->get(inKey, v)) - continue; - - input[dpos++] = (TA_Real) v; - } - - rc = TA_MA(0, dpos - 1, &input[0], period, (TA_MAType) type, &outBeg, &outNb, &out[0]); - if (rc != TA_SUCCESS) - { - qDebug() << "ROC::getMA: TA-Lib error" << rc; - return 0; - } - - int keyLoop = keys.size() - 1; - int outLoop = outNb - 1; - while (keyLoop > -1 && outLoop > -1) - { - CBar *bar = g_symbol->bar(keys.at(keyLoop)); - bar->set(outKey, out[outLoop]); - keyLoop--; - outLoop--; - } - - return 1; - } - - int - ROC::settings (PluginData *pd) - { - Entity *command = new Entity; - BarType bt; - MAType mat; - CurveLineType clt; - ROCType rt; - - command->set(QString("plugin"), new QVariant(QString("ROC"))); - command->set(QString("type"), new QVariant(QString("indicator"))); - - command->set(QString("input"), new QVariant(bt.indexToString(BarType::_CLOSE))); - command->set(QString("upColor"), new QVariant(QString("green"))); - command->set(QString("downColor"), new QVariant(QString("red"))); - command->set(QString("period"), new QVariant(14)); - command->set(QString("label"), new QVariant(QString("ROC"))); - command->set(QString("method"), new QVariant(rt.indexToString(ROCType::_ROC))); - command->set(QString("rocShow"), new QVariant(TRUE)); - - command->set(QString("maType"), new QVariant(mat.indexToString(MAType::_EMA))); - command->set(QString("maStyle"), new QVariant(clt.indexToString(CurveLineType::_SOLID))); - command->set(QString("maWidth"), new QVariant(1)); - command->set(QString("maColor"), new QVariant(QString("yellow"))); - command->set(QString("maPeriod"), new QVariant(10)); - command->set(QString("maLabel"), new QVariant(QString("MA"))); - command->set(QString("maShow"), new QVariant(TRUE)); - - pd->settings = command; - - return 1; - } - - int - ROC::draw (QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRect &, void *) - { - return 0; - } - - // do not remove ! Q_EXPORT_PLUGIN2(roc, ROC); --- 52,55 ---- } // do not remove ! Q_EXPORT_PLUGIN2(ROC, ROC); Index: ROC.h =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROC.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROC.h 25 Jun 2012 22:28:02 -0000 1.1 --- ROC.h 15 Feb 2013 04:37:09 -0000 1.2 *************** *** 24,29 **** #define PLUGIN_ROC_H - #include <QObject> - #include "Plugin.h" --- 24,27 ---- *************** *** 34,45 **** public: ! int draw (QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRect &, void *); ! int command (PluginData *); ! Curve * getMA (Entity *settings); ! int settings (PluginData *); ! int dialog (PluginData *); ! int run (PluginData *); ! int getROC (QString ikey, int method, int period, QString okey); ! int getMA (QString inKey, QString outKey, int type, int period); }; --- 32,40 ---- public: ! ROC (); ! int command (PluginCommand *); ! ! protected: ! QStringList _commandList; }; --- NEW FILE: ROCObject.h --- /* * Qtstalker stock charter * * Copyright (C) 2001-2010 Stefan S. Stratigakos * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #ifndef PLUGIN_ROC_OBJECT_HPP #define PLUGIN_ROC_OBJECT_HPP #include <QStringList> #include <QMap> #include "Object.h" #include "ROCDialog.h" class ROCObject : public Object { Q_OBJECT public: ROCObject (QString profile, QString name); ~ROCObject (); void clear (); int update (ObjectCommand *); int dialog (ObjectCommand *); int output (ObjectCommand *); int load (ObjectCommand *); int save (ObjectCommand *); int outputKeys (ObjectCommand *); public slots: int message (ObjectCommand *); void dialogDone (void *); private: QStringList _commandList; QMap<int, Data *> _bars; QString _inputObject; QString _inputKey; QString _outputKey; QString _method; int _period; }; #endif Index: ROCDialog.cpp =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROCDialog.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROCDialog.cpp 25 Jun 2012 22:28:02 -0000 1.1 --- ROCDialog.cpp 15 Feb 2013 04:37:09 -0000 1.2 *************** *** 21,286 **** #include "ROCDialog.h" ! #include "Doc.h" ! #include "Global.h" ! #include "MAType.h" ! #include "CurveLineType.h" ! #include "CurveHistogramType.h" ! #include "BarType.h" #include "ROCType.h" ! #include <QtDebug> ! #include <QVariant> ! #include <QLayout> ! #include <QFormLayout> ! ! ! ROCDialog::ROCDialog (QWidget *p) : QDialog (p) { ! _settings = 0; ! _modified = 0; ! _helpFile = "main.html"; ! connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater())); ! ! // main vbox ! QVBoxLayout *vbox = new QVBoxLayout; ! vbox->setSpacing(2); ! vbox->setMargin(5); ! setLayout(vbox); ! _tabs = new QTabWidget; ! vbox->addWidget(_tabs); ! ! // buttonbox ! _buttonBox = new QDialogButtonBox(QDialogButtonBox::Help); ! connect(_buttonBox, SIGNAL(accepted()), this, SLOT(done())); ! connect(_buttonBox, SIGNAL(rejected()), this, SLOT(cancel())); ! vbox->addWidget(_buttonBox); ! ! // ok button ! _okButton = _buttonBox->addButton(QDialogButtonBox::Ok); ! _okButton->setText(tr("&OK")); ! ! // cancel button ! _cancelButton = _buttonBox->addButton(QDialogButtonBox::Cancel); ! _cancelButton->setText(tr("&Cancel")); ! _cancelButton->setDefault(TRUE); ! _cancelButton->setFocus(); ! ! // help button ! QPushButton *b = _buttonBox->button(QDialogButtonBox::Help); ! b->setText(tr("&Help")); ! connect(b, SIGNAL(clicked()), this, SLOT(help())); ! } ! ! void ROCDialog::done () ! { ! saveSettings(); ! save(); ! accept(); ! } ! ! void ROCDialog::help () ! { ! Doc *doc = new Doc; ! doc->showDocumentation(_helpFile); } ! void ROCDialog::cancel () { saveSettings(); - reject(); - } - - void ROCDialog::loadSettings () - { - QSettings settings(g_settings); - settings.beginGroup(g_session); - - QSize sz = settings.value("roc_dialog_size", QSize(200,200)).toSize(); - resize(sz); - - // restore the position of the app - QPoint p = settings.value("roc_dialog_pos").toPoint(); - if (! p.isNull()) - move(p); - } - - void ROCDialog::saveSettings () - { - QSettings settings(g_settings); - settings.beginGroup(g_session); - settings.setValue("roc_dialog_size", size()); - settings.setValue("roc_dialog_pos", pos()); } ! void ROCDialog::setGUI (Entity *settings) { ! _settings = settings; - // ROC page QWidget *w = new QWidget; QFormLayout *form = new QFormLayout; w->setLayout(form); ! ! // up color ! QVariant *set = _settings->get(QString("upColor")); ! ! _upColor = new ColorButton(this, QColor(set->toString())); ! connect(_upColor, SIGNAL(valueChanged(QColor)), this, SLOT(modified())); ! form->addRow(tr("Up Color"), _upColor); ! ! // down color ! set = _settings->get(QString("downColor")); ! ! _downColor = new ColorButton(this, QColor(set->toString())); ! connect(_downColor, SIGNAL(valueChanged(QColor)), this, SLOT(modified())); ! form->addRow(tr("Down Color"), _downColor); // method - set = _settings->get(QString("method")); - ROCType rt; _method = new QComboBox; _method->addItems(rt.list()); - _method->setCurrentIndex(_method->findText(set->toString(), Qt::MatchExactly)); connect(_method, SIGNAL(currentIndexChanged(int)), this, SLOT(modified())); form->addRow(tr("Method"), _method); - // input - set = _settings->get(QString("input")); - - BarType bt; - _input = new QComboBox; - _input->addItems(bt.list()); - _input->setCurrentIndex(_input->findText(set->toString(), Qt::MatchExactly)); - connect(_input, SIGNAL(currentIndexChanged(int)), this, SLOT(modified())); - form->addRow(tr("Input"), _input); - // period - set = _settings->get(QString("period")); - _period = new QSpinBox; _period->setRange(1, 999999); ! _period->setValue(set->toInt()); ! connect(_period, SIGNAL(valueChanged(const QString &)), this, SLOT(modified())); form->addRow(tr("Period"), _period); ! // show ! set = _settings->get(QString("rocShow")); ! ! _rocShow = new QCheckBox; ! _rocShow->setChecked(set->toBool()); ! connect(_rocShow, SIGNAL(toggled(bool)), this, SLOT(modified())); ! form->addRow(tr("Show"), _rocShow); ! ! _tabs->addTab(w, QString("ROC")); ! ! // MA page ! w = new QWidget; ! ! form = new QFormLayout; ! w->setLayout(form); ! ! // type ! set = _settings->get(QString("maType")); ! ! MAType mat; ! _maType = new QComboBox; ! _maType->addItems(mat.list()); ! _maType->setCurrentIndex(_maType->findText(set->toString(), Qt::MatchExactly)); ! connect(_maType, SIGNAL(currentIndexChanged(int)), this, SLOT(modified())); ! form->addRow(tr("Type"), _maType); ! ! // style ! set = _settings->get(QString("maStyle")); ! ! CurveLineType clt; ! _maStyle = new QComboBox; ! _maStyle->addItems(clt.list()); ! _maStyle->setCurrentIndex(_maStyle->findText(set->toString(), Qt::MatchExactly)); ! connect(_maStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(modified())); ! form->addRow(tr("Style"), _maStyle); ! ! // width ! set = _settings->get(QString("maWidth")); ! ! _maWidth = new QSpinBox; ! _maWidth->setRange(1, 99); ! _maWidth->setValue(set->toInt()); ! connect(_maWidth, SIGNAL(valueChanged(const QString &)), this, SLOT(modified())); ! form->addRow(tr("Width"), _maWidth); ! ! // color ! set = _settings->get(QString("maColor")); ! ! _maColor = new ColorButton(this, QColor(set->toString())); ! connect(_maColor, SIGNAL(valueChanged(QColor)), this, SLOT(modified())); ! form->addRow(tr("Color"), _maColor); ! ! // period ! set = _settings->get(QString("maPeriod")); ! ! _maPeriod = new QSpinBox; ! _maPeriod->setRange(1, 999999); ! _maPeriod->setValue(set->toInt()); ! connect(_maPeriod, SIGNAL(valueChanged(const QString &)), this, SLOT(modified())); ! form->addRow(tr("Period"), _maPeriod); ! ! // show ! set = _settings->get(QString("maShow")); ! ! _maShow = new QCheckBox; ! _maShow->setChecked(set->toBool()); ! connect(_maShow, SIGNAL(toggled(bool)), this, SLOT(modified())); ! form->addRow(tr("Show"), _maShow); ! ! _tabs->addTab(w, QString("MA")); } ! void ROCDialog::save () { ! if (! _modified) ! return; ! ! QVariant *set = _settings->get(QString("upColor")); ! set->setValue(_upColor->color().name()); ! ! set = _settings->get(QString("downColor")); ! set->setValue(_downColor->color().name()); ! ! set = _settings->get(QString("period")); ! set->setValue(_period->value()); ! ! set = _settings->get(QString("input")); ! set->setValue(_input->currentText()); ! ! set = _settings->get(QString("method")); ! set->setValue(_method->currentText()); ! ! set = _settings->get(QString("rocShow")); ! set->setValue(_rocShow->isChecked()); ! ! set = _settings->get(QString("maType")); ! set->setValue(_maType->currentText()); ! ! set = _settings->get(QString("maStyle")); ! set->setValue(_maStyle->currentText()); ! ! set = _settings->get(QString("maWidth")); ! set->setValue(_maWidth->value()); ! set = _settings->get(QString("maColor")); ! set->setValue(_maColor->color().name()); ! set = _settings->get(QString("maPeriod")); ! set->setValue(_maPeriod->value()); ! set = _settings->get(QString("maShow")); ! set->setValue(_maShow->isChecked()); } ! void ROCDialog::modified () { ! _modified = 1; } --- 21,120 ---- #include "ROCDialog.h" ! #include "Util.h" #include "ROCType.h" ! ROCDialog::ROCDialog (QHash<QString, void *> objects, QString name) : Dialog (0, name) { ! QStringList tl; ! QDir dir(QDir::homePath()); ! tl << dir.absolutePath() << QString("OTA") << QString("ROC") << QString("settings") << QString("dialog"); ! _settingsPath = tl.join("/"); ! createTab(objects); ! loadSettings(); } ! ROCDialog::~ROCDialog () { saveSettings(); } ! void ! ROCDialog::createTab (QHash<QString, void *> l) { ! QHash<QString, void *> ol; ! QHashIterator<QString, void *> it(l); ! while (it.hasNext()) ! { ! it.next(); ! Object *o = (Object *) it.value(); ! if (o->hasOutput()) ! ol.insert(it.key(), it.value()); ! } QWidget *w = new QWidget; QFormLayout *form = new QFormLayout; + form->setSpacing(2); + form->setMargin(10); w->setLayout(form); ! ! _input = new InputObjectWidget; ! _input->setObjects(ol); ! connect(_input, SIGNAL(valueChanged()), this, SLOT(modified())); ! form->addRow(tr("Input"), _input); // method ROCType rt; _method = new QComboBox; _method->addItems(rt.list()); connect(_method, SIGNAL(currentIndexChanged(int)), this, SLOT(modified())); form->addRow(tr("Method"), _method); // period _period = new QSpinBox; _period->setRange(1, 999999); ! connect(_period, SIGNAL(valueChanged(int)), this, SLOT(modified())); form->addRow(tr("Period"), _period); ! _tabs->addTab(w, tr("Settings")); } ! void ! ROCDialog::done () { ! emit signalDone((void *) this); ! Dialog::done(); ! } ! void ! ROCDialog::loadSettings () ! { ! QSettings settings(_settingsPath, QSettings::NativeFormat); ! Dialog::loadSettings(settings); ! } ! void ! ROCDialog::saveSettings() ! { ! QSettings settings(_settingsPath, QSettings::NativeFormat); ! Dialog::saveSettings(settings); ! } ! void ! ROCDialog::setSettings (QString i, QString ik, QString m, int p) ! { ! _input->setInput(i); ! _input->setKey(tr("Input"), ik); ! _method->setCurrentIndex(_method->findText(m)); ! _period->setValue(p); } ! void ! ROCDialog::settings (QString &i, QString &ik, QString &m, int &p) { ! i = _input->input(); ! ik = _input->key(tr("Input")); ! m = _method->currentText(); ! p = _period->value(); } Index: ROCType.h =================================================================== RCS file: /cvsroot/qtstalker/qtstalker/plugins/ROC/ROCType.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ROCType.h 25 Jun 2012 22:28:03 -0000 1.1 --- ROCType.h 15 Feb 2013 04:37:09 -0000 1.2 *************** *** 23,28 **** // ************************************************************************************************* ! #ifndef PLUGIN_ROC_TYPE_HPP ! #define PLUGIN_ROC_TYPE_HPP #include <QStringList> --- 23,28 ---- // ************************************************************************************************* ! #ifndef PLUGIN_ROC_ROC_TYPE_HPP ! #define PLUGIN_ROC_ROC_TYPE_HPP #include <QStringList> --- NEW FILE: ROCObject.cpp --- /* * Qtstalker stock charter * * Copyright (C) 2001-2010 Stefan S. Stratigakos * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #include "ROCObject.h" #include "ta_libc.h" #include "ROCDialog.h" #include "Util.h" #include "ROCType.h" #include <QtDebug> ROCObject::ROCObject (QString profile, QString name) { TA_RetCode rc = TA_Initialize(); if (rc != TA_SUCCESS) qDebug() << "ROCObject::ROCObject: error on TA_Initialize"; _profile = profile; _name = name; _plugin = QString("ROC"); _type = QString("indicator"); _method = QString("ROC"); _period = 14; _outputKey = QString("v"); _hasOutput = TRUE; _inputObject = QString("symbol"); _inputKey = QString("C"); _commandList << QString("update"); _commandList << QString("dialog"); _commandList << QString("output"); _commandList << QString("load"); _commandList << QString("save"); _commandList << QString("output_keys"); } ROCObject::~ROCObject () { clear(); } void ROCObject::clear () { qDeleteAll(_bars); _bars.clear(); } int ROCObject::message (ObjectCommand *oc) { int rc = 0; switch (_commandList.indexOf(oc->command())) { case 0: rc = update(oc); break; case 1: rc = dialog(oc); break; case 2: rc = output(oc); break; case 3: rc = load(oc); break; case 4: rc = save(oc); break; case 5: rc = outputKeys(oc); break; default: break; } return rc; } int ROCObject::update (ObjectCommand *oc) { clear(); // input object Object *io = (Object *) oc->getObject(_inputObject); if (! io) { qDebug() << "ROCObject::update: invalid input" << _inputObject; return 0; } // get input bars ObjectCommand toc(QString("output")); if (! io->message(&toc)) { qDebug() << "ROCObject::update: message error" << io->plugin() << toc.command(); return 0; } QMap<int, Data *> data = toc.map(); int size = data.size(); TA_Real input[size]; TA_Real out[size]; TA_Integer outBeg; TA_Integer outNb; int dpos = 0; QMapIterator<int, Data *> it(data); while (it.hasNext()) { it.next(); Data *d = it.value(); if (d->contains(_inputKey)) input[dpos++] = (TA_Real) d->value(_inputKey).toDouble(); } TA_RetCode rc = TA_SUCCESS; ROCType rt; switch ((ROCType::Key) rt.stringToIndex(_method)) { case ROCType::_ROC: rc = TA_ROC (0, dpos - 1, &input[0], _period, &outBeg, &outNb, &out[0]); break; case ROCType::_ROCP: rc = TA_ROCP (0, dpos - 1, &input[0], _period, &outBeg, &outNb, &out[0]); break; case ROCType::_ROCR: rc = TA_ROCR (0, dpos - 1, &input[0], _period, &outBeg, &outNb, &out[0]); break; case ROCType::_ROCR100: rc = TA_ROCR100 (0, dpos - 1, &input[0], _period, &outBeg, &outNb, &out[0]); break; default: break; } if (rc != TA_SUCCESS) { qDebug() << "ROCObject::getROC: TA-Lib error" << rc; return 0; } int outLoop = outNb - 1; it.toBack(); while (it.hasPrevious() && outLoop > -1) { it.previous(); Data *b = new Data; b->insert(_outputKey, out[outLoop--]); _bars.insert(it.key(), b); } return 1; } int ROCObject::dialog (ObjectCommand *oc) { ROCDialog *dialog = new ROCDialog(oc->getObjects(), _name); dialog->setSettings(_inputObject, _inputKey, _method, _period); connect(dialog, SIGNAL(signalDone(void *)), this, SLOT(dialogDone(void *))); dialog->setModified(FALSE); dialog->show(); return 1; } void ROCObject::dialogDone (void *dialog) { ROCDialog *d = (ROCDialog *) dialog; d->settings(_inputObject, _inputKey, _method, _period); ObjectCommand oc(QString("modified")); emit signalMessage(oc); } int ROCObject::outputKeys (ObjectCommand *oc) { QStringList keys; keys << _outputKey; oc->setValue(QString("output_keys"), keys); return 1; } int ROCObject::output (ObjectCommand *oc) { outputKeys(oc); oc->setMap(_bars); return 1; } int ROCObject::load (ObjectCommand *oc) { QSettings *settings = (QSettings *) oc->getObject(QString("QSettings")); if (! settings) { qDebug() << "ROCObject::load: invalid QSettings"; return 0; } _inputObject = settings->value(QString("input_object")).toString(); _inputKey = settings->value(QString("input_key")).toString(); _method = settings->value(QString("method")).toString(); _period = settings->value(QString("period")).toInt(); return 1; } int ROCObject::save (ObjectCommand *oc) { QSettings *settings = (QSettings *) oc->getObject(QString("QSettings")); if (! settings) { qDebug() << "ROCObject::save: invalid QSettings"; return 0; } settings->setValue(QString("plugin"), _plugin); settings->setValue(QString("input_object"), _inputObject); settings->setValue(QString("input_key"), _inputKey); settings->setValue(QString("method"), _method); settings->setValue(QString("period"), _period); return 1; } |