CFEL - ASG Software Suite  2.5.0
CASS
jocassviewer.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file jocassviewer.h contains the jocassviewer class
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _JOCASSVIEW_
10 #define _JOCASSVIEW_
11 
12 #include <QtCore/QObject>
13 #include <QtCore/QMap>
14 #include <QtCore/QString>
15 #include <QtCore/QTimer>
16 #include <QtCore/QStringList>
17 
18 #if QT_VERSION >= 0x050000
19 #include <QtWidgets/QMainWindow>
20 #else
21 #include <QtGui/QMainWindow>
22 #endif
23 
24 #include "result.hpp"
25 
26 class QLineEdit;
27 class QSpinBox;
28 class QDoubleSpinBox;
29 class QListWidgetItem;
30 
31 namespace jocassview
32 {
33 class StatusLED;
34 class DataViewer;
35 class DataSource;
36 
37 /** the jocassview class
38  *
39  * @author Lutz Foucar
40  */
41 class JoCASSViewer : public QMainWindow
42 {
43  Q_OBJECT
44 
45 public:
46  /** constructor
47  *
48  * create a main window, initialize the privates and set up the connections
49  *
50  * @param parent the parent widget. Default is 0
51  * @param flags the flags
52  */
53  JoCASSViewer(QWidget *parent=0, Qt::WindowFlags flags=0);
54 
55  /** destructor
56  *
57  */
58  ~JoCASSViewer();
59 
60 public slots:
61  /** load data from a file
62  *
63  * @param filename the file to load the data from
64  * @param key the key of the datafield in case its an h5 file
65  */
66  void openFile(QString filename=QString(), QString key=QString());
67 
68 private slots:
69  /** save the data displayed by all windows as png images
70  *
71  * call autoSave with parameter onlyPNG as true
72  *
73  * @sa autoSave();
74  */
75  void autoSaveImages() const;
76 
77  /** save the data displayed by all windows in the possible files
78  *
79  * generate the correct filenames and call saveFile() to save the data.
80  *
81  * @sa saveFile();
82  *
83  * @param onlyPNG flag that allows to only save png files fo the open viewer
84  */
85  void autoSave(bool onlyPNG=false) const;
86 
87  /** save a data from specific viewer or all viewers to the given filename
88  *
89  * @param filename The name of the file
90  * @param keys The list of keys of the window whos contens should be written
91  */
92  void saveFile(QString filename=QString(),
93  QStringList keys=QStringList()) const;
94 
95 public slots:
96  /** start the viewer
97  *
98  * uses on_autoupdate_changed() to initalize the autoupdate parameters.
99  */
100  void startViewer();
101 
102 private slots:
103  /** display about this box */
104  void about();
105 
106  /** retrieve the rate as interval in ms
107  *
108  * convert the rate in hz to an interval in ms (1000/rate()) and return it.
109  *
110  * @return the interval in ms
111  */
112  double interval() const;
113 
114  /** retrieve the user set rate in Hz
115  *
116  * @return the rate in Hz
117  */
118  double rate() const;
119 
120  /** change the autoupdate based upon what the user set
121  *
122  * change the interval. If the autoupdate button is checked, start the timer.
123  * Otherwise just stop the timer.
124  */
125  void changeAutoUpdate();
126 
127  /** update the contents within the viewers in the map */
128  void updateViewers();
129 
130  /** react on when an item in the list has been checked
131  *
132  * @param item the item that has changed and by which the viewers will change
133  */
134  void changeViewers(QListWidgetItem *item);
135 
136  /** remove the viewer from the container when it has been destroyed
137  *
138  * @param obj The viewer object that has been destroyed
139  */
140  void removeViewer(DataViewer *obj);
141 
142 public slots:
143  /** refresh the items on the displayable list
144  *
145  * retrieve the list of possible displayable items from the current source and
146  * set them in the list.
147  */
149 
150  /** check an item in the list
151  *
152  * find the listwidget item by the itemname. In case there is no or more than
153  * one item with the requested name return without doing anything. Otherwise
154  * change the checked state of the item to the requested state and call the
155  * slot on_listitem_clicked() to ensure that it is the same behavious as if the
156  * user clicked the item in the gui.
157  *
158  * @param itemName the name of the item
159  * @param state the state of the item
160  * @param simulateClickedSignal if set to true emit the clicked signal
161  */
162  void setDisplayedItem(QString itemName, bool state, bool simulateClickedSignal=true);
163 
164 private slots:
165  /** retrieve a list with all items
166  *
167  * @return list with all items
168  */
170 
171  /** retrieve a list with the selected items
172  *
173  * @return list with all selected items
174  */
175  QStringList displayedItems() const;
176 
177  /** react when print has been triggered
178  *
179  * ask the user which window should be printed, and then call print for the
180  * requested window.
181  */
182  void print();
183 
184  /** react on when the source has been changed
185  *
186  * hide the server toolbar when the source is not the server, show it otherwise
187  * Then refresh the list by calling refreshDisplayableItemsList()
188  *
189  * @param newSource the name of source that has been activated
190  */
191  void on_source_changed(QString newSource);
192 
193  /** retrieve the server address
194  *
195  * assemble the server string and port to a server address, save them in the
196  * ini file and return and emit serverChanged signal
197  */
198  void changeServerAddress()const;
199 
200  /** broadcast the darkcal command */
201  void broadcastDarkcalCommand()const;
202 
203  /** broadcast the gaincal command */
204  void broadcastGaincalCommand()const;
205 
206  /** send a custom command
207  *
208  * ask to whom the command should be sent to and for the command to send and
209  * tell the server to send the command.
210  */
211  void sendCustomCommand()const;
212 
213  /** send clear histograms
214  *
215  * ask the user which processors histograms should be cleared and tell
216  * the server to clear the requested histogram
217  */
218  void clearHistogram()const;
219 
220 private:
221  /** convenience function to create a viewer thats appropriate for a given type
222  * of data
223  *
224  * @param view iterator to the item in the viewer list where the viewer needs
225  * to be created.
226  * @param hist pointer to the histogram that hold the data
227  */
230 
231 protected:
232  /** receive move events to store the current position to the settings
233  *
234  * @param event the move event
235  */
236  void moveEvent(QMoveEvent *event);
237 
238  /** receive resize events to store the current size to the settings
239  *
240  * @param event the resize event
241  */
242  void resizeEvent(QResizeEvent *event);
243 
244 private:
245  /** the status LED */
247 
248  /** the servername input widget */
250 
251  /** the server port input widget */
253 
254  /** the rate input */
256 
257  /** the auto update input */
259 
260  /** the toolbar with the server options */
262 
263  /** the container for all opened viewers */
265 
266  /** timer for the auto update function it is used as singleshot timer */
268 
269  /** flag to tell whether an update is in progess */
271 };
272 }//end namspace jocassview
273 
274 #endif
void autoSaveImages() const
save the data displayed by all windows as png images
void clearHistogram() const
send clear histograms
void autoSave(bool onlyPNG=false) const
save the data displayed by all windows in the possible files
void startViewer()
start the viewer
base class for viewers
Definition: data_viewer.h:37
QStringList displayableItems() const
retrieve a list with all items
void on_source_changed(QString newSource)
react on when the source has been changed
a LED that should display the status
Definition: status_led.h:22
QSpinBox * _serverport
the server port input widget
Definition: jocassviewer.h:252
QToolBar * _serverToolBar
the toolbar with the server options
Definition: jocassviewer.h:261
void print()
react when print has been triggered
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
QTimer _updateTimer
timer for the auto update function it is used as singleshot timer
Definition: jocassviewer.h:267
StatusLED * _statusLED
the status LED
Definition: jocassviewer.h:246
QMap< QString, DataViewer * > _viewers
the container for all opened viewers
Definition: jocassviewer.h:264
result classes
QLineEdit * _servername
the servername input widget
Definition: jocassviewer.h:249
void changeAutoUpdate()
change the autoupdate based upon what the user set
the jocassview class
Definition: jocassviewer.h:41
QAction * _autoUpdate
the auto update input
Definition: jocassviewer.h:258
void removeViewer(DataViewer *obj)
remove the viewer from the container when it has been destroyed
QDoubleSpinBox * _rate
the rate input
Definition: jocassviewer.h:255
void sendCustomCommand() const
send a custom command
event(QEvent *event)
void openFile(QString filename=QString(), QString key=QString())
load data from a file
void setDisplayedItem(QString itemName, bool state, bool simulateClickedSignal=true)
check an item in the list
void refreshDisplayableItemsList()
refresh the items on the displayable list
JoCASSViewer(QWidget *parent=0, Qt::WindowFlags flags=0)
constructor
QStringList displayedItems() const
retrieve a list with the selected items
void saveFile(QString filename=QString(), QStringList keys=QStringList()) const
save a data from specific viewer or all viewers to the given filename
void changeServerAddress() const
retrieve the server address
void resizeEvent(QResizeEvent *event)
receive resize events to store the current size to the settings
double interval() const
retrieve the rate as interval in ms
void about()
display about this box
void changeViewers(QListWidgetItem *item)
react on when an item in the list has been checked
bool _updateInProgress
flag to tell whether an update is in progess
Definition: jocassviewer.h:270
double rate() const
retrieve the user set rate in Hz
void broadcastGaincalCommand() const
broadcast the gaincal command
void broadcastDarkcalCommand() const
broadcast the darkcal command
void createViewerForType(QMap< QString, DataViewer * >::iterator view, cass::Result< float >::shared_pointer result)
convenience function to create a viewer thats appropriate for a given type of data ...
void updateViewers()
update the contents within the viewers in the map
void moveEvent(QMoveEvent *event)
receive move events to store the current position to the settings