source: fact/Evidence/GUI.h@ 13776

Last change on this file since 13776 was 12940, checked in by ogrimm, 13 years ago
History handling in Edd faster, improved drag and drop functionality, version of Edd for La Palma
  • Property svn:keywords set to Revision
File size: 6.8 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_item.h>
20#include <qwt_symbol.h>
21#include <qwt_plot_marker.h>
22#include <qwt_data.h>
23#include <qwt_color_map.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// DeleteCurve() is pure virtual and needs to be implemented iin the application class
47class EddBasePlot: public QwtPlot {
48 Q_OBJECT
49
50 protected:
51 QMenu *Menu;
52 QAction *StripAction;
53
54 private:
55 struct PlotItem {
56 QwtPlotCurve *Signal;
57 QVector<double> x;
58 QVector<double> y;
59 double Smallest;
60 double Largest;
61 double Mean;
62 double Sigma;
63 };
64 QList<struct PlotItem> Items;
65
66 QAction *YLogAction;
67 QAction *NormAction;
68 QAction *StyleAction;
69 QAction *StatisticsAction;
70
71 QwtPlotPanner *Panner;
72 QwtPlotGrid *Grid;
73 QwtPlotZoomer *Zoomer;
74 QwtPlotMagnifier *Magnifier;
75 QwtPicker *Picker;
76 QwtDoubleRect BBox;
77 QwtPlotMarker *Stats;
78
79 public:
80 EddBasePlot(QWidget * = NULL);
81 ~EddBasePlot();
82
83 QTimer *Timer;
84 bool NewData;
85 QwtPlotCurve *NewCurve(QwtText);
86 void DeleteCurve(QwtPlotCurve *);
87 void ClearCurve(unsigned int);
88 void AddPoint(unsigned int, double, double);
89
90 protected slots:
91 void UpdatePlot();
92
93 private slots:
94 void ReDoStats();
95 void HandleZoom(const QwtDoubleRect &);
96 void MouseSelection(const QwtPolygon &);
97 void contextMenuEvent(QContextMenuEvent *);
98 void MenuSetUpdateRate();
99 void MenuZoomOut();
100 void MenuSaveASCII();
101 void MenuSave();
102 void MenuPrint();
103 void MenuPlotHelp();
104};
105
106// General indicator for DIM service
107class EddLineDisplay: public QLineEdit, public EddWidget {
108 Q_OBJECT
109
110 QMenu *Menu;
111 QPoint dragStart;
112 QWidget *LastHist;
113
114 QString ServiceName;
115 int Index;
116
117 void mousePressEvent(QMouseEvent *);
118 void mouseReleaseEvent(QMouseEvent *);
119 void mouseMoveEvent(QMouseEvent *);
120
121 public:
122 EddLineDisplay(QString, int=-1, QWidget * = NULL);
123 ~EddLineDisplay();
124 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
125
126 bool ShowAsTime;
127
128 private slots:
129 void contextMenuEvent(QContextMenuEvent *);
130 void MenuOpenHistory();
131 void MenuCopyService();
132 void MenuCopyData();
133};
134
135// Sending command to DIM server
136class EddCommand: public QLineEdit {
137 Q_OBJECT
138
139 QString Name;
140
141 QString GetFormat();
142
143 public:
144 EddCommand(QString, QWidget * = NULL);
145
146 private slots:
147 void SendCommand();
148 void contextMenuEvent(QContextMenuEvent *);
149 void MenuCommandHelp();
150};
151
152// Graph class for history display
153class EddPlot: public EddBasePlot, public EddWidget {
154 Q_OBJECT
155
156 // Time scale for axis
157 class EddTimeScale: public QwtScaleDraw {
158
159 public:
160 EddTimeScale() {}
161
162 virtual QwtText label(double v) const {
163 // Adapt text format to time span
164 QString Format;
165 if (scaleDiv().range() < 60*60) Format = "hh' h\n'mm:ss";
166 else if (scaleDiv().range() < 24*60*60) Format = "hh:mm";
167 else if (scaleDiv().range() < 30*24*60*60) Format = "h' h\n'd-MMM";
168 else Format = "d-MMM'\n'yyyy";
169
170 // Generate text
171 QwtText Text = QDateTime::fromTime_t((int) v).toString(Format);
172 QFont Font = Text.font();
173 Font.setPointSize(7);
174 Text.setFont(Font);
175
176 return Text;
177 }
178 };
179
180 struct ItemDetails {
181 QString Name;
182 int Index;
183 QwtPlotCurve *Curve;
184 };
185 QList<struct ItemDetails> List;
186
187 private:
188 QwtLegend *Legend;
189 QTimer *SingleShot;
190 QPoint dragStart;
191
192 void dragEnterEvent(QDragEnterEvent *);
193 void dropEvent(QDropEvent *);
194 void paintEvent(QPaintEvent *);
195
196 public:
197 EddPlot(QString = QString(), int = 0, QWidget * = NULL);
198 ~EddPlot();
199 void AddService(QString, int = 0);
200 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
201
202 public slots:
203 void RemoveService(QwtPlotCurve *);
204
205 private slots:
206 void MenuPasteService();
207 void MenuShowLastHour();
208 void MenuShowLastDay();
209 void MenuAllAsText();
210};
211
212
213// Legend
214class EddLegend: public QwtLegendItem {
215 Q_OBJECT
216
217 QMenu *Menu;
218 QPoint dragStart;
219 QwtPlotCurve *Curve;
220 EddPlot *Plot;
221
222 public:
223 EddLegend(QwtPlotCurve *, EddPlot *);
224
225 void contextMenuEvent(QContextMenuEvent *);
226 void mousePressEvent(QMouseEvent *);
227 void mouseReleaseEvent(QMouseEvent *);
228 void mouseMoveEvent(QMouseEvent *);
229
230 private slots:
231 void MenuOpenHistory();
232 void MenuCopyService();
233 void MenuNormalLine();
234 void MenuThickLine();
235 void MenuRemove();
236
237 signals:
238 void DeleteCurve(QwtPlotCurve *);
239};
240
241// Text history and output class
242class EddText: public QTextEdit, public EddWidget {
243 Q_OBJECT
244
245 private:
246 QString Name;
247 bool Pure;
248
249 public:
250 EddText(QString, bool = false, QWidget * = NULL);
251 ~EddText();
252 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
253
254 bool Accumulate;
255};
256
257
258// Interface to DIM system
259class EddDim: public QObject, public DimInfo {
260 Q_OBJECT
261
262 public:
263 struct HistItem {
264 int Time;
265 QVector<QPair<int, QByteArray> > DataRaw;
266 QVector<QPair<int, QStringList> > DataText;
267 QString Format;
268 };
269
270 private:
271 struct Item {
272 DimStampedInfo *DIMService;
273 QList<QPair<class EddWidget *, int> > Subscribers;
274 int TimeStamp;
275 QByteArray ByteArray;
276 QString Format;
277 QString Text;
278 QStringList Items;
279 };
280
281 QMap<QString, struct Item> ServiceList;
282 QMap<QString, bool> IgnoreMap;
283 QMutex *Mutex, IgnoreMutex;
284 QMap<QString, struct HistItem> HistoryList;
285
286 unsigned int Period;
287 long long Volume;
288
289 void infoHandler();
290
291 private slots:
292 void Update(QString, int, QByteArray, QString);
293 void UpdateStatistics();
294
295 public:
296 EddDim();
297 ~EddDim();
298
299 void Subscribe(QString, class EddWidget *, int = -1);
300 void Unsubscribe (QString, class EddWidget *, int = -1);
301 void Ignore (QString, bool);
302 struct HistItem GetHistory(QString);
303
304 signals:
305 void INT(QString, int, QByteArray = QByteArray(), QString = QString());
306};
307
308// Open new window
309class EddWindow: public QPushButton {
310 Q_OBJECT
311
312 QMainWindow *M;
313 QGridLayout *L;
314
315 public:
316 EddWindow(QString, QString);
317 QGridLayout *Layout();
318 QMainWindow *Window();
319};
320
321#endif
Note: See TracBrowser for help on using the repository browser.