Commit e02f9ec0 authored by tstellanova's avatar tstellanova

Better data model update debouncing

parent 11e1379a
...@@ -51,7 +51,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -51,7 +51,8 @@ This file is part of the QGROUNDCONTROL project
*/ */
QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) :
QGCUASParamManager(uas, parent), QGCUASParamManager(uas, parent),
componentItems(new QMap<int, QTreeWidgetItem*>()) componentItems(new QMap<int, QTreeWidgetItem*>()),
updatingParamNameLock("")
{ {
layoutWidget(); layoutWidget();
...@@ -202,20 +203,17 @@ void QGCParamWidget::addComponentItem(int compId, QString compName) ...@@ -202,20 +203,17 @@ void QGCParamWidget::addComponentItem(int compId, QString compName)
void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending) void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending)
{ {
qDebug() << "handlePendingParamUpdate:" << paramName << "with updatedLineItem_weak:" << updatedLineItem_weak; qDebug() << "handlePendingParamUpdate:" << paramName << "with updatingParamNameLock:" << updatingParamNameLock;
if (updatedLineItem_weak) { if (updatingParamNameLock == paramName) {
QString key = updatedLineItem_weak->data(0, Qt::DisplayRole).toString(); qDebug() << "ignoring bounce from " << paramName;
if (paramName == key) { return;
//debounce echo from data model }
return; else {
} updatingParamNameLock = paramName;
} }
QTreeWidgetItem* paramItem = updateParameterDisplay(compId,paramName,value); QTreeWidgetItem* paramItem = updateParameterDisplay(compId,paramName,value);
if (updatedLineItem_weak == NULL) {
updatedLineItem_weak = paramItem;
}
if (isPending) { if (isPending) {
paramItem->setBackground(0, QBrush(QColor(QGC::colorOrange))); paramItem->setBackground(0, QBrush(QColor(QGC::colorOrange)));
paramItem->setBackground(1, QBrush(QColor(QGC::colorOrange))); paramItem->setBackground(1, QBrush(QColor(QGC::colorOrange)));
...@@ -225,17 +223,20 @@ void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramNa ...@@ -225,17 +223,20 @@ void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramNa
paramItem->setBackground(1, Qt::NoBrush); paramItem->setBackground(1, Qt::NoBrush);
} }
updatingParamNameLock.clear();
} }
void QGCParamWidget::handleParameterUpdate(int componentId, const QString& paramName, QVariant value) void QGCParamWidget::handleParameterUpdate(int componentId, const QString& paramName, QVariant value)
{ {
updatingParamNameLock = paramName;
updateParameterDisplay(componentId, paramName, value); updateParameterDisplay(componentId, paramName, value);
updatingParamNameLock.clear();
} }
void QGCParamWidget::handleParameterListUpToDate() void QGCParamWidget::handleParameterListUpToDate()
{ {
//turn off updates while we refresh the entire list //turn off updates while we refresh the entire list
tree->setUpdatesEnabled(false); tree->setUpdatesEnabled(false);
...@@ -340,7 +341,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para ...@@ -340,7 +341,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
parameterItem->setData(1, Qt::DisplayRole, value); parameterItem->setData(1, Qt::DisplayRole, value);
} }
parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable); parameterItem->setFlags(parameterItem->flags() | Qt::ItemIsEditable);
updatedLineItem_weak = parameterItem; //keep a temporary ref to the item that's being updated
//TODO insert alphabetically //TODO insert alphabetically
parentItem->addChild(parameterItem); parentItem->addChild(parameterItem);
...@@ -362,8 +362,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para ...@@ -362,8 +362,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
} }
} }
updatedLineItem_weak = parameterItem; //keep a temporary ref to the item that's being updated
//update the parameterItem's data //update the parameterItem's data
if (value.type() == QVariant::Char) { if (value.type() == QVariant::Char) {
parameterItem->setData(1, Qt::DisplayRole, value.toUInt()); parameterItem->setData(1, Qt::DisplayRole, value.toUInt());
...@@ -381,7 +379,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para ...@@ -381,7 +379,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
parameterItem->setTextColor(0, QGC::colorDarkWhite); parameterItem->setTextColor(0, QGC::colorDarkWhite);
parameterItem->setTextColor(1, QGC::colorDarkWhite); parameterItem->setTextColor(1, QGC::colorDarkWhite);
updatedLineItem_weak = NULL;
} }
return parameterItem; return parameterItem;
...@@ -391,12 +388,19 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para ...@@ -391,12 +388,19 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column) void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column)
{ {
if (paramItem && column > 0) { if (paramItem && column > 0) {
if (!paramItem->isSelected() || (paramItem == updatedLineItem_weak)) { QString key = paramItem->data(0, Qt::DisplayRole).toString();
//ignore updates reflected back from the data model, to avoid infinite loop qDebug() << "parameterItemChanged:" << key << "with updatingParamNameLock:" << updatingParamNameLock;
if (key == updatingParamNameLock) {
qDebug() << "ignoring parameterItemChanged" << key;
return; return;
} }
else {
updatingParamNameLock = key;
}
QTreeWidgetItem* parent = paramItem->parent(); QTreeWidgetItem* parent = paramItem->parent();
while (parent->parent() != NULL) { while (parent->parent() != NULL) {
...@@ -404,10 +408,9 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column ...@@ -404,10 +408,9 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column
} }
// Parent is now top-level component // Parent is now top-level component
int componentId = componentItems->key(parent); int componentId = componentItems->key(parent);
QString key = paramItem->data(0, Qt::DisplayRole).toString();
QVariant value = paramItem->data(1, Qt::DisplayRole); QVariant value = paramItem->data(1, Qt::DisplayRole);
bool pending = paramDataModel->updatePendingParamWithValue(componentId,key,value); bool pending = paramDataModel->updatePendingParamWithValue(componentId,key,value);
// If the value will result in an update // If the value will result in an update
...@@ -430,6 +433,7 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column ...@@ -430,6 +433,7 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column
paramItem->setBackground(1, Qt::NoBrush); paramItem->setBackground(1, Qt::NoBrush);
} }
updatingParamNameLock.clear();
} }
} }
......
...@@ -100,8 +100,7 @@ protected: ...@@ -100,8 +100,7 @@ protected:
QLabel* statusLabel; ///< User-facing parameter status label QLabel* statusLabel; ///< User-facing parameter status label
QMap<int, QTreeWidgetItem*>* componentItems; ///< The tree of component items, stored by component ID QMap<int, QTreeWidgetItem*>* componentItems; ///< The tree of component items, stored by component ID
QMap<int, QMap<QString, QTreeWidgetItem*>* > paramGroups; ///< Parameter groups to organize component items QMap<int, QMap<QString, QTreeWidgetItem*>* > paramGroups; ///< Parameter groups to organize component items
QTreeWidgetItem* updatedLineItem_weak;///< weak ref to user-edited line QString updatingParamNameLock; ///< Name of param currently being updated-- used for reducing echo on param change
// QTreeWidgetItem* updatedPendingItem_weak;///< weak ref to pending-modified line
}; };
......
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