Exemple #1
0
 /*
  * Loads symbol data from DB. Loaded data is stored in
  * the global Bar* g_symbol
  *
  * @return true if new data was loaded
  *
  * TODO: fix compare between old and new data and
  * only return true if new data was loaded
  */
bool PlotWidget::loadSymbolData() {

    Bars sym = _toolbarWidget->currentSymbol();

    //Don't load new data unless symbol or barlength changed
    if(!(g_symbol->symbol() != sym.symbol() || g_symbol->barLength() != _toolbarWidget->length()))
        return false;

    if (! _plots.size())
      return false;

    // load fresh symbol data
    if (! _toolbarWidget->count())
      return false;

    IDBPlugin *qplug = dynamic_cast<IDBPlugin *>(((PluginFactory*)PluginFactory::getPluginFactory())->loadPlugin(QString("Database")));

    if (! qplug)
      return false;

    g_symbol->clear();
    g_symbol->setSymbol(sym.symbol());
    g_symbol->setBarLength(_toolbarWidget->length());
    g_symbol->setPlotRange(_controlWidget->getRange());

    if (! qplug->getBars(g_symbol))
      return false;

    return true;
}
Exemple #2
0
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(" "));
}
Exemple #3
0
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(" "));
}