diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-07-12 12:49:07 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-07-12 12:49:07 +0200 |
commit | d570037331f68f77eb010e65fa41129074123318 (patch) | |
tree | 4c36bbc8008bdb5010538c04e922182cc5f29c4b /gui/groupview | |
parent | 6a8984a21d5ab7b20821c8c6624e135c1a4c9e34 (diff) | |
download | MultiMC-d570037331f68f77eb010e65fa41129074123318.tar MultiMC-d570037331f68f77eb010e65fa41129074123318.tar.gz MultiMC-d570037331f68f77eb010e65fa41129074123318.tar.lz MultiMC-d570037331f68f77eb010e65fa41129074123318.tar.xz MultiMC-d570037331f68f77eb010e65fa41129074123318.zip |
Cache group view geometry -- speed up instance view by caching sizes of stuff
Diffstat (limited to 'gui/groupview')
-rw-r--r-- | gui/groupview/GroupView.cpp | 30 | ||||
-rw-r--r-- | 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 <QPersistentModelIndex> #include <QDrag> #include <QMimeData> +#include <QCache> #include <QScrollBar> #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<QString, Group *> cats; @@ -658,17 +660,25 @@ QRect GroupView::geometryRect(const QModelIndex &index) const return QRect(); } - const Group *cat = category(index); - QPair<int, int> 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)); + int row = index.row(); + if(geometryCache.contains(row)) + { + return *geometryCache[row]; + } + else + { + const Group *cat = category(index); + QPair<int, int> pos = categoryInternalPosition(index); + int x = pos.first; + // int y = pos.second; - 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<QCache<int, QRect>&>(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 <QListView> #include <QLineEdit> #include <QScrollBar> +#include <QCache> struct GroupViewRoles { @@ -128,6 +129,7 @@ private: /* variables */ QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag; QPoint m_lastDragPosition; int m_spacing = 5; + QCache<int, QRect> geometryCache; private: /* methods */ QPair<int, int> categoryInternalPosition(const QModelIndex &index) const; |