1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-25 10:52:11 +01:00

260 lines
9.3 KiB
C
Raw Normal View History

2012-02-05 18:16:38 +00:00
/**
******************************************************************************
*
* @file configtaskwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
2012-02-05 20:07:19 +00:00
* @addtogroup UAVObjectWidgetUtils Plugin
2012-02-05 18:16:38 +00:00
* @{
2012-02-05 20:07:19 +00:00
* @brief Utility plugin for UAVObject to Widget relation management
2012-02-05 18:16:38 +00:00
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONFIGTASKWIDGET_H
#define CONFIGTASKWIDGET_H
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "uavobjectutilmanager.h"
#include <QQueue>
#include <QWidget>
2012-02-05 18:16:38 +00:00
#include <QList>
#include <QLabel>
#include "smartsavebutton.h"
#include "mixercurvewidget.h"
#include <QTableWidget>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QPushButton>
#include "uavobjectwidgetutils_global.h"
#include <QDesktopServices>
#include <QUrl>
#include <QEvent>
2012-02-05 18:16:38 +00:00
class ShadowWidgetBinding : public QObject {
2012-02-05 18:16:38 +00:00
Q_OBJECT
public:
2014-01-02 20:47:23 +01:00
ShadowWidgetBinding(QWidget *widget, double scale, bool isLimited);
~ShadowWidgetBinding();
QWidget *widget() const;
double scale() const;
bool isLimited() const;
protected:
QWidget *m_widget;
2014-01-02 20:47:23 +01:00
double m_scale;
bool m_isLimited;
};
2012-02-05 18:16:38 +00:00
class WidgetBinding : public ShadowWidgetBinding {
Q_OBJECT
2012-02-05 18:16:38 +00:00
public:
2014-01-02 20:47:23 +01:00
WidgetBinding(QWidget *widget, UAVObject *object, UAVObjectField *field, int index, double scale, bool isLimited);
~WidgetBinding();
2012-02-05 18:16:38 +00:00
QString units() const;
QString type() const;
bool isInteger() const;
2014-01-02 20:47:23 +01:00
UAVObject *object() const;
UAVObjectField *field() const;
2014-01-02 20:47:23 +01:00
int index() const;
QList<ShadowWidgetBinding *> shadows() const;
2014-01-02 20:47:23 +01:00
void addShadow(QWidget *widget, double scale, bool isLimited);
bool matches(QString objectName, QString fieldName, int index, quint32 instanceId);
bool isEnabled() const;
void setIsEnabled(bool isEnabled);
QVariant value() const;
void setValue(const QVariant &value);
void updateObjectFieldFromValue();
void updateValueFromObjectField();
private:
UAVObject *m_object;
UAVObjectField *m_field;
int m_index;
bool m_isEnabled;
QList<ShadowWidgetBinding *> m_shadows;
QVariant m_value;
};
class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget {
Q_OBJECT
public:
2012-02-05 18:16:38 +00:00
ConfigTaskWidget(QWidget *parent = 0);
virtual ~ConfigTaskWidget();
2012-02-05 18:16:38 +00:00
void disableMouseWheelEvents();
bool eventFilter(QObject *obj, QEvent *evt);
2012-02-05 18:16:38 +00:00
void saveObjectToSD(UAVObject *obj);
UAVObjectManager *getObjectManager();
2012-02-05 18:16:38 +00:00
void addUAVObject(QString objectName, QList<int> *reloadGroups = NULL);
void addUAVObject(UAVObject *objectName, QList<int> *reloadGroups = NULL);
void addWidget(QWidget *widget);
2012-02-05 18:16:38 +00:00
2014-01-02 20:47:23 +01:00
void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
2014-01-02 20:47:23 +01:00
void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, int index = 0, double scale = 1,
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
2014-01-02 20:47:23 +01:00
void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, QString elementName, double scale,
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
2014-01-02 20:47:23 +01:00
void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName, double scale,
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
2014-01-02 20:47:23 +01:00
void addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, QString elementName);
void addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName);
2012-02-05 18:16:38 +00:00
void addApplySaveButtons(QPushButton *update, QPushButton *save);
void addReloadButton(QPushButton *button, int buttonGroup);
void addDefaultButton(QPushButton *button, int buttonGroup);
2012-02-05 18:16:38 +00:00
void addWidgetToReloadGroups(QWidget *widget, QList<int> *reloadGroupIDs);
2012-02-05 18:16:38 +00:00
2014-01-02 20:47:23 +01:00
bool addShadowWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
bool isLimited = false, QList<int> *m_reloadGroups = NULL, quint32 instID = 0);
2012-02-05 18:16:38 +00:00
void autoLoadWidgets();
bool isDirty();
virtual void setDirty(bool value);
2012-02-05 18:16:38 +00:00
bool allObjectsUpdated();
void setOutOfLimitsStyle(QString style)
{
m_outOfLimitsStyle = style;
}
void addHelpButton(QPushButton *button, QString url);
void forceShadowUpdates();
void forceConnectedState();
2013-06-25 22:31:10 +02:00
virtual bool shouldObjectBeSaved(UAVObject *object);
2012-02-05 18:16:38 +00:00
public slots:
void onAutopilotDisconnect();
void onAutopilotConnect();
void invalidateObjects();
void apply();
void save();
void setWidgetBindingObjectEnabled(QString objectName, bool enabled);
2012-02-05 18:16:38 +00:00
signals:
// fired when a widgets contents changes
void widgetContentsChanged(QWidget *widget);
// fired when the framework requests that the widgets values be populated, use for custom behaviour
void populateWidgetsRequested();
// fired when the framework requests that the widgets values be refreshed, use for custom behaviour
void refreshWidgetsValuesRequested();
// fired when the framework requests that the UAVObject values be updated from the widgets value, use for custom behaviour
void updateObjectsFromWidgetsRequested();
// fired when the autopilot connects
void autoPilotConnected();
// fired when the autopilot disconnects
void autoPilotDisconnected();
void defaultRequested(int group);
void enableControlsChanged(bool enable);
2012-02-05 18:16:38 +00:00
private slots:
void objectUpdated(UAVObject *object);
2012-02-05 18:16:38 +00:00
void defaultButtonClicked();
void reloadButtonClicked();
2012-02-05 18:16:38 +00:00
private:
2014-01-01 23:17:31 +01:00
struct objectComparator {
quint32 objid;
quint32 objinstid;
bool operator==(const objectComparator & lhs)
{
return lhs.objid == this->objid && lhs.objinstid == this->objinstid;
}
};
enum buttonTypeEnum { none, save_button, apply_button, reload_button, default_button, help_button };
struct bindingStruct {
QString objectName;
QString fieldName;
QString elementName;
2014-01-18 00:32:50 +01:00
int index;
2014-01-01 23:17:31 +01:00
QString url;
buttonTypeEnum buttonType;
QList<int> buttonGroup;
double scale;
bool haslimits;
};
int m_currentBoardId;
bool m_isConnected;
bool m_isWidgetUpdatesAllowed;
QStringList m_objects;
QMultiHash<int, WidgetBinding *> m_reloadGroups;
QMultiHash<QWidget *, WidgetBinding *> m_widgetBindingsPerWidget;
QMultiHash<UAVObject *, WidgetBinding *> m_widgetBindingsPerObject;
ExtensionSystem::PluginManager *m_pluginManager;
UAVObjectUtilManager *m_objectUtilManager;
SmartSaveButton *m_saveButton;
QHash<UAVObject *, bool> m_updatedObjects;
QHash<QPushButton *, QString> m_helpButtons;
QList<QPushButton *> m_reloadButtons;
bool m_isDirty;
QString m_outOfLimitsStyle;
QTimer *m_realtimeUpdateTimer;
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, WidgetBinding *binding);
QVariant getVariantFromWidget(QWidget *widget, WidgetBinding *binding);
bool setWidgetFromVariant(QWidget *widget, QVariant value, WidgetBinding *binding);
2012-02-05 18:16:38 +00:00
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, double sclale);
2014-01-02 20:47:23 +01:00
int fieldIndexFromElementName(QString objectName, QString fieldName, QString elementName);
2014-01-06 12:56:30 +01:00
void doAddWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
2014-01-09 19:52:56 +01:00
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
2014-01-06 12:56:30 +01:00
2012-02-05 18:16:38 +00:00
protected slots:
virtual void disableObjectUpdates();
virtual void enableObjectUpdates();
2012-02-05 18:16:38 +00:00
virtual void clearDirty();
virtual void widgetsContentsChanged();
virtual void populateWidgets();
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
2012-02-05 18:16:38 +00:00
virtual void updateObjectsFromWidgets();
virtual void helpButtonPressed();
2012-02-05 18:16:38 +00:00
protected:
virtual void enableControls(bool enable);
virtual QString mapObjectName(const QString objectName);
virtual UAVObject *getObject(const QString name, quint32 instId = 0);
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
void updateEnableControls();
2012-02-05 18:16:38 +00:00
};
#endif // CONFIGTASKWIDGET_H