Commit 0a23dd4e authored by Daniel Teske's avatar Daniel Teske
Browse files

ProjectTree: Improve resizing of project tree



On each resize event the treeview iterated over all rows to get the
maximum width of them. That involves text layout and is very slow
with bigger trees.

So cache the size hint for the column and connect to all signals
that can potentially change the size hint.

Change-Id: I83a13982848df56515fed8225ced336096370546
Task-number: QTCREATORBUG-8075
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 4b1cda0f
......@@ -96,15 +96,71 @@ public:
m_context = new IContext(this);
m_context->setContext(Context(ProjectExplorer::Constants::C_PROJECT_TREE));
m_context->setWidget(this);
ICore::addContextObject(m_context);
connect(this, &ProjectTreeView::expanded,
this, &ProjectTreeView::invalidateSize);
connect(this, &ProjectTreeView::collapsed,
this, &ProjectTreeView::invalidateSize);
}
void invalidateSize()
{
m_cachedSize = -1;
}
void setModel(QAbstractItemModel *newModel)
{
// Note: Don't connect to column signals, as we have only one column
if (model()) {
QAbstractItemModel *m = model();
disconnect(m, &QAbstractItemModel::dataChanged,
this, &ProjectTreeView::invalidateSize);
disconnect(m, &QAbstractItemModel::layoutChanged,
this, &ProjectTreeView::invalidateSize);
disconnect(m, &QAbstractItemModel::modelReset,
this, &ProjectTreeView::invalidateSize);
disconnect(m, &QAbstractItemModel::rowsInserted,
this, &ProjectTreeView::invalidateSize);
disconnect(m, &QAbstractItemModel::rowsMoved,
this, &ProjectTreeView::invalidateSize);
disconnect(m, &QAbstractItemModel::rowsRemoved,
this, &ProjectTreeView::invalidateSize);
}
if (newModel) {
connect(newModel, &QAbstractItemModel::dataChanged,
this, &ProjectTreeView::invalidateSize);
connect(newModel, &QAbstractItemModel::layoutChanged,
this, &ProjectTreeView::invalidateSize);
connect(newModel, &QAbstractItemModel::modelReset,
this, &ProjectTreeView::invalidateSize);
connect(newModel, &QAbstractItemModel::rowsInserted,
this, &ProjectTreeView::invalidateSize);
connect(newModel, &QAbstractItemModel::rowsMoved,
this, &ProjectTreeView::invalidateSize);
connect(newModel, &QAbstractItemModel::rowsRemoved,
this, &ProjectTreeView::invalidateSize);
}
Utils::NavigationTreeView::setModel(newModel);
}
~ProjectTreeView()
{
ICore::removeContextObject(m_context);
delete m_context;
}
int sizeHintForColumn(int column) const override
{
if (m_cachedSize < 0)
m_cachedSize = Utils::NavigationTreeView::sizeHintForColumn(column);
return m_cachedSize;
}
private:
mutable int m_cachedSize = -1;
IContext *m_context;
};
......
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