Go to the documentation of this file.00001 #ifndef DragableWidget_H
00002 #define DragableWidget_H
00003
00004 #include <map>
00005 #include <deque>
00006 #include <QObject>
00007 #include <QTextEdit>
00008 #include <QDomDocument>
00009 #include <QMessageBox>
00010 #include <QTime>
00011 #include "plotmagnifier.h"
00012 #include "plotzoomer.h"
00013 #include "qwt_plot.h"
00014 #include "qwt_plot_curve.h"
00015 #include "qwt_plot_grid.h"
00016 #include "qwt_symbol.h"
00017 #include "qwt_legend.h"
00018 #include "qwt_plot_rescaler.h"
00019 #include "qwt_plot_panner.h"
00020 #include "qwt_plot_legenditem.h"
00021 #include "timeseries_qwt.h"
00022 #include "customtracker.h"
00023 #include "axis_limits_dialog.h"
00024 #include "transforms/transform_selector.h"
00025 #include "transforms/custom_function.h"
00026 #include "plotlegend.h"
00027
00028 class PlotWidget : public QwtPlot
00029 {
00030 Q_OBJECT
00031
00032 public:
00033
00034 PlotWidget(PlotDataMapRef& datamap, QWidget *parent=nullptr);
00035
00036 virtual ~PlotWidget() override;
00037
00038 bool isEmpty() const;
00039
00040 const std::map<std::string, QwtPlotCurve*> &curveList() const;
00041
00042 QDomElement xmlSaveState(QDomDocument &doc) const;
00043
00044 bool xmlLoadState(QDomElement &element);
00045
00046 PlotData::RangeTime getMaximumRangeX() const;
00047
00048 PlotData::RangeValue getMaximumRangeY(PlotData::RangeTime range_X) const;
00049
00050 void setZoomRectangle( QRectF rect, bool emit_signal );
00051
00052 void reloadPlotData( );
00053
00054 void changeAxisX(QString curve_name);
00055
00056 bool isXYPlot() const;
00057
00058 void changeBackgroundColor(QColor color);
00059
00060 const PlotLegend* legend() const { return _legend; }
00061
00062 void setLegendSize(int size);
00063
00064 bool isLegendVisible() const;
00065
00066 void setLegendAlignment( Qt::Alignment alignment );
00067
00068 void setZoomEnabled(bool enabled);
00069
00070 bool isZoomEnabled() const;
00071
00072 QRectF canvasBoundingRect() const;
00073
00074 virtual void resizeEvent( QResizeEvent *ev ) override;
00075
00076 virtual void updateLayout() override;
00077
00078 void setConstantRatioXY(bool active);
00079
00080 protected:
00081 void dragEnterEvent(QDragEnterEvent *event) override;
00082 void dropEvent(QDropEvent *event) override;
00083 bool eventFilter(QObject *obj, QEvent *event) override;
00084 void dragLeaveEvent(QDragLeaveEvent *event) override;
00085
00086 bool canvasEventFilter(QEvent *event);
00087
00088 signals:
00089 void swapWidgetsRequested(PlotWidget* source, PlotWidget* destination);
00090 void rectChanged(PlotWidget* self, QRectF rect );
00091 void undoableChange();
00092 void trackerMoved(QPointF pos);
00093 void curveListChanged();
00094 void curvesDropped();
00095 void legendSizeChanged(int new_size);
00096
00097 public slots:
00098
00099 void replot() override;
00100
00101 void updateCurves();
00102
00103 void detachAllCurves();
00104
00105 void on_panned(int dx, int dy);
00106
00107 void zoomOut(bool emit_signal);
00108
00109 void on_zoomOutHorizontal_triggered(bool emit_signal = true);
00110
00111 void on_zoomOutVertical_triggered(bool emit_signal = true);
00112
00113 void removeCurve(const std::string &name);
00114
00115 void activateLegend(bool activate);
00116
00117 void activateGrid(bool activate);
00118
00119 void configureTracker(CurveTracker::Parameter val);
00120
00121 void enableTracker(bool enable);
00122
00123 void setTrackerPosition(double abs_time);
00124
00125 void on_changeTimeOffset(double offset);
00126
00127 void on_changeDateTimeScale(bool enable);
00128
00129 private slots:
00130
00131 void on_changeToBuiltinTransforms(QString new_transform);
00132
00133 void on_convertToXY_triggered(bool checked);
00134
00135 void on_customTransformsDialog();
00136
00137 void on_savePlotToFile();
00138
00139 void on_editAxisLimits_triggered();
00140
00141 private slots:
00142 void launchRemoveCurveDialog();
00143
00144 void canvasContextMenuTriggered(const QPoint &pos);
00145
00146 void on_changeColorsDialog_triggered();
00147
00148 void on_changeColor(QString curve_name, QColor new_color);
00149
00150 void on_showPoints_triggered();
00151
00152 void on_externallyResized(const QRectF &new_rect);
00153
00154 private:
00155
00156 std::map<std::string, QwtPlotCurve* > _curve_list;
00157 std::map<std::string, QwtPlotMarker*> _point_marker;
00158
00159 QAction *_action_removeCurve;
00160 QAction *_action_removeAllCurves;
00161 QAction *_action_changeColorsDialog;
00162 QAction *_action_showPoints;
00163 QAction *_action_zoomOutMaximum;
00164 QAction *_action_zoomOutHorizontally;
00165 QAction *_action_zoomOutVertically;
00166 QAction *_action_noTransform;
00167 QAction *_action_1stDerivativeTransform;
00168 QAction *_action_2ndDerivativeTransform;
00169 QAction *_action_phaseXY;
00170 QAction *_action_custom_transform;
00171 QAction *_action_saveToFile;
00172 QAction *_action_editLimits;
00173
00174 PlotZoomer* _zoomer;
00175 PlotMagnifier* _magnifier;
00176 QwtPlotPanner* _panner1;
00177 QwtPlotPanner* _panner2;
00178
00179 CurveTracker* _tracker;
00180 PlotLegend* _legend;
00181 QwtPlotGrid* _grid;
00182
00183 bool _use_date_time_scale;
00184
00185 PlotDataMapRef& _mapped_data;
00186 QString _default_transform;
00187 std::map<std::string, QString> _curves_transform;
00188
00189 struct DragInfo{
00190 enum{ NONE, CURVES, NEW_X, SWAP_PLOTS} mode;
00191 std::vector<QString> curves;
00192 QObject* source;
00193 };
00194
00195 DragInfo _dragging;
00196
00197 bool addCurve(const std::string &name);
00198
00199 void buildActions();
00200
00201 void buildLegend();
00202
00203 void updateAvailableTransformers();
00204
00205 QwtPlotCurve::CurveStyle _curve_style;
00206
00207 void setDefaultRangeX();
00208
00209 DataSeriesBase* createSeriesData(const QString& ID, const PlotData *data);
00210
00211 double _time_offset;
00212
00213 const PlotData* _axisX = nullptr;
00214
00215 PlotData::RangeValue _custom_Y_limits;
00216
00217 AxisLimitsDialog* _axis_limits_dialog;
00218
00219 TransformSelector* _transform_select_dialog;
00220
00221 SnippetsMap _snippets;
00222
00223 bool _zoom_enabled;
00224
00225 bool _keep_aspect_ratio;
00226
00227 QRectF _max_zoom_rect;
00228
00229 void transformCustomCurves();
00230 void updateMaximumZoomArea();
00231 void rescaleEqualAxisScaling();
00232 };
00233
00234 #endif