1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

LP-245 config: consolidate widget refresh logic in base class

remove error prone duplication of dirty flag handling in derived classes
side effect is that some derived classes now get behavior that they used to override
This commit is contained in:
Philippe Renon 2016-09-02 22:27:49 +02:00
parent c9d7761f0e
commit 6c210e4ef0
23 changed files with 87 additions and 130 deletions

View File

@ -190,6 +190,7 @@ void ConfigCustomWidget::registerWidgets(ConfigTaskWidget &parent)
parent.addWidget(m_aircraft->customThrottle1Curve);
parent.addWidget(m_aircraft->customThrottle2Curve->getCurveWidget());
parent.addWidget(m_aircraft->customThrottle2Curve);
// TODO why is curve2SourceCombo registered twice ?
parent.addWidgetBinding("MixerSettings", "Curve2Source", m_aircraft->curve2SourceCombo);
parent.addWidget(m_aircraft->curve2SourceCombo);
}

View File

@ -120,7 +120,7 @@ QString VehicleConfig::updateConfigObjectsFromWidgets()
return NULL;
}
void VehicleConfig::refreshWidgetsValues(UAVObject *obj)
void VehicleConfig::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_UNUSED(obj);
}

View File

@ -244,8 +244,9 @@ protected:
double getCurveMin(QList<double> *curve);
double getCurveMax(QList<double> *curve);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private:

View File

@ -149,13 +149,8 @@ void ConfigAutotuneWidget::recomputeStabilization()
m_autotune->pitchAttitudeKi->setText(QString().number(stabSettings.PitchPI[StabilizationSettings::PITCHPI_KI]));
}
void ConfigAutotuneWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigAutotuneWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());
if (obj == hwSettings) {
@ -163,8 +158,6 @@ void ConfigAutotuneWidget::refreshWidgetsValues(UAVObject *obj)
m_autotune->enableAutoTune->setChecked(
hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_AUTOTUNE] == HwSettings::OPTIONALMODULES_ENABLED);
}
setRefreshing(false);
}
void ConfigAutotuneWidget::updateObjectsFromWidgets()

View File

@ -50,10 +50,10 @@ private:
Ui_AutotuneWidget *m_autotune;
StabilizationSettings::DataFields stabSettings;
signals:
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:

View File

@ -117,12 +117,9 @@ ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget()
* 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)
void ConfigCameraStabilizationWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
// Set module enable checkbox from OptionalModules UAVObject item.
// It needs special processing because ConfigTaskWidget uses TRUE/FALSE
@ -171,8 +168,6 @@ void ConfigCameraStabilizationWidget::refreshWidgetsValues(UAVObject *obj)
}
}
}
setRefreshing(false);
}
/*

View File

@ -43,13 +43,15 @@ public:
ConfigCameraStabilizationWidget(QWidget *parent = 0);
~ConfigCameraStabilizationWidget();
private:
Ui_CameraStabilizationWidget *ui;
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private:
Ui_CameraStabilizationWidget *ui;
private slots:
void defaultRequestedSlot(int group);
};

View File

@ -314,12 +314,9 @@ void ConfigOutputWidget::setColor(QWidget *widget, const QColor color)
/**
Request the current config from the board (RC Output)
*/
void ConfigOutputWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigOutputWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
// Get Actuator Settings
ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(getObjectManager());
@ -423,8 +420,6 @@ void ConfigOutputWidget::refreshWidgetsValues(UAVObject *obj)
}
updateSpinStabilizeCheckComboBoxes();
setRefreshing(false);
}
/**

View File

@ -88,6 +88,10 @@ public:
protected:
void enableControls(bool enable);
void setWarning(QString message);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void updateObjectsFromWidgets();
private:
Ui_OutputWidget *m_ui;
@ -102,10 +106,6 @@ private:
void setColor(QWidget *widget, const QColor color);
void sendAllChannelTests();
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:
void updateWarnings(UAVObject *);
void updateSpinStabilizeCheckComboBoxes();

View File

@ -103,19 +103,14 @@ void ConfigRevoHWWidget::setupCustomCombos()
connect(m_ui->cbRcvr, SIGNAL(currentIndexChanged(int)), this, SLOT(rcvrPortChanged(int)));
}
void ConfigRevoHWWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigRevoHWWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
usbVCPPortChanged(0);
mainPortChanged(0);
flexiPortChanged(0);
rcvrPortChanged(0);
setRefreshing(false);
}
void ConfigRevoHWWidget::updateObjectsFromWidgets()

View File

@ -42,15 +42,17 @@ public:
ConfigRevoHWWidget(QWidget *parent = 0);
~ConfigRevoHWWidget();
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void updateObjectsFromWidgets();
private:
Ui_RevoHWWidget *m_ui;
void setupCustomCombos();
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:
void usbVCPPortChanged(int index);
void usbHIDPortChanged(int index);

View File

@ -96,19 +96,14 @@ void ConfigRevoNanoHWWidget::setupCustomCombos()
connect(m_ui->cbRcvr, SIGNAL(currentIndexChanged(int)), this, SLOT(rcvrPortChanged(int)));
}
void ConfigRevoNanoHWWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigRevoNanoHWWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
usbVCPPortChanged(0);
mainPortChanged(0);
flexiPortChanged(0);
rcvrPortChanged(0);
setRefreshing(false);
}
void ConfigRevoNanoHWWidget::updateObjectsFromWidgets()

View File

@ -42,14 +42,17 @@ public:
ConfigRevoNanoHWWidget(QWidget *parent = 0);
~ConfigRevoNanoHWWidget();
private:
Ui_RevoNanoHWWidget *m_ui;
void setupCustomCombos();
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private:
Ui_RevoNanoHWWidget *m_ui;
void setupCustomCombos();
private slots:
void usbVCPPortChanged(int index);
void usbHIDPortChanged(int index);

View File

@ -414,12 +414,9 @@ void ConfigRevoWidget::displayTemperatureRange(float temperatureRange)
* Called by the ConfigTaskWidget parent when RevoCalibration is updated
* to update the UI
*/
void ConfigRevoWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigRevoWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
m_ui->isSetCheckBox->setEnabled(false);
@ -432,8 +429,6 @@ void ConfigRevoWidget::refreshWidgetsValues(UAVObject *obj)
updateMagBeVector();
onBoardAuxMagError();
setRefreshing(false);
}
void ConfigRevoWidget::updateObjectsFromWidgets()

