mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-15 18:39:51 +00:00
Cache topic/journal first rows in InfoTableProxyModel
This commit is contained in:
parent
2e40b68862
commit
a6624ca576
@ -15,6 +15,11 @@ void CSMWorld::InfoTableProxyModel::setSourceModel(QAbstractItemModel *sourceMod
|
|||||||
{
|
{
|
||||||
IdTableProxyModel::setSourceModel(sourceModel);
|
IdTableProxyModel::setSourceModel(sourceModel);
|
||||||
mSourceModel = dynamic_cast<IdTableBase *>(sourceModel);
|
mSourceModel = dynamic_cast<IdTableBase *>(sourceModel);
|
||||||
|
connect(mSourceModel,
|
||||||
|
SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
|
||||||
|
this,
|
||||||
|
SLOT(modelDataChanged(const QModelIndex &, const QModelIndex &)));
|
||||||
|
mFirstRowCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
@ -33,8 +38,21 @@ int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
int column = mSourceModel->findColumnIndex(columnId);
|
int column = mSourceModel->findColumnIndex(columnId);
|
||||||
QVariant info = mSourceModel->data(mSourceModel->index(currentRow, column));
|
QString info = mSourceModel->data(mSourceModel->index(currentRow, column)).toString();
|
||||||
while (--currentRow >= 0 &&
|
|
||||||
|
if (mFirstRowCache.contains(info))
|
||||||
|
{
|
||||||
|
return mFirstRowCache[info];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (--currentRow >= 0 &&
|
||||||
mSourceModel->data(mSourceModel->index(currentRow, column)) == info);
|
mSourceModel->data(mSourceModel->index(currentRow, column)) == info);
|
||||||
|
|
||||||
|
mFirstRowCache[info] = currentRow + 1;
|
||||||
return currentRow + 1;
|
return currentRow + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::InfoTableProxyModel::modelDataChanged(const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/)
|
||||||
|
{
|
||||||
|
mFirstRowCache.clear();
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
#ifndef CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
||||||
#define CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
#define CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#include "idtableproxymodel.hpp"
|
#include "idtableproxymodel.hpp"
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
@ -10,9 +12,13 @@ namespace CSMWorld
|
|||||||
|
|
||||||
class InfoTableProxyModel : public IdTableProxyModel
|
class InfoTableProxyModel : public IdTableProxyModel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
UniversalId::Type mType;
|
UniversalId::Type mType;
|
||||||
IdTableBase *mSourceModel;
|
IdTableBase *mSourceModel;
|
||||||
|
|
||||||
|
mutable QHash<QString, int> mFirstRowCache;
|
||||||
|
|
||||||
int getFirstInfoRow(int currentRow) const;
|
int getFirstInfoRow(int currentRow) const;
|
||||||
///< Finds the first row with the same topic (journal entry) as in \a currentRow
|
///< Finds the first row with the same topic (journal entry) as in \a currentRow
|
||||||
|
|
||||||
@ -23,6 +29,9 @@ namespace CSMWorld
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user