Commit 3c6bc561 authored by tstellanova's avatar tstellanova

fix change checking for params; better pending status indication

parent 25150144
......@@ -18,25 +18,21 @@ UASParameterDataModel::UASParameterDataModel(QObject *parent) :
bool UASParameterDataModel::checkParameterChanged(int componentId, const QString& key, const QVariant &value)
bool UASParameterDataModel::checkParameterChanged(int compId, const QString& key, const QVariant& value)
{
bool changed = true;
addComponent(componentId);
QMap<QString, QVariant>* existParams = getOnbardParametersForComponent(componentId);
//ensure we have this component in our onboard and pending lists already
addComponent(compId);
QMap<QString, QVariant>* existParams = getOnbardParametersForComponent(compId);
if (existParams->contains(key)) {
QVariant existValue = existParams->value(key);
QMap<QString, QVariant>* pendParams = getPendingParametersForComponent(componentId);
if (pendParams->contains(key)) {
QVariant pendValue = pendParams->value(key);
if (existValue == pendValue) {
changed = false;
}
if (existValue == value) {
changed = false;
}
}
return changed;
}
bool UASParameterDataModel::addPendingIfParameterChanged(int componentId, QString& key, QVariant &value)
......
......@@ -45,7 +45,7 @@ public:
virtual void forgetAllOnboardParameters();
/**
* @return true if the parameter has changed
* @return true if the given value for the parameter is different from the existing value
*/
virtual bool checkParameterChanged(int componentId, const QString& key, const QVariant &value);
......
......@@ -267,72 +267,12 @@ void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, Q
componentItems->value(compId)->insertChild(insertIdx,groupItem);
}
// Append child to group
//bool found = false;
//parent item for this tree widget item will be a group widget item
//parent item for this parameter item will be a group widget item
parentItem = compParamGroups->value(parentStr);
// 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;
// }
// }
// if (!found) {
// // Insert parameter into map
// QStringList plist;
// plist.append(parameterName);
// // CREATE PARAMETER ITEM
// parameterItem = new QTreeWidgetItem(plist);
// // CONFIGURE PARAMETER ITEM
// if (value.type() == QVariant::Char) {
// parameterItem->setData(1, Qt::DisplayRole, value.toUInt());
// }
// else {
// parameterItem->setData(1, Qt::DisplayRole, value);
// }
// parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable);
// parentItem->addChild(parameterItem);
// }
}
else {
//bool found = false;
//parent item for this parameter will be the top level component widget item
parentItem = componentItems->value(compId);
// for (int i = 0; i < parent->childCount(); i++) {
// QTreeWidgetItem* child = parent->child(i);
// QString key = child->data(0, Qt::DisplayRole).toString();
// if (key == parameterName) {
// //qDebug() << "UPDATED CHILD";
// parameterItem = child;
// parameterItem->setData(1, Qt::DisplayRole, value);
// found = true;
// }
// }
// if (!found) {
// // Insert parameter into map
// QStringList plist;
// plist.append(parameterName);
// // CREATE PARAMETER ITEM
// parameterItem = new QTreeWidgetItem(plist);
// // CONFIGURE PARAMETER ITEM
// parameterItem->setData(1, Qt::DisplayRole, value);
// componentItems->value(compId)->addChild(parameterItem);
// parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable);
// }
}
if (parentItem) {
......@@ -367,7 +307,7 @@ void QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, Q
parameterItem->setData(1, Qt::DisplayRole, value);
}
parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable);
//TODO insert alphabetically
parentItem->addChild(parameterItem);
}
}
......@@ -411,25 +351,25 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column)
QString key = current->data(0, Qt::DisplayRole).toString();
QVariant value = current->data(1, Qt::DisplayRole);
// Set parameter on changed list to be transmitted to MAV
QPalette pal = statusLabel->palette();
pal.setColor(backgroundRole(), QGC::colorOrange);
statusLabel->setPalette(pal);
statusLabel->setText(tr("Transmit pend. %1:%2: %3").arg(componentId).arg(key).arg(value.toFloat(), 5, 'f', 1, QChar(' ')));
//qDebug() << "PARAM CHANGED: COMP:" << key << "KEY:" << str << "VALUE:" << value;
// Changed values list
bool changed = paramDataModel->addPendingIfParameterChanged(componentId,key,value);
// If the value was numerically changed, display it differently
if (changed) {
// Set parameter on changed list to be transmitted to MAV
statusLabel->setText(tr("Transmit pend. %1:%2: %3").arg(componentId).arg(key).arg(value.toFloat(), 5, 'f', 1, QChar(' ')));
if (current == 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)));
//TODO this seems incorrect-- we're pre-updating the onboard value before we've received confirmation
//paramDataModel->setOnboardParameterWithType(componentId,key,value);
tree->update();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment