UPlot.h
Go to the documentation of this file.
00001 /*
00002 *  utilite is a cross-platform library with
00003 *  useful utilities for fast and small developing.
00004 *  Copyright (C) 2010  Mathieu Labbe
00005 *
00006 *  utilite is free library: you can redistribute it and/or modify
00007 *  it under the terms of the GNU Lesser General Public License as published by
00008 *  the Free Software Foundation, either version 3 of the License, or
00009 *  (at your option) any later version.
00010 *
00011 *  utilite 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 Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public License
00017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef UPLOT_H_
00021 #define UPLOT_H_
00022 
00023 #include "rtabmap/gui/RtabmapGuiExp.h" // DLL export/import defines
00024 
00025 #include <QFrame>
00026 #include <QtCore/QList>
00027 #include <QtCore/QMap>
00028 #include <QtGui/QPen>
00029 #include <QtGui/QBrush>
00030 #include <QGraphicsEllipseItem>
00031 #include <QtCore/QMutex>
00032 #include <QLabel>
00033 #include <QPushButton>
00034 #include <QtCore/QTime>
00035 
00036 class QGraphicsView;
00037 class QGraphicsScene;
00038 class QGraphicsItem;
00039 class QFormLayout;
00040 
00045 class RTABMAPGUI_EXP UPlotItem : public QGraphicsEllipseItem
00046 {
00047 public:
00051         UPlotItem(qreal dataX, qreal dataY, qreal width=2);
00055         UPlotItem(const QPointF & data, qreal width=2);
00056         virtual ~UPlotItem();
00057 
00058 public:
00059         void setNextItem(UPlotItem * nextItem);
00060         void setPreviousItem(UPlotItem * previousItem);
00061         void setData(const QPointF & data);
00062 
00063         UPlotItem * nextItem() const {return _nextItem;}
00064         UPlotItem * previousItem() const {return _previousItem;};
00065         const QPointF & data() const {return _data;}
00066 
00067 protected:
00068         virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
00069         virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
00070         virtual void focusInEvent(QFocusEvent * event);
00071         virtual void focusOutEvent(QFocusEvent * event);
00072         virtual void keyReleaseEvent(QKeyEvent * keyEvent);
00073 
00074         virtual void showDescription(bool shown);
00075 private:
00076         void init(qreal dataX, qreal dataY);
00077 
00078 private:
00079         QPointF _data;
00080         UPlotItem * _previousItem;
00081         UPlotItem * _nextItem;
00082         QGraphicsTextItem * _text;
00083         QGraphicsRectItem * _textBackground;
00084 };
00085 
00086 class UPlot;
00087 
00091 class RTABMAPGUI_EXP UPlotCurve : public QObject
00092 {
00093         Q_OBJECT
00094 
00095 public:
00099         UPlotCurve(const QString & name, QObject * parent = 0);
00103         UPlotCurve(const QString & name, const QVector<UPlotItem *> data, QObject * parent = 0);
00107         UPlotCurve(const QString & name, const QVector<float> & x, const QVector<float> & y, QObject * parent = 0);
00108         virtual ~UPlotCurve();
00109 
00113         const QPen & pen() const {return _pen;}
00117         const QBrush & brush() const {return _brush;}
00118 
00122         void setPen(const QPen & pen);
00126         void setBrush(const QBrush & brush);
00127 
00128         void setItemsColor(const QColor & color);
00129         QColor itemsColor() const  {return _itemsColor;}
00130 
00134         QString name() const {return _name;}
00138         int itemsSize() const;
00139         QPointF getItemData(int index);
00140         bool isVisible() const {return _visible;}
00141         void setData(QVector<UPlotItem*> & data); // take the ownership
00142         void getData(QVector<float> & x, QVector<float> & y) const; // only call in Qt MainThread
00143         void getData(QMap<float,float> & data) const; // only call in Qt MainThread
00144         void draw(QPainter * painter, const QRect & limits);
00145 
00146 public Q_SLOTS:
00151         virtual void clear();
00156     void setVisible(bool visible);
00161     void setXIncrement(float increment);
00166     void setXStart(float val);
00171         void addValue(UPlotItem * data); // take the ownership
00177         void addValue(float y);
00182         void addValue(float x, float y);
00189         void addValue(const QString & y);
00195         void addValues(QVector<UPlotItem *> & data); // take the ownership
00200         void addValues(const QVector<float> & xs, const QVector<float> & ys);
00206         void addValues(const QVector<float> & ys);
00207         void addValues(const QVector<int> & ys); // for convenience
00213         void addValues(const std::vector<float> & ys); // for convenience
00214         void addValues(const std::vector<int> & ys); // for convenience
00215 
00216         void setData(const QVector<float> & x, const QVector<float> & y);
00217         void setData(const std::vector<float> & x, const std::vector<float> & y);
00218         void setData(const QVector<float> & y);
00219         void setData(const std::vector<float> & y);
00220 
00221 Q_SIGNALS:
00226         void dataChanged(const UPlotCurve *);
00227 
00228 protected:
00229         friend class UPlot;
00230         void attach(UPlot * plot);
00231         void detach(UPlot * plot);
00232         void updateMinMax();
00233         const QVector<float> & getMinMax() const {return _minMax;}
00234         int removeItem(int index);
00235         void _addValue(UPlotItem * data);;
00236         virtual bool isMinMaxValid() const {return _minMax.size();}
00237         virtual void update(float scaleX, float scaleY, float offsetX, float offsetY, float xDir, float yDir, int maxItemsKept);
00238         QList<QGraphicsItem *> _items;
00239         UPlot * _plot;
00240 
00241 private:
00242         void removeItem(UPlotItem * item);
00243 
00244 private:
00245         QString _name;
00246         QPen _pen;
00247         QBrush _brush;
00248         float _xIncrement;
00249         float _xStart;
00250         bool _visible;
00251         bool _valuesShown;
00252         QVector<float> _minMax; // minX, maxX, minY, maxY
00253         QGraphicsRectItem * _rootItem;
00254         QColor _itemsColor;
00255 };
00256 
00257 
00261 class RTABMAPGUI_EXP UPlotCurveThreshold : public UPlotCurve
00262 {
00263         Q_OBJECT
00264 
00265 public:
00269         UPlotCurveThreshold(const QString & name, float thesholdValue, Qt::Orientation orientation = Qt::Horizontal, QObject * parent = 0);
00270         virtual ~UPlotCurveThreshold();
00271 
00272 public Q_SLOTS:
00276         void setThreshold(float threshold);
00280         void setOrientation(Qt::Orientation orientation);
00281 
00282 protected:
00283         friend class UPlot;
00284         virtual void update(float scaleX, float scaleY, float offsetX, float offsetY, float xDir, float yDir, int maxItemsKept);
00285         virtual bool isMinMaxValid() const {return false;}
00286 
00287 private:
00288         Qt::Orientation _orientation;
00289 };
00290 
00294 class RTABMAPGUI_EXP UPlotAxis : public QWidget
00295 {
00296 public:
00300         UPlotAxis(Qt::Orientation orientation = Qt::Horizontal, float min=0, float max=1, QWidget * parent = 0);
00301         virtual ~UPlotAxis();
00302 
00303 public:
00308         void setAxis(float & min, float & max);
00312         int border() const {return _border;}
00316         int step() const {return _step;}
00320         int count() const {return _count;}
00324         void setReversed(bool reversed); // Vertical :bottom->up, horizontal :right->left
00325 
00326 protected:
00327         virtual void paintEvent(QPaintEvent * event);
00328 
00329 private:
00330         Qt::Orientation _orientation;
00331         float _min;
00332         float _max;
00333         int _count;
00334         int _step;
00335         bool _reversed;
00336         int _gradMaxDigits;
00337         int _border;
00338 };
00339 
00340 
00344 class RTABMAPGUI_EXP UPlotLegendItem : public QPushButton
00345 {
00346         Q_OBJECT
00347 
00348 public:
00352         UPlotLegendItem(UPlotCurve * curve, QWidget * parent = 0);
00353         virtual ~UPlotLegendItem();
00354         const UPlotCurve * curve() const {return _curve;}
00355         QPixmap createSymbol(const QPen & pen, const QBrush & brush);
00356 
00357 Q_SIGNALS:
00358         void legendItemRemoved(const UPlotCurve *);
00359         void moveUpRequest(UPlotLegendItem *);
00360         void moveDownRequest(UPlotLegendItem *);
00361 
00362 private Q_SLOTS:
00363         void updateStdDev();
00364 
00365 protected:
00366         virtual void contextMenuEvent(QContextMenuEvent * event);
00367 
00368 private:
00369         UPlotCurve * _curve;
00370         QMenu * _menu;
00371         QAction * _aChangeText;
00372         QAction * _aResetText;
00373         QAction * _aChangeColor;
00374         QAction * _aCopyToClipboard;
00375         QAction * _aShowStdDev;
00376         QAction * _aRemoveCurve;
00377         QAction * _aMoveUp;
00378         QAction * _aMoveDown;
00379 };
00380 
00384 class RTABMAPGUI_EXP UPlotLegend : public QWidget
00385 {
00386         Q_OBJECT
00387 
00388 public:
00392         UPlotLegend(QWidget * parent = 0);
00393         virtual ~UPlotLegend();
00394 
00395         void setFlat(bool on);
00396         bool isFlat() const {return _flat;}
00397         void addItem(UPlotCurve * curve);
00398         bool remove(const UPlotCurve * curve);
00399 
00400 private Q_SLOTS:
00401         void removeLegendItem(const UPlotCurve * curve);
00402         void moveUp(UPlotLegendItem * item);
00403         void moveDown(UPlotLegendItem * item);
00404 
00405 Q_SIGNALS:
00406         void legendItemRemoved(const UPlotCurve * curve);
00407         void legendItemToggled(const UPlotCurve * curve, bool toggled);
00408         void legendItemMoved(const UPlotCurve * curve, int);
00409 
00410 protected:
00411         virtual void contextMenuEvent(QContextMenuEvent * event);
00412 
00413 private Q_SLOTS:
00414         void redirectToggled(bool);
00415 
00416 private:
00417         bool _flat;
00418         QMenu * _menu;
00419         QAction * _aUseFlatButtons;
00420         QAction * _aCopyAllCurveToClipboard;
00421 };
00422 
00423 
00427 class RTABMAPGUI_EXP UOrientableLabel : public QLabel
00428 {
00429         Q_OBJECT
00430 
00431 public:
00435         UOrientableLabel(const QString & text, Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0);
00436         virtual ~UOrientableLabel();
00440         Qt::Orientation orientation() const {return _orientation;}
00444         void setOrientation(Qt::Orientation orientation);
00445         QSize sizeHint() const;
00446         QSize minimumSizeHint() const;
00447 protected:
00448     virtual void paintEvent(QPaintEvent* event);
00449 private:
00450     Qt::Orientation _orientation;
00451 };
00452 
00483 class RTABMAPGUI_EXP UPlot : public QWidget
00484 {
00485         Q_OBJECT
00486 
00487 public:
00491         UPlot(QWidget * parent = 0);
00492         virtual ~UPlot();
00493 
00497         UPlotCurve * addCurve(const QString & curveName, const QColor & color = QColor());
00501         bool addCurve(UPlotCurve * curve, bool ownershipTransferred = true);
00505         QStringList curveNames();
00506         bool contains(const QString & curveName);
00507         void removeCurves();
00511         UPlotCurveThreshold * addThreshold(const QString & name, float value, Qt::Orientation orientation = Qt::Horizontal);
00512         QString title() const {return this->objectName();}
00513         QPen getRandomPenColored();
00514         void showLegend(bool shown);
00515         void showGrid(bool shown);
00516         void showRefreshRate(bool shown);
00517         void trackMouse(bool tracking);
00518         void keepAllData(bool kept);
00519         void showXAxis(bool shown) {_horizontalAxis->setVisible(shown);}
00520         void showYAxis(bool shown) {_verticalAxis->setVisible(shown);}
00521         void setVariableXAxis() {_fixedAxis[0] = false;}
00522         void setVariableYAxis() {_fixedAxis[1] = false;}
00523         void setFixedXAxis(float x1, float x2);
00524         void setFixedYAxis(float y1, float y2);
00525         void setMaxVisibleItems(int maxVisibleItems);
00526         void setTitle(const QString & text);
00527         void setXLabel(const QString & text);
00528         void setYLabel(const QString & text, Qt::Orientation orientation = Qt::Vertical);
00529         void setWorkingDirectory(const QString & workingDirectory);
00530         void setGraphicsView(bool on);
00531         void setBackgroundColor(const QColor & color);
00532         QRectF sceneRect() const;
00533 
00534 public Q_SLOTS:
00539         void removeCurve(const UPlotCurve * curve);
00540         void showCurve(const UPlotCurve * curve, bool shown);
00541         void updateAxis(); //reset axis and recompute it with all curves minMax
00546         void clearData();
00547 
00548 private Q_SLOTS:
00549         void captureScreen();
00550         void updateAxis(const UPlotCurve * curve);
00551         void moveCurve(const UPlotCurve *, int index);
00552 
00553 protected:
00554         virtual void contextMenuEvent(QContextMenuEvent * event);
00555         virtual void paintEvent(QPaintEvent * event);
00556         virtual void resizeEvent(QResizeEvent * event);
00557         virtual void mousePressEvent(QMouseEvent * event);
00558         virtual void mouseMoveEvent(QMouseEvent * event);
00559         virtual void mouseReleaseEvent(QMouseEvent * event);
00560         virtual void mouseDoubleClickEvent(QMouseEvent * event);
00561 
00562 private:
00563         friend class UPlotCurve;
00564         void addItem(QGraphicsItem * item);
00565 
00566 private:
00567         void replot(QPainter * painter);
00568         bool updateAxis(float x, float y);
00569         bool updateAxis(float x1, float x2, float y1, float y2);
00570         void setupUi();
00571         void createActions();
00572         void createMenus();
00573         void selectScreenCaptureFormat();
00574         bool mousePosToValue(const QPoint & pos, float & x, float & y);
00575 
00576 private:
00577         UPlotLegend * _legend;
00578         QGraphicsView * _view;
00579         QGraphicsItem * _sceneRoot;
00580         QWidget * _graphicsViewHolder;
00581         float _axisMaximums[4]; // {x1->x2, y1->y2}
00582         bool _axisMaximumsSet[4]; // {x1->x2, y1->y2}
00583         bool _fixedAxis[2];
00584         UPlotAxis * _verticalAxis;
00585         UPlotAxis * _horizontalAxis;
00586         int _penStyleCount;
00587         int _maxVisibleItems;
00588         QList<QGraphicsLineItem *> hGridLines;
00589         QList<QGraphicsLineItem *> vGridLines;
00590         QList<UPlotCurve*> _curves;
00591         QLabel * _title;
00592         QLabel * _xLabel;
00593         UOrientableLabel * _yLabel;
00594         QLabel * _refreshRate;
00595         QString _workingDirectory;
00596         QTime _refreshIntervalTime;
00597         int _lowestRefreshRate;
00598         QTime _refreshStartTime;
00599         QString _autoScreenCaptureFormat;
00600         QPoint _mousePressedPos;
00601         QPoint _mouseCurrentPos;
00602         QColor _bgColor;
00603 
00604         QMenu * _menu;
00605         QAction * _aShowLegend;
00606         QAction * _aShowGrid;
00607         QAction * _aKeepAllData;
00608         QAction * _aLimit0;
00609         QAction * _aLimit10;
00610         QAction * _aLimit50;
00611         QAction * _aLimit100;
00612         QAction * _aLimit500;
00613         QAction * _aLimit1000;
00614         QAction * _aLimitCustom;
00615         QAction * _aAddVerticalLine;
00616         QAction * _aAddHorizontalLine;
00617         QAction * _aChangeTitle;
00618         QAction * _aChangeXLabel;
00619         QAction * _aChangeYLabel;
00620         QAction * _aChangeBackgroundColor;
00621         QAction * _aYLabelVertical;
00622         QAction * _aShowRefreshRate;
00623         QAction * _aMouseTracking;
00624         QAction * _aSaveFigure;
00625         QAction * _aAutoScreenCapture;
00626         QAction * _aClearData;
00627         QAction * _aGraphicsView;
00628 };
00629 
00630 #endif /* UPLOT_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:32