From 0af584991bdaca375e82be6d658bbc8496733ba3 Mon Sep 17 00:00:00 2001 From: tstellanova Date: Fri, 9 Aug 2013 13:57:21 -0700 Subject: [PATCH] propagate pending list updates fix pending items indicator --- src/uas/UASParameterDataModel.cc | 6 ++ src/uas/UASParameterDataModel.h | 3 + src/ui/QGCParamWidget.cc | 130 +++++++++++++++++++------------ src/ui/QGCParamWidget.h | 11 +-- 4 files changed, 95 insertions(+), 55 deletions(-) diff --git a/src/uas/UASParameterDataModel.cc b/src/uas/UASParameterDataModel.cc index c942b4437..1806ec23f 100644 --- a/src/uas/UASParameterDataModel.cc +++ b/src/uas/UASParameterDataModel.cc @@ -49,6 +49,10 @@ void UASParameterDataModel::removePendingParam(int compId, QString& key) QMap *params = getPendingParamsForComponent(compId); if (params) { params->remove(key); + //broadcast the existing value + QVariant existVal; + bool ok = getOnboardParamValue(compId,key,existVal); + emit pendingParamUpdate(compId, key,existVal, false); } } @@ -59,6 +63,8 @@ void UASParameterDataModel::setPendingParam(int compId, QString& key, const QVa addComponent(compId); QMap *params = getPendingParamsForComponent(compId); params->insert(key,value); + emit pendingParamUpdate(compId, key, value, true); + } void UASParameterDataModel::setOnboardParam(int compId, QString& key, const QVariant& value) diff --git a/src/uas/UASParameterDataModel.h b/src/uas/UASParameterDataModel.h index 6ae4f685c..fde760b70 100644 --- a/src/uas/UASParameterDataModel.h +++ b/src/uas/UASParameterDataModel.h @@ -85,6 +85,9 @@ signals: /** @brief We've received an update of a parameter's value */ void parameterUpdated(int compId, QString paramName, QVariant value); + /** @brief Notifies listeners that a param was added to or removed from the pending list */ + void pendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending); + public slots: diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index 7f18df8c9..ce20a29d6 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -66,6 +66,9 @@ 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))); + // Listen for param list reload finished connect(paramCommsMgr, SIGNAL(parameterListUpToDate()), this, SLOT(handleParameterListUpToDate())); @@ -197,6 +200,19 @@ void QGCParamWidget::addComponentItem(int compId, QString compName) } +void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending) +{ + QTreeWidgetItem* paramItem = updateParameterDisplay(compId,paramName,value); + if (isPending) { + paramItem->setBackground(0, QBrush(QColor(QGC::colorOrange))); + paramItem->setBackground(1, QBrush(QColor(QGC::colorOrange))); + } + else { + paramItem->setBackground(0, Qt::NoBrush); + paramItem->setBackground(1, Qt::NoBrush); + } + +} void QGCParamWidget::handleParameterUpdate(int componentId, const QString& paramName, QVariant value) { @@ -206,7 +222,6 @@ void QGCParamWidget::handleParameterUpdate(int componentId, const QString& param void QGCParamWidget::handleParameterListUpToDate() { -// tree->collapseAll(); //turn off updates while we refresh the entire list tree->setUpdatesEnabled(false); @@ -231,27 +246,30 @@ void QGCParamWidget::handleParameterListUpToDate() } - -void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, QVariant value) +QTreeWidgetItem* QGCParamWidget::findChildWidgetItemForParam(QTreeWidgetItem* parentItem, const QString& paramName) { -// qDebug() << "QGCParamWidget::updateParameterDisplay" << parameterName; - - // Reference to item in tree - QTreeWidgetItem* parameterItem = NULL; - - // Add component item if necessary - if (!componentItems->contains(compId)) { - QString componentName = tr("Component #%1").arg(compId); - addComponentItem(compId, componentName); + QTreeWidgetItem* childItem = NULL; + + for (int i = 0; i < parentItem->childCount(); i++) { + QTreeWidgetItem* child = parentItem->child(i); + QString key = child->data(0, Qt::DisplayRole).toString(); + if (key == paramName) { + childItem = child; + break; + } } - //default parent item for this parameter widget item will be the top level component item + return childItem; +} + +QTreeWidgetItem* QGCParamWidget::getParentWidgetItemForParam(int compId, const QString& paramName) +{ QTreeWidgetItem* parentItem = componentItems->value(compId); QString splitToken = "_"; // Check if auto-grouping can work - if (parameterName.contains(splitToken)) { - QString parentStr = parameterName.section(splitToken, 0, 0, QString::SectionSkipEmpty); + if (paramName.contains(splitToken)) { + QString parentStr = paramName.section(splitToken, 0, 0, QString::SectionSkipEmpty); QMap* compParamGroups = paramGroups.value(compId); if (!compParamGroups->contains(parentStr)) { // Insert group item @@ -271,29 +289,31 @@ void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, Q parentItem = compParamGroups->value(parentStr); } else { - //parent item for this parameter will be the top level component widget item + //parent item for this parameter will be the top level (component) widget item parentItem = componentItems->value(compId); } - if (parentItem) { - bool found = false; - for (int i = 0; i < parentItem->childCount(); i++) { - QTreeWidgetItem* child = parentItem->child(i); - QString key = child->data(0, Qt::DisplayRole).toString(); - if (key == parameterName) { - //qDebug() << "UPDATED CHILD"; - parameterItem = child; - if (value.type() == QVariant::Char) { - parameterItem->setData(1, Qt::DisplayRole, value.toUInt()); - } - else { - parameterItem->setData(1, Qt::DisplayRole, value); - } - found = true; - } - } + return parentItem; +} + +QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, QVariant value) +{ +// qDebug() << "QGCParamWidget::updateParameterDisplay" << parameterName; + + // Reference to item in tree + QTreeWidgetItem* parameterItem = NULL; - if (!found) { + // Add component item if necessary + if (!componentItems->contains(compId)) { + QString componentName = tr("Component #%1").arg(compId); + addComponentItem(compId, componentName); + } + + //default parent item for this parameter widget item will be the top level component item + QTreeWidgetItem* parentItem = getParentWidgetItemForParam(compId,parameterName); + if (parentItem) { + parameterItem = findChildWidgetItemForParam(parentItem,parameterName); + if (!parameterItem) { // Insert parameter into map QStringList plist; plist.append(parameterName); @@ -309,6 +329,30 @@ void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, Q parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable); //TODO insert alphabetically parentItem->addChild(parameterItem); + + //only add the tooltip when the parameter item is first added + QString paramDesc = paramDataModel->getParamDescription(parameterName); + if (!paramDesc.isEmpty()) { + QString tooltipFormat; + if (paramDataModel->isParamDefaultKnown(parameterName)) { + tooltipFormat = tr("Default: %1, %2"); + double paramDefValue = paramDataModel->getParamDefault(parameterName); + tooltipFormat = tooltipFormat.arg(paramDefValue).arg(paramDesc); + } + else { + tooltipFormat = paramDesc; + } + parameterItem->setToolTip(0, tooltipFormat); + parameterItem->setToolTip(1, tooltipFormat); + } + } + + //update the parameterItem's data + if (value.type() == QVariant::Char) { + parameterItem->setData(1, Qt::DisplayRole, value.toUInt()); + } + else { + parameterItem->setData(1, Qt::DisplayRole, value); } } @@ -319,21 +363,7 @@ void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, Q parameterItem->setTextColor(0, QGC::colorDarkWhite); parameterItem->setTextColor(1, QGC::colorDarkWhite); - // Add tooltip - QString paramDesc = paramDataModel->getParamDescription(parameterName); - if (!paramDesc.isEmpty()) { - QString tooltipFormat; - if (paramDataModel->isParamDefaultKnown(parameterName)) { - tooltipFormat = tr("Default: %1, %2"); - double paramDefValue = paramDataModel->getParamDefault(parameterName); - tooltipFormat = tooltipFormat.arg(paramDefValue).arg(paramDesc); - } - else { - tooltipFormat = paramDesc; - } - parameterItem->setToolTip(0, tooltipFormat); - parameterItem->setToolTip(1, tooltipFormat); - } + return parameterItem; } @@ -367,7 +397,7 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column) current->setBackground(1, QBrush(QColor(QGC::colorOrange))); } else { - QMap* pendingParams = paramDataModel->getOnboardParamsForComponent(componentId); + QMap* pendingParams = paramDataModel->getPendingParamsForComponent(componentId); int pendingCount = pendingParams->count(); statusLabel->setText(tr("Pending items: %1").arg(pendingCount)); current->setBackground(0, Qt::NoBrush); diff --git a/src/ui/QGCParamWidget.h b/src/ui/QGCParamWidget.h index 2176b5b4a..33df32200 100644 --- a/src/ui/QGCParamWidget.h +++ b/src/ui/QGCParamWidget.h @@ -52,10 +52,11 @@ public: protected: virtual void setParameterStatusMsg(const QString& msg); virtual void layoutWidget(); + virtual QTreeWidgetItem* getParentWidgetItemForParam(int compId, const QString& paramName); + virtual QTreeWidgetItem* findChildWidgetItemForParam(QTreeWidgetItem* parentItem, const QString& paramName); + signals: - /** @brief A parameter was changed in the widget, NOT onboard */ - //void parameterChanged(int component, QString parametername, float value); // defined in QGCUASParamManager already public slots: @@ -65,16 +66,16 @@ public slots: */ void addComponentItem(int compId, QString compName); - /** @brief Add a parameter to the list with retransmission / safety checks */ -// void receivedParameterUpdate(int uas, int component, int paramCount, int paramId, QString parameterName, QVariant value); virtual void handleParameterUpdate(int component,const QString& parameterName, QVariant value); + virtual void handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending); + virtual void handleParameterListUpToDate(); virtual void handleParamStatusMsgUpdate(QString msg, int level); /** @brief Ensure that view of parameter matches data in the model */ - void updateParameterDisplay(int component, QString parameterName, QVariant value); + QTreeWidgetItem* updateParameterDisplay(int component, QString parameterName, QVariant value); /** @brief Request list of parameters from MAV */ void requestAllParamsUpdate(); -- 2.22.0