source: fact/Evidence/GUI.h@ 11205

Last change on this file since 11205 was 11088, checked in by ogrimm, 13 years ago
Updates to Edd. History server now periodically saves histories to disk.
  • Property svn:keywords set to Revision
File size: 5.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_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>
25#include <float.h>
26#include <limits>
27
28#include "dic.hxx"
29#include "Evidence.h"
30
31const QColor EddPlotBackgroundColor(Qt::yellow);
32
33void OpenHistory(char *, int);
34bool SetStatus(QWidget *, QString, int, QString, int = -1);
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 QTimer *Timer;
75 bool NewData;
76 QwtPlotCurve *NewCurve(QwtText);
77 void ClearCurve(unsigned int);
78 void AddPoint(unsigned int, double, double);
79 virtual void DeleteCurve(QwtPlotCurve *) = 0;
80
81 protected slots:
82 void UpdatePlot();
83
84 private slots:
85 void ReDoStats();
86 void HandleZoom(const QwtDoubleRect &);
87 void MouseSelection(const QwtPolygon &);
88 void contextMenuEvent(QContextMenuEvent *);
89 void MenuSingleTrace();
90 void MenuSetUpdateRate();
91 void MenuZoomOut();
92 void MenuSaveASCII();
93 void MenuSave();
94 void MenuPrint();
95 void MenuPlotHelp();
96};
97
98// General indicator for DIM service
99class EddLineDisplay: public QLineEdit {
100 Q_OBJECT
101
102 QMenu *Menu;
103 QPoint dragStart;
104 QWidget *LastHist;
105
106 QString ServiceName;
107 int Index;
108
109 void mousePressEvent(QMouseEvent *);
110 void mouseReleaseEvent(QMouseEvent *);
111 void mouseMoveEvent(QMouseEvent *);
112
113 public:
114 EddLineDisplay(QString, int=0, QWidget * = NULL);
115 ~EddLineDisplay();
116
117 bool ShowAsTime;
118
119 private slots:
120 void Update(QString, int, QByteArray, QString, QString);
121 void contextMenuEvent(QContextMenuEvent *);
122 void MenuOpenHistory();
123 void MenuCopyService();
124 void MenuCopyData();
125};
126
127// Sending command to DIM server
128class EddCommand: public QLineEdit {
129 Q_OBJECT
130
131 QString Name;
132
133 QString GetFormat();
134
135 public:
136 EddCommand(QString, QWidget * = NULL);
137
138 private slots:
139 void SendCommand();
140 void contextMenuEvent(QContextMenuEvent *);
141 void MenuCommandHelp();
142};
143
144// Graph class for history display
145class EddPlot: public EddBasePlot {
146 Q_OBJECT
147
148 // Time scale for axis
149 class EddTimeScale: public QwtScaleDraw {
150
151 public:
152 EddTimeScale() {}
153
154 virtual QwtText label(double v) const {
155 // Adapt text format to time span
156 QString Format;
157 if (scaleDiv().range() < 60*60) Format = "hh' h\n'mm:ss";
158 else if (scaleDiv().range() < 24*60*60) Format = "hh:mm";
159 else if (scaleDiv().range() < 30*24*60*60) Format = "h' h\n'd-MMM";
160 else Format = "d-MMM'\n'yyyy";
161
162 // Generate text
163 QwtText Text = QDateTime::fromTime_t((int) v).toString(Format);
164 QFont Font = Text.font();
165 Font.setPointSize(7);
166 Text.setFont(Font);
167
168 return Text;
169 }
170 };
171
172 struct ItemDetails {
173 QString Name;
174 int Index;
175 QwtPlotCurve *Signal;
176 };
177 QList<struct ItemDetails> List;
178
179 private:
180 QwtLegend *Legend;
181 QTimer *SingleShot;
182
183 void dragEnterEvent(QDragEnterEvent *);
184 void dropEvent(QDropEvent *);
185 void paintEvent(QPaintEvent *);
186
187 public:
188 EddPlot(QString = QString(), int = 0, QWidget * = NULL);
189 ~EddPlot();
190 void AddService(QString, int = 0);
191 void DeleteCurve(QwtPlotCurve *);
192
193 private slots:
194 void Update(QString, int, QByteArray, QString, QString);
195 void LegendClicked(QwtPlotItem *);
196 void MenuPasteService();
197 void MenuShowLastHour();
198 void MenuShowLastDay();
199};
200
201
202// Text history and output class
203class EddText: public QTextEdit {
204 Q_OBJECT
205
206 private:
207 QString Name;
208 bool Pure;
209
210 public:
211 EddText(QString, bool = false, QWidget * = NULL);
212 ~EddText();
213
214 bool Accumulate;
215
216 private slots:
217 void Update(QString, int, QByteArray, QString, QString);
218};
219
220
221// Interface to DIM system
222class EddDim: public QObject, public DimInfo {
223 Q_OBJECT
224
225 private:
226 struct Item {
227 DimStampedInfo *DIMService;
228 int Count;
229 int TimeStamp;
230 QByteArray ByteArray;
231 QString Format;
232 QString Text;
233 };
234 QMap<QString, struct Item> ServiceList;
235 QMutex *Mutex;
236 QList<QString> WaitingList;
237
238 struct HistItem {
239 int Count;
240 int LastUpdate;
241 class EvidenceHistory *HistClass;
242 };
243 QMap<QString, struct HistItem> HistoryList;
244
245 unsigned int Period;
246 long long Volume;
247
248 void infoHandler();
249
250 private slots:
251 void Update(QString, int, QByteArray, QString, QString);
252 void UpdateStatistics();
253 void MakeSubscriptions();
254
255 public:
256 EddDim();
257 ~EddDim();
258
259 void Subscribe(QString);
260 void Unsubscribe (QString);
261 class EvidenceHistory *GetHistory(QString);
262 void DropHistory(QString);
263 void ForceEmit();
264
265 signals:
266 void YEP(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
267 void INT(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
268};
269
270// Open new window
271class EddWindow: public QPushButton {
272 Q_OBJECT
273
274 QMainWindow *M;
275 QGridLayout *L;
276
277 public:
278 EddWindow(QString, QString);
279 QGridLayout *Layout();
280 QMainWindow *Window();
281};
282
283#endif
Note: See TracBrowser for help on using the repository browser.