src/qvgui/qvplot.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVPLOT_H
00026 #define QVPLOT_H
00027 
00028 #include <QTimer>
00029 #include <QVWorker>
00030 
00031 #include <qwt_plot.h>
00032 #include <qwt_plot_curve.h>
00033 
00034 
00035 #ifndef DOXYGEN_IGNORE_THIS
00036 #define MAX_HISTORY 60 // seconds
00037 
00046 
00047 class QVPlot: public QwtPlot, public QVPropertyContainer
00048         {
00049         Q_OBJECT
00050         public:
00061                 QVPlot(const QString name = QString(), bool decorations = true, bool havePie = false, bool brush = false, bool _autoShow = false, bool time = true,
00062                        int step = 10, QWidget *parent = 0);
00063 
00072                 virtual bool linkProperty(QVWorker &worker, const QString propertyName);
00073 
00074                 virtual bool unlink(QVWorker *worker, const QString propertyName);
00075 
00079                 bool isAutoShow() const { return autoShow; }
00080 
00084                 bool isInitied() const { return initied; }
00085 
00086         public slots:
00089                 virtual void init();
00090 
00093                 virtual void stop();
00094 
00099                 void update(uint id, int iteration);
00100 
00105                 void workerChange(QVWorker::TWorkerStatus status);
00106  
00107         protected:
00112                 virtual QStringList getPropertyCurvNames(QString property) const = 0;
00113 
00118                 virtual QList<double> getPropertyCurvValues(QString property) const = 0;
00119 
00125                 virtual QList<int> getPropertyCurvOrders(QString property) const = 0;
00126 
00127                         class Curve
00128                                 {
00129                                 public:
00130                                         Curve(QString n, QwtPlotCurve *qwtpc, int tempSize): name(n), plot(qwtpc)
00131                                                 {
00132                                                 for (int i = 0; i < MAX_HISTORY; i++) history[i] = 0;
00133                                                 if (tempSize > 0)
00134                                                         {
00135                                                         temp = new double[tempSize];
00136                                                         for (int i = 0; i < tempSize; i++) temp[i] = 0;
00137                                                         }
00138                                                 }
00139                                         QString name;
00140                                         QwtPlotCurve * plot;
00141                                         double history[MAX_HISTORY];
00142                                         double * temp;
00143                                 };
00144         
00145                         class Property
00146                                 {
00147                                 public:
00148                                         Property(QString n): name(n) {}
00149                                         QString name;
00150                                         QList<Curve> curves;
00151                                 };
00152         
00153                         class LinkedContainer
00154                                 {
00155                                 public:
00156                                         LinkedContainer(int ident): id(ident), iter(0), meanItems(0) {}
00157                                         uint id;
00158                                         int iter;
00159                                         QList<Property> properties;
00160                                         int meanItems;
00161                                 };
00162 
00163                 QList<LinkedContainer> linkCont;
00164                 const bool byTime;
00165                 int iterationIndex;
00166 
00167                 QColor nextColor();
00168                 virtual void advancePlot();
00169                 void timerEvent(QTimerEvent *e);
00170                 virtual void insertNewFlags(int cont, int prop);
00171                 void updateValue(const int cont, const int prop, const int curv);
00172                 double getValue(const int cont, const int prop, const int curv) const;
00173 
00174                 static QColor colors[];
00175                 const bool decorations, hPie, doBrush;
00176                 const int nStep;
00177 
00178                         friend class PieMarker;
00179                         class PieMarker: public QwtPlotItem
00180                                 {
00181                                 public:
00182                                         PieMarker(QVPlot *plot);
00183                                         virtual int rtti() const;
00184                                         virtual void draw(QPainter *p, const QwtScaleMap &, const QwtScaleMap &, const QRect &rect) const;
00185                         
00186                                 private:
00187                                         QVPlot *qvplot;
00188                                 };
00189 
00190                 bool initied, autoShow;
00191                 int timer;
00192                 PieMarker *pie;
00193                 bool haveCurves;
00194                 int activeWorkers;
00195                 QList<QVPropertyContainer *> pcl_Workers;
00196                 double timeData[MAX_HISTORY];
00197                 int dataCount;
00198                 int usedColors;
00199         };
00200 
00201 #endif
00202 #endif