LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / scope / scopegadgetwidget.h
blob786cc9d22450ce9e63377c460b25614977b4ff5d
1 /**
2 ******************************************************************************
4 * @file scopegadgetwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief Scope Plugin Gadget Widget
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup scopeplugin
9 * @{
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef SCOPEGADGETWIDGET_H_
29 #define SCOPEGADGETWIDGET_H_
31 #include "plotdata.h"
33 #include "qwt/src/qwt.h"
34 #include "qwt/src/qwt_legend.h"
35 #include "qwt/src/qwt_plot.h"
36 #include "qwt/src/qwt_plot_curve.h"
37 #include "qwt/src/qwt_scale_draw.h"
38 #include "qwt/src/qwt_scale_widget.h"
39 #include "qwt/src/qwt_plot_picker.h"
41 #include <QTimer>
42 #include <QTime>
43 #include <QVector>
44 #include <QMutex>
46 class QSettings;
48 /*!
49 \brief This class is used to render the time values on the horizontal axis for the
50 ChronoPlot.
52 class TimeScaleDraw : public QwtScaleDraw {
53 public:
54 TimeScaleDraw() {}
55 virtual QwtText label(double v) const
57 uint seconds = (uint)(v);
58 QDateTime upTime = QDateTime::fromTime_t(seconds);
59 QTime timePart = upTime.time().addMSecs((v - seconds) * 1000);
61 upTime.setTime(timePart);
62 return upTime.toLocalTime().toString("hh:mm:ss");
66 class ScopeGadgetWidget : public QwtPlot {
67 Q_OBJECT
69 public:
70 ScopeGadgetWidget(QWidget *parent = 0);
71 ~ScopeGadgetWidget();
73 void setupSequentialPlot();
74 void setupChronoPlot();
75 void setupUAVObjectPlot();
76 PlotType plotType()
78 return m_plotType;
81 void setPlotDataSize(double plotDataSize)
83 m_plotDataSize = plotDataSize;
85 double plotDataSize()
87 return m_plotDataSize;
89 void setRefreshInterval(double refreshInterval)
91 m_refreshInterval = refreshInterval;
93 int refreshInterval()
95 return m_refreshInterval;
99 void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
100 QString mathFunction = "None", QPen pen = QPen(Qt::black), bool antialiased = true);
101 void clearCurvePlots();
103 void saveState(QSettings *qSettings);
104 void restoreState(QSettings *qSettings);
106 int csvLoggingStart();
107 int csvLoggingStop();
108 void csvLoggingSetName(QString);
110 void setLoggingEnabled(bool value)
112 m_csvLoggingEnabled = value;
114 void setLoggingNewFileOnConnect(bool value)
116 m_csvLoggingNewFileOnConnect = value;
118 void setLoggingPath(QString value)
120 m_csvLoggingPath = value;
122 signals:
123 void visibilityChanged(QwtPlotItem *item);
125 protected:
126 void mousePressEvent(QMouseEvent *e);
127 void mouseReleaseEvent(QMouseEvent *e);
128 void mouseDoubleClickEvent(QMouseEvent *e);
129 void mouseMoveEvent(QMouseEvent *e);
130 void wheelEvent(QWheelEvent *e);
131 void showEvent(QShowEvent *e);
133 private slots:
134 void uavObjectReceived(UAVObject *);
135 void replotNewData();
136 void showCurve(QVariant itemInfo, bool visible, int index);
137 void startPlotting();
138 void stopPlotting();
139 void csvLoggingConnect();
140 void csvLoggingDisconnect();
141 void popUpMenu(const QPoint &mousePosition);
142 void clearPlot();
143 void copyToClipboardAsImage();
144 void showOptionDialog();
146 private:
147 void preparePlot(PlotType plotType);
148 void setupExamplePlot();
150 PlotType m_plotType;
152 double m_plotDataSize;
153 int m_refreshInterval;
154 QList<QString> m_connectedUAVObjects;
155 QMap<QString, PlotData *> m_curvesData;
157 QTimer *replotTimer;
159 bool m_csvLoggingStarted;
160 bool m_csvLoggingEnabled;
161 bool m_csvLoggingHeaderSaved;
162 bool m_csvLoggingDataSaved;
163 bool m_csvLoggingNameSet;
164 bool m_csvLoggingDataValid;
165 bool m_csvLoggingDataUpdated;
166 bool m_csvLoggingConnected;
167 bool m_csvLoggingNewFileOnConnect;
169 QDateTime m_csvLoggingStartTime;
171 QString m_csvLoggingName;
172 QString m_csvLoggingPath;
173 QString m_csvLoggingBuffer;
174 QFile m_csvLoggingFile;
176 QMutex m_mutex;
177 QwtLegend *m_plotLegend;
178 QwtPlotPicker *m_picker;
180 int csvLoggingInsertHeader();
181 int csvLoggingAddData();
182 int csvLoggingInsertData();
184 void deleteLegend();
185 void addLegend();
189 #endif /* SCOPEGADGETWIDGET_H_ */