void PlotWidget::addPlot (QString plugin, int row, QString name) { PluginFactory fac; Plugin *plug = fac.load(plugin); if (! plug) return; PluginData pd; pd.command = QString("settings"); if (! plug->command(&pd)) return; Entity *settings = pd.settings; settings->setName(name); _settings.insert(name, settings); addPlotSettings(settings); QVariant *tset = settings->get(QString("row")); if (tset) tset->setValue(row); Plot *plot = new Plot(name, 0); plot->setMinimumHeight(30); _plots.insert(name, plot); _csplitter->insertWidget(row, plot); plot->setStartIndex(_cw->scrollBarValue()); // connect all we need here connect(plot, SIGNAL(signalResizeScrollBar(Plot *)), _cw, SLOT(resizeScrollBar(Plot *))); connect(this, SIGNAL(signalClear()), plot, SLOT(clear())); connect(this, SIGNAL(signalDraw()), plot, SLOT(updatePlot())); connect(this, SIGNAL(signalSetDates()), plot, SLOT(setDates())); connect(this, SIGNAL(signalBarLength(int)), plot, SLOT(setBarLength(int))); connect(this, SIGNAL(signalIndex(int)), plot, SLOT(setStartIndex(int))); connect(plot, SIGNAL(signalMessage(QString)), this, SIGNAL(signalMessage(QString))); connect(plot, SIGNAL(signalDeleteMarkers(QStringList)), this, SLOT(deleteMarkers(QStringList))); }
void PlotWidget::addPlot (QString plugin, int row, QString name) { qWarning() << "PlotWidget::addPlot - " << name; IIndicatorPlugin *plug = dynamic_cast<IIndicatorPlugin*>(((PluginFactory*)PluginFactory::getPluginFactory())->loadPlugin(plugin)); if (! plug) return; Entity *settings = plug->querySettings(); settings->setName(name); _settings.insert(name, settings); addPlotSettings(settings); QVariant *tset = settings->get(QString("row")); if (tset) tset->setValue(row); Plot *plot = new Plot(name, 0); plot->setMinimumHeight(30); _plots.insert(name, plot); _csplitter->insertWidget(row, plot); plot->setStartIndex(_controlWidget->scrollBarValue()); // connect all we need here connect(plot, SIGNAL(signalResizePanScrollBar(Plot *)), _controlWidget, SLOT(resizePanScrollBar(Plot *))); connect(this, SIGNAL(signalClear()), plot, SLOT(clear())); connect(this, SIGNAL(signalDraw()), plot, SLOT(updatePlot())); connect(this, SIGNAL(signalSetDates()), plot, SLOT(setDates())); connect(this, SIGNAL(signalBarLength(int)), plot, SLOT(setBarLength(int))); connect(this, SIGNAL(signalIndex(int)), plot, SLOT(setStartIndex(int))); connect(plot, SIGNAL(signalMessage(QString)), this, SIGNAL(signalMessage(QString))); connect(plot, SIGNAL(signalDeleteMarkers(QStringList)), this, SLOT(deleteMarkers(QStringList))); connect(_controlWidget, SIGNAL(signalRange(int)), plot, SLOT(setPage(int))); }
void PlotWidget::refresh () { if (! _plots.size()) return; // load fresh symbol data if (! _cw->count()) return; PluginFactory fac; Plugin *qplug = fac.load(QString("DBSymbol")); if (! qplug) return; DataBase db(g_session); saveMarkers(db); Bars sym = _cw->currentSymbol(); g_symbol->clear(); g_symbol->setSymbol(sym.symbol()); g_symbol->setLength(_cw->length()); g_symbol->setRange(_cw->range()); PluginData pd; pd.command = QString("getBars"); pd.bars = g_symbol; if (! qplug->command(&pd)) return; else emit signalClear(); // refresh dates emit signalSetDates(); QHashIterator<QString, Plot *> it(_plots); while (it.hasNext()) { it.next(); Plot *plot = it.value(); Entity *e = _settings.value(it.key()); if (! e) continue; QVariant *plugin = e->get(QString("plugin")); if (! plugin) continue; Plugin *iplug = fac.load(plugin->toString()); if (! iplug) continue; PluginData tpd; tpd.command = QString("runIndicator"); tpd.settings = e; if (! iplug->command(&tpd)) continue; for (int tpos = 0; tpos < tpd.curves.size(); tpos++) plot->setCurve(tpd.curves.at(tpos)); for (int tpos = 0; tpos < tpd.markers.size(); tpos++) plot->setMarker(tpd.markers.at(tpos)); } loadMarkers(db); emit signalDraw(); setScrollBarSize(); QStringList tl; tl << "OTA" << "-" << sym.symbol() << "(" + sym.name() + ")" << _cw->lengthText() << _cw->rangeText(); emit signalTitle(tl.join(" ")); }
void PlotWidget::refresh () { qDebug() << "PlotWidget::refresh ()"; DataBase db(g_session); bool newData = loadSymbolData(); //Save all markers before clearing the plot saveMarkers(db); emit signalClear(); // refresh dates emit signalSetDates(); Bars sym = _toolbarWidget->currentSymbol(); //Plot all Indicators QHashIterator<QString, Plot *> it(_plots); while (it.hasNext()) { it.next(); Plot *plot = it.value(); Entity *pEntity = _settings.value(it.key()); if (! pEntity) continue; QVariant *plugin = pEntity->get(QString("plugin")); if (! plugin) continue; IIndicatorPlugin *pPlugin = dynamic_cast<IIndicatorPlugin*>(((PluginFactory*)PluginFactory::getPluginFactory())->loadPlugin(plugin->toString())); if (! pPlugin) continue; QList<Curve*> curves = pPlugin->runIndicator(pEntity); if(newData){ pPlugin->newDataLoaded(); } for (int tpos = 0; tpos < curves.size(); tpos++) plot->setCurve(curves.at(tpos)); // for (int tpos = 0; tpos < tpd.markers.size(); tpos++) // plot->setMarker(tpd.markers.at(tpos)); } //relaod all markers after plot have been updated loadMarkers(db); updateScrollBars(); emit signalDraw(); setPanScrollBarSize(); QStringList tl; tl << "QtTrader" << "-" << sym.symbol() << "(" + sym.name() + ")" << _toolbarWidget->lengthText(); emit signalTitle(tl.join(" ")); }