diff --git a/ground/openpilotgcs/src/plugins/config/camerastabilization.ui b/ground/openpilotgcs/src/plugins/config/camerastabilization.ui index e4e9dcefc..a394820e7 100644 --- a/ground/openpilotgcs/src/plugins/config/camerastabilization.ui +++ b/ground/openpilotgcs/src/plugins/config/camerastabilization.ui @@ -6,855 +6,808 @@ 0 0 - 820 - 845 + 720 + 739 - - Qt::DefaultContextMenu - Form - - false - - - - 12 - - - 12 - + - - - false + + + QFrame::NoFrame - - 0 + + true - - Qt::ElideMiddle - - - - false + + + + 0 + 0 + 702 + 660 + - - Camera Stabilization - - - - 12 - - - 0 - + - - - - - - - - 255 - 255 - 255 - - - - - - - 232 - 232 - 232 - - - - - - - - - 255 - 255 - 255 - - - - - - - 232 - 232 - 232 - - - - - - - - - 232 - 232 - 232 - - - - - - - 232 - 232 - 232 - - - - - + + + Qt::StrongFocus - - false + + Enable CameraStabilization module - - QFrame::NoFrame + + + + + + After enabling the module, you must power cycle before using and configuring. - - QFrame::Plain + + + + + + Qt::Horizontal - - true + + + + + + Qt::Vertical - - - - 0 - 0 - 790 - 678 - - - - true - - - - 12 - - - - - - - - - 12 - - - - - Qt::StrongFocus - - - Enable CameraStabilization module - - - - - - - After enabling you must power cycle your board before using and configuring - - - - - - - - - - - 0 - 0 - - - - - 0 - 131 - - - - Basic Settings (Stabilization) - - - false - - - - 12 - - - 12 - - - - - Qt::StrongFocus - - - Camera yaw angle for 100% output value, deg. + + QSizePolicy::Preferred + + + + 20 + 10 + + + + + + + + + 0 + 0 + + + + + 0 + 100 + + + + Basic Settings (Stabilization) + + + + + + Qt::StrongFocus + + + Camera yaw angle for 100% output value, deg. This value should be tuned for particular gimbal and servo. You also have to define channel output range using Output configuration tab. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Camera pitch angle for 100% output value, deg. + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:OutputRange + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Camera pitch angle for 100% output value, deg. This value should be tuned for particular gimbal and servo. You also have to define channel output range using Output configuration tab. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Camera roll angle for 100% output value, deg. + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:OutputRange + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Camera roll angle for 100% output value, deg. This value should be tuned for particular gimbal and servo. You also have to define channel output range using Output configuration tab. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Yaw output channel for camera gimbal - - - - None - - - - - - - - Qt::StrongFocus - - - Pitch output channel for camera gimbal - - - - None - - - - - - - - Qt::StrongFocus - - - Roll output channel for camera gimbal - - - - None - - - - - - - - Output Channel - - - - - - - Output Range - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:OutputRange + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Yaw output channel for camera gimbal + + + + None + + + + + + + + Qt::StrongFocus + + + Pitch output channel for camera gimbal + + + + None + + + + + + + + Qt::StrongFocus + + + Roll output channel for camera gimbal + + + + None + + + + + + + + Output Channel + + + + + + + Output Range + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Yaw - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + Yaw + + + Qt::AlignCenter + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Pitch - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + Pitch + + + Qt::AlignCenter + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Roll - - - Qt::AlignCenter - - - - - - - - - - true - - - Qt::Horizontal - - - - - - - Qt::Vertical - - - QSizePolicy::Preferred - - - - 20 - 10 - - - - - - - - - 0 - 0 - - - - - 0 - 266 - - - - Advanced Settings (Control) - - - - 12 - - - 12 - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + Roll + + + Qt::AlignCenter + + + + + + + + + + + 0 + 0 + + + + + 0 + 204 + + + + Advanced Settings (Control) + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Yaw - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + Yaw + + + Qt::AlignCenter + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Pitch - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); + + + Pitch + + + Qt::AlignCenter + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); border-radius: 5; font: bold 12px; margin:1px; - - - Roll - - - Qt::AlignCenter - - - - - - - Qt::StrongFocus - - - Input channel to control camera yaw + + + Roll + + + Qt::AlignCenter + + + + + + + Qt::StrongFocus + + + Input channel to control camera yaw Don't forget to map this channel using Input configuration tab. - - - - None - - - - - - - - Qt::StrongFocus - - - Input channel to control camera pitch + + + + objname:CameraStabSettings + fieldname:Input + element:Yaw + buttongroup:1 + + + + + None + + + + + + + + Qt::StrongFocus + + + Input channel to control camera pitch Don't forget to map this channel using Input configuration tab. - - - - None - - - - - - - - Qt::StrongFocus - - - Input channel to control camera roll + + + + objname:CameraStabSettings + fieldname:Input + element:Pitch + buttongroup:1 + + + + + None + + + + + + + + Qt::StrongFocus + + + Input channel to control camera roll Don't forget to map this channel using Input configuration tab. - - - - None - - - - - - - - Input Channel - - - - - - - Qt::StrongFocus - - - Axis stabilization mode + + + + objname:CameraStabSettings + fieldname:Input + element:Roll + buttongroup:1 + + + + + None + + + + + + + + Input Channel + + + + + + + Qt::StrongFocus + + + Axis stabilization mode Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. - - - - Attitude - - - - - - - - Qt::StrongFocus - - - Maximum camera yaw deflection for 100% input in Attitude mode, deg. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Maximum camera yaw rate for 100% input in AxisLock mode, deg/s. - - - 180 - - - 50 - - - - - - - Qt::StrongFocus - - - Input low-pass filter response time for yaw axis, ms. + + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Yaw + buttongroup:1 + + + + + Attitude + + + + + + + + Qt::StrongFocus + + + Maximum camera yaw deflection for 100% input in Attitude mode, deg. + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:InputRange + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Maximum camera yaw rate for 100% input in AxisLock mode, deg/s. + + + 180 + + + 50 + + + + objname:CameraStabSettings + fieldname:InputRate + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Input low-pass filter response time for yaw axis, ms. This option smoothes the stick input. Zero value disables LPF. - - - 1000 - - - 150 - - - - - - - Qt::StrongFocus - - - Axis stabilization mode + + + 1000 + + + 150 + + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Axis stabilization mode Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. - - - - Attitude - - - - - - - - Qt::StrongFocus - - - Maximum camera pitch deflection for 100% input in Attitude mode, deg. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Maximum camera pitch rate for 100% input in AxisLock mode, deg/s. - - - 180 - - - 50 - - - - - - - Qt::StrongFocus - - - Input low-pass filter response time for pitch axis, ms. + + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Pitch + buttongroup:1 + + + + + Attitude + + + + + + + + Qt::StrongFocus + + + Maximum camera pitch deflection for 100% input in Attitude mode, deg. + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:InputRange + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Maximum camera pitch rate for 100% input in AxisLock mode, deg/s. + + + 180 + + + 50 + + + + objname:CameraStabSettings + fieldname:InputRate + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Input low-pass filter response time for pitch axis, ms. This option smoothes the stick input. Zero value disables LPF. - - - 1000 - - - 150 - - - - - - - Qt::StrongFocus - - - Axis stabilization mode + + + 1000 + + + 150 + + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Axis stabilization mode Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. - - - - Attitude - - - - - - - - Qt::StrongFocus - - - Maximum camera roll deflection for 100% input in Attitude mode, deg. - - - 180 - - - 20 - - - - - - - Qt::StrongFocus - - - Maximum camera roll rate for 100% input in AxisLock mode, deg/s. - - - 180 - - - 50 - - - - - - - Qt::StrongFocus - - - Input low-pass filter response time for roll axis, ms. + + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Roll + buttongroup:1 + + + + + Attitude + + + + + + + + Qt::StrongFocus + + + Maximum camera roll deflection for 100% input in Attitude mode, deg. + + + 180 + + + 20 + + + + objname:CameraStabSettings + fieldname:InputRange + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Maximum camera roll rate for 100% input in AxisLock mode, deg/s. + + + 180 + + + 50 + + + + objname:CameraStabSettings + fieldname:InputRate + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + Qt::StrongFocus + + + Input low-pass filter response time for roll axis, ms. This option smoothes the stick input. Zero value disables LPF. - - - 1000 - - - 150 - - - - - - - MaxAxisLockRate - - - - - - - Response Time - - - - - - - Input Rate - - - - - - - Input Range - - - - - - - Stabilization Mode - - - - - - - (the same value for Roll, Pitch, Yaw) - - - - - - - Qt::StrongFocus - - - Stick input deadband for all axes in AxisLock mode, deg/s. + + + 1000 + + + 150 + + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + MaxAxisLockRate + + + + + + + Response Time + + + + + + + Input Rate + + + + + + + Input Range + + + + + + + Stabilization Mode + + + + + + + (the same value for Roll, Pitch, Yaw) + + + + + + + Qt::StrongFocus + + + Stick input deadband for all axes in AxisLock mode, deg/s. When stick input is within the MaxAxisLockRate range, camera tracks current attitude. Otherwise it starts moving according to input with @@ -862,222 +815,211 @@ rate depending on input value. If you have drift in your Tx controls, you may want to increase this value. - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + 1 + + + 0.100000000000000 + + + 1.000000000000000 + + + + objname:CameraStabSettings + fieldname:MaxAxisLockRate + haslimits:no + scale:1 + buttongroup:1 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + - - - false - - - Messages - - - - 9 - - - - - - - - - - - - - - - - 0 - 0 - - - - - 0 - 45 - - - - - - - - 4 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 456 - 20 - - - - - - - - - 0 - 0 - - - - - 32 - 26 - - - - - true - - - - - - - - :/core/images/helpicon.svg:/core/images/helpicon.svg - - - - 25 - 25 - - - - Ctrl+S - - - false - - - true - - - - button:help - url:http://wiki.openpilot.org/x/cACrAQ - - - - - - - - - 140 - 16 - - - - Load default CameraStabilization settings except output channels + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + true + + + + + + + + :/core/images/helpicon.svg:/core/images/helpicon.svg + + + + 32 + 32 + + + + Ctrl+S + + + false + + + true + + + + button:help + url:http://wiki.openpilot.org/display/Doc/Camera+Stabilization+Configuration + + + + + + + + Load default CameraStabilization settings except output channels into GCS. Loaded settings are not applied automatically. You have to click the Apply or Save button afterwards. - - - - - - Reset To Defaults - - - - - - - - 78 - 16 - - - - Send settings to the board but do not save to the non-volatile memory - - - - - - Apply - - - - - - - - 71 - 16 - - - - Send settings to the board and save to the non-volatile memory - - - - - - Save - - - false - - - - - + + + Reset To Defaults + + + + button:default + buttongroup:1 + + + + + + + + Reloads saved CameraStabilization settings except output channels +from board into GCS. Useful if you have accidentally changed some +settings. + +Loaded settings are not applied automatically. You have to click the +Apply or Save button afterwards. + + + Reload Board Data + + + + button:reload + buttongroup:1 + + + + + + + + Send settings to the board but do not save to the non-volatile memory + + + Apply + + + + button:apply + + + + + + + + Send settings to the board and save to the non-volatile memory + + + Save + + + false + + + + button:save + + + + + + + + enableCameraStabilization rollChannel pitchChannel yawChannel @@ -1100,7 +1042,7 @@ Apply or Save button afterwards. pitchResponseTime yawResponseTime MaxAxisLockRate - camerastabilizationResetToDefaults + camerastabilizationHelp camerastabilizationSaveRAM camerastabilizationSaveSD scrollArea diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp index a6874c0c4..9c4470a1d 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configcamerastabilizationwidget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011-2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup ConfigPlugin Config Plugin @@ -30,73 +30,51 @@ #include "mixersettings.h" #include "actuatorcommand.h" -#include -#include -#include -#include -#include - ConfigCameraStabilizationWidget::ConfigCameraStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent) { - // TODO: this widget should use the addUAVObjectToWidgetRelation() m_camerastabilization = new Ui_CameraStabilizationWidget(); m_camerastabilization->setupUi(this); - - ExtensionSystem::PluginManager *pm=ExtensionSystem::PluginManager::instance(); - Core::Internal::GeneralSettings * settings=pm->getObject(); - if(!settings->useExpertMode()) - m_camerastabilization->camerastabilizationSaveRAM->setVisible(false); - QComboBox *outputs[3] = { + // These widgets don't have direct relation to UAVObjects + // and need special processing + QComboBox *outputs[] = { m_camerastabilization->rollChannel, m_camerastabilization->pitchChannel, m_camerastabilization->yawChannel, }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); - QComboBox *inputs[3] = { - m_camerastabilization->rollInputChannel, - m_camerastabilization->pitchInputChannel, - m_camerastabilization->yawInputChannel, - }; - - QComboBox *stabilizationMode[3] = { - m_camerastabilization->rollStabilizationMode, - m_camerastabilization->pitchStabilizationMode, - m_camerastabilization->yawStabilizationMode, - }; - - CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStab->getData(); - - for (int i = 0; i < 3; i++) { + // Populate widgets with channel numbers + for (int i = 0; i < NUM_OUTPUTS; i++) { outputs[i]->clear(); outputs[i]->addItem("None"); for (quint32 j = 0; j < ActuatorCommand::CHANNEL_NUMELEM; j++) outputs[i]->addItem(QString("Channel %1").arg(j+1)); - - UAVObjectField *field; - - field = cameraStab->getField("Input"); - Q_ASSERT(field); - inputs[i]->clear(); - inputs[i]->addItems(field->getOptions()); - inputs[i]->setCurrentIndex(cameraStabData.Input[i]); - - field = cameraStab->getField("StabilizationMode"); - Q_ASSERT(field); - stabilizationMode[i]->clear(); - stabilizationMode[i]->addItems(field->getOptions()); - stabilizationMode[i]->setCurrentIndex(cameraStabData.StabilizationMode[i]); } - connectUpdates(); - - // Connect buttons - connect(m_camerastabilization->camerastabilizationResetToDefaults, SIGNAL(clicked()), this, SLOT(resetToDefaults())); - connect(m_camerastabilization->camerastabilizationSaveRAM, SIGNAL(clicked()), this, SLOT(applySettings())); - connect(m_camerastabilization->camerastabilizationSaveSD, SIGNAL(clicked()), this, SLOT(saveSettings())); + // Load UAVObjects to widget relations from UI file + // using objrelation dynamic property autoLoadWidgets(); + // Add some widgets to track their UI dirty state and handle smartsave + addWidget(m_camerastabilization->enableCameraStabilization); + addWidget(m_camerastabilization->rollChannel); + addWidget(m_camerastabilization->pitchChannel); + addWidget(m_camerastabilization->yawChannel); + + // Add some UAVObjects to monitor their changes in addition to autoloaded ones. + // Note also that we want to reload some UAVObjects by "Reload" button and have + // to pass corresponding reload group numbers (defined also in objrelation property) + // to the montitor. We don't reload HwSettings (module enable state) but reload + // output channels. + QList reloadGroups; + reloadGroups << 1; + addUAVObject("HwSettings"); + addUAVObject("MixerSettings", &reloadGroups); + + // To set special widgets to defaults when requested + connect(this, SIGNAL(defaultRequested(int)), this, SLOT(defaultRequestedSlot(int))); + disableMouseWheelEvents(); } @@ -105,52 +83,32 @@ ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget() // Do nothing } -void ConfigCameraStabilizationWidget::connectUpdates() +/* + * This overridden function refreshes widgets which have no direct relation + * to any of UAVObjects. It saves their dirty state first because update comes + * from UAVObjects, and then restores it. Aftewards it calls base class + * function to take care of other widgets which were dynamically added. + */ +void ConfigCameraStabilizationWidget::refreshWidgetsValues(UAVObject *obj) { - // Now connect the widget to the StabilizationSettings object - connect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - connect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - // TODO: This will need to support both CC and OP later - connect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); -} + bool dirty = isDirty(); -void ConfigCameraStabilizationWidget::disconnectUpdates() -{ - // Now connect the widget to the StabilizationSettings object - disconnect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - disconnect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - // TODO: This will need to support both CC and OP later - disconnect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); -} - -/** - * @brief Populate the gui settings into the appropriate - * UAV structures - */ -void ConfigCameraStabilizationWidget::applySettings() -{ - // Enable or disable the settings + // Set module enable checkbox from OptionalModules UAVObject item. + // It needs special processing because ConfigTaskWidget uses TRUE/FALSE + // for QCheckBox, but OptionalModules uses Enabled/Disabled enum values. HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); HwSettings::DataFields hwSettingsData = hwSettings->getData(); - hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] = - m_camerastabilization->enableCameraStabilization->isChecked() ? - HwSettings::OPTIONALMODULES_ENABLED : - HwSettings::OPTIONALMODULES_DISABLED; - // Update the mixer settings + m_camerastabilization->enableCameraStabilization->setChecked( + hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == HwSettings::OPTIONALMODULES_ENABLED); + + // Load mixer outputs which are mapped to camera controls MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); - const int NUM_MIXERS = 10; - - QComboBox *outputs[3] = { - m_camerastabilization->rollChannel, - m_camerastabilization->pitchChannel, - m_camerastabilization->yawChannel, - }; // TODO: Need to reformat object so types are an // array themselves. This gets really awkward - quint8 * mixerTypes[NUM_MIXERS] = { + quint8 *mixerTypes[] = { &mixerSettingsData.Mixer1Type, &mixerSettingsData.Mixer2Type, &mixerSettingsData.Mixer3Type, @@ -162,182 +120,140 @@ void ConfigCameraStabilizationWidget::applySettings() &mixerSettingsData.Mixer9Type, &mixerSettingsData.Mixer10Type, }; + const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]); - m_camerastabilization->message->setText(""); - for (int i = 0; i < 3; i++) - { - // Channel 1 is second entry, so becomes zero - int mixerNum = outputs[i]->currentIndex() - 1; - - if ( mixerNum >= 0 && // Short circuit in case of none - *mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_DISABLED && - (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_CAMERAROLL + i) ) { - // If the mixer channel already to something that isn't what we are - // about to set it to reset to none - outputs[i]->setCurrentIndex(0); - m_camerastabilization->message->setText("One of the channels is already assigned, reverted to none"); - } else { - // Make sure no other channels have this output set - for (int j = 0; j < NUM_MIXERS; j++) - if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i)) - *mixerTypes[j] = MixerSettings::MIXER1TYPE_DISABLED; - - // If this channel is assigned to one of the outputs that is not disabled - // set it - if(mixerNum >= 0 && mixerNum < NUM_MIXERS) - *mixerTypes[mixerNum] = MixerSettings::MIXER1TYPE_CAMERAROLL + i; - } - } - - // Update the settings - CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStab->getData(); - - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL] = m_camerastabilization->rollOutputRange->value(); - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH] = m_camerastabilization->pitchOutputRange->value(); - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW] = m_camerastabilization->yawOutputRange->value(); - - cameraStabData.Input[CameraStabSettings::INPUT_ROLL] = m_camerastabilization->rollInputChannel->currentIndex(); - cameraStabData.Input[CameraStabSettings::INPUT_PITCH] = m_camerastabilization->pitchInputChannel->currentIndex(); - cameraStabData.Input[CameraStabSettings::INPUT_YAW] = m_camerastabilization->yawInputChannel->currentIndex(); - - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL] = m_camerastabilization->rollStabilizationMode->currentIndex(); - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH] = m_camerastabilization->pitchStabilizationMode->currentIndex(); - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW] = m_camerastabilization->yawStabilizationMode->currentIndex(); - - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL] = m_camerastabilization->rollInputRange->value(); - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH] = m_camerastabilization->pitchInputRange->value(); - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW] = m_camerastabilization->yawInputRange->value(); - - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL] = m_camerastabilization->rollInputRate->value(); - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH] = m_camerastabilization->pitchInputRate->value(); - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW] = m_camerastabilization->yawInputRate->value(); - - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL] = m_camerastabilization->rollResponseTime->value(); - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH] = m_camerastabilization->pitchResponseTime->value(); - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW] = m_camerastabilization->yawResponseTime->value(); - - cameraStabData.MaxAxisLockRate = m_camerastabilization->MaxAxisLockRate->value(); - - // Because multiple objects are updated, and all of them trigger the callback - // they must be done together (if update one then load settings from second - // the first update would wipe the UI controls). However to be extra cautious - // I'm also disabling updates during the setting to the UAVObjects - disconnectUpdates(); - hwSettings->setData(hwSettingsData); - mixerSettings->setData(mixerSettingsData); - cameraStab->setData(cameraStabData); - connectUpdates(); -} - -/** - * Push settings into UAV objects then save them - */ -void ConfigCameraStabilizationWidget::saveSettings() -{ - applySettings(); - UAVObject *obj = HwSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); - obj = MixerSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); - obj = CameraStabSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); -} - -/** - * Refresh UI with new settings of CameraStabSettings object - * (either from active configuration or just loaded defaults - * to be applied or saved) - */ -void ConfigCameraStabilizationWidget::refreshUIValues(CameraStabSettings::DataFields &cameraStabData) -{ - m_camerastabilization->rollOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL]); - m_camerastabilization->pitchOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH]); - m_camerastabilization->yawOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW]); - - m_camerastabilization->rollInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_ROLL]); - m_camerastabilization->pitchInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_PITCH]); - m_camerastabilization->yawInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_YAW]); - - m_camerastabilization->rollStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL]); - m_camerastabilization->pitchStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH]); - m_camerastabilization->yawStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW]); - - m_camerastabilization->rollInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL]); - m_camerastabilization->pitchInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH]); - m_camerastabilization->yawInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW]); - - m_camerastabilization->rollInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL]); - m_camerastabilization->pitchInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH]); - m_camerastabilization->yawInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW]); - - m_camerastabilization->rollResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL]); - m_camerastabilization->pitchResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH]); - m_camerastabilization->yawResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW]); - - m_camerastabilization->MaxAxisLockRate->setValue(cameraStabData.MaxAxisLockRate); -} - -void ConfigCameraStabilizationWidget::refreshValues() -{ - HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); - HwSettings::DataFields hwSettingsData = hwSettings->getData(); - m_camerastabilization->enableCameraStabilization->setChecked( - hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == - HwSettings::OPTIONALMODULES_ENABLED); - - CameraStabSettings *cameraStabSettings = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStabSettings->getData(); - refreshUIValues(cameraStabData); - - MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); - MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); - const int NUM_MIXERS = 10; - QComboBox *outputs[3] = { + QComboBox *outputs[] = { m_camerastabilization->rollChannel, m_camerastabilization->pitchChannel, m_camerastabilization->yawChannel }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); - // TODO: Need to reformat object so types are an - // array themselves. This gets really awkward - quint8 * mixerTypes[NUM_MIXERS] = { - &mixerSettingsData.Mixer1Type, - &mixerSettingsData.Mixer2Type, - &mixerSettingsData.Mixer3Type, - &mixerSettingsData.Mixer4Type, - &mixerSettingsData.Mixer5Type, - &mixerSettingsData.Mixer6Type, - &mixerSettingsData.Mixer7Type, - &mixerSettingsData.Mixer8Type, - &mixerSettingsData.Mixer9Type, - &mixerSettingsData.Mixer10Type, - }; - - for (int i = 0; i < 3; i++) - { - // Default to none if not found. Then search for any mixer channels set to - // this + for (int i = 0; i < NUM_OUTPUTS; i++) { + // Default to none if not found. + // Then search for any mixer channels set to this outputs[i]->setCurrentIndex(0); for (int j = 0; j < NUM_MIXERS; j++) if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i) && outputs[i]->currentIndex() != (j + 1)) outputs[i]->setCurrentIndex(j + 1); } + + setDirty(dirty); + + ConfigTaskWidget::refreshWidgetsValues(obj); } -void ConfigCameraStabilizationWidget::resetToDefaults() +/* + * This overridden function updates UAVObjects which have no direct relation + * to any of widgets. Aftewards it calls base class function to take care of + * other object to widget relations which were dynamically added. + */ +void ConfigCameraStabilizationWidget::updateObjectsFromWidgets() { - CameraStabSettings cameraStabDefaults; - CameraStabSettings::DataFields defaults = cameraStabDefaults.getData(); - refreshUIValues(defaults); + // Save state of the module enable checkbox first + HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); + quint8 value = m_camerastabilization->enableCameraStabilization->isChecked() ? + HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED; + hwSettings->setOptionalModules(HwSettings::OPTIONALMODULES_CAMERASTAB,value); + + // Update mixer channels which were mapped to camera outputs in case they are + // not used for other function yet + MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); + MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); + + // TODO: Need to reformat object so types are an + // array themselves. This gets really awkward + quint8 *mixerTypes[] = { + &mixerSettingsData.Mixer1Type, + &mixerSettingsData.Mixer2Type, + &mixerSettingsData.Mixer3Type, + &mixerSettingsData.Mixer4Type, + &mixerSettingsData.Mixer5Type, + &mixerSettingsData.Mixer6Type, + &mixerSettingsData.Mixer7Type, + &mixerSettingsData.Mixer8Type, + &mixerSettingsData.Mixer9Type, + &mixerSettingsData.Mixer10Type, + }; + const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]); + + QComboBox *outputs[] = { + m_camerastabilization->rollChannel, + m_camerastabilization->pitchChannel, + m_camerastabilization->yawChannel + }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); + + m_camerastabilization->message->setText(""); + bool widgetUpdated; + do { + widgetUpdated = false; + + for (int i = 0; i < NUM_OUTPUTS; i++) { + // Channel 1 is second entry, so becomes zero + int mixerNum = outputs[i]->currentIndex() - 1; + + if ((mixerNum >= 0) && // Short circuit in case of none + (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_DISABLED) && + (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_CAMERAROLL + i) ) { + // If the mixer channel already mapped to something, it should not be + // used for camera output, we reset it to none + outputs[i]->setCurrentIndex(0); + m_camerastabilization->message->setText("One of the channels is already assigned, reverted to none"); + + // Loop again or we may have inconsistent widget and UAVObject + widgetUpdated = true; + } else { + // Make sure no other channels have this output set + for (int j = 0; j < NUM_MIXERS; j++) + if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i)) + *mixerTypes[j] = MixerSettings::MIXER1TYPE_DISABLED; + + // If this channel is assigned to one of the outputs that is not disabled + // set it + if ((mixerNum >= 0) && (mixerNum < NUM_MIXERS)) + *mixerTypes[mixerNum] = MixerSettings::MIXER1TYPE_CAMERAROLL + i; + } + } + } while(widgetUpdated); + + mixerSettings->setData(mixerSettingsData); + + ConfigTaskWidget::updateObjectsFromWidgets(); } -void ConfigCameraStabilizationWidget::enableControls(bool enable) +/* + * This slot function is called when "Default" button is clicked. + * All special widgets which belong to the group passed should be set here. + */ +void ConfigCameraStabilizationWidget::defaultRequestedSlot(int group) { - m_camerastabilization->camerastabilizationResetToDefaults->setEnabled(enable); - m_camerastabilization->camerastabilizationSaveSD->setEnabled(enable); - m_camerastabilization->camerastabilizationSaveRAM->setEnabled(enable); + Q_UNUSED(group); + + // Here is the example of how to reset the state of QCheckBox. It is + // commented out because we normally don't want to reset the module + // enable state to default "disabled" (or we don't care about values at all). + // But if you want, you could use the dirtyClone() function to get default + // values of an object and then use them to set a widget state. + // + //HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); + //HwSettings *hwSettingsDefault=(HwSettings*)hwSettings->dirtyClone(); + //HwSettings::DataFields hwSettingsData = hwSettingsDefault->getData(); + //m_camerastabilization->enableCameraStabilization->setChecked( + // hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == HwSettings::OPTIONALMODULES_ENABLED); + + // For outputs we set them all to none, so don't use any UAVObject to get defaults + QComboBox *outputs[] = { + m_camerastabilization->rollChannel, + m_camerastabilization->pitchChannel, + m_camerastabilization->yawChannel, + }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); + + for (int i = 0; i < NUM_OUTPUTS; i++) { + outputs[i]->setCurrentIndex(0); + } } /** diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h index 8e1305268..871193e82 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h @@ -41,20 +41,14 @@ class ConfigCameraStabilizationWidget: public ConfigTaskWidget public: ConfigCameraStabilizationWidget(QWidget *parent = 0); ~ConfigCameraStabilizationWidget(); + private: Ui_CameraStabilizationWidget *m_camerastabilization; - virtual void enableControls(bool enable); - void refreshUIValues(CameraStabSettings::DataFields &cameraStabData); + void refreshWidgetsValues(UAVObject *obj); + void updateObjectsFromWidgets(); private slots: - void resetToDefaults(); - void applySettings(); - void saveSettings(); - void refreshValues(); - -protected: - void connectUpdates(); - void disconnectUpdates(); + void defaultRequestedSlot(int group); }; #endif // CONFIGCAMERASTABILIZATIONWIDGET_H diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp index ac3543806..0e5c6ddcf 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp @@ -58,9 +58,18 @@ void ConfigTaskWidget::addWidget(QWidget * widget) * Add an object to the management system * @param objectName name of the object to add to the management system */ -void ConfigTaskWidget::addUAVObject(QString objectName) +void ConfigTaskWidget::addUAVObject(QString objectName,QList * reloadGroups) { - addUAVObjectToWidgetRelation(objectName,"",NULL); + addUAVObjectToWidgetRelation(objectName,"",NULL,0,1,false,reloadGroups); +} + +void ConfigTaskWidget::addUAVObject(UAVObject *objectName, QList *reloadGroups) +{ + QString objstr; + if(objectName) + objstr=objectName->getName(); + addUAVObject(objstr, reloadGroups); + } /** * Add an UAVObject field to widget relation to the management system @@ -79,6 +88,17 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel Q_ASSERT(_field); addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index)); } + +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, QString index) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr, fieldstr, widget, index); +} /** * Add a UAVObject field to widget relation to the management system * @param object name of the object to add @@ -104,6 +124,28 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel } addUAVObjectToWidgetRelation(object, field, widget,index,scale,isLimited,defaultReloadGroups,instID); } + +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField *field, QWidget *widget, QString element, double scale, bool isLimited, QList *defaultReloadGroups, quint32 instID) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr, fieldstr, widget, element, scale, isLimited, defaultReloadGroups, instID); +} +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject * obj,UAVObjectField * field, QWidget * widget, int index,double scale,bool isLimited,QList* defaultReloadGroups, quint32 instID) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr,fieldstr,widget,index,scale,isLimited,defaultReloadGroups,instID); +} + /** * Add an UAVObject field to widget relation to the management system * @param object name of the object to add @@ -149,7 +191,21 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel } if(widget==NULL) { - // do nothing + if(defaultReloadGroups && obj) + { + foreach(int i,*defaultReloadGroups) + { + if(this->defaultReloadGroups.contains(i)) + { + this->defaultReloadGroups.value(i)->append(ow); + } + else + { + this->defaultReloadGroups.insert(i,new QList()); + this->defaultReloadGroups.value(i)->append(ow); + } + } + } } else { @@ -177,10 +233,6 @@ ConfigTaskWidget::~ConfigTaskWidget() if(oTw) delete oTw; } - if(timeOut) - { - delete timeOut; - } } void ConfigTaskWidget::saveObjectToSD(UAVObject *obj) @@ -225,7 +277,7 @@ void ConfigTaskWidget::onAutopilotDisconnect() invalidateObjects(); } -void ConfigTaskWidget::forceConnectedState() +void ConfigTaskWidget::forceConnectedState()//dynamic widgets don't recieve the connected signal. This should be called instead. { isConnected=true; setDirty(false); @@ -554,7 +606,7 @@ bool ConfigTaskWidget::addShadowWidget(QString object, QString field, QWidget *w { foreach(objectToWidget * oTw,objOfInterest) { - if(!oTw->object || !oTw->widget) + if(!oTw->object || !oTw->widget || !oTw->field) continue; if(oTw->object->getName()==object && oTw->field->getName()==field && oTw->index==index && oTw->object->getInstID()==instID) { @@ -711,10 +763,12 @@ void ConfigTaskWidget::autoLoadWidgets() forceShadowUpdates(); foreach(objectToWidget * ow,objOfInterest) { - qDebug()<<"Master:"<widget->objectName(); + if(ow->widget) + qDebug()<<"Master:"<widget->objectName(); foreach(shadow * sh,ow->shadowsList) { - qDebug()<<"Child"<widget->objectName(); + if(sh->widget) + qDebug()<<"Child"<widget->objectName(); } } } @@ -783,10 +837,11 @@ void ConfigTaskWidget::addReloadButton(QPushButton *button, int buttonGroup) void ConfigTaskWidget::defaultButtonClicked() { int group=sender()->property("group").toInt(); + emit defaultRequested(group); QList * list=defaultReloadGroups.value(group); foreach(objectToWidget * oTw,*list) { - if(!oTw->object) + if(!oTw->object || !oTw->field) continue; UAVDataObject * temp=((UAVDataObject*)oTw->object)->dirtyClone(); setWidgetFromField(oTw->widget,temp->getField(oTw->field->getName()),oTw->index,oTw->scale,oTw->isLimited); @@ -797,9 +852,8 @@ void ConfigTaskWidget::defaultButtonClicked() */ void ConfigTaskWidget::reloadButtonClicked() { - QPushButton * button=qobject_cast(sender()); - if(button) - button->setEnabled(false); + if(timeOut) + return; int group=sender()->property("group").toInt(); QList * list=defaultReloadGroups.value(group,NULL); if(!list) @@ -834,7 +888,8 @@ void ConfigTaskWidget::reloadButtonClicked() if(timeOut->isActive()) { oTw->object->requestUpdate(); - setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited); + if(oTw->widget) + setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited); } timeOut->stop(); } @@ -849,8 +904,6 @@ void ConfigTaskWidget::reloadButtonClicked() delete timeOut; timeOut=NULL; } - if(button) - button->setEnabled(true); } /** diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index 778d7fa9c..b0364ae53 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -103,12 +103,19 @@ public: UAVObjectManager* getObjectManager(); static double listMean(QList list); - void addUAVObject(QString objectName); + void addUAVObject(QString objectName, QList *reloadGroups=NULL); + void addUAVObject(UAVObject * objectName, QList *reloadGroups=NULL); + void addWidget(QWidget * widget); void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,double scale=1,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, int index=0, double scale=1, bool isLimited=false, QList *defaultReloadGroups=0, quint32 instID=0); + void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,QString element,double scale,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field,QWidget * widget,QString element,double scale,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, QString index); //BUTTONS// void addApplySaveButtons(QPushButton * update,QPushButton * save); @@ -150,6 +157,7 @@ signals: void autoPilotConnected(); //fired when the autopilot disconnects void autoPilotDisconnected(); + void defaultRequested(int group); private slots: void objectUpdated(UAVObject*); void defaultButtonClicked(); diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp index 42a6d5e62..5bc29994b 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp @@ -162,6 +162,7 @@ void smartSaveButton::setObjects(QList list) void smartSaveButton::addObject(UAVDataObject * obj) { + Q_ASSERT(obj); if(!objects.contains(obj)) objects.append(obj); }