Optimise tree view expand/collapse all to avoid slow Qt path

This commit is contained in:
baldurk
2021-05-21 14:30:02 +01:00
parent 5252a3b9b7
commit 58b38337f1
2 changed files with 33 additions and 6 deletions
+30 -6
View File
@@ -376,20 +376,44 @@ void RDTreeView::copyIndex(QPoint pos, QModelIndex index)
selectionModel()->clear();
}
void RDTreeView::expandAll(QModelIndex index)
void RDTreeView::expandAllInternal(QModelIndex index)
{
int rows = model()->rowCount(index);
if(rows == 0)
return;
expand(index);
for(int r = 0, rows = model()->rowCount(index); r < rows; r++)
for(int r = 0; r < rows; r++)
expandAll(model()->index(r, 0, index));
}
void RDTreeView::collapseAllInternal(QModelIndex index)
{
int rows = model()->rowCount(index);
if(rows == 0)
return;
collapse(index);
for(int r = 0; r < rows; r++)
collapseAll(model()->index(r, 0, index));
}
void RDTreeView::expandAll(QModelIndex index)
{
setUpdatesEnabled(false);
expandAllInternal(index);
setUpdatesEnabled(true);
}
void RDTreeView::collapseAll(QModelIndex index)
{
collapse(index);
for(int r = 0, rows = model()->rowCount(index); r < rows; r++)
collapseAll(model()->index(r, 0, index));
setUpdatesEnabled(false);
collapseAllInternal(index);
setUpdatesEnabled(true);
}
bool RDTreeView::viewportEvent(QEvent *event)
+3
View File
@@ -214,6 +214,9 @@ private:
bool m_customCopyPaste = false;
bool m_instantTooltips = false;
void expandAllInternal(QModelIndex index);
void collapseAllInternal(QModelIndex index);
QMap<uint, RDTreeViewExpansionState> m_Expansions;
void updateExpansionFromRow(RDTreeViewExpansionState &state, QModelIndex idx, uint seed,