diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index 532efe813a55e64403d95fd29e2aa88a0c489087..dc11769a905fd05c054b79470e1f8ccbb3374a3e 100644 --- a/src/uas/QGCUASParamManager.cc +++ b/src/uas/QGCUASParamManager.cc @@ -16,13 +16,19 @@ QGCUASParamManager::QGCUASParamManager(UASInterface* uas, QWidget *parent) : } - - -bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const { +bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const +{ return paramDataModel->getOnboardParameterValue(component,parameter,value); } +void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter) +{ + if (mav) { + mav->requestParameter(component, parameter); + } +} + /** * Send a request to deliver the list of onboard parameters * to the MAV. diff --git a/src/uas/QGCUASParamManager.h b/src/uas/QGCUASParamManager.h index 3607552df25461295c37897124d6ef7a27b089d3..872273c5229a876cc6fa2e227638e2f4dbb5ab8c 100644 --- a/src/uas/QGCUASParamManager.h +++ b/src/uas/QGCUASParamManager.h @@ -17,9 +17,6 @@ public: virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const; - /** @brief Request an update for this specific parameter */ - virtual void requestParameterUpdate(int component, const QString& parameter) = 0; - /** @brief Provide tooltips / user-visible descriptions for parameters */ virtual void setParamDescriptions(const QMap& paramDescs); @@ -36,8 +33,7 @@ signals: void parameterListUpToDate(int component); /** @brief Request a single parameter */ void requestParameter(int component, int parameter); - /** @brief Request a single parameter by name */ - void requestParameter(int component, const QString& parameter); + public slots: /** @brief Write one parameter to the MAV */ @@ -47,6 +43,10 @@ public slots: /** @brief Check for missing parameters */ virtual void retransmissionGuardTick(); + + /** @brief Request one single parameter */ + virtual void requestParameterUpdate(int component, const QString& parameter); + protected: // Parameter data model diff --git a/src/ui/ParameterInterface.cc b/src/ui/ParameterInterface.cc index 8ad4a450cad2ec7b3f118a8d32263baafa1d9958..2936394cec02ce966555f5f9b6ded62ec8f7c46b 100644 --- a/src/ui/ParameterInterface.cc +++ b/src/ui/ParameterInterface.cc @@ -72,6 +72,7 @@ ParameterInterface::ParameterInterface(QWidget *parent) : ParameterInterface::~ParameterInterface() { + delete paramWidgets; delete m_ui; } @@ -97,8 +98,8 @@ void ParameterInterface::addUAS(UASInterface* uas) QGCParamWidget* param = new QGCParamWidget(uas, this); QString ptrStr; - ptrStr.sprintf("%8p", param); - qDebug() << "Created QGCParamWidget " << ptrStr << "for UAS id: " << uasId << " count: " << paramWidgets->count(); + ptrStr.sprintf("QGCParamWidget %8p (parent %8p)", param,this); + qDebug() << "Created " << ptrStr << " for UAS id: " << uasId << " count: " << paramWidgets->count(); paramWidgets->insert(uasId, param); m_ui->stackedWidget->addWidget(param); diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index b26348be63bd307badf63b380ed0365425511f7d..6b10632b7e5a2c670624e62a31ce44f9e9d129cc 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -49,7 +49,7 @@ This file is part of the QGROUNDCONTROL project */ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : QGCUASParamManager(uas, parent), - components(new QMap()) + componentItems(new QMap()) { // Load settings loadSettings(); @@ -145,8 +145,8 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : connect(uas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(receivedParameterUpdate(int,int,int,int,QString,QVariant))); // Connect retransmission guard - connect(this, SIGNAL(requestParameter(int,QString)), uas, SLOT(requestParameter(int,QString))); - connect(this, SIGNAL(requestParameter(int,int)), uas, SLOT(requestParameter(int,int))); + connect(this, SIGNAL(requestParameterByName(int,QString)), uas, SLOT(requestParameterByName(int,QString))); + connect(this, SIGNAL(requestParameterByName(int,int)), uas, SLOT(requestParameterByName(int,int))); connect(&retransmissionTimer, SIGNAL(timeout()), this, SLOT(retransmissionGuardTick())); // Get parameters @@ -214,20 +214,20 @@ UASInterface* QGCParamWidget::getUAS() * @param component id of the component * @param componentName human friendly name of the component */ -void QGCParamWidget::addComponent(int uas, int component, QString componentName) +void QGCParamWidget::addComponentItem(int uas, int component, QString componentName) { Q_UNUSED(uas); - if (components->contains(component)) { + if (componentItems->contains(component)) { // Update existing - components->value(component)->setData(0, Qt::DisplayRole, QString("%1 (#%2)").arg(componentName).arg(component)); + componentItems->value(component)->setData(0, Qt::DisplayRole, QString("%1 (#%2)").arg(componentName).arg(component)); //components->value(component)->setData(1, Qt::DisplayRole, QString::number(component)); - components->value(component)->setFirstColumnSpanned(true); + componentItems->value(component)->setFirstColumnSpanned(true); } else { // Add new QStringList list(QString("%1 (#%2)").arg(componentName).arg(component)); QTreeWidgetItem* comp = new QTreeWidgetItem(list); comp->setFirstColumnSpanned(true); - components->insert(component, comp); + componentItems->insert(component, comp); // Create grouping and update maps paramGroups.insert(component, new QMap()); tree->addTopLevelItem(comp); @@ -391,40 +391,26 @@ void QGCParamWidget::receivedParameterUpdate(int uas, int component, int paramCo * @param component id of the component * @param parameterName human friendly name of the parameter */ -void QGCParamWidget::updateParameterDisplay(int uas, int component, QString parameterName, QVariant value) +void QGCParamWidget::updateParameterDisplay(int uas, int componentId, QString parameterName, QVariant value) { Q_UNUSED(uas); - QString ptrStr; - ptrStr.sprintf("%8p", this); - qDebug() << "QGCParamWidget " << ptrStr << " got param" << parameterName; +// QString ptrStr; +// ptrStr.sprintf("%8p", this); +// qDebug() << "QGCParamWidget " << ptrStr << " got param" << parameterName; // Reference to item in tree QTreeWidgetItem* parameterItem = NULL; // Get component - if (!components->contains(component)) - { - // QString componentName; - // switch (component) - // { - // case MAV_COMP_ID_CAMERA: - // componentName = tr("Camera (#%1)").arg(component); - // break; - // case MAV_COMP_ID_IMU: - // componentName = tr("IMU (#%1)").arg(component); - // break; - // default: - // componentName = tr("Component #").arg(component); - // break; - // } - QString componentName = tr("Component #%1").arg(component); - addComponent(uas, component, componentName); + if (!componentItems->contains(componentId)) { + QString componentName = tr("Component #%1").arg(componentId); + addComponentItem(uas, componentId, componentName); } // Replace value in data model - paramDataModel->handleParameterUpdate(component,parameterName,value); + paramDataModel->handleParameterUpdate(componentId,parameterName,value); QString splitToken = "_"; @@ -432,7 +418,7 @@ void QGCParamWidget::updateParameterDisplay(int uas, int component, QString para if (parameterName.contains(splitToken)) { QString parent = parameterName.section(splitToken, 0, 0, QString::SectionSkipEmpty); - QMap* compParamGroups = paramGroups.value(component); + QMap* compParamGroups = paramGroups.value(componentId); if (!compParamGroups->contains(parent)) { // Insert group item @@ -440,7 +426,7 @@ void QGCParamWidget::updateParameterDisplay(int uas, int component, QString para glist.append(parent); QTreeWidgetItem* item = new QTreeWidgetItem(glist); compParamGroups->insert(parent, item); - components->value(component)->addChild(item); + componentItems->value(componentId)->addChild(item); } // Append child to group @@ -489,7 +475,7 @@ void QGCParamWidget::updateParameterDisplay(int uas, int component, QString para else { bool found = false; - QTreeWidgetItem* parent = components->value(component); + QTreeWidgetItem* parent = componentItems->value(componentId); for (int i = 0; i < parent->childCount(); i++) { QTreeWidgetItem* child = parent->child(i); @@ -513,7 +499,7 @@ void QGCParamWidget::updateParameterDisplay(int uas, int component, QString para // CONFIGURE PARAMETER ITEM parameterItem->setData(1, Qt::DisplayRole, value); - components->value(component)->addChild(parameterItem); + componentItems->value(componentId)->addChild(parameterItem); parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable); } //tree->expandAll(); @@ -535,7 +521,7 @@ void QGCParamWidget::updateParameterDisplay(int uas, int component, QString para parameterItem->setToolTip(0, tooltipFormat); parameterItem->setToolTip(1, tooltipFormat); - paramDataModel->handleParameterUpdate(component,parameterName,value); + paramDataModel->handleParameterUpdate(componentId,parameterName,value); } @@ -549,7 +535,7 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column) parent = parent->parent(); } // Parent is now top-level component - int componentId = components->key(parent); + int componentId = componentItems->key(parent); QString key = current->data(0, Qt::DisplayRole).toString(); QVariant value = current->data(1, Qt::DisplayRole); @@ -603,7 +589,6 @@ void QGCParamWidget::loadParametersFromFile() QTextStream in(&file); paramDataModel->readUpdateParametersFromStream(in); file.close(); - } void QGCParamWidget::setParameterStatusMsg(const QString& msg) @@ -632,14 +617,6 @@ void QGCParamWidget::requestAllParamsUpdate() requestParameterList(); } -/** - * The .. signal is emitted - */ -void QGCParamWidget::requestParameterUpdate(int component, const QString& parameter) -{ - if (mav) mav->requestParameter(component, parameter); -} - /** @@ -830,5 +807,5 @@ void QGCParamWidget::readParameters() void QGCParamWidget::clear() { tree->clear(); - components->clear(); + componentItems->clear(); } diff --git a/src/ui/QGCParamWidget.h b/src/ui/QGCParamWidget.h index 48edbb3103f0baa446cb8d71584db2284c7e8830..06a15b83bb2d078a49f70849d72b0d446083dab3 100644 --- a/src/ui/QGCParamWidget.h +++ b/src/ui/QGCParamWidget.h @@ -61,15 +61,13 @@ signals: public slots: /** @brief Add a component to the list */ - void addComponent(int uas, int component, QString componentName); + void addComponentItem(int uas, int component, QString componentName); /** @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); /** @brief Add a parameter to the list */ void updateParameterDisplay(int uas, int component, QString parameterName, QVariant value); /** @brief Request list of parameters from MAV */ void requestAllParamsUpdate(); - /** @brief Request one single parameter */ - void requestParameterUpdate(int component, const QString& parameter); /** @brief Set one parameter, changes value in RAM of MAV */ void setParameter(int component, QString parameterName, QVariant value); /** @brief Set all parameters, changes the value in RAM of MAV */ @@ -93,7 +91,7 @@ public slots: protected: QTreeWidget* tree; ///< The parameter tree QLabel* statusLabel; ///< Parameter transmission label - QMap* components; ///< The list of components + QMap* componentItems; ///< The list of component items, stored by component ID QMap* > paramGroups; ///< Parameter groups