Cache group view geometry -- speed up instance view by caching sizes of stuff
This commit is contained in:
parent
6a8984a21d
commit
d570037331
@ -8,6 +8,7 @@
|
|||||||
#include <QPersistentModelIndex>
|
#include <QPersistentModelIndex>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QCache>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
@ -68,6 +69,7 @@ void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e
|
|||||||
|
|
||||||
void GroupView::updateGeometries()
|
void GroupView::updateGeometries()
|
||||||
{
|
{
|
||||||
|
geometryCache.clear();
|
||||||
int previousScroll = verticalScrollBar()->value();
|
int previousScroll = verticalScrollBar()->value();
|
||||||
|
|
||||||
QMap<QString, Group *> cats;
|
QMap<QString, Group *> cats;
|
||||||
@ -658,6 +660,13 @@ QRect GroupView::geometryRect(const QModelIndex &index) const
|
|||||||
return QRect();
|
return QRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int row = index.row();
|
||||||
|
if(geometryCache.contains(row))
|
||||||
|
{
|
||||||
|
return *geometryCache[row];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
const Group *cat = category(index);
|
const Group *cat = category(index);
|
||||||
QPair<int, int> pos = categoryInternalPosition(index);
|
QPair<int, int> pos = categoryInternalPosition(index);
|
||||||
int x = pos.first;
|
int x = pos.first;
|
||||||
@ -667,9 +676,10 @@ QRect GroupView::geometryRect(const QModelIndex &index) const
|
|||||||
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
||||||
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
||||||
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
||||||
|
const_cast<QCache<int, QRect>&>(geometryCache).insert(row, new QRect(out));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void CategorizedView::startCategoryEditor(Category *category)
|
void CategorizedView::startCategoryEditor(Category *category)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QCache>
|
||||||
|
|
||||||
struct GroupViewRoles
|
struct GroupViewRoles
|
||||||
{
|
{
|
||||||
@ -128,6 +129,7 @@ private: /* variables */
|
|||||||
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
||||||
QPoint m_lastDragPosition;
|
QPoint m_lastDragPosition;
|
||||||
int m_spacing = 5;
|
int m_spacing = 5;
|
||||||
|
QCache<int, QRect> geometryCache;
|
||||||
|
|
||||||
private: /* methods */
|
private: /* methods */
|
||||||
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user