source: fact/Evidence/GUI.h@ 10928

Last change on this file since 10928 was 10928, checked in by ogrimm, 13 years ago
Improved responsiveness of GUI at start-up
  • Property svn:keywords set to Revision
File size: 5.7 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_scale_engine.h>
14#include <qwt_analog_clock.h>
15#include <qwt_scale_widget.h>
16#include <qwt_plot_layout.h>
17#include <qwt_legend.h>
18#include <qwt_legend_item.h>
19#include <qwt_symbol.h>
20#include <qwt_plot_marker.h>
21#include <qwt_data.h>
22#include <qwt_color_map.h>
23
24#include <limits.h>
25#include <float.h>
26
27#include "dic.hxx"
28#include "Evidence.h"
29
30const QColor EddPlotBackgroundColor(Qt::yellow);
31
32QWidget *OpenHistory(char *, int);
33bool SetStatus(QWidget *, QString, int, QString, int = -1);
34
35
36// Base class for Edd plot
37// DeleteCurve() is pure virtual and needs to be implemented iin the application class
38class EddBasePlot: public QwtPlot {
39 Q_OBJECT
40
41 protected:
42 QMenu *Menu;
43 QAction *StripAction;
44
45 private:
46 struct PlotItem {
47 QwtPlotCurve *Signal;
48 QVector<double> x;
49 QVector<double> y;
50 double Smallest;
51 double Largest;
52 double Mean;
53 double Sigma;
54 };
55 QList<struct PlotItem> Items;
56
57 QAction *YLogAction;
58 QAction *NormAction;
59 QAction *StyleAction;
60 QAction *StatisticsAction;
61
62 QwtPlotPanner *Panner;
63 QwtPlotGrid *Grid;
64 QwtPlotZoomer *Zoomer;
65 QwtPlotMagnifier *Magnifier;
66 QwtPicker *Picker;
67 QwtDoubleRect BBox;
68 QwtPlotMarker *Stats;
69
70 public:
71 EddBasePlot(QWidget * = NULL);
72 ~EddBasePlot();
73
74 QwtPlotCurve *NewCurve(QwtText);
75 void ClearCurve(unsigned int);
76 void AddPoint(unsigned int, double, double);
77 virtual void DeleteCurve(QwtPlotCurve *) = 0;
78
79 protected slots:
80 void UpdatePlot();
81
82 private slots:
83 void ReDoStats();
84 void HandleZoom(const QwtDoubleRect &);
85 void MouseSelection(const QwtPolygon &);
86 void contextMenuEvent(QContextMenuEvent *);
87 void MenuSingleTrace();
88 void MenuZoomOut();
89 void MenuSaveASCII();
90 void MenuSave();
91 void MenuPrint();
92 void MenuPlotHelp();
93};
94
95// General indicator for DIM service
96class EddLineDisplay: public QLineEdit {
97 Q_OBJECT
98
99 QMenu *Menu;
100 QPoint dragStart;
101 QWidget *LastHist;
102
103 QString ServiceName;
104 int Index;
105
106 void mousePressEvent(QMouseEvent *);
107 void mouseReleaseEvent(QMouseEvent *);
108 void mouseMoveEvent(QMouseEvent *);
109
110 public:
111 EddLineDisplay(QString, int=0, QWidget * = NULL);
112 ~EddLineDisplay();
113
114 bool ShowAsTime;
115
116 private slots:
117 void Update(QString, int, QByteArray, QString, QString);
118 void contextMenuEvent(QContextMenuEvent *);
119 void MenuOpenHistory();
120 void MenuCopyService();
121 void MenuCopyData();
122};
123
124// Sending command to DIM server
125class EddCommand: public QLineEdit {
126 Q_OBJECT
127
128 QString Name;
129
130 public:
131 EddCommand(QString, QWidget * = NULL);
132
133 private slots:
134 void SendCommand();
135};
136
137// Graph class for history display
138class EddPlot: public EddBasePlot {
139 Q_OBJECT
140
141 // Time scale for axis
142 class EddTimeScale: public QwtScaleDraw {
143
144 public:
145 EddTimeScale() {}
146
147 virtual QwtText label(double v) const {
148 // Adapt text format to time span
149 QString Format;
150 if (scaleDiv().range() < 60*60) Format = "hh' h\n'mm:ss";
151 else if (scaleDiv().range() < 24*60*60) Format = "hh:mm";
152 else if (scaleDiv().range() < 30*24*60*60) Format = "h' h\n'd-MMM";
153 else Format = "d-MMM'\n'yyyy";
154
155 // Generate text
156 QwtText Text = QDateTime::fromTime_t((int) v).toString(Format);
157 QFont Font = Text.font();
158 Font.setPointSize(7);
159 Text.setFont(Font);
160
161 return Text;
162 }
163 };
164
165 struct ItemDetails {
166 QString Name;
167 int Index;
168 QwtPlotCurve *Signal;
169 };
170 QList<struct ItemDetails> List;
171
172 private:
173 QwtLegend *Legend;
174 int SizeLimit;
175
176 void dragEnterEvent(QDragEnterEvent *);
177 void dropEvent(QDropEvent *);
178 void paintEvent(QPaintEvent *);
179
180 public:
181 EddPlot(QString = QString(), int = 0, QWidget * = NULL);
182 ~EddPlot();
183 void AddService(QString, int = 0);
184 void DeleteCurve(QwtPlotCurve *);
185
186 private slots:
187 void Update(QString, int, QByteArray, QString, QString);
188 void LegendClicked(QwtPlotItem *);
189 void MenuPasteService();
190};
191
192
193// Text history and output class
194class EddText: public QTextEdit {
195 Q_OBJECT
196
197 private:
198 QString Name;
199 bool Pure;
200
201 public:
202 EddText(QString, bool = false, QWidget * = NULL);
203 ~EddText();
204
205 bool Accumulate;
206
207 private slots:
208 void Update(QString, int, QByteArray, QString, QString);
209};
210
211
212// Interface to DIM system
213class EddDim: public QObject, public DimInfo {
214 Q_OBJECT
215
216 private:
217 struct Item {
218 DimStampedInfo *DIMService;
219 int Count;
220 int TimeStamp;
221 QByteArray ByteArray;
222 QString Format;
223 QString Text;
224 };
225 QMap<QString, struct Item> ServiceList;
226 QMutex *Mutex;
227 QList<QString> WaitingList;
228
229 struct HistItem {
230 int Count;
231 int LastUpdate;
232 class EvidenceHistory *HistClass;
233 };
234 QMap<QString, struct HistItem> HistoryList;
235
236 long long Volume;
237
238 void infoHandler();
239
240 private slots:
241 void Update(QString, int, QByteArray, QString, QString);
242 void UpdateStatistics();
243 void MakeSubscriptions();
244
245 public:
246 EddDim();
247 ~EddDim();
248
249 void Subscribe(QString);
250 void Unsubscribe (QString);
251 class EvidenceHistory *GetHistory(QString);
252 void DropHistory(QString);
253 void ForceEmit();
254
255 signals:
256 void YEP(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
257 void INT(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
258};
259
260// Open new window
261class EddWindow: public QPushButton {
262 Q_OBJECT
263
264 QMainWindow *M;
265 QGridLayout *L;
266
267 public:
268 EddWindow(QString, QString);
269 QGridLayout *Layout();
270 QMainWindow *Window();
271 private slots:
272 void Toggle();
273};
274
275#endif
Note: See TracBrowser for help on using the repository browser.