PARP Research Group University of Murcia, Spain


src/qvgui/qvplot.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. 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 #define MAX_HISTORY 60 // seconds
00035 
00044 
00045 class QVPlot: public QwtPlot, public QVPropertyContainer
00046         {
00047         Q_OBJECT
00048         public:
00059                 QVPlot(const QString name = QString(), bool decorations = true, bool havePie = false, bool brush = false, bool _autoShow = false, bool time = true,
00060                        int step = 10, QWidget *parent = 0);
00061 
00062                 ~QVPlot();
00063 
00072                 bool linkProperty(QString sourcePropertyName, QVPropertyContainer *destinyContainer, QString destinyPropertyName, LinkType linkType = AsynchronousLink);
00073                 bool linkProperty(QString sourcePropertyName, QVPropertyContainer &destinyContainer, QString destinyPropertyName, LinkType linkType = AsynchronousLink);
00074                 bool linkProperty(QVPropertyContainer *destinyContainer, QString destinyPropertyName, LinkType linkType = AsynchronousLink);
00075                 bool linkProperty(QVPropertyContainer &destinyContainer, QString destinyPropertyName, LinkType linkType = AsynchronousLink);
00076                 bool linkProperty(QString sourcePropertyName, QVPropertyContainer *destinyContainer, LinkType linkType = AsynchronousLink);
00077                 bool linkProperty(QString sourcePropertyName, QVPropertyContainer &destinyContainer, LinkType linkType = AsynchronousLink);
00078                 void linkProperty(QVPropertyContainer *container, LinkType linkType = AsynchronousLink);
00079                 void linkProperty(QVPropertyContainer &container, LinkType linkType = AsynchronousLink);
00080                 bool unlinkProperty(QString origName, QVPropertyContainer *destCont, QString destName);
00081                 bool unlinkProperty(QString origName, QVPropertyContainer &destCont, QString destName);
00082                 void unlink();
00083 
00084 
00088                 bool isAutoShow() const { return autoShow; }
00089 
00093                 bool isInitied() const { return initied; }
00094 
00095         public slots:
00098                 virtual void init();
00099 
00102                 virtual void stop();
00103 
00108                 void update(uint id, int iteration);
00109 
00114                 void workerChange(QVWorker::TWorkerStatus status);
00115 
00120                 void legendItemCheked(bool check);
00121 
00122         signals:
00123                 void closed();
00124 
00125 #ifndef DOXYGEN_IGNORE_THIS
00126         protected:
00138                 virtual bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType = AsynchronousLink);
00139 
00140                 bool treatUnlinkInputProperty(QString destPropName, QVPropertyContainer *sourceCont, QString sourcePropName);
00141 
00142                 void closeEvent(QCloseEvent *event) { Q_UNUSED(event); emit closed(); }
00143 
00144 
00149                 virtual QStringList getPropertyCurvNames(QString property) const = 0;
00150 
00155                 virtual QList<double> getPropertyCurvValues(QString property) const = 0;
00156 
00162                 virtual QList<int> getPropertyCurvOrders(QString property) const = 0;
00163 
00164                 class Curve
00165                         {
00166                         public:
00167                                 Curve(QString n, QwtPlotCurve *qwtpc, int tempSize): name(n), plot(qwtpc)
00168                                         {
00169                                         for (int i = 0; i < MAX_HISTORY; i++) history[i] = 0;
00170                                         if (tempSize > 0)
00171                                                 {
00172                                                 temp = new double[tempSize];
00173                                                 for (int i = 0; i < tempSize; i++) temp[i] = 0;
00174                                                 }
00175                                         }
00176                                 QString name;
00177                                 QwtPlotCurve * plot;
00178                                 double history[MAX_HISTORY];
00179                                 double brushHistory[MAX_HISTORY];
00180                                 double * temp;
00181                         };
00182 
00183                 class Property
00184                         {
00185                         public:
00186                                 Property(QString n): name(n) {}
00187                                 QString name;
00188                                 QList<Curve> curves;
00189                         };
00190 
00191                 class LinkedContainer
00192                         {
00193                         public:
00194                                 LinkedContainer(int ident): id(ident), iter(0), meanItems(0) {}
00195                                 uint id;
00196                                 int iter;
00197                                 QList<Property> properties;
00198                                 int meanItems;
00199                         };
00200 
00201                 QList<LinkedContainer> linkCont;
00202                 const bool byTime;
00203                 int iterationIndex;
00204 
00205                 QColor nextColor();
00206                 virtual void advancePlot();
00207                 void timerEvent(QTimerEvent *e);
00208                 virtual void insertNewFlags(int cont, int prop);
00209                 void updateLegendItems();
00210                 void hideStat(const QString labelText);
00211                 void showStat(const QString labelText);
00212 
00213                 const bool decorations, hPie, doBrush;
00214                 const int nStep;
00215 
00216                 friend class PieMarker;
00217                 class PieMarker: public QwtPlotItem
00218                         {
00219                         public:
00220                                 PieMarker(QVPlot *plot);
00221                                 virtual int rtti() const;
00222                                 virtual void draw(QPainter *p, const QwtScaleMap &, const QwtScaleMap &, const QRect &rect) const;
00223                 
00224                         private:
00225                                 QVPlot *qvplot;
00226                         };
00227 
00228                 bool initied, autoShow;
00229                 int timer;
00230                 PieMarker *pie;
00231                 bool haveCurves;
00232                 int activeWorkers;
00233                 QList<QVPropertyContainer *> pcl_Workers;
00234                 double timeData[MAX_HISTORY];
00235                 int usedColors;
00236         };
00237 
00238 #endif
00239 #endif
00240 



QVision framework. PARP research group, copyright 2007, 2008.