[Qtstalker-cvs-commits] qtstalker/plugins/WILLR .cvsignore, NONE, 1.1 WILLR.cpp, NONE, 1.1 WILLR.h,
Brought to you by:
sstratos
Update of /cvsroot/qtstalker/qtstalker/plugins/WILLR In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv10101/qtstalker/plugins/WILLR Added Files: .cvsignore WILLR.cpp WILLR.h WILLR.pro WILLRDialog.cpp WILLRDialog.h WILLRObject.cpp WILLRObject.h Log Message: --- NEW FILE: .cvsignore --- Makefile moc_*.cpp --- NEW FILE: WILLRObject.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 "WILLRObject.h" #include "ta_libc.h" #include "WILLRDialog.h" #include "Util.h" #include <QtDebug> WILLRObject::WILLRObject (QString profile, QString name) { TA_RetCode rc = TA_Initialize(); if (rc != TA_SUCCESS) qDebug() << "WILLRObject::WILLRObject: error on TA_Initialize"; _profile = profile; _name = name; _plugin = QString("WILLR"); _type = QString("indicator"); _period = 10; _outputKey = QString("v"); _hasOutput = TRUE; _inputObject = QString("symbol"); _highKey = QString("H"); _lowKey = QString("L"); _closeKey = QString("C"); _commandList << QString("update"); _commandList << QString("dialog"); _commandList << QString("output"); _commandList << QString("load"); _commandList << QString("save"); _commandList << QString("output_keys"); } WILLRObject::~WILLRObject () { clear(); } void WILLRObject::clear () { qDeleteAll(_bars); _bars.clear(); } int WILLRObject::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 WILLRObject::update (ObjectCommand *oc) { clear(); // input object Object *io = (Object *) oc->getObject(_inputObject); if (! io) { qDebug() << "WILLRObject::update: invalid input" << _inputObject; return 0; } // get input bars ObjectCommand toc(QString("output")); if (! io->message(&toc)) { qDebug() << "WILLRObject::update: message error" << io->plugin() << toc.command(); return 0; } QMap<int, Data *> data = toc.map(); int size = data.size(); TA_Real high[size]; TA_Real low[size]; TA_Real close[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(_highKey)) continue; if (! d->contains(_lowKey)) continue; if (! d->contains(_closeKey)) continue; high[dpos] = (TA_Real) d->value(_highKey).toDouble(); low[dpos] = (TA_Real) d->value(_lowKey).toDouble(); close[dpos++] = (TA_Real) d->value(_closeKey).toDouble(); } TA_RetCode rc = TA_WILLR(0, dpos - 1, &high[0], &low[0], &close[0], _period, &outBeg, &outNb, &out[0]); if (rc != TA_SUCCESS) { qDebug() << "WILLRObject::update: 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 WILLRObject::dialog (ObjectCommand *oc) { WILLRDialog *dialog = new WILLRDialog(oc->getObjects(), _name); dialog->setSettings(_inputObject, _highKey, _lowKey, _closeKey, _period); connect(dialog, SIGNAL(signalDone(void *)), this, SLOT(dialogDone(void *))); dialog->setModified(FALSE); dialog->show(); return 1; } void WILLRObject::dialogDone (void *dialog) { WILLRDialog *d = (WILLRDialog *) dialog; d->settings(_inputObject, _highKey, _lowKey, _closeKey, _period); ObjectCommand oc(QString("modified")); emit signalMessage(oc); } int WILLRObject::outputKeys (ObjectCommand *oc) { QStringList keys; keys << _outputKey; oc->setValue(QString("output_keys"), keys); return 1; } int WILLRObject::output (ObjectCommand *oc) { outputKeys(oc); oc->setMap(_bars); return 1; } int WILLRObject::load (ObjectCommand *oc) { QSettings *settings = (QSettings *) oc->getObject(QString("QSettings")); if (! settings) { qDebug() << "WILLRObject::load: invalid QSettings"; return 0; } _inputObject = settings->value(QString("input_object")).toString(); _highKey = settings->value(QString("high_key")).toString(); _lowKey = settings->value(QString("low_key")).toString(); _closeKey = settings->value(QString("close_key")).toString(); _period = settings->value(QString("period")).toInt(); return 1; } int WILLRObject::save (ObjectCommand *oc) { QSettings *settings = (QSettings *) oc->getObject(QString("QSettings")); if (! settings) { qDebug() << "WILLRObject::save: invalid QSettings"; return 0; } settings->setValue(QString("plugin"), _plugin); settings->setValue(QString("input_object"), _inputObject); settings->setValue(QString("high_key"), _highKey); settings->setValue(QString("low_key"), _lowKey); settings->setValue(QString("close_key"), _closeKey); settings->setValue(QString("period"), _period); return 1; } --- NEW FILE: WILLR.h --- /* * Qtstalker stock charter * * Copyright (C) 2001-2007 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_WILLR_H #define PLUGIN_WILLR_H #include "Plugin.h" class WILLR : public QObject, public Plugin { Q_OBJECT Q_INTERFACES(Plugin) public: WILLR (); int command (PluginCommand *); protected: QStringList _commandList; }; #endif --- NEW FILE: WILLR.cpp --- /* * Qtstalker stock charter * * Copyright (C) 2001-2007 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 "WILLR.h" #include "WILLRObject.h" WILLR::WILLR () { _commandList << QString("type"); _commandList << QString("object"); } int WILLR::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 WILLRObject(pc->profile, pc->name); rc = 1; break; default: break; } return rc; } // do not remove Q_EXPORT_PLUGIN2(WILLR, WILLR); --- NEW FILE: WILLRDialog.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 "WILLRDialog.h" #include "Util.h" WILLRDialog::WILLRDialog (QHash<QString, void *> objects, QString name) : Dialog (0, name) { QStringList tl; QDir dir(QDir::homePath()); tl << dir.absolutePath() << QString("OTA") << QString("WILLR") << QString("settings") << QString("dialog"); _settingsPath = tl.join("/"); createTab(objects); loadSettings(); } WILLRDialog::~WILLRDialog () { saveSettings(); } void WILLRDialog::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); // 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 WILLRDialog::done () { emit signalDone((void *) this); Dialog::done(); } void WILLRDialog::loadSettings () { QSettings settings(_settingsPath, QSettings::NativeFormat); Dialog::loadSettings(settings); } void WILLRDialog::saveSettings() { QSettings settings(_settingsPath, QSettings::NativeFormat); Dialog::saveSettings(settings); } void WILLRDialog::setSettings (QString i, QString hk, QString lk, QString ck, int p) { _input->setInput(i); _input->setKey(tr("High"), hk); _input->setKey(tr("Low"), lk); _input->setKey(tr("Close"), ck); _period->setValue(p); } void WILLRDialog::settings (QString &i, QString &hk, QString &lk, QString &ck, int &p) { i = _input->input(); hk = _input->key(tr("High")); lk = _input->key(tr("Low")); ck = _input->key(tr("Close")); p = _period->value(); } --- NEW FILE: WILLR.pro --- TEMPLATE = lib CONFIG += plugin MOC_DIR += build OBJECTS_DIR += build INCLUDEPATH += ../../src HEADERS += WILLR.h SOURCES += WILLR.cpp HEADERS += WILLRObject.h SOURCES += WILLRObject.cpp HEADERS += WILLRDialog.h SOURCES += WILLRDialog.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 --- NEW FILE: WILLRObject.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_WILLR_OBJECT_HPP #define PLUGIN_WILLR_OBJECT_HPP #include <QStringList> #include <QMap> #include "Object.h" #include "WILLRDialog.h" class WILLRObject : public Object { Q_OBJECT public: WILLRObject (QString profile, QString name); ~WILLRObject (); 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 _highKey; QString _lowKey; QString _closeKey; QString _outputKey; int _period; }; #endif --- NEW FILE: WILLRDialog.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_WILLR_DIALOG_HPP #define PLUGIN_WILLR_DIALOG_HPP #include <QtGui> #include "Dialog.h" #include "InputObjectWidget.h" class WILLRDialog : public Dialog { Q_OBJECT public: WILLRDialog (QHash<QString, void *> objects, QString name); ~WILLRDialog (); void createTab (QHash<QString, void *>); void setSettings(QString i, QString hk, QString lk, QString ck, int p); void settings(QString &i, QString &hk, QString &lk, QString &ck, int &p); public slots: void done (); void loadSettings (); void saveSettings (); protected: InputObjectWidget *_input; QSpinBox *_period; }; #endif |