2 ******************************************************************************
4 * @file configtaskwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup UAVObjectWidgetUtils Plugin
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
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 "uavobjectwidgetutils_global.h"
36 namespace ExtensionSystem
{
41 class UAVObjectManager
;
42 class UAVObjectUtilManager
;
43 class SmartSaveButton
;
49 class ShadowWidgetBinding
: public QObject
{
52 ShadowWidgetBinding(QWidget
*widget
, double scale
, bool isLimited
);
53 ~ShadowWidgetBinding();
54 QWidget
*widget() const;
56 bool isLimited() const;
64 class WidgetBinding
: public ShadowWidgetBinding
{
67 WidgetBinding(QWidget
*widget
, UAVObject
*object
, UAVObjectField
*field
, int index
, double scale
, bool isLimited
);
70 QString
units() const;
72 bool isInteger() const;
73 UAVObject
*object() const;
74 UAVObjectField
*field() const;
76 QList
<ShadowWidgetBinding
*> shadows() const;
78 void addShadow(QWidget
*widget
, double scale
, bool isLimited
);
79 bool matches(QString objectName
, QString fieldName
, int index
, quint32 instanceId
);
81 bool isEnabled() const;
82 void setIsEnabled(bool isEnabled
);
84 QVariant
value() const;
85 void setValue(const QVariant
&value
);
87 void updateObjectFieldFromValue();
88 void updateValueFromObjectField();
92 UAVObjectField
*m_field
;
95 QList
<ShadowWidgetBinding
*> m_shadows
;
99 class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget
: public QWidget
{
103 enum ConfigTaskType
{ AutoPilot
, OPLink
, Child
};
105 ConfigTaskWidget(QWidget
*parent
= 0, ConfigTaskType configType
= AutoPilot
);
106 virtual ~ConfigTaskWidget();
111 void setDirty(bool value
);
114 virtual bool shouldObjectBeSaved(UAVObject
*object
);
117 // Combobox helper functions
118 static bool isComboboxOptionSelected(QComboBox
*combo
, int optionValue
);
119 static int getComboboxSelectedOption(QComboBox
*combo
);
120 static void setComboboxSelectedOption(QComboBox
*combo
, int optionValue
);
121 static int getComboboxIndexForOption(QComboBox
*combo
, int optionValue
);
122 static void enableComboBoxOptionItem(QComboBox
*combo
, int optionValue
, bool enable
);
124 void disableMouseWheelEvents();
125 bool eventFilter(QObject
*obj
, QEvent
*evt
);
127 UAVObjectManager
*getObjectManager();
129 void addUAVObject(QString objectName
, QList
<int> *reloadGroups
= NULL
);
130 void addUAVObject(UAVObject
*objectName
, QList
<int> *reloadGroups
= NULL
);
132 // TODO should be protected (see VehicleConfig::registerWidgets(ConfigTaskWidget &parent)
134 void addWidget(QWidget
*widget
);
136 void addWidgetBinding(QString objectName
, QString fieldName
, QWidget
*widget
, int index
= 0, double scale
= 1,
137 bool isLimited
= false, QList
<int> *reloadGroupIDs
= 0, quint32 instID
= 0);
138 void addWidgetBinding(UAVObject
*object
, UAVObjectField
*field
, QWidget
*widget
, int index
= 0, double scale
= 1,
139 bool isLimited
= false, QList
<int> *reloadGroupIDs
= 0, quint32 instID
= 0);
142 void addAutoBindings();
144 void addWidgetBinding(QString objectName
, QString fieldName
, QWidget
*widget
, QString elementName
, double scale
,
145 bool isLimited
= false, QList
<int> *reloadGroupIDs
= 0, quint32 instID
= 0);
146 void addWidgetBinding(UAVObject
*object
, UAVObjectField
*field
, QWidget
*widget
, QString elementName
, double scale
,
147 bool isLimited
= false, QList
<int> *reloadGroupIDs
= 0, quint32 instID
= 0);
149 void addWidgetBinding(QString objectName
, QString fieldName
, QWidget
*widget
, QString elementName
);
150 void addWidgetBinding(UAVObject
*object
, UAVObjectField
*field
, QWidget
*widget
, QString elementName
);
152 void addWidgetToReloadGroups(QWidget
*widget
, QList
<int> *reloadGroupIDs
);
154 bool addShadowWidgetBinding(QString objectName
, QString fieldName
, QWidget
*widget
, int index
= 0, double scale
= 1,
155 bool isLimited
= false, QList
<int> *m_reloadGroups
= NULL
, quint32 instID
= 0);
157 bool allObjectsUpdated();
158 void setOutOfLimitsStyle(QString style
)
160 m_outOfLimitsStyle
= style
;
162 void addHelpButton(QPushButton
*button
, QString url
);
163 void setWikiURL(QString url
);
172 void widgetContentsChanged(QWidget
*widget
);
173 void defaultRequested(int group
);
174 void enableControlsChanged(bool enable
);
177 int boardModel() const
179 return m_currentBoardId
;
181 bool expertMode() const;
182 virtual QString
mapObjectName(const QString objectName
);
183 virtual UAVObject
*getObject(const QString name
, quint32 instId
= 0);
184 virtual void buildOptionComboBox(QComboBox
*combo
, UAVObjectField
*field
, int index
, bool applyLimits
);
186 virtual void enableControls(bool enable
);
187 virtual void refreshWidgetsValuesImpl(UAVObject
*) {};
188 virtual void updateObjectsFromWidgetsImpl() {};
190 bool isConnected() const;
191 void updateEnableControls();
194 void setWidgetBindingObjectEnabled(QString objectName
, bool enabled
);
196 virtual void widgetsContentsChanged();
197 void refreshWidgetsValues(UAVObject
*obj
= NULL
);
198 void updateObjectsFromWidgets();
204 void disableObjectUpdates();
205 void enableObjectUpdates();
206 void objectUpdated(UAVObject
*object
);
207 void invalidateObjects();
209 void saveSuccessful();
211 void defaultButtonClicked();
212 void reloadButtonClicked();
213 void helpButtonPressed();
216 struct ObjectComparator
{
219 bool operator==(const ObjectComparator
& lhs
)
221 return lhs
.objid
== this->objid
&& lhs
.objinstid
== this->objinstid
;
225 enum ButtonTypeEnum
{ None
, SaveButton
, ApplyButton
, ReloadButton
, DefaultButton
, HelpButton
};
226 struct BindingStruct
{
232 ButtonTypeEnum buttonType
;
233 QList
<int> buttonGroup
;
238 // indicates if this is an "autopilot" widget (CC3D, Revolution, ...), an OPLink widget or a Child widget (for vehicle config)
239 // TODO the logic that this flag controls should be moved to derived classes
240 ConfigTaskType m_configType
;
242 // only valid for "autopilot" widgets
243 int m_currentBoardId
;
246 bool m_isWidgetUpdatesAllowed
;
250 QStringList m_objects
;
252 // Wiki address for help button (will be concatenated with WIKI_URL_ROOT)
255 QMultiHash
<int, WidgetBinding
*> m_reloadGroups
;
256 QMultiHash
<QWidget
*, WidgetBinding
*> m_widgetBindingsPerWidget
;
257 QMultiHash
<UAVObject
*, WidgetBinding
*> m_widgetBindingsPerObject
;
259 ExtensionSystem::PluginManager
*m_pluginManager
;
260 UAVObjectUtilManager
*m_objectUtilManager
;
262 QHash
<UAVObject
*, bool> m_updatedObjects
;
264 SmartSaveButton
*m_saveButton
;
265 QHash
<QPushButton
*, QString
> m_helpButtons
;
266 QList
<QPushButton
*> m_reloadButtons
;
268 QString m_outOfLimitsStyle
;
269 QTimer
*m_realtimeUpdateTimer
;
271 bool setWidgetFromField(QWidget
*widget
, UAVObjectField
*field
, WidgetBinding
*binding
);
273 QVariant
getVariantFromWidget(QWidget
*widget
, WidgetBinding
*binding
);
274 bool setWidgetFromVariant(QWidget
*widget
, QVariant value
, WidgetBinding
*binding
);
276 void connectWidgetUpdatesToSlot(QWidget
*widget
, const char *function
);
277 void disconnectWidgetUpdatesToSlot(QWidget
*widget
, const char *function
);
281 void loadWidgetLimits(QWidget
*widget
, UAVObjectField
*field
, int index
, bool applyLimits
, double scale
);
283 void checkWidgetsLimits(QWidget
*widget
, UAVObjectField
*field
, int index
, bool hasLimits
, QVariant value
, double scale
);
287 int fieldIndexFromElementName(QString objectName
, QString fieldName
, QString elementName
);
289 void doAddWidgetBinding(QString objectName
, QString fieldName
, QWidget
*widget
, int index
= 0, double scale
= 1,
290 bool isLimited
= false, QList
<int> *reloadGroupIDs
= 0, quint32 instID
= 0);
292 void addApplyButton(QPushButton
*button
);
293 void addSaveButton(QPushButton
*button
);
294 void addReloadButton(QPushButton
*button
, int buttonGroup
);
295 void addDefaultButton(QPushButton
*button
, int buttonGroup
);
298 #endif // CONFIGTASKWIDGET_H