lib/Plot.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "Plot.h"
00023 #include <qlayout.h>
00024 
00025 Plot::Plot (QWidget *w, DBIndex *i) : QWidget(w)
00026 {
00027   QVBoxLayout *vbox = new QVBoxLayout(this);
00028   vbox->setMargin(0);
00029   vbox->setSpacing(0);
00030   
00031   QHBoxLayout *hbox = new QHBoxLayout(vbox);
00032   hbox->setMargin(0);
00033   hbox->setSpacing(0);
00034 
00035   indicatorPlot = new IndicatorPlot(this, i);
00036   hbox->addWidget(indicatorPlot, 1, 0);
00037   
00038   scalePlot = new ScalePlot(this);
00039   hbox->addWidget(scalePlot);
00040   
00041   datePlot = new DatePlot(this);
00042   vbox->addWidget(datePlot);
00043   
00044   connect(indicatorPlot, SIGNAL(signalDraw()), this, SLOT(slotUpdateScalePlot()));
00045   connect(indicatorPlot, SIGNAL(signalDateFlag(bool)), this, SLOT(slotDateFlagChanged(bool)));
00046   connect(indicatorPlot, SIGNAL(signalLogFlag(bool)), this, SLOT(slotLogScaleChanged(bool)));
00047 }
00048 
00049 Plot::~Plot ()
00050 {
00051 }
00052 
00053 void Plot::clear ()
00054 {
00055   datePlot->clear();
00056   scalePlot->clear();
00057   indicatorPlot->clear();
00058 }
00059 
00060 void Plot::setData (BarData *l)
00061 {
00062   if (! l->count())
00063     return;
00064 
00065   datePlot->setData(l);
00066   indicatorPlot->setXGrid(datePlot->getXGrid());
00067   
00068   scalePlot->setData(l->getClose(l->count() - 1));
00069   
00070   indicatorPlot->setData(l);
00071 }
00072 
00073 void Plot::setScaleToScreen (bool d)
00074 {
00075   indicatorPlot->setScaleToScreen(d);
00076   scalePlot->setScaleToScreen(d);
00077 }
00078 
00079 void Plot::setLogScale (bool d)
00080 {
00081   indicatorPlot->setLogScale(d);
00082   scalePlot->setLogScale(d);
00083 }
00084 
00085 void Plot::setChartPath (QString d)
00086 {
00087   indicatorPlot->setChartPath(d);
00088 }
00089 
00090 void Plot::setDrawMode (bool d)
00091 {
00092   indicatorPlot->setDrawMode(d);
00093 }
00094 
00095 void Plot::setInfoFlag (bool d)
00096 {
00097   indicatorPlot->setInfoFlag(d);
00098 }
00099 
00100 void Plot::draw ()
00101 {
00102   datePlot->draw();
00103   indicatorPlot->draw();
00104   scalePlot->setScaler(indicatorPlot->getScaler());
00105   scalePlot->draw();
00106 }
00107 
00108 void Plot::drawRefresh ()
00109 {
00110   datePlot->drawRefresh();
00111   indicatorPlot->drawRefresh();
00112   scalePlot->drawRefresh();
00113 }
00114 
00115 void Plot::setBackgroundColor (QColor d)
00116 {
00117   datePlot->setBackgroundColor(d);
00118   scalePlot->setBackgroundColor(d);
00119   indicatorPlot->setBackgroundColor(d);
00120 }
00121 
00122 void Plot::setBorderColor (QColor d)
00123 {
00124   datePlot->setBorderColor(d);
00125   scalePlot->setBorderColor(d);
00126   indicatorPlot->setBorderColor(d);
00127 }
00128 
00129 void Plot::setGridColor (QColor d)
00130 {
00131   indicatorPlot->setGridColor(d);
00132 }
00133 
00134 void Plot::setPlotFont (QFont d)
00135 {
00136   datePlot->setPlotFont(d);
00137   scalePlot->setPlotFont(d);
00138   indicatorPlot->setPlotFont(d);
00139 }
00140 
00141 void Plot::setGridFlag (bool d)
00142 {
00143   indicatorPlot->setGridFlag(d);
00144 }
00145 
00146 void Plot::setPixelspace (int d)
00147 {
00148   datePlot->setPixelspace(d);
00149   indicatorPlot->setPixelspace(d);
00150 }
00151 
00152 void Plot::setIndex (int d)
00153 {
00154   datePlot->setIndex(d);
00155   indicatorPlot->setIndex(d);
00156 }
00157 
00158 void Plot::setInterval (BarData::BarLength d)
00159 {
00160   datePlot->setInterval(d);    
00161   indicatorPlot->setInterval(d);    
00162 }
00163 
00164 void Plot::setDateFlag (bool d)
00165 {
00166   indicatorPlot->setDateFlag(d);
00167 
00168   if (d)
00169   {
00170     datePlot->show();
00171     datePlot->draw();
00172   }
00173   else
00174     datePlot->hide();
00175 }
00176 
00177 void Plot::addIndicator (Indicator *i)
00178 {
00179   setDateFlag(i->getDateFlag());
00180 
00181   indicatorPlot->setLogScale(i->getLogScale());
00182 
00183   indicatorPlot->addIndicator(i);
00184 }
00185 
00186 Indicator * Plot::getIndicator ()
00187 {
00188   return indicatorPlot->getIndicator();
00189 }
00190 
00191 bool Plot::deleteIndicator ()
00192 {
00193   return indicatorPlot->deleteIndicator();
00194 }
00195 
00196 void Plot::setCrosshairsStatus (bool status)
00197 {
00198   indicatorPlot->setCrosshairsStatus(status);
00199 }
00200 
00201 void Plot::slotSliderChanged (int v)
00202 {
00203   setIndex(v);
00204   draw();
00205 }
00206 
00207 void Plot::slotGridChanged (bool d)
00208 {
00209   setGridFlag(d);
00210 }
00211 
00212 void Plot::slotScaleToScreenChanged (bool d)
00213 {
00214   setScaleToScreen(d);
00215   indicatorPlot->draw();
00216 }
00217 
00218 void Plot::slotDrawModeChanged (bool d)
00219 {
00220   setDrawMode(d);
00221 }
00222 
00223 void Plot::slotDateFlagChanged (bool d)
00224 {
00225   setDateFlag(d);
00226 }
00227 
00228 void Plot::slotLogScaleChanged (bool d)
00229 {
00230   setLogScale(d);
00231   indicatorPlot->draw();
00232 }
00233 
00234 void Plot::addChartObject (Setting &set)
00235 {
00236   indicatorPlot->addChartObject(set);
00237 }
00238 
00239 void Plot::setCrosshairsFlag (bool d)
00240 {
00241   indicatorPlot->setCrosshairsFlag(d);
00242 }
00243 
00244 void Plot::crossHair (int d, int d2, bool d3)
00245 {
00246   indicatorPlot->crossHair(d, d2, d3);
00247 }
00248 
00249 int Plot::getWidth ()
00250 {
00251   return indicatorPlot->getWidth();
00252 }
00253 
00254 IndicatorPlot * Plot::getIndicatorPlot ()
00255 {
00256   return indicatorPlot;
00257 }
00258 
00259 DatePlot * Plot::getDatePlot ()
00260 {
00261   return datePlot;
00262 }
00263 
00264 void Plot::slotUpdateScalePlot ()
00265 {
00266   scalePlot->setScaler(indicatorPlot->getScaler());
00267   scalePlot->draw();
00268 }
00269 
00270 void Plot::setMenuFlag (bool d)
00271 {
00272   indicatorPlot->setMenuFlag(d);
00273 }
00274 
00275 
00276