From 529a08739edb903ee13d94f540d1c92c8b1ace8e Mon Sep 17 00:00:00 2001 From: tstellanova Date: Mon, 5 Aug 2013 21:43:24 -0700 Subject: [PATCH] Move handleParameterUpdate into data model class --- src/uas/UASParameterDataModel.cc | 24 +++++++++++++++++++++++- src/uas/UASParameterDataModel.h | 2 ++ src/ui/QGCParamWidget.cc | 14 ++------------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/uas/UASParameterDataModel.cc b/src/uas/UASParameterDataModel.cc index 8396594e1..dbf461060 100644 --- a/src/uas/UASParameterDataModel.cc +++ b/src/uas/UASParameterDataModel.cc @@ -1,5 +1,6 @@ #include "UASParameterDataModel.h" +#include #include UASParameterDataModel::UASParameterDataModel(QObject *parent) : @@ -31,7 +32,7 @@ void UASParameterDataModel::setPendingParameter(int componentId, QString& key, params->insert(key,value); } -void UASParameterDataModel::setOnboardParameter(int componentId, QString& key, QVariant &value) +void UASParameterDataModel::setOnboardParameter(int componentId, QString& key, QVariant& value) { //ensure we have a placeholder map for this component addComponent(componentId); @@ -48,3 +49,24 @@ void UASParameterDataModel::addComponent(int componentId) pendingParameters.insert(componentId, new QMap()); } } + + +void UASParameterDataModel::handleParameterUpdate(int componentId, QString& key, QVariant& value) +{ + //verify that the value requested by the user matches the set value + //if it doesn't match, leave the pending parameter in the pending list! + if (pendingParameters.contains(componentId)) { + QMap *pendingParams = pendingParameters.value(componentId); + if ((NULL != pendingParams) && pendingParams->contains(key)) { + QVariant reqVal = pendingParams->value(key); + if (reqVal == value) { + pendingParams->remove(key); + } + else { + qDebug() << "Pending commit for " << key << " want: " << reqVal << " got: " << value; + } + } + } + + setOnboardParameter(componentId,key, value); +} diff --git a/src/uas/UASParameterDataModel.h b/src/uas/UASParameterDataModel.h index 7122d523e..b3e56b7a7 100644 --- a/src/uas/UASParameterDataModel.h +++ b/src/uas/UASParameterDataModel.h @@ -22,6 +22,8 @@ public: virtual void addPendingIfParameterChanged(int componentId, QString& key, QVariant &value); + void handleParameterUpdate(int componentId, QString& key, QVariant& value); + QMap* getPendingParametersForComponent(int componentId) { return pendingParameters.value(componentId); } diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index fb1e6eb96..0e415d8bd 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -636,18 +636,8 @@ void QGCParamWidget::receivedParameterUpdate(int uas, int component, QString par parameterItem->setToolTip(0, tooltipFormat); parameterItem->setToolTip(1, tooltipFormat); - //verify that the value requested by the user matches the set value - //if it doesn't match, leave the pending parameter in the pending list! - QMap *> changedValues = this->paramDataModel->getPendingParameters(); - if (changedValues.contains(component)) { - QMap *compReqVals = changedValues.value(component); - if ((NULL != compReqVals) && compReqVals->contains(parameterName)) { - QVariant reqVal = compReqVals->value(parameterName); - if (reqVal == value) { - compReqVals->remove(parameterName); - } - } - } + paramDataModel->handleParameterUpdate(component,parameterName,value); + } /** -- 2.22.0