LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / uavobjectwidgetutils / configtaskwidget.h
blob7809df60231c95519efe3647cef792d4ca1fd552
1 /**
2 ******************************************************************************
4 * @file configtaskwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup UAVObjectWidgetUtils Plugin
9 * @{
10 * @brief Utility plugin for UAVObject to Widget relation management
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef CONFIGTASKWIDGET_H
28 #define CONFIGTASKWIDGET_H
30 #include "extensionsystem/pluginmanager.h"
31 #include "uavobjectmanager.h"
32 #include "uavobject.h"
33 #include "uavobjectutilmanager.h"
34 #include <QQueue>
35 #include <QWidget>
36 #include <QList>
37 #include <QLabel>
38 #include "smartsavebutton.h"
39 #include "mixercurvewidget.h"
40 #include <QTableWidget>
41 #include <QDoubleSpinBox>
42 #include <QSpinBox>
43 #include <QCheckBox>
44 #include <QPushButton>
45 #include "uavobjectwidgetutils_global.h"
46 #include <QDesktopServices>
47 #include <QUrl>
48 #include <QEvent>
50 class ShadowWidgetBinding : public QObject {
51 Q_OBJECT
52 public:
53 ShadowWidgetBinding(QWidget *widget, double scale, bool isLimited);
54 ~ShadowWidgetBinding();
55 QWidget *widget() const;
56 double scale() const;
57 bool isLimited() const;
59 protected:
60 QWidget *m_widget;
61 double m_scale;
62 bool m_isLimited;
65 class WidgetBinding : public ShadowWidgetBinding {
66 Q_OBJECT
67 public:
68 WidgetBinding(QWidget *widget, UAVObject *object, UAVObjectField *field, int index, double scale, bool isLimited);
69 ~WidgetBinding();
71 QString units() const;
72 QString type() const;
73 bool isInteger() const;
74 UAVObject *object() const;
75 UAVObjectField *field() const;
76 int index() const;
77 QList<ShadowWidgetBinding *> shadows() const;
79 void addShadow(QWidget *widget, double scale, bool isLimited);
80 bool matches(QString objectName, QString fieldName, int index, quint32 instanceId);
82 bool isEnabled() const;
83 void setIsEnabled(bool isEnabled);
85 QVariant value() const;
86 void setValue(const QVariant &value);
88 void updateObjectFieldFromValue();
89 void updateValueFromObjectField();
91 private:
92 UAVObject *m_object;
93 UAVObjectField *m_field;
94 int m_index;
95 bool m_isEnabled;
96 QList<ShadowWidgetBinding *> m_shadows;
97 QVariant m_value;
100 class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget {
101 Q_OBJECT
103 public:
104 ConfigTaskWidget(QWidget *parent = 0);
105 virtual ~ConfigTaskWidget();
107 // Combobox helper functions
108 static bool isComboboxOptionSelected(QComboBox *combo, int optionValue);
109 static int getComboboxSelectedOption(QComboBox *combo);
110 static void setComboboxSelectedOption(QComboBox *combo, int optionValue);
111 static int getComboboxIndexForOption(QComboBox *combo, int optionValue);
112 static void enableComboBoxOptionItem(QComboBox *combo, int optionValue, bool enable);
114 void disableMouseWheelEvents();
115 bool eventFilter(QObject *obj, QEvent *evt);
117 void saveObjectToSD(UAVObject *obj);
118 UAVObjectManager *getObjectManager();
120 void addUAVObject(QString objectName, QList<int> *reloadGroups = NULL);
121 void addUAVObject(UAVObject *objectName, QList<int> *reloadGroups = NULL);
123 void addWidget(QWidget *widget);
125 void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
126 bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
127 void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, int index = 0, double scale = 1,
128 bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
130 void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, QString elementName, double scale,
131 bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
132 void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName, double scale,
133 bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
135 void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, QString elementName);
136 void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName);
138 void addApplySaveButtons(QPushButton *update, QPushButton *save);
139 void addReloadButton(QPushButton *button, int buttonGroup);
140 void addDefaultButton(QPushButton *button, int buttonGroup);
142 void addWidgetToReloadGroups(QWidget *widget, QList<int> *reloadGroupIDs);
144 bool addShadowWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
145 bool isLimited = false, QList<int> *m_reloadGroups = NULL, quint32 instID = 0);
147 void autoLoadWidgets();
149 bool isDirty();
150 virtual void setDirty(bool value);
152 bool allObjectsUpdated();
153 void setOutOfLimitsStyle(QString style)
155 m_outOfLimitsStyle = style;
157 void addHelpButton(QPushButton *button, QString url);
158 void forceShadowUpdates();
159 void forceConnectedState();
160 virtual bool shouldObjectBeSaved(UAVObject *object);
162 public slots:
163 void onAutopilotDisconnect();
164 void onAutopilotConnect();
165 void invalidateObjects();
166 void apply();
167 void save();
168 void setWidgetBindingObjectEnabled(QString objectName, bool enabled);
170 signals:
171 // fired when a widgets contents changes
172 void widgetContentsChanged(QWidget *widget);
173 // fired when the framework requests that the widgets values be populated, use for custom behaviour
174 void populateWidgetsRequested();
175 // fired when the framework requests that the widgets values be refreshed, use for custom behaviour
176 void refreshWidgetsValuesRequested();
177 // fired when the framework requests that the UAVObject values be updated from the widgets value, use for custom behaviour
178 void updateObjectsFromWidgetsRequested();
179 // fired when the autopilot connects
180 void autoPilotConnected();
181 // fired when the autopilot disconnects
182 void autoPilotDisconnected();
183 void defaultRequested(int group);
184 void enableControlsChanged(bool enable);
186 private slots:
187 void objectUpdated(UAVObject *object);
188 void defaultButtonClicked();
189 void reloadButtonClicked();
191 private:
192 struct objectComparator {
193 quint32 objid;
194 quint32 objinstid;
195 bool operator==(const objectComparator & lhs)
197 return lhs.objid == this->objid && lhs.objinstid == this->objinstid;
201 enum buttonTypeEnum { none, save_button, apply_button, reload_button, default_button, help_button };
202 struct bindingStruct {
203 QString objectName;
204 QString fieldName;
205 QString elementName;
206 int index;
207 QString url;
208 buttonTypeEnum buttonType;
209 QList<int> buttonGroup;
210 double scale;
211 bool haslimits;
214 int m_currentBoardId;
215 bool m_isConnected;
216 bool m_isWidgetUpdatesAllowed;
217 QStringList m_objects;
219 QMultiHash<int, WidgetBinding *> m_reloadGroups;
220 QMultiHash<QWidget *, WidgetBinding *> m_widgetBindingsPerWidget;
221 QMultiHash<UAVObject *, WidgetBinding *> m_widgetBindingsPerObject;
223 ExtensionSystem::PluginManager *m_pluginManager;
224 UAVObjectUtilManager *m_objectUtilManager;
225 SmartSaveButton *m_saveButton;
226 QHash<UAVObject *, bool> m_updatedObjects;
227 QHash<QPushButton *, QString> m_helpButtons;
228 QList<QPushButton *> m_reloadButtons;
229 bool m_isDirty;
230 QString m_outOfLimitsStyle;
231 QTimer *m_realtimeUpdateTimer;
233 bool setWidgetFromField(QWidget *widget, UAVObjectField *field, WidgetBinding *binding);
235 QVariant getVariantFromWidget(QWidget *widget, WidgetBinding *binding);
236 bool setWidgetFromVariant(QWidget *widget, QVariant value, WidgetBinding *binding);
238 void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
239 void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
241 void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, double sclale);
243 int fieldIndexFromElementName(QString objectName, QString fieldName, QString elementName);
245 void doAddWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
246 bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
248 protected slots:
249 virtual void disableObjectUpdates();
250 virtual void enableObjectUpdates();
251 virtual void clearDirty();
252 virtual void widgetsContentsChanged();
253 virtual void populateWidgets();
254 virtual void refreshWidgetsValues(UAVObject *obj = NULL);
255 virtual void updateObjectsFromWidgets();
256 virtual void helpButtonPressed();
258 protected:
259 virtual void enableControls(bool enable);
260 virtual QString mapObjectName(const QString objectName);
261 virtual UAVObject *getObject(const QString name, quint32 instId = 0);
262 void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
263 void updateEnableControls();
266 #endif // CONFIGTASKWIDGET_H