@@ -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
307292QModelIndex 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
474454ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem (UAVObject *object)
@@ -503,18 +483,29 @@ MetaObjectTreeItem *UAVObjectTreeModel::findMetaObjectTreeItem(UAVMetaObject *ob
503483
504484void 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
512502void 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
520511void UAVObjectTreeModel::isKnownChanged (UAVObject *object, bool isKnown)
0 commit comments