VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
libgui.h
Go to the documentation of this file.
1 /*
2  libgui.h
3 
4  Copyright 2012 - 2018 Brenton Ross
5 
6 This file is part of VICI.
7 
8 VICI is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 VICI is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
31 #ifndef VICI_LIBGUI_H
32 #define VICI_LIBGUI_H
33 
34 #include <QWidget>
35 #include <QDialog>
36 #include <QMainWindow>
37 #include <QItemDelegate>
38 #include <QTextBrowser>
39 #include <QListWidget>
40 #include <list>
41 #include <functional>
42 #include <memory>
43 #include <thread>
44 #include "gth.h"
45 #include <vici/test.h>
46 
47 // This is a project wide library so is in just the VICI namespace
48 namespace VICI
49 {
50 // -------------------------------------------------------------
51 
53 
57 {
58 private:
59  // only do registration's once
60  bool doneRegistration;
61 
62 protected:
64  void registerWindow();
65 
66 public:
68  virtual ~GTHWindowWidget();
69 
71  virtual void RegnFn( std::function<void (void *, gth::WidgetType, csr )> reg ) = 0;
72 };
73 
74 // -------------------------------------------------------------
75 
77 
81 {
82 public:
83  virtual ~WidgetMgrClient(){}
85  virtual void windowHasRegistered( GTHWindowWidget * ) = 0;
86 
88  virtual void windowHasDeregistered( GTHWindowWidget * ) = 0;
89 };
90 
91 // -------------------------------------------------------------
92 
94 
103 {
104 private:
105  WidgetMgr(){}
106  std::list< GTHWindowWidget *> widgets;
107  std::list< WidgetMgrClient * > clients;
108 public:
110  static WidgetMgr & instance();
111 
114 
117 
119  void addClient(WidgetMgrClient * );
120 
123 };
124 
125 // -------------------------------------------------------------
126 
128 
131 class VMainWindow : public QMainWindow, public GTHWindowWidget
132 {
133  Q_OBJECT
134 signals:
136  void widgetsRealised();
137 
138 protected slots:
140  virtual void startUp()
141  { emit widgetsRealised(); }
142 
143 
144 protected:
146  virtual void showEvent ( QShowEvent * event );
147 
148 public:
150  VMainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0);
151 
152 };
153 
154 // -------------------------------------------------------------
155 
157 
161 class VDialog : public QDialog, public GTHWindowWidget
162 {
163 protected:
165  virtual void showEvent ( QShowEvent * event );
166 public:
168  VDialog(QWidget *parent = 0, Qt::WindowFlags f = 0 ) : QDialog(parent, f) {}
169 
172 };
173 
174 // -------------------------------------------------------------
175 
177 
185 class ItemDelegate : public QItemDelegate
186 {
187  Q_OBJECT
188 private:
189  mutable bool editing;
190 public:
192  ItemDelegate( QObject *parent = 0);
193 
195  QWidget *createEditor(QWidget *parent,
196  const QStyleOptionViewItem &option,
197  const QModelIndex &index) const;
198 
200  void setEditorData(QWidget *editor, const QModelIndex &index) const;
201 
203  void setModelData(QWidget *editor, QAbstractItemModel *model,
204  const QModelIndex &index) const;
205 
207  void updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option,
208  const QModelIndex & index ) const;
209 
211  bool hasEditor() const { return editing; }
212 
213 private slots:
214  void commitAndCloseEditor();
215 
216 signals:
218  void validationError(const QModelIndex &) const;
219 };
220 
221 // -------------------------------------------------------------
222 
224 
231 class VEditList : public QListWidget
232 {
233  Q_OBJECT
234 public:
235  explicit VEditList( QWidget *parent = 0 );
236  void append( const std::vector< std::string > & );
237  std::vector< std::string > getVals() const;
238 
239 protected slots:
240  virtual void addBlank(QListWidgetItem *);
241  virtual void changed(QListWidgetItem *it, QListWidgetItem *);
242 };
243 
244 // -------------------------------------------------------------
245 
247 
255 class Metrics
256 {
257 private:
258  static int pixelsPerM;
259 public:
261  static int ppm(int m = 1);
262 };
263 
264 // -------------------------------------------------------------
265 
267 
273 class SignalToQtSignal : public QObject
274 {
275  Q_OBJECT
276 private:
277  std::unique_ptr< std::thread> thread;
278  bool gotSignal;
279  bool terminating;
280  int fds[2];
281 
282  void threadFn();
283 public:
285  ~SignalToQtSignal();
286 
288  void emitSignal();
289 signals:
291  void notifySignal();
292 };
293 
294 // -------------------------------------------------------------
295 
297 
300 class AboutDialog : public VDialog
301 {
302  Q_OBJECT
303 
304 private:
305  QTextBrowser *text;
306  void setText(csr progName, csr descr);
307  QPushButton * okBtn;
308 
309 public:
311  AboutDialog( QWidget * parent, csr progName, csr description );
312 
313  virtual void RegnFn( std::function<void (void *, gth::WidgetType, csr )> reg );
314 
315 private slots:
316  void openLink( const QUrl & link );
317 };
318 
319 
320 // -------------------------------------------------------------
321 
322 
323 } // end VICI namespace
324 
325 
326 
327 #endif /* LIBGUI_H_ */
void deregisterWindowWidget(GTHWindowWidget *)
Remove a window and inform any clients.
Definition: libgui.cpp:103
A mix-in class with the functions required for the gui test harness.
Definition: libgui.h:56
Builds on QListWidget to provide better editing ability.
Definition: libgui.h:231
AboutDialog(QWidget *parent, csr progName, csr description)
Constructor.
Definition: libgui.cpp:438
void widgetsRealised()
Emitted when the widgets have been made visible.
An interface for the WidgetMgr to call its clients when a window registers itself.
Definition: libgui.h:80
A dialog class that automatically registers itself.
Definition: libgui.h:161
~VDialog()
Destructor.
Definition: libgui.h:171
A singleton class that window widgets register with.
Definition: libgui.h:102
void append(const std::vector< std::string > &)
Add list of strings.
Definition: libgui.cpp:310
virtual void startUp()
This is called to do things that require the widgets to have been realized.
Definition: libgui.h:140
virtual void windowHasDeregistered(GTHWindowWidget *)=0
Called to notify that a window has deregistered itself,.
Provide the interface between the GUI applications and the GUI Test Harness.
void removeClient(WidgetMgrClient *)
Remove a client.
Definition: libgui.cpp:131
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Notification that the shape of the owner has changed.
Definition: libgui.cpp:216
void setEditorData(QWidget *editor, const QModelIndex &index) const
Copy the data from the model to the editor.
Definition: libgui.cpp:194
A main window class that automatically registers itself.
Definition: libgui.h:131
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Create a QLineEdit for editing the item.
Definition: libgui.cpp:180
A standard About Vici dialog for the project.
Definition: libgui.h:300
WidgetType
List the types of widgets that we can interact with during testing.
Definition: gth.h:43
virtual void RegnFn(std::function< void(void *, gth::WidgetType, csr)> reg)=0
This may be called by the test harness to get pointers to the individual widgets. ...
virtual void RegnFn(std::function< void(void *, gth::WidgetType, csr)> reg)
This may be called by the test harness to get pointers to the individual widgets. ...
Definition: libgui.cpp:466
void addClient(WidgetMgrClient *)
Add client to list and inform it about any registered windows.
Definition: libgui.cpp:115
void notifySignal()
This signal is emitted when an operating signal arrives.
VMainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
Constructor.
Definition: libgui.cpp:140
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Copy the data from the editor to the model.
Definition: libgui.cpp:203
virtual void changed(QListWidgetItem *it, QListWidgetItem *)
Called if a row has been changed.
Definition: libgui.cpp:284
void registerWindowWidget(GTHWindowWidget *)
Add window to list and inform any clients.
Definition: libgui.cpp:87
VEditList(QWidget *parent=0)
Constructor.
Definition: libgui.cpp:239
void validationError(const QModelIndex &) const
This signal can be emitted if there is a validation error.
static int ppm(int m=1)
return the number of pixels for something m ems wide.
Definition: libgui.cpp:349
virtual void showEvent(QShowEvent *event)
Called when the dialog is shown.
Definition: libgui.cpp:164
virtual void windowHasRegistered(GTHWindowWidget *)=0
Called to notify of a new window registering itself.
A class to encapsulate measurements.
Definition: libgui.h:255
bool hasEditor() const
Check if delegate is in edit mode.
Definition: libgui.h:211
An item delegate that uses QLineEdit for editing list and table entries.
Definition: libgui.h:185
VDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
Definition: libgui.h:168
virtual void addBlank(QListWidgetItem *)
Add a blank row at the end.
Definition: libgui.cpp:258
const std::string & csr
short cut for string constants
Definition: vici.h:80
virtual void showEvent(QShowEvent *event)
Called when the window gets shown.
Definition: libgui.cpp:147
static WidgetMgr & instance()
Get a reference to the window widget manager.
Definition: libgui.cpp:78
void emitSignal()
Called by signal handler when a signal arrives.
Definition: libgui.cpp:418
std::vector< std::string > getVals() const
Get the rows as std::strings.
Definition: libgui.cpp:327
ItemDelegate(QObject *parent=0)
Constructor.
Definition: libgui.cpp:173
A class to convert operating system signals into Qt signals.
Definition: libgui.h:273
void registerWindow()
This is called by showEvent on first show.
Definition: libgui.cpp:64