View File

@ -48,6 +48,12 @@ public:
ConfigRevoWidget(QWidget *parent = 0);
~ConfigRevoWidget();
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void updateObjectsFromWidgets();
private:
OpenPilot::SixPointCalibrationModel *m_accelCalibrationModel;
OpenPilot::SixPointCalibrationModel *m_magCalibrationModel;
@ -73,10 +79,6 @@ private:
int auxMagWarningCount;
int auxMagErrorCount;
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:
void storeAndClearBoardRotation();
void recallBoardRotation();

View File

@ -99,18 +99,13 @@ void ConfigSparky2HWWidget::setupCustomCombos()
connect(m_ui->cbMain, SIGNAL(currentIndexChanged(int)), this, SLOT(mainPortChanged(int)));
}
void ConfigSparky2HWWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigSparky2HWWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
usbVCPPortChanged(0);
mainPortChanged(0);
flexiPortChanged(0);
setRefreshing(false);
}
void ConfigSparky2HWWidget::updateObjectsFromWidgets()

View File

@ -43,15 +43,17 @@ public:
ConfigSparky2HWWidget(QWidget *parent = 0);
~ConfigSparky2HWWidget();
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void updateObjectsFromWidgets();
private:
Ui_Sparky2HWWidget *m_ui;
void setupCustomCombos();
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:
void usbVCPPortChanged(int index);
void usbHIDPortChanged(int index);

View File

@ -247,12 +247,9 @@ ConfigStabilizationWidget::~ConfigStabilizationWidget()
// Do nothing
}
void ConfigStabilizationWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigStabilizationWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
// make sure to unset at the end
setRefreshing(true);
Q_UNUSED(obj);
updateThrottleCurveFromObject();
@ -270,8 +267,6 @@ void ConfigStabilizationWidget::refreshWidgetsValues(UAVObject *obj)
ui->advancedResponsivenessCheckBox->setChecked(true);
}
}
setRefreshing(false);
}
void ConfigStabilizationWidget::updateObjectsFromWidgets()

View File

@ -53,6 +53,13 @@ public:
~ConfigStabilizationWidget();
bool shouldObjectBeSaved(UAVObject *object);
protected:
QString mapObjectName(const QString objectName);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void updateObjectsFromWidgets();
private:
Ui_StabilizationWidget *ui;
QTimer *realtimeUpdates;
@ -86,13 +93,6 @@ private:
void resetStabBank(int bank);
void restoreStabBank(int bank);
protected:
QString mapObjectName(const QString objectName);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private slots:
void realtimeUpdatesSlot(bool value);
void linkCheckBoxes(bool value);

View File

