Skip to content

Commit 849f784

Browse files
committed
LP-567 fix performance issue (high CPU) when highlighting items
we now emit data changes column by column emitting a dataChanged that spans multiple columns kills performance (CPU shoots up) this is probably because we configure the sort/filter proxy to be dynamic this happens when calling setDynamicSortFilter(true) on it which we do
1 parent 4c40d7f commit 849f784

2 files changed

Lines changed: 19 additions & 28 deletions

File tree

ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,13 @@ QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &pa
280280
TreeItem *childItem = parentItem->getChild(row);
281281
if (childItem) {
282282
return createIndex(row, column, childItem);
283-
} else {
284-
return QModelIndex();
285283
}
284+
return QModelIndex();
286285
}
287286

288-
QModelIndex UAVObjectTreeModel::index(TreeItem *item)
287+
QModelIndex UAVObjectTreeModel::index(TreeItem *item, int column)
289288
{
290-
if (item->parent() == 0) {
291-
return QModelIndex();
292-
}
293-
294-
QModelIndex root = index(item->parent());
295-
296-
for (int i = 0; i < rowCount(root); ++i) {
297-
QModelIndex childIndex = index(i, 0, root);
298-
TreeItem *child = static_cast<TreeItem *>(childIndex.internalPointer());
299-
if (child == item) {
300-
return childIndex;
301-
}
302-
}
303-
Q_ASSERT(false);
304-
return QModelIndex();
289+
return createIndex(item->row(), column, item);
305290
}
306291

307292
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
@@ -464,11 +449,6 @@ void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
464449
item->setHighlight(true);
465450
}
466451
item->update();
467-
if (!m_onlyHilightChangedValues) {
468-
QModelIndex itemIndex = index(item);
469-
Q_ASSERT(itemIndex != QModelIndex());
470-
emit dataChanged(itemIndex, itemIndex);
471-
}
472452
}
473453

474454
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
@@ -503,18 +483,29 @@ MetaObjectTreeItem *UAVObjectTreeModel::findMetaObjectTreeItem(UAVMetaObject *ob
503483

504484
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
505485
{
506-
QModelIndex itemIndex = index(item);
486+
// performance note: here we emit data changes column by column
487+
// emitting a dataChanged that spans multiple columns kills performance (CPU shoots up)
488+
// this is probably because we configure the sort/filter proxy to be dynamic
489+
// this happens when calling setDynamicSortFilter(true) on it which we do
490+
491+
QModelIndex itemIndex;
492+
493+
itemIndex = index(item, TreeItem::TITLE_COLUMN);
494+
Q_ASSERT(itemIndex != QModelIndex());
495+
emit dataChanged(itemIndex, itemIndex);
507496

497+
itemIndex = index(item, TreeItem::DATA_COLUMN);
508498
Q_ASSERT(itemIndex != QModelIndex());
509-
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::DATA_COLUMN));
499+
emit dataChanged(itemIndex, itemIndex);
510500
}
511501

512502
void UAVObjectTreeModel::updateIsKnown(TreeItem *item)
513503
{
514-
QModelIndex itemIndex = index(item);
504+
QModelIndex itemIndex;
515505

506+
itemIndex = index(item, TreeItem::TITLE_COLUMN);
516507
Q_ASSERT(itemIndex != QModelIndex());
517-
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::TITLE_COLUMN));
508+
emit dataChanged(itemIndex, itemIndex);
518509
}
519510

520511
void UAVObjectTreeModel::isKnownChanged(UAVObject *object, bool isKnown)

ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private slots:
100100

101101
private:
102102
void setupModelData(UAVObjectManager *objManager);
103-
QModelIndex index(TreeItem *item);
103+
QModelIndex index(TreeItem *item, int column = 0);
104104
void addDataObject(UAVDataObject *obj);
105105
MetaObjectTreeItem *addMetaObject(UAVMetaObject *obj, TreeItem *parent);
106106
void addArrayField(UAVObjectField *field, TreeItem *parent);

0 commit comments

Comments
 (0)