From 088197ac695d014f6cad3f1c4d4416a82be86646 Mon Sep 17 00:00:00 2001 From: m_thread Date: Thu, 9 Jan 2014 13:02:03 +0100 Subject: [PATCH] OP-984 Added backing store for values when switching between uavos. --- .../config/configstabilizationwidget.cpp | 12 +++- .../config/configstabilizationwidget.h | 3 +- .../src/plugins/coreplugin/coreplugin.pro | 1 - .../uavobjectwidgetutils/configtaskwidget.cpp | 57 +++++++++++-------- .../uavobjectwidgetutils/configtaskwidget.h | 10 +++- 5 files changed, 50 insertions(+), 33 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp index 50cf64115..43f0e9470 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp @@ -41,19 +41,25 @@ #include #include #include "altitudeholdsettings.h" +#include "stabilizationsettings.h" ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent), - boardModel(0), m_currentPIDBank(0) + boardModel(0), m_pidBankCount(0), m_currentPIDBank(0) { ui = new Ui_StabilizationWidget(); ui->setupUi(this); + StabilizationSettings* stabSettings = qobject_cast(getObject("StabilizationSettings")); + Q_ASSERT(stabSettings); + + m_pidBankCount = stabSettings->getField("FlightModeMap")->getOptions().count(); + // Set up fake tab widget stuff for pid banks support m_pidTabBars.append(ui->basicPIDBankTabBar); m_pidTabBars.append(ui->advancedPIDBankTabBar); m_pidTabBars.append(ui->expertPIDBankTabBar); foreach(QTabBar * tabBar, m_pidTabBars) { - for (int i = 0; i < PID_BANKS; i++) { + for (int i = 0; i < m_pidBankCount; i++) { tabBar->addTab(tr("PID Bank %1").arg(i + 1)); tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1)); } @@ -61,7 +67,7 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int))); } - for (int i = 0; i < PID_BANKS; i++) { + for (int i = 0; i < m_pidBankCount; i++) { if(i > 0) { m_stabilizationObjectsString.append(","); } diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h index f5331137b..67c7e246a 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h @@ -54,8 +54,7 @@ private: // Milliseconds between automatic 'Instant Updates' static const int AUTOMATIC_UPDATE_RATE = 500; - static const int PID_BANKS = 3; - + int m_pidBankCount; int boardModel; int m_currentPIDBank; protected: diff --git a/ground/openpilotgcs/src/plugins/coreplugin/coreplugin.pro b/ground/openpilotgcs/src/plugins/coreplugin/coreplugin.pro index 40fb468ea..5c4269c69 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/coreplugin.pro +++ b/ground/openpilotgcs/src/plugins/coreplugin/coreplugin.pro @@ -129,7 +129,6 @@ HEADERS += mainwindow.h \ uavgadgetdecorator.h \ workspacesettings.h \ uavconfiginfo.h \ - authorsdialog.h \ iconfigurableplugin.h \ aboutdialog.h diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp index 69a31f45d..ab619581c 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp @@ -278,7 +278,7 @@ void ConfigTaskWidget::onAutopilotConnect() void ConfigTaskWidget::populateWidgets() { - bool dirtyBack = m_isDirty; + bool dirtyBack = isDirty(); emit populateWidgetsRequested(); foreach(WidgetBinding * binding, m_widgetBindingsPerObject) { @@ -295,7 +295,7 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj) return; } - bool dirtyBack = m_isDirty; + bool dirtyBack = isDirty(); emit refreshWidgetsValuesRequested(); foreach(WidgetBinding * binding, m_widgetBindingsPerObject.values(obj)) { if (binding->isEnabled() && binding->field() != NULL && binding->widget() != NULL) { @@ -310,8 +310,9 @@ void ConfigTaskWidget::updateObjectsFromWidgets() emit updateObjectsFromWidgetsRequested(); foreach(WidgetBinding * binding, m_widgetBindingsPerObject) { - if (binding->isEnabled() && binding->object() != NULL && binding->field() != NULL) { - setFieldFromWidget(binding->widget(), binding->field(), binding->index(), binding->scale()); + if (binding->object() != NULL && binding->field() != NULL) { + binding->updateObjectFieldFromValue(); + //setFieldFromWidget(binding->widget(), binding->field(), binding->index(), binding->scale()); } } } @@ -399,6 +400,7 @@ void ConfigTaskWidget::widgetsContentsChanged() QWidget *emitter = ((QWidget *)sender()); emit widgetContentsChanged(emitter); double scale; + QVariant value; foreach(WidgetBinding *binding ,m_widgetBindingsPerWidget.values(emitter)) { if (binding && binding->isEnabled()) { @@ -415,12 +417,15 @@ void ConfigTaskWidget::widgetsContentsChanged() } } } + value = getVariantFromWidget(emitter, scale, binding->units()); + binding->setValue(value); + if (binding->widget() != emitter) { disconnectWidgetUpdatesToSlot(binding->widget(), SLOT(widgetsContentsChanged())); checkWidgetsLimits(binding->widget(), binding->field(), binding->index(), binding->isLimited(), - getVariantFromWidget(emitter, scale, binding->units()), binding->scale()); - setWidgetFromVariant(binding->widget(), getVariantFromWidget(emitter, scale, binding->units()), binding->scale()); + value, binding->scale()); + setWidgetFromVariant(binding->widget(), value, binding->scale()); emit widgetContentsChanged(binding->widget()); connectWidgetUpdatesToSlot(binding->widget(), SLOT(widgetsContentsChanged())); @@ -430,8 +435,8 @@ void ConfigTaskWidget::widgetsContentsChanged() disconnectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged())); checkWidgetsLimits(shadow->widget(), binding->field(), binding->index(), shadow->isLimited(), - getVariantFromWidget(emitter, scale, binding->units()), shadow->scale()); - setWidgetFromVariant(shadow->widget(), getVariantFromWidget(emitter, scale, binding->units()), shadow->scale()); + value, shadow->scale()); + setWidgetFromVariant(shadow->widget(), value, shadow->scale()); emit widgetContentsChanged(shadow->widget()); connectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged())); @@ -828,22 +833,6 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char } } -bool ConfigTaskWidget::setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale) -{ - if (!widget || !field) { - return false; - } - QVariant ret = getVariantFromWidget(widget, scale, field->getUnits()); - if (ret.isValid()) { - field->setValue(ret, index); - return true; - } - { - qDebug() << __FUNCTION__ << "widget to uavobject relation not implemented" << widget->metaObject()->className(); - return false; - } -} - QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, QString units) { if (QComboBox * cb = qobject_cast(widget)) { @@ -1139,6 +1128,7 @@ bool WidgetBinding::matches(QString objectName, QString fieldName, int index, qu return false; } } + bool WidgetBinding::isEnabled() const { return m_isEnabled; @@ -1149,6 +1139,25 @@ void WidgetBinding::setIsEnabled(bool isEnabled) m_isEnabled = isEnabled; } +QVariant WidgetBinding::value() const +{ + return m_value; +} + +void WidgetBinding::setValue(const QVariant &value) +{ + m_value = value; + if(m_object && m_field) { + qDebug() << "WidgetBinding" << m_object->getName() << ":" << m_field->getName() << "value =" << value.toString(); + } +} + +void WidgetBinding::updateObjectFieldFromValue() +{ + if (m_value.isValid()) { + m_field->setValue(m_value, m_index); + } +} ShadowWidgetBinding::ShadowWidgetBinding(QWidget *widget, double scale, bool isLimited) { diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index 5707eeaf9..408da0e7d 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -80,12 +80,18 @@ public: bool isEnabled() const; void setIsEnabled(bool isEnabled); + QVariant value() const; + void setValue(const QVariant &value); + + void updateObjectFieldFromValue(); + private: UAVObject *m_object; UAVObjectField *m_field; int m_index; bool m_isEnabled; QList m_shadows; + QVariant m_value; }; class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget { @@ -214,7 +220,6 @@ private: QString m_outOfLimitsStyle; QTimer *m_realtimeUpdateTimer; - bool setFieldFromWidget(QWidget *widget, UAVObjectField *field, int index, double scale); bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits); QVariant getVariantFromWidget(QWidget *widget, double scale, const QString units); @@ -225,7 +230,6 @@ private: void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function); void loadWidgetLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, double sclale); - virtual UAVObject *getObject(const QString name, quint32 instId = 0); int fieldIndexFromElementName(QString objectName, QString fieldName, QString elementName); @@ -245,7 +249,7 @@ protected slots: 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(); };