source: fact/Evidence/GUI.h@ 19490

Last change on this file since 19490 was 18023, checked in by daqct3, 10 years ago
Added copy/paste for time scale in Evidence GUI history plots
  • Property svn:keywords set to Revision
File size: 6.9 KB
Line 
1#ifndef GUI_H_SEEN
2#define GUI_H_SEEN
3
4#include <QtGui>
5#include <QtConcurrentRun>
6
7#include <qwt_plot.h>
8#include <qwt_plot_curve.h>
9#include <qwt_plot_grid.h>
10#include <qwt_plot_zoomer.h>
11#include <qwt_plot_magnifier.h>
12#include <qwt_plot_panner.h>
13#include <qwt_picker_machine.h>
14#include <qwt_scale_engine.h>
15#include <qwt_analog_clock.h>
16#include <qwt_scale_widget.h>
17#include <qwt_plot_layout.h>
18#include <qwt_legend.h>
19#include <qwt_legend_label.h>
20#include <qwt_symbol.h>
21#include <qwt_plot_marker.h>
22#include <qwt_color_map.h>
23#include <qwt_date_scale_draw.h>
24
25#include <limits>
26#include <float.h>
27#include <limits>
28
29#include "dic.hxx"
30#include "Evidence.h"
31
32const QColor EddPlotBackgroundColor(Qt::yellow);
33
34void OpenHistory(char *, int, int=-1);
35bool SetStatus(QWidget *, QString, int, QString, int = -1);
36
37// General Edd Widget: has Update() method called by DIM interface
38class EddWidget {
39
40 public:
41 virtual void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int=-1) = 0;
42};
43
44
45// Base class for Edd plot
46// RemoveService() is pure virtual and needs to be implemented in the application class,
47// it will be called through signal by context menu of legend entries
48class EddBasePlot: public QwtPlot {
49 Q_OBJECT
50
51 protected:
52 QMenu *Menu;
53 QAction *StripAction;
54
55 private:
56 struct PlotItem {
57 QwtPlotCurve *Signal;
58 QVector<double> x;
59 QVector<double> y;
60 double Smallest;
61 double Largest;
62 double Mean;
63 double Sigma;
64 };
65 QList<struct PlotItem> Items;
66
67 QAction *YLogAction;
68 QAction *NormAction;
69 QAction *StyleAction;
70 QAction *StatisticsAction;
71
72 QwtPlotPanner *Panner;
73 QwtPlotGrid *Grid;
74 QwtPlotZoomer *Zoomer;
75 QwtPlotMagnifier *Magnifier;
76 QwtPicker *Picker;
77 QRectF BBox;
78 QwtPlotMarker *Stats;
79 class EddLegend *Legend;
80 bool MouseMoved;
81
82 public:
83 EddBasePlot(QWidget * = NULL);
84 ~EddBasePlot();
85
86 QTimer *Timer;
87 bool NewData;
88 QwtPlotCurve *NewCurve(QwtText);
89 virtual void RemoveService(QwtPlotCurve *) = 0;
90 void DeleteCurve(QwtPlotCurve *);
91 void ClearCurve(unsigned int);
92 void AddPoint(unsigned int, double, double);
93
94 protected slots:
95 void UpdatePlot();
96
97 private slots:
98 void ReDoStats();
99 void HandleZoom(const QRectF &);
100 void MouseSelection(const QPolygon &);
101 void mousePressEvent(QMouseEvent *);
102 void mouseReleaseEvent(QMouseEvent *);
103 void mouseMoveEvent(QMouseEvent *);
104 void contextMenuEvent(QContextMenuEvent *);
105 void MenuSetUpdateRate();
106 void MenuZoomOut();
107 void MenuSaveASCII();
108 void MenuSave();
109 void MenuPrint();
110 void MenuPlotHelp();
111};
112
113// General indicator for DIM service
114class EddLineDisplay: public QLineEdit, public EddWidget {
115 Q_OBJECT
116
117 QMenu *Menu;
118 QPoint dragStart;
119 QWidget *LastHist;
120
121 QString ServiceName;
122 int Index;
123
124 void mousePressEvent(QMouseEvent *);
125 void mouseReleaseEvent(QMouseEvent *);
126 void mouseMoveEvent(QMouseEvent *);
127
128 public:
129 EddLineDisplay(QString, int=-1, QWidget * = NULL);
130 ~EddLineDisplay();
131 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
132
133 bool ShowAsTime;
134
135 private slots:
136 void contextMenuEvent(QContextMenuEvent *);
137 void MenuOpenHistory();
138 void MenuCopyService();
139 void MenuCopyData();
140};
141
142// Sending command to DIM server
143class EddCommand: public QLineEdit {
144 Q_OBJECT
145
146 QString Name;
147
148 QString GetFormat();
149
150 public:
151 EddCommand(QString, QWidget * = NULL);
152
153 private slots:
154 void SendCommand();
155 void contextMenuEvent(QContextMenuEvent *);
156 void MenuCommandHelp();
157};
158
159// Graph class for history display
160class EddPlot: public EddBasePlot, public EddWidget {
161 Q_OBJECT
162
163 struct ItemDetails {
164 QString Name;
165 int Index;
166 QwtPlotCurve *Curve;
167 };
168 QList<struct ItemDetails> List;
169
170 private:
171 QwtLegend *Legend;
172 QTimer *SingleShot;
173 QPoint dragStart;
174
175 void dragEnterEvent(QDragEnterEvent *);
176 void dropEvent(QDropEvent *);
177
178 public:
179 EddPlot(QString = QString(), int = 0, QWidget * = NULL);
180 ~EddPlot();
181 void AddService(QString, int = 0);
182 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
183
184 public slots:
185 void RemoveService(QwtPlotCurve *);
186 void borderPath(QRect) {}; //Dummy method for qwtPicker, prevents QMetaObject::invokeMethod: No such method EddPlot::borderPath(QRect)
187
188 private slots:
189 void MenuPaste();
190 void MenuCopyTimeScale();
191 void MenuShowLastHour();
192 void MenuShowLastDay();
193 void MenuAllAsText();
194};
195
196// Scale showing date and time
197class EddDateScale: public QwtDateScaleDraw {
198
199 public:
200 QwtText label(double) const;
201};
202
203// Legend and legend label with protected methods implemented
204class EddLegend: public QwtLegend {
205
206 protected:
207 QWidget *createWidget(const QwtLegendData &) const;
208};
209
210class EddLegendLabel: public QwtLegendLabel {
211 Q_OBJECT
212
213 QMenu *Menu;
214 QPoint dragStart;
215
216 public:
217 EddLegendLabel();
218
219 void contextMenuEvent(QContextMenuEvent *);
220 void mousePressEvent(QMouseEvent *);
221 void mouseReleaseEvent(QMouseEvent *);
222 void mouseMoveEvent(QMouseEvent *);
223
224 QwtPlotCurve *Curve;
225 QAction *ThickLineAction;
226
227 private slots:
228 void MenuOpenHistory();
229 void MenuCopyService();
230 void MenuThickLine(bool);
231 void MenuRemove();
232
233 signals:
234 void DeleteCurve(QwtPlotCurve *);
235};
236
237// Text history and output class
238class EddText: public QTextEdit, public EddWidget {
239 Q_OBJECT
240
241 private:
242 QString Name;
243 bool Pure;
244
245 public:
246 EddText(QString, bool = false, QWidget * = NULL);
247 ~EddText();
248 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
249
250 bool Accumulate;
251};
252
253
254// Interface to DIM system
255class EddDim: public QObject, public DimInfo {
256 Q_OBJECT
257
258 public:
259 struct HistItem {
260 int Time;
261 QVector<QPair<int, QByteArray> > DataRaw;
262 QVector<QPair<int, QStringList> > DataText;
263 QString Format;
264 };
265
266 private:
267 struct Item {
268 DimStampedInfo *DIMService;
269 QList<QPair<class EddWidget *, int> > Subscribers;
270 int TimeStamp;
271 QByteArray ByteArray;
272 QString Format;
273 QString Text;
274 QStringList Items;
275 };
276
277 QMap<QString, struct Item> ServiceList;
278 QMap<QString, bool> IgnoreMap;
279 QMutex *Mutex, IgnoreMutex;
280 QMap<QString, struct HistItem> HistoryList;
281
282 unsigned int Period;
283 long long Volume;
284
285 void infoHandler();
286
287 private slots:
288 void Update(QString, int, QByteArray, QString);
289 void UpdateStatistics();
290
291 public:
292 EddDim();
293 ~EddDim();
294
295 void Subscribe(QString, class EddWidget *, int = -1);
296 void Unsubscribe (QString, class EddWidget *, int = -1);
297 void Ignore (QString, bool);
298 struct HistItem GetHistory(QString);
299
300 signals:
301 void INT(QString, int, QByteArray = QByteArray(), QString = QString());
302};
303
304// Open new window
305class EddWindow: public QPushButton {
306 Q_OBJECT
307
308 QMainWindow *M;
309 QGridLayout *L;
310
311 public:
312 EddWindow(QString, QString);
313 QGridLayout *Layout();
314 QMainWindow *Window();
315};
316
317#endif
Note: See TracBrowser for help on using the repository browser.