dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
scopegadgetwidget.h
Go to the documentation of this file.
1 
19 /*
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful, but
26  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28  * for more details.
29  *
30  * You should have received a copy of the GNU General Public License along
31  * with this program; if not, see <http://www.gnu.org/licenses/>
32  *
33  * Additional note on redistribution: The copyright and license notices above
34  * must be maintained in each individual source file that is a derivative work
35  * of this source file; otherwise redistribution is prohibited.
36  */
37 
38 #ifndef SCOPEGADGETWIDGET_H_
39 #define SCOPEGADGETWIDGET_H_
40 
41 class ScopeConfig;
42 class UAVDataObject;
43 
44 #include "qwt/src/qwt.h"
45 #include "qwt/src/qwt_legend.h"
46 #include "qwt/src/qwt_plot.h"
47 #include "qwt/src/qwt_plot_grid.h"
48 #include "qwt/src/qwt_plot_layout.h"
49 #include "qwt/src/qwt_scale_draw.h"
50 
51 #include "uavobjects/uavobject.h"
52 #include "plotdata.h"
53 
54 #include <QTimer>
55 #include <QTime>
56 #include <QVector>
57 
62 class TimeScaleDraw : public QwtScaleDraw
63 {
64 public:
66  {
67  // baseTime = QDateTime::currentDateTime().toTime_t();
68  }
69  virtual QwtText label(double v) const
70  {
71  uint seconds = (uint)(v);
72  QDateTime upTime = QDateTime::fromTime_t(seconds);
73  QTime timePart = upTime.time().addMSecs((v - seconds) * 1000);
74  upTime.setTime(timePart);
75  return upTime.toLocalTime().toString("hh:mm:ss");
76  }
77 
78 private:
79  // double baseTime;
80 };
81 
82 class ScopeGadgetWidget : public QwtPlot
83 {
84  Q_OBJECT
85 
86 public:
87  ScopeGadgetWidget(QWidget *parent = nullptr);
89 
90  QString getUavObjectFieldUnits(QString uavObjectName, QString uavObjectFieldName);
91  void connectUAVO(UAVDataObject *obj);
92 
93  void setScope(ScopeConfig *val) { m_scope = val; }
94  QMap<QString, PlotData *> getDataSources() { return m_dataSources; }
95  void insertDataSources(QString stringVal, PlotData *dataVal)
96  {
97  m_dataSources.insert(stringVal, dataVal);
98  }
99 
100  void addLegend();
101  void deleteLegend();
102  void clearPlotWidget();
103  void startTimer(int);
104  QwtPlotGrid *m_grid;
105  QwtLegend *m_legend;
106  void setScopeName(QString val) { scopeName = val; }
107 
108 protected:
109  void mousePressEvent(QMouseEvent *e);
110  void mouseReleaseEvent(QMouseEvent *e);
111  void mouseDoubleClickEvent(QMouseEvent *e);
112  void mouseMoveEvent(QMouseEvent *e);
113  void wheelEvent(QWheelEvent *e);
114  void showEvent(QShowEvent *event);
115 
116 private slots:
117  void uavObjectReceived(UAVObject *);
118  void replotNewData();
119  void showCurve(const QVariant &itemInfo, bool on, int index);
120  void startPlotting();
121  void stopPlotting();
122  void popUpMenu(const QPoint &mousePosition);
123  void clearPlot();
124  void copyToClipboardAsImage();
125  void showOptionDialog();
126 
127 private:
128  int m_refreshInterval;
129  ScopeConfig *m_scope;
130  QMap<QString, PlotData *> m_dataSources;
131  double m_xWindowSize;
132  static QTimer *replotTimer;
133  QList<QString> m_connectedUAVObjects;
134  QString scopeName;
135 };
136 
137 #endif /* SCOPEGADGETWIDGET_H_ */
This class is used to render the time values on the horizontal axis for the ChronoPlot.
void mouseDoubleClickEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseDoubleClickEvent Turn legend on and off, then pass double-click even to QwtPl...
void connectUAVO(UAVDataObject *obj)
ScopeGadgetWidget::connectUAVO Connects UAVO update signal, but only if it hasn't yet been connected...
~ScopeGadgetWidget()
ScopeGadgetWidget::~ScopeGadgetWidget Destructor.
void deleteLegend()
ScopeGadgetWidget::deleteLegend Delete legend from plot.
void setScope(ScopeConfig *val)
void wheelEvent(QWheelEvent *e)
ScopeGadgetWidget::wheelEvent Zoom in or out, then pass mouse wheel event to QwtPlot.
void addLegend()
ScopeGadgetWidget::addLegend Add legend to plot.
void setScopeName(QString val)
ScopeGadgetWidget(QWidget *parent=nullptr)
void mouseReleaseEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseReleaseEvent Pass mouse release event to QwtPlot.
The ScopeConfig class The parent class for scope configuration classes data sources.
Definition: scopesconfig.h:56
virtual QwtText label(double v) const
QString getUavObjectFieldUnits(QString uavObjectName, QString uavObjectFieldName)
ScopeGadgetWidget::getUavObjectFieldUnits Gets the UAVOs units, as defined in the XML...
void insertDataSources(QString stringVal, PlotData *dataVal)
QMap< QString, PlotData * > getDataSources()
void clearPlotWidget()
ScopeGadgetWidget::clearPlotWidget.
void startTimer(int)
ScopeGadgetWidget::startTimer Starts timer.
void mousePressEvent(QMouseEvent *e)
ScopeGadgetWidget::mousePressEvent Pass mouse press event to QwtPlot.
void showEvent(QShowEvent *event)
ScopeGadgetWidget::showEvent Reimplemented from QwtPlot.
e
Definition: OPPlots.m:99
QwtPlotGrid * m_grid
void mouseMoveEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseMoveEvent Pass mouse move event to QwtPlot.