dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
configtaskwidget.h
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 #ifndef CONFIGTASKWIDGET_H
29 #define CONFIGTASKWIDGET_H
30 
33 
34 #include <QQueue>
35 #include <QWidget>
36 #include <QList>
37 #include <QLabel>
38 #include <QTableWidget>
39 #include <QDoubleSpinBox>
40 #include <QSpinBox>
41 #include <QCheckBox>
42 #include <QGroupBox>
43 #include <QPushButton>
44 #include <QDesktopServices>
45 #include <QUrl>
46 #include <QEvent>
47 
48 class UAVObject;
49 class UAVDataObject;
50 class UAVObjectField;
51 class UAVObjectManager;
53 class smartSaveButton;
54 
55 class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget
56 {
57  Q_OBJECT
58 
59 public:
60  struct shadow
61  {
62  QWidget *widget;
63  double scale;
64  bool isLimited;
65  bool useUnits;
66  };
68  {
71  QWidget *widget;
72  int index;
73  double scale;
74  bool isLimited;
75  bool useUnits;
76  bool oneWayBind;
78  };
79 
80  struct temphelper
81  {
82  quint32 objid;
83  quint32 objinstid;
84  bool operator==(const temphelper &lhs)
85  {
86  return (lhs.objid == this->objid && lhs.objinstid == this->objinstid);
87  }
88  };
89 
98  connections_button
99  };
100  enum metadataSetEnum { ALL_METADATA, SETTINGS_METADATA_ONLY, NONSETTINGS_METADATA_ONLY };
101 
103  {
104  QString objname;
105  QString fieldname;
106  QString element;
107  QString url;
108  unsigned instanceId;
109  double scale;
110  bool haslimits;
111  bool useUnits;
115  };
116 
117  ConfigTaskWidget(QWidget *parent = nullptr);
118  virtual ~ConfigTaskWidget();
119 
120  void disableMouseWheelEvents();
121  bool eventFilter(QObject *obj, QEvent *evt);
122 
123  void saveObjectToSD(UAVObject *obj);
124  UAVObjectManager *getObjectManager();
125  UAVObjectUtilManager *getObjectUtilManager();
126  static double listMean(QList<double> list);
127  static double listVar(QList<double> list);
128 
129  void addUAVObject(QString objectName, QList<int> *reloadGroups = NULL);
130  void addUAVObject(UAVObject *objectName, QList<int> *reloadGroups = NULL);
131 
132  void addWidget(QWidget *widget);
133 
149  void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, int index = 0,
150  double scale = 1, bool isLimited = false,
151  bool useUnits = false, QList<int> *defaultReloadGroups = nullptr,
152  quint32 instID = 0, bool oneWayBind = false);
153 
158  void addConnectionsButton(QPushButton *button);
159 
160  void addWidgetToDefaultReloadGroups(QWidget *widget, QList<int> *groups);
161 
162  // bool addShadowWidget(QWidget *masterWidget, QWidget *shadowWidget, double shadowScale = 1,
163  // bool shadowIsLimited = false, bool shadowUseUnits = false);
164  bool addShadowWidget(QString object, QString field, QWidget *widget, int index = 0,
165  double scale = 1, bool isLimited = false, bool useUnits = false,
166  QList<int> *defaultReloadGroups = NULL, quint32 instID = 0);
167 
168  void autoLoadWidgets();
169  void loadAllLimits();
170 
171  bool isAutopilotConnected();
172  bool isDirty();
173  void setDirty(bool value);
174 
175  bool allObjectsUpdated();
176  void setOutOfLimitsStyle(QString style) { outOfLimitsStyle = style; }
177  void addHelpButton(QPushButton *button, QString url);
178  void forceShadowUpdates();
179  void forceConnectedState();
180 
181  void setNotMandatory(QString object);
182 
183  virtual void tabSwitchingAway() {}
184 
185 public slots:
186  void onAutopilotDisconnect();
187  void onAutopilotConnect();
188  void invalidateObjects();
189  void apply();
190  void save();
191 signals:
192  // fired when a widgets contents changes
193  void widgetContentsChanged(QWidget *widget);
194  // fired when the framework requests that the widgets values be populated, use for custom
195  // behaviour
196  void populateWidgetsRequested();
197  // fired when the framework requests that the widgets values be refreshed, use for custom
198  // behaviour
199  void refreshWidgetsValuesRequested();
200  // fired when the framework requests that the UAVObject values be updated from the widgets
201  // value, use for custom behaviour
202  void updateObjectsFromWidgetsRequested();
203  // fired when the autopilot connects
204  void autoPilotConnected();
205  // fired when the autopilot disconnects
206  void autoPilotDisconnected();
207  void defaultRequested(int group);
208 
209 private slots:
210  void objectUpdated(UAVObject *);
211  void defaultButtonClicked();
212  void reloadButtonClicked();
213  void rebootButtonClicked();
214  void connectionsButtonClicked();
215  void doRefreshHiddenObjects(UAVDataObject *);
216 
217 private:
218  int currentBoard;
219  bool isConnected;
220  bool allowWidgetUpdates;
221  QStringList objectsList;
222  QList<objectToWidget *> objOfInterest;
224  UAVObjectManager *objManager;
225  smartSaveButton *smartsave;
226  QMap<UAVObject *, bool> objectUpdates;
227  QMap<int, QList<objectToWidget *> *> defaultReloadGroups;
228  QMap<QWidget *, objectToWidget *> shadowsList;
229  QMap<QPushButton *, QString> helpButtonList;
230  QList<QPushButton *> reloadButtonList;
231  QList<QPushButton *> rebootButtonList;
232  QList<QPushButton *> connectionsButtonList;
233  bool dirty;
234  bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale,
235  bool usesUnits = false);
246  bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale,
247  bool hasLimits, bool useUnits = false);
248  bool widgetReadOnly(QWidget *widget) const;
249  void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
250  void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
251  void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits,
252  bool useUnits, double scale);
259  QString applyScaleToUnits(QString units, double scale);
260  void setWidgetEnabledByObj(QWidget *widget, bool enabled);
261 
262  // BUTTONS
263  void addApplySaveButtons(QPushButton *update, QPushButton *save);
264  void addReloadButton(QPushButton *button, int buttonGroup);
265  void addDefaultButton(QPushButton *button, int buttonGroup);
266  void addRebootButton(QPushButton *button);
267 
283  void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget,
284  QString element, double scale, bool isLimited = false,
285  bool useUnits = false, QList<int> *defaultReloadGroups = nullptr,
286  quint32 instID = 0, bool oneWayBind = false);
287 
288 
289  QString outOfLimitsStyle;
290  QTimer *timeOut;
291 protected slots:
292  virtual void disableObjUpdates();
293  virtual void enableObjUpdates();
294  virtual void clearDirty();
295  virtual void widgetsContentsChanged();
296  virtual void populateWidgets();
297  virtual void refreshWidgetsValues(UAVObject *obj = NULL);
298  virtual void updateObjectsFromWidgets();
299  virtual void helpButtonPressed();
300 
301 protected:
302  virtual void enableControls(bool enable);
303  void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits,
304  bool useUnits, QVariant value, double scale);
305  virtual QVariant getVariantFromWidget(QWidget *widget, double scale, bool usesUnits = false);
306  virtual bool setWidgetFromVariant(QWidget *widget, QVariant value, double scale,
307  QString units = "");
308  virtual QString getOptionFromChecked(QWidget *widget, bool checked);
309  virtual bool getCheckedFromOption(QWidget *widget, QString option);
315  bool resetWidgetToDefault(QWidget *widget);
324  void setWidgetProperty(QWidget *widget, const char *prop, const QVariant &value);
330  void setWidgetEnabled(QWidget *widget, bool enabled = true);
331 
333 };
334 
335 #endif // CONFIGTASKWIDGET_H
UAVObjectUtilManager * utilMngr
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
virtual void tabSwitchingAway()
Definition: icore.h:39
save(matfile $(SAVEOBJECTSCODE))
void setOutOfLimitsStyle(QString style)
bool operator==(const temphelper &lhs)