mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 16:15:35 +00:00
Add a custom proxy model for Info tables
This commit is contained in:
parent
62c5f185d7
commit
2e40b68862
3 changed files with 70 additions and 1 deletions
|
@ -18,7 +18,7 @@ opencs_hdrs_noqt (model/doc
|
||||||
|
|
||||||
|
|
||||||
opencs_units (model/world
|
opencs_units (model/world
|
||||||
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree
|
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree infotableproxymodel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
40
apps/opencs/model/world/infotableproxymodel.cpp
Normal file
40
apps/opencs/model/world/infotableproxymodel.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include "infotableproxymodel.hpp"
|
||||||
|
|
||||||
|
#include "idtablebase.hpp"
|
||||||
|
#include "columns.hpp"
|
||||||
|
|
||||||
|
CSMWorld::InfoTableProxyModel::InfoTableProxyModel(CSMWorld::UniversalId::Type type, QObject *parent)
|
||||||
|
: IdTableProxyModel(parent),
|
||||||
|
mType(type),
|
||||||
|
mSourceModel(NULL)
|
||||||
|
{
|
||||||
|
Q_ASSERT(type == UniversalId::Type_TopicInfos || type == UniversalId::Type_JournalInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::InfoTableProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||||
|
{
|
||||||
|
IdTableProxyModel::setSourceModel(sourceModel);
|
||||||
|
mSourceModel = dynamic_cast<IdTableBase *>(sourceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
QModelIndex first = mSourceModel->index(getFirstInfoRow(left.row()), left.column());
|
||||||
|
QModelIndex second = mSourceModel->index(getFirstInfoRow(right.row()), right.column());
|
||||||
|
return IdTableProxyModel::lessThan(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const
|
||||||
|
{
|
||||||
|
Columns::ColumnId columnId = Columns::ColumnId_Topic;
|
||||||
|
if (mType == UniversalId::Type_JournalInfos)
|
||||||
|
{
|
||||||
|
columnId = Columns::ColumnId_Journal;
|
||||||
|
}
|
||||||
|
|
||||||
|
int column = mSourceModel->findColumnIndex(columnId);
|
||||||
|
QVariant info = mSourceModel->data(mSourceModel->index(currentRow, column));
|
||||||
|
while (--currentRow >= 0 &&
|
||||||
|
mSourceModel->data(mSourceModel->index(currentRow, column)) == info);
|
||||||
|
return currentRow + 1;
|
||||||
|
}
|
29
apps/opencs/model/world/infotableproxymodel.hpp
Normal file
29
apps/opencs/model/world/infotableproxymodel.hpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
||||||
|
#define CSM_WORLD_INFOTABLEPROXYMODEL_HPP
|
||||||
|
|
||||||
|
#include "idtableproxymodel.hpp"
|
||||||
|
#include "universalid.hpp"
|
||||||
|
|
||||||
|
namespace CSMWorld
|
||||||
|
{
|
||||||
|
class IdTableBase;
|
||||||
|
|
||||||
|
class InfoTableProxyModel : public IdTableProxyModel
|
||||||
|
{
|
||||||
|
UniversalId::Type mType;
|
||||||
|
IdTableBase *mSourceModel;
|
||||||
|
|
||||||
|
int getFirstInfoRow(int currentRow) const;
|
||||||
|
///< Finds the first row with the same topic (journal entry) as in \a currentRow
|
||||||
|
|
||||||
|
public:
|
||||||
|
InfoTableProxyModel(UniversalId::Type type, QObject *parent = 0);
|
||||||
|
|
||||||
|
void setSourceModel(QAbstractItemModel *sourceModel);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue