From 8f165fa48973a13c7b8ac79029110641ac4fd17a Mon Sep 17 00:00:00 2001 From: tstellanova Date: Fri, 9 Aug 2013 17:24:45 -0700 Subject: [PATCH] fix slot wiring; debounce echo from data model --- src/uas/UASParameterCommsMgr.cc | 6 +----- src/ui/QGCParamWidget.cc | 31 +++++++++++++++++++------------ src/ui/QGCParamWidget.h | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/uas/UASParameterCommsMgr.cc b/src/uas/UASParameterCommsMgr.cc index c80b6e522..ec1395041 100644 --- a/src/uas/UASParameterCommsMgr.cc +++ b/src/uas/UASParameterCommsMgr.cc @@ -224,11 +224,7 @@ void UASParameterCommsMgr::resetAfterListReceive() transmissionListMode = false; transmissionListSizeKnown.clear(); - //TODO we shouldn't clear missingPackets because other transactions might be using them? - //for list reception we only clear receive packets? -// foreach (int key, transmissionMissingPackets.keys()) { -// transmissionMissingPackets.value(key)->clear(); -// } + //We shouldn't clear missingPackets because other transactions might be using them? } diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index ce20a29d6..52bfc208c 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -66,8 +66,8 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : connect(paramDataModel, SIGNAL(parameterUpdated(int, QString , QVariant )), this, SLOT(handleParameterUpdate(int,QString,QVariant))); - connect(paramDataModel, SIGNAL(pendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending)), - this, SLOT(handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending))); + connect(paramDataModel, SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )), + this, SLOT(handlePendingParamUpdate(int , const QString& , QVariant, bool ))); // Listen for param list reload finished connect(paramCommsMgr, SIGNAL(parameterListUpToDate()), @@ -348,6 +348,7 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para } //update the parameterItem's data + updatedLineItem_weak = parameterItem; //keep a temporary ref to the item that's being updated if (value.type() == QVariant::Char) { parameterItem->setData(1, Qt::DisplayRole, value.toUInt()); } @@ -363,24 +364,30 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para parameterItem->setTextColor(0, QGC::colorDarkWhite); parameterItem->setTextColor(1, QGC::colorDarkWhite); + updatedLineItem_weak = NULL; return parameterItem; } -void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column) +void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column) { - if (current && column > 0) { - QTreeWidgetItem* parent = current->parent(); + if (paramItem && column > 0) { + if (paramItem == updatedLineItem_weak) { + //ignore updates reflected back from the data model, to avoid infinite loop + return; + } + + QTreeWidgetItem* parent = paramItem->parent(); while (parent->parent() != NULL) { parent = parent->parent(); } // Parent is now top-level component int componentId = componentItems->key(parent); - QString key = current->data(0, Qt::DisplayRole).toString(); - QVariant value = current->data(1, Qt::DisplayRole); + QString key = paramItem->data(0, Qt::DisplayRole).toString(); + QVariant value = paramItem->data(1, Qt::DisplayRole); bool pending = paramDataModel->updatePendingParamWithValue(componentId,key,value); @@ -389,19 +396,19 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column) // Set parameter on changed list to be transmitted to MAV statusLabel->setText(tr("Pending: %1:%2: %3").arg(componentId).arg(key).arg(value.toFloat(), 5, 'f', 1, QChar(' '))); - if (current == tree->currentItem()) { + if (paramItem == tree->currentItem()) { //need to unset current item to clear highlighting (green by default) tree->setCurrentItem(NULL); //clear the selected line } - current->setBackground(0, QBrush(QColor(QGC::colorOrange))); - current->setBackground(1, QBrush(QColor(QGC::colorOrange))); + paramItem->setBackground(0, QBrush(QColor(QGC::colorOrange))); + paramItem->setBackground(1, QBrush(QColor(QGC::colorOrange))); } else { QMap* pendingParams = paramDataModel->getPendingParamsForComponent(componentId); int pendingCount = pendingParams->count(); statusLabel->setText(tr("Pending items: %1").arg(pendingCount)); - current->setBackground(0, Qt::NoBrush); - current->setBackground(1, Qt::NoBrush); + paramItem->setBackground(0, Qt::NoBrush); + paramItem->setBackground(1, Qt::NoBrush); } } diff --git a/src/ui/QGCParamWidget.h b/src/ui/QGCParamWidget.h index 33df32200..d0e6f96c3 100644 --- a/src/ui/QGCParamWidget.h +++ b/src/ui/QGCParamWidget.h @@ -100,6 +100,7 @@ protected: QLabel* statusLabel; ///< User-facing parameter status label QMap* componentItems; ///< The tree of component items, stored by component ID QMap* > paramGroups; ///< Parameter groups to organize component items + QTreeWidgetItem* updatedLineItem_weak;///< weak ref to user-edited line }; -- 2.22.0