@ -139,7 +139,7 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi
addUAVObject("MixerSettings");
addUAVObject("ActuatorSettings");
// The order of the tabs is important since they correspond with the AirframCategory enum
// The order of the tabs is important since they correspond with the AirframeCategory enum
m_aircraft->aircraftType->addTab(tr("Multirotor"));
m_aircraft->aircraftType->addTab(tr("Fixed Wing"));
m_aircraft->aircraftType->addTab(tr("Helicopter"));
@ -174,21 +174,18 @@ void ConfigVehicleTypeWidget::switchAirframeType(int index)
}
/**
Refreshes the current value of the SystemSettings which holds the aircraft type
Note: The default behavior of ConfigTaskWidget is bypassed.
Therefore no automatic synchronization of UAV Objects to UI is done.
Refreshes the current value of the SystemSettings which holds the aircraft type.
Note: no widgets are bound so the default behavior of ConfigTaskWidget will not do much.
Almost everything is handled here to the exception of one case (see ConfigCustomWidget...)
*/
void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *obj)
void ConfigVehicleTypeWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
ConfigTaskWidget::refreshWidgetsValues(obj);
Q_UNUSED(obj);
if (!allObjectsUpdated()) {
return;
}
// make sure to unset at the end
setRefreshing(true);
// Get the Airframe type from the system settings:
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
Q_ASSERT(system);
@ -234,8 +231,6 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *obj)
}
}
m_aircraft->nameEdit->setText(name);
setRefreshing(false);
}
/**

View File

@ -41,10 +41,7 @@ class Ui_AircraftWidget;
class QWidget;
/*
* This class derives from ConfigTaskWidget and overrides its default "binding" mechanism.
* This widget bypasses automatic synchronization of UAVObjects and UI by providing its own implementations of
* virtual void refreshWidgetsValues(UAVObject *obj = NULL);
* virtual void updateObjectsFromWidgets();
* This class derives from ConfigTaskWidget but almost bypasses the need its default "binding" mechanism.
*
* It does use the "dirty" state management and registers its relevant widgets with ConfigTaskWidget to do so.
*
@ -52,7 +49,6 @@ class QWidget;
* Note: for "dirty" state management it is important to register the fields of child widgets with the parent
* ConfigVehicleTypeWidget class.
*
* TODO consider to call "super" to benefit from default logic...
* TODO improve handling of relationship with VehicleConfig derived classes (i.e. ConfigTaskWidget within ConfigTaskWidget)
*/
class ConfigVehicleTypeWidget : public ConfigTaskWidget {
@ -64,8 +60,10 @@ public:
ConfigVehicleTypeWidget(QWidget *parent = 0);
~ConfigVehicleTypeWidget();
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
protected slots:
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
private:

View File

@ -190,8 +190,7 @@ void ConfigTaskWidget::setWidgetBindingObjectEnabled(QString objectName, bool en
Q_ASSERT(object);
// make sure to unset at the end
setRefreshing(true);
m_refreshing = true;
foreach(WidgetBinding * binding, m_widgetBindingsPerObject.values(object)) {
binding->setIsEnabled(enabled);
@ -204,7 +203,7 @@ void ConfigTaskWidget::setWidgetBindingObjectEnabled(QString objectName, bool en
}
}
setRefreshing(false);
m_refreshing = true;
}
ConfigTaskWidget::~ConfigTaskWidget()
@ -327,7 +326,7 @@ void ConfigTaskWidget::onAutopilotConnect()
void ConfigTaskWidget::populateWidgets()
{
setRefreshing(true);
m_refreshing = true;
emit populateWidgetsRequested();
@ -337,7 +336,7 @@ void ConfigTaskWidget::populateWidgets()
}
}
setRefreshing(false);
m_refreshing = false;
}
void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
@ -346,10 +345,10 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
return;
}
// make sure to unset at the end
setRefreshing(true);
m_refreshing = true;
emit refreshWidgetsValuesRequested();
QList<WidgetBinding *> bindings = obj == NULL ? m_widgetBindingsPerObject.values() : m_widgetBindingsPerObject.values(obj);
foreach(WidgetBinding * binding, bindings) {
if (binding->field() != NULL && binding->widget() != NULL) {
@ -361,7 +360,10 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
}
}
setRefreshing(false);
// call specific implementation
refreshWidgetsValuesImpl(obj);
m_refreshing = false;
}
void ConfigTaskWidget::updateObjectsFromWidgets()
@ -517,7 +519,7 @@ void ConfigTaskWidget::clearDirty()
void ConfigTaskWidget::setDirty(bool value)
{
if (isRefreshing()) {
if (m_refreshing) {
return;
}
m_isDirty = value;
@ -552,16 +554,6 @@ void ConfigTaskWidget::enableObjectUpdates()
}
}
bool ConfigTaskWidget::isRefreshing()
{
return m_refreshing;
}
void ConfigTaskWidget::setRefreshing(bool refreshing)
{
m_refreshing = refreshing;
}
void ConfigTaskWidget::objectUpdated(UAVObject *object)
{
m_updatedObjects[object] = true;

View File

@ -250,15 +250,16 @@ private:
void doAddWidgetBinding(QString objectName, QString fieldName, QWidget *widget, int index = 0, double scale = 1,
bool isLimited = false, QList<int> *reloadGroupIDs = 0, quint32 instID = 0);
protected:
virtual void refreshWidgetsValuesImpl(UAVObject *) {};
protected slots:
virtual void disableObjectUpdates();
virtual void enableObjectUpdates();
virtual void clearDirty();
bool isRefreshing();
void setRefreshing(bool refreshing);
virtual void widgetsContentsChanged();
virtual void populateWidgets();
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
void refreshWidgetsValues(UAVObject *obj = NULL);
virtual void updateObjectsFromWidgets();
virtual void helpButtonPressed();