SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
mainwindow.h
Go to the documentation of this file.
1 // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
3 // written by Christian Daniel //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef INCLUDE_MAINWINDOW_H
20 #define INCLUDE_MAINWINDOW_H
21 
22 #include <QMainWindow>
23 #include <QTimer>
24 #include <QList>
25 
26 #include "settings/mainsettings.h"
27 #include "util/message.h"
28 #include "util/messagequeue.h"
29 #include "export.h"
30 #include "mainparser.h"
31 
32 class QLabel;
33 class QTreeWidgetItem;
34 class QDir;
35 
36 class DSPEngine;
39 class Indicator;
40 class SpectrumVis;
41 class GLSpectrum;
42 class GLSpectrumGUI;
43 class ChannelWindow;
44 class PluginAPI;
45 class PluginInstanceGUI;
46 class ChannelMarker;
47 class PluginManager;
48 class DeviceAPI;
49 class DeviceUISet;
50 class PluginInterface;
51 class QWidget;
53 class WebAPIServer;
54 class WebAPIAdapterGUI;
55 class Preset;
56 class Command;
57 class CommandKeyReceiver;
58 
59 namespace qtwebapp {
60  class LoggerWithFile;
61 }
62 
63 namespace Ui {
64  class MainWindow;
65 }
66 
67 class SDRGUI_API MainWindow : public QMainWindow {
68  Q_OBJECT
69 
70 public:
71  explicit MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QWidget* parent = 0);
72  ~MainWindow();
73  static MainWindow *getInstance() { return m_instance; } // Main Window is de facto a singleton so this just returns its reference
74 
75  MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; }
76 
77  void addViewAction(QAction* action);
78 
79  void addChannelRollup(int deviceTabIndex, QWidget* widget);
80  void setDeviceGUI(int deviceTabIndex, QWidget* gui, const QString& deviceDisplayName, int deviceType = 0);
81 
82  const QTimer& getMasterTimer() const { return m_masterTimer; }
83  const MainSettings& getMainSettings() const { return m_settings; }
84  void commandKeysConnect(QObject *object, const char *slot);
85  void commandKeysDisconnect(QObject *object, const char *slot);
86 
87  friend class WebAPIAdapterGUI;
88 
89 private:
90  class MsgLoadPreset : public Message {
92 
93  public:
94  const Preset *getPreset() const { return m_preset; }
95  int getDeviceSetIndex() const { return m_deviceSetIndex; }
96 
97  static MsgLoadPreset* create(const Preset *preset, int deviceSetIndex)
98  {
99  return new MsgLoadPreset(preset, deviceSetIndex);
100  }
101 
102  private:
103  const Preset *m_preset;
105 
106  MsgLoadPreset(const Preset *preset, int deviceSetIndex) :
107  Message(),
108  m_preset(preset),
109  m_deviceSetIndex(deviceSetIndex)
110  { }
111  };
112 
113  class MsgSavePreset : public Message {
115 
116  public:
117  Preset *getPreset() const { return m_preset; }
118  int getDeviceSetIndex() const { return m_deviceSetIndex; }
119  bool isNewPreset() const { return m_newPreset; }
120 
121  static MsgSavePreset* create(Preset *preset, int deviceSetIndex, bool newPreset)
122  {
123  return new MsgSavePreset(preset, deviceSetIndex, newPreset);
124  }
125 
126  private:
130 
131  MsgSavePreset(Preset *preset, int deviceSetIndex, bool newPreset) :
132  Message(),
133  m_preset(preset),
134  m_deviceSetIndex(deviceSetIndex),
135  m_newPreset(newPreset)
136  { }
137  };
138 
139  class MsgDeletePreset : public Message {
141 
142  public:
143  const Preset *getPreset() const { return m_preset; }
144 
145  static MsgDeletePreset* create(const Preset *preset)
146  {
147  return new MsgDeletePreset(preset);
148  }
149 
150  private:
151  const Preset *m_preset;
152 
153  MsgDeletePreset(const Preset *preset) :
154  Message(),
155  m_preset(preset)
156  { }
157  };
158 
159  class MsgAddDeviceSet : public Message {
161 
162  public:
163  int getDirection() const { return m_direction; }
164 
165  static MsgAddDeviceSet* create(int direction)
166  {
167  return new MsgAddDeviceSet(direction);
168  }
169 
170  private:
172 
173  MsgAddDeviceSet(int direction) :
174  Message(),
175  m_direction(direction)
176  { }
177  };
178 
181 
182  public:
184  {
185  return new MsgRemoveLastDeviceSet();
186  }
187 
188  private:
190  Message()
191  { }
192  };
193 
194  class MsgSetDevice : public Message {
196 
197  public:
198  int getDeviceSetIndex() const { return m_deviceSetIndex; }
199  int getDeviceIndex() const { return m_deviceIndex; }
200  int getDeviceType() const { return m_deviceType; }
201 
202  static MsgSetDevice* create(int deviceSetIndex, int deviceIndex, bool tx)
203  {
204  return new MsgSetDevice(deviceSetIndex, deviceIndex, tx);
205  }
206 
207  private:
211 
212  MsgSetDevice(int deviceSetIndex, int deviceIndex, int deviceType) :
213  Message(),
214  m_deviceSetIndex(deviceSetIndex),
215  m_deviceIndex(deviceIndex),
216  m_deviceType(deviceType)
217  { }
218  };
219 
220  class MsgAddChannel : public Message {
222 
223  public:
224  int getDeviceSetIndex() const { return m_deviceSetIndex; }
225  int getChannelRegistrationIndex() const { return m_channelRegistrationIndex; }
226  bool isTx() const { return m_tx; }
227 
228  static MsgAddChannel* create(int deviceSetIndex, int channelRegistrationIndex, bool tx)
229  {
230  return new MsgAddChannel(deviceSetIndex, channelRegistrationIndex, tx);
231  }
232 
233  private:
236  bool m_tx;
237 
238  MsgAddChannel(int deviceSetIndex, int channelRegistrationIndex, bool tx) :
239  Message(),
240  m_deviceSetIndex(deviceSetIndex),
241  m_channelRegistrationIndex(channelRegistrationIndex),
242  m_tx(tx)
243  { }
244  };
245 
246  class MsgDeleteChannel : public Message {
248 
249  public:
250  int getDeviceSetIndex() const { return m_deviceSetIndex; }
251  int getChannelIndex() const { return m_channelIndex; }
252  bool isTx() const { return m_tx; }
253 
254  static MsgDeleteChannel* create(int deviceSetIndex, int channelIndex, bool tx)
255  {
256  return new MsgDeleteChannel(deviceSetIndex, channelIndex, tx);
257  }
258 
259  private:
262  bool m_tx;
263 
264  MsgDeleteChannel(int deviceSetIndex, int channelIndex, bool tx) :
265  Message(),
266  m_deviceSetIndex(deviceSetIndex),
267  m_channelIndex(channelIndex),
268  m_tx(tx)
269  { }
270  };
271 
272  enum {
274  PItem
275  };
276 
278  {
279  QWidget *gui;
280  QString displayName;
281  QString tabName;
282  };
283 
284  class MsgDeviceSetFocus : public Message {
286 
287  public:
288  int getDeviceSetIndex() const { return m_deviceSetIndex; }
289 
290  static MsgDeviceSetFocus* create(int deviceSetIndex)
291  {
292  return new MsgDeviceSetFocus(deviceSetIndex);
293  }
294 
295  private:
297 
298  MsgDeviceSetFocus(int deviceSetIndex) :
299  Message(),
300  m_deviceSetIndex(deviceSetIndex)
301  { }
302  };
303 
305  Ui::MainWindow* ui;
308  std::vector<DeviceUISet*> m_deviceUIs;
309  QList<DeviceWidgetTabData> m_deviceWidgetTabs;
311 
314 
318 
321 
322  QWidget* m_inputGUI;
323 
326  std::string m_sampleFileName;
327 
329 
333  QString m_apiHost;
335 
337 
338  void loadSettings();
339  void loadPresetSettings(const Preset* preset, int tabIndex);
340  void savePresetSettings(Preset* preset, int tabIndex);
341  void saveCommandSettings();
342 
343  void createStatusBar();
344  void closeEvent(QCloseEvent*);
345  void updatePresetControls();
346  QTreeWidgetItem* addPresetToTree(const Preset* preset);
347  QTreeWidgetItem* addCommandToTree(const Command* command);
348  void applySettings();
349 
350  void addSourceDevice(int deviceIndex);
351  void addSinkDevice();
352  void addMIMODevice();
353  void removeLastDevice();
354  void deleteChannel(int deviceSetIndex, int channelIndex);
355 
356  void setLoggingOptions();
357 
358  bool handleMessage(const Message& cmd);
359 
360 private slots:
361  void handleMessages();
362  void updateStatus();
363  void on_action_View_Fullscreen_toggled(bool checked);
364  void on_presetSave_clicked();
365  void on_presetUpdate_clicked();
366  void on_presetEdit_clicked();
367  void on_presetExport_clicked();
368  void on_presetImport_clicked();
369  void on_settingsSave_clicked();
370  void on_presetLoad_clicked();
371  void on_presetDelete_clicked();
372  void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
373  void on_presetTree_itemActivated(QTreeWidgetItem *item, int column);
374  void on_commandNew_clicked();
375  void on_commandDuplicate_clicked();
376  void on_commandEdit_clicked();
377  void on_commandDelete_clicked();
378  void on_commandRun_clicked();
379  void on_commandOutput_clicked();
380  void on_commandsSave_clicked();
381  void on_commandKeyboardConnect_toggled(bool checked);
382  void on_action_Audio_triggered();
383  void on_action_Logging_triggered();
384  void on_action_AMBE_triggered();
385  void on_action_My_Position_triggered();
386  void on_action_DeviceUserArguments_triggered();
387  void sampleSourceChanged();
388  void sampleSinkChanged();
389  void sampleMIMOChanged();
390  void channelAddClicked(bool checked);
391  void on_action_Loaded_Plugins_triggered();
392  void on_action_About_triggered();
393  void on_action_addSourceDevice_triggered();
394  void on_action_addSinkDevice_triggered();
395  void on_action_addMIMODevice_triggered();
396  void on_action_removeLastDevice_triggered();
397  void tabInputViewIndexChanged();
398  void commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release);
399 };
400 
401 #endif // INCLUDE_MAINWINDOW_H
MessageQueue m_inputMessageQueue
Definition: mainwindow.h:306
std::string m_sampleFileName
Definition: mainwindow.h:326
static MsgLoadPreset * create(const Preset *preset, int deviceSetIndex)
Definition: mainwindow.h:97
static MainWindow * getInstance()
Definition: mainwindow.h:73
DSPEngine * m_dspEngine
Definition: mainwindow.h:312
int getDeviceIndex() const
Definition: mainwindow.h:199
MsgDeviceSetFocus(int deviceSetIndex)
Definition: mainwindow.h:298
Ui::MainWindow * ui
Definition: mainwindow.h:305
MsgDeleteChannel(int deviceSetIndex, int channelIndex, bool tx)
Definition: mainwindow.h:264
QWidget * m_inputGUI
Definition: mainwindow.h:322
const QTimer & getMasterTimer() const
Definition: mainwindow.h:82
int getDeviceSetIndex() const
Definition: mainwindow.h:224
std::vector< DeviceUISet * > m_deviceUIs
Definition: mainwindow.h:308
WebAPIRequestMapper * m_requestMapper
Definition: mainwindow.h:330
const Preset * m_preset
Definition: mainwindow.h:103
int getChannelRegistrationIndex() const
Definition: mainwindow.h:225
MsgAddDeviceSet(int direction)
Definition: mainwindow.h:173
MsgSetDevice(int deviceSetIndex, int deviceIndex, int deviceType)
Definition: mainwindow.h:212
static MsgSetDevice * create(int deviceSetIndex, int deviceIndex, bool tx)
Definition: mainwindow.h:202
quint64 m_centerFrequency
Definition: mainwindow.h:325
qtwebapp::LoggerWithFile * m_logger
Definition: mainwindow.h:328
static MsgAddDeviceSet * create(int direction)
Definition: mainwindow.h:165
const MainSettings & getMainSettings() const
Definition: mainwindow.h:83
int m_sampleRate
Definition: mainwindow.h:324
static MsgDeviceSetFocus * create(int deviceSetIndex)
Definition: mainwindow.h:290
static MsgRemoveLastDeviceSet * create()
Definition: mainwindow.h:183
static MsgDeletePreset * create(const Preset *preset)
Definition: mainwindow.h:145
Preset * getPreset() const
Definition: mainwindow.h:117
CommandKeyReceiver * m_commandKeyReceiver
Definition: mainwindow.h:336
#define SDRGUI_API
Definition: export.h:52
QList< DeviceWidgetTabData > m_deviceWidgetTabs
Definition: mainwindow.h:309
int getDeviceSetIndex() const
Definition: mainwindow.h:95
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
int getDeviceSetIndex() const
Definition: mainwindow.h:198
WebAPIServer * m_apiServer
Definition: mainwindow.h:331
Definition: preset.h:28
WebAPIAdapterGUI * m_apiAdapter
Definition: mainwindow.h:332
MsgDeletePreset(const Preset *preset)
Definition: mainwindow.h:153
int m_lastEngineState
Definition: mainwindow.h:317
MsgLoadPreset(const Preset *preset, int deviceSetIndex)
Definition: mainwindow.h:106
static MainWindow * m_instance
Definition: mainwindow.h:304
int getDeviceType() const
Definition: mainwindow.h:200
MessageQueue * getInputMessageQueue()
Definition: mainwindow.h:75
MsgAddChannel(int deviceSetIndex, int channelRegistrationIndex, bool tx)
Definition: mainwindow.h:238
const Preset * getPreset() const
Definition: mainwindow.h:143
static MsgAddChannel * create(int deviceSetIndex, int channelRegistrationIndex, bool tx)
Definition: mainwindow.h:228
MainSettings m_settings
Definition: mainwindow.h:307
QTimer m_statusTimer
Definition: mainwindow.h:316
QLabel * m_dateTimeWidget
Definition: mainwindow.h:319
QLabel * m_showSystemWidget
Definition: mainwindow.h:320
const Preset * getPreset() const
Definition: mainwindow.h:94
static MsgSavePreset * create(Preset *preset, int deviceSetIndex, bool newPreset)
Definition: mainwindow.h:121
MsgSavePreset(Preset *preset, int deviceSetIndex, bool newPreset)
Definition: mainwindow.h:131
QString m_apiHost
Definition: mainwindow.h:333
PluginManager * m_pluginManager
Definition: mainwindow.h:313
QTimer m_masterTimer
Definition: mainwindow.h:315
int m_apiPort
Definition: mainwindow.h:334
int m_masterTabIndex
Definition: mainwindow.h:310
int getDeviceSetIndex() const
Definition: mainwindow.h:118
static MsgDeleteChannel * create(int deviceSetIndex, int channelIndex, bool tx)
Definition: mainwindow.h:254
bool isNewPreset() const
Definition: mainwindow.h:119