forked from mirror/openmw-tes3mp
Refine InfoTableProxyModel::getFirstInfoRow() code
This commit is contained in:
parent
844e5c504d
commit
ea97b0a20c
2 changed files with 14 additions and 14 deletions
|
@ -16,7 +16,9 @@ namespace
|
||||||
CSMWorld::InfoTableProxyModel::InfoTableProxyModel(CSMWorld::UniversalId::Type type, QObject *parent)
|
CSMWorld::InfoTableProxyModel::InfoTableProxyModel(CSMWorld::UniversalId::Type type, QObject *parent)
|
||||||
: IdTableProxyModel(parent),
|
: IdTableProxyModel(parent),
|
||||||
mType(type),
|
mType(type),
|
||||||
mSourceModel(NULL)
|
mSourceModel(NULL),
|
||||||
|
mInfoColumnId(type == UniversalId::Type_TopicInfos ? Columns::ColumnId_Topic :
|
||||||
|
Columns::ColumnId_Journal)
|
||||||
{
|
{
|
||||||
Q_ASSERT(type == UniversalId::Type_TopicInfos || type == UniversalId::Type_JournalInfos);
|
Q_ASSERT(type == UniversalId::Type_TopicInfos || type == UniversalId::Type_JournalInfos);
|
||||||
}
|
}
|
||||||
|
@ -54,26 +56,21 @@ bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QMod
|
||||||
|
|
||||||
int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const
|
int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const
|
||||||
{
|
{
|
||||||
Columns::ColumnId columnId = Columns::ColumnId_Topic;
|
int row = currentRow;
|
||||||
if (mType == UniversalId::Type_JournalInfos)
|
int column = mSourceModel->findColumnIndex(mInfoColumnId);
|
||||||
{
|
QString info = toLower(mSourceModel->data(mSourceModel->index(row, column)).toString());
|
||||||
columnId = Columns::ColumnId_Journal;
|
|
||||||
}
|
|
||||||
|
|
||||||
int column = mSourceModel->findColumnIndex(columnId);
|
|
||||||
QString info = toLower(mSourceModel->data(mSourceModel->index(currentRow, column)).toString());
|
|
||||||
|
|
||||||
if (mFirstRowCache.contains(info))
|
if (mFirstRowCache.contains(info))
|
||||||
{
|
{
|
||||||
return mFirstRowCache[info];
|
return mFirstRowCache[info];
|
||||||
}
|
}
|
||||||
|
|
||||||
while (--currentRow >= 0 &&
|
while (--row >= 0 &&
|
||||||
toLower(mSourceModel->data(mSourceModel->index(currentRow, column)).toString()) == info);
|
toLower(mSourceModel->data(mSourceModel->index(row, column)).toString()) == info);
|
||||||
++currentRow;
|
++row;
|
||||||
|
|
||||||
mFirstRowCache[info] = currentRow;
|
mFirstRowCache[info] = row;
|
||||||
return currentRow;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::InfoTableProxyModel::modelRowsChanged(const QModelIndex &/*parent*/, int /*start*/, int /*end*/)
|
void CSMWorld::InfoTableProxyModel::modelRowsChanged(const QModelIndex &/*parent*/, int /*start*/, int /*end*/)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
#include "idtableproxymodel.hpp"
|
#include "idtableproxymodel.hpp"
|
||||||
|
#include "columns.hpp"
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
|
@ -16,6 +17,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
UniversalId::Type mType;
|
UniversalId::Type mType;
|
||||||
IdTableBase *mSourceModel;
|
IdTableBase *mSourceModel;
|
||||||
|
Columns::ColumnId mInfoColumnId;
|
||||||
|
///< Contains ID for Topic or Journal ID
|
||||||
|
|
||||||
mutable QHash<QString, int> mFirstRowCache;
|
mutable QHash<QString, int> mFirstRowCache;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue