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
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
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_
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"
49 \brief This class is used to render the time values on the horizontal axis for the
52 class TimeScaleDraw
: public QwtScaleDraw
{
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
{
70 ScopeGadgetWidget(QWidget
*parent
= 0);
73 void setupSequentialPlot();
74 void setupChronoPlot();
75 void setupUAVObjectPlot();
81 void setPlotDataSize(double plotDataSize
)
83 m_plotDataSize
= plotDataSize
;
87 return m_plotDataSize
;
89 void setRefreshInterval(double refreshInterval
)
91 m_refreshInterval
= 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
;
123 void visibilityChanged(QwtPlotItem
*item
);
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
);
134 void uavObjectReceived(UAVObject
*);
135 void replotNewData();
136 void showCurve(QVariant itemInfo
, bool visible
, int index
);
137 void startPlotting();
139 void csvLoggingConnect();
140 void csvLoggingDisconnect();
141 void popUpMenu(const QPoint
&mousePosition
);
143 void copyToClipboardAsImage();
144 void showOptionDialog();
147 void preparePlot(PlotType plotType
);
148 void setupExamplePlot();
152 double m_plotDataSize
;
153 int m_refreshInterval
;
154 QList
<QString
> m_connectedUAVObjects
;
155 QMap
<QString
, PlotData
*> m_curvesData
;
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
;
177 QwtLegend
*m_plotLegend
;
178 QwtPlotPicker
*m_picker
;
180 int csvLoggingInsertHeader();
181 int csvLoggingAddData();
182 int csvLoggingInsertData();
189 #endif /* SCOPEGADGETWIDGET_H_ */