mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-26 15:54:15 +01:00
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
This commit is contained in:
parent
4c40d7f620
commit
849f7845a1
@ -280,28 +280,13 @@ QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &pa
|
|||||||
TreeItem *childItem = parentItem->getChild(row);
|
TreeItem *childItem = parentItem->getChild(row);
|
||||||
if (childItem) {
|
if (childItem) {
|
||||||
return createIndex(row, column, childItem);
|
return createIndex(row, column, childItem);
|
||||||
} else {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
}
|
||||||
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex UAVObjectTreeModel::index(TreeItem *item)
|
QModelIndex UAVObjectTreeModel::index(TreeItem *item, int column)
|
||||||
{
|
{
|
||||||
if (item->parent() == 0) {
|
return createIndex(item->row(), column, item);
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex root = index(item->parent());
|
|
||||||
|
|
||||||
for (int i = 0; i < rowCount(root); ++i) {
|
|
||||||
QModelIndex childIndex = index(i, 0, root);
|
|
||||||
TreeItem *child = static_cast<TreeItem *>(childIndex.internalPointer());
|
|
||||||
if (child == item) {
|
|
||||||
return childIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
|
QModelIndex UAVObjectTreeModel::parent(const QModelIndex &index) const
|
||||||
@ -464,11 +449,6 @@ void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
|
|||||||
item->setHighlight(true);
|
item->setHighlight(true);
|
||||||
}
|
}
|
||||||
item->update();
|
item->update();
|
||||||
if (!m_onlyHilightChangedValues) {
|
|
||||||
QModelIndex itemIndex = index(item);
|
|
||||||
Q_ASSERT(itemIndex != QModelIndex());
|
|
||||||
emit dataChanged(itemIndex, itemIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
|
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
|
||||||
@ -503,18 +483,29 @@ MetaObjectTreeItem *UAVObjectTreeModel::findMetaObjectTreeItem(UAVMetaObject *ob
|
|||||||
|
|
||||||
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
|
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
|
||||||
{
|
{
|
||||||
QModelIndex itemIndex = index(item);
|
// performance note: here we 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
|
||||||
|
|
||||||
|
QModelIndex itemIndex;
|
||||||
|
|
||||||
|
itemIndex = index(item, TreeItem::TITLE_COLUMN);
|
||||||
Q_ASSERT(itemIndex != QModelIndex());
|
Q_ASSERT(itemIndex != QModelIndex());
|
||||||
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::DATA_COLUMN));
|
emit dataChanged(itemIndex, itemIndex);
|
||||||
|
|
||||||
|
itemIndex = index(item, TreeItem::DATA_COLUMN);
|
||||||
|
Q_ASSERT(itemIndex != QModelIndex());
|
||||||
|
emit dataChanged(itemIndex, itemIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVObjectTreeModel::updateIsKnown(TreeItem *item)
|
void UAVObjectTreeModel::updateIsKnown(TreeItem *item)
|
||||||
{
|
{
|
||||||
QModelIndex itemIndex = index(item);
|
QModelIndex itemIndex;
|
||||||
|
|
||||||
|
itemIndex = index(item, TreeItem::TITLE_COLUMN);
|
||||||
Q_ASSERT(itemIndex != QModelIndex());
|
Q_ASSERT(itemIndex != QModelIndex());
|
||||||
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::TITLE_COLUMN));
|
emit dataChanged(itemIndex, itemIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVObjectTreeModel::isKnownChanged(UAVObject *object, bool isKnown)
|
void UAVObjectTreeModel::isKnownChanged(UAVObject *object, bool isKnown)
|
||||||
|
@ -100,7 +100,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setupModelData(UAVObjectManager *objManager);
|
void setupModelData(UAVObjectManager *objManager);
|
||||||
QModelIndex index(TreeItem *item);
|
QModelIndex index(TreeItem *item, int column = 0);
|
||||||
void addDataObject(UAVDataObject *obj);
|
void addDataObject(UAVDataObject *obj);
|
||||||
MetaObjectTreeItem *addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
MetaObjectTreeItem *addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
||||||
void addArrayField(UAVObjectField *field, TreeItem *parent);
|
void addArrayField(UAVObjectField *field, TreeItem *parent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user