From d570037331f68f77eb010e65fa41129074123318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 12 Jul 2014 12:49:07 +0200 Subject: [PATCH] Cache group view geometry -- speed up instance view by caching sizes of stuff --- gui/groupview/GroupView.cpp | 30 ++++++++++++++++++++---------- gui/groupview/GroupView.h | 2 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gui/groupview/GroupView.cpp b/gui/groupview/GroupView.cpp index 69a06fd3..6f6f0f8e 100644 --- a/gui/groupview/GroupView.cpp +++ b/gui/groupview/GroupView.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "Group.h" @@ -68,6 +69,7 @@ void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e void GroupView::updateGeometries() { + geometryCache.clear(); int previousScroll = verticalScrollBar()->value(); QMap cats; @@ -658,17 +660,25 @@ QRect GroupView::geometryRect(const QModelIndex &index) const return QRect(); } - const Group *cat = category(index); - QPair pos = categoryInternalPosition(index); - int x = pos.first; - // int y = pos.second; + int row = index.row(); + if(geometryCache.contains(row)) + { + return *geometryCache[row]; + } + else + { + const Group *cat = category(index); + QPair pos = categoryInternalPosition(index); + int x = pos.first; + // int y = pos.second; - QRect out; - out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index)); - out.setLeft(m_spacing + x * (itemWidth() + m_spacing)); - out.setSize(itemDelegate()->sizeHint(viewOptions(), index)); - - return out; + QRect out; + out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index)); + out.setLeft(m_spacing + x * (itemWidth() + m_spacing)); + out.setSize(itemDelegate()->sizeHint(viewOptions(), index)); + const_cast&>(geometryCache).insert(row, new QRect(out)); + return out; + } } /* diff --git a/gui/groupview/GroupView.h b/gui/groupview/GroupView.h index b3ab5357..736bfbeb 100644 --- a/gui/groupview/GroupView.h +++ b/gui/groupview/GroupView.h @@ -3,6 +3,7 @@ #include #include #include +#include struct GroupViewRoles { @@ -128,6 +129,7 @@ private: /* variables */ QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag; QPoint m_lastDragPosition; int m_spacing = 5; + QCache geometryCache; private: /* methods */ QPair categoryInternalPosition(const QModelIndex &index) const;