forked from mirror/openmw-tes3mp
adding proxy model that is ment to be used by the dialoguesubview
This commit is contained in:
parent
75b5513c6c
commit
1fb18873cb
4 changed files with 78 additions and 0 deletions
|
@ -19,6 +19,7 @@ opencs_hdrs_noqt (model/doc
|
||||||
|
|
||||||
opencs_units (model/world
|
opencs_units (model/world
|
||||||
idtable idtableproxymodel regionmap data commanddispatcher
|
idtable idtableproxymodel regionmap data commanddispatcher
|
||||||
|
nestedtablemodel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ namespace CSMWorld
|
||||||
ColumnId_Scope = 155,
|
ColumnId_Scope = 155,
|
||||||
ColumnId_ReferenceableId = 156,
|
ColumnId_ReferenceableId = 156,
|
||||||
ColumnId_ContainerContent = 157,
|
ColumnId_ContainerContent = 157,
|
||||||
|
ColumnId_ItemCount = 158,
|
||||||
|
|
||||||
// Allocated to a separate value range, so we don't get a collision should we ever need
|
// Allocated to a separate value range, so we don't get a collision should we ever need
|
||||||
// to extend the number of use values.
|
// to extend the number of use values.
|
||||||
|
|
34
apps/opencs/model/world/nestedtablemodel.cpp
Normal file
34
apps/opencs/model/world/nestedtablemodel.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "nestedtablemodel.hpp"
|
||||||
|
|
||||||
|
#include "./idtable.hpp"
|
||||||
|
|
||||||
|
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
|
||||||
|
ColumnBase::Display columnId,
|
||||||
|
CSMWorld::IdTable* parentModel)
|
||||||
|
: mParentColumn(parent.column())
|
||||||
|
{
|
||||||
|
const int parentRow = parent.row();
|
||||||
|
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
|
||||||
|
QAbstractProxyModel::setSourceModel(parentModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const
|
||||||
|
{
|
||||||
|
const QModelIndex& testedParent = sourceModel()->parent(sourceIndex);
|
||||||
|
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
|
||||||
|
if (testedParent == parent)
|
||||||
|
{
|
||||||
|
return createIndex(sourceIndex.row(), sourceIndex.column());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CSMWorld::NestedTableModel::mapToSource(const QModelIndex& proxyIndex) const
|
||||||
|
{
|
||||||
|
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
|
||||||
|
return sourceModel()->index(proxyIndex.row(), proxyIndex.column(), parent);
|
||||||
|
}
|
42
apps/opencs/model/world/nestedtablemodel.hpp
Normal file
42
apps/opencs/model/world/nestedtablemodel.hpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
#ifndef CSM_WOLRD_NESTEDTABLEMODEL_H
|
||||||
|
#define CSM_WOLRD_NESTEDTABLEMODEL_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QAbstractProxyModel>
|
||||||
|
|
||||||
|
#include "universalid.hpp"
|
||||||
|
#include "columns.hpp"
|
||||||
|
#include "columnbase.hpp"
|
||||||
|
|
||||||
|
/*! \brief
|
||||||
|
* Proxy model used to connect view in the dialogue into the nested columns of the main model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CSMWorld
|
||||||
|
{
|
||||||
|
class CollectionBase;
|
||||||
|
class RecordBase;
|
||||||
|
class IdTable;
|
||||||
|
|
||||||
|
class NestedTableModel : public QAbstractProxyModel
|
||||||
|
{
|
||||||
|
const int mParentColumn;
|
||||||
|
std::string mId;
|
||||||
|
std::vector<std::string> mHeaderTitle;
|
||||||
|
std::vector<ColumnBase::Display> mHeaderDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NestedTableModel(const QModelIndex& parent,
|
||||||
|
ColumnBase::Display displayType,
|
||||||
|
IdTable* parentModel);
|
||||||
|
//parent is the parent of columns to work with. Columnid provides information about the column
|
||||||
|
|
||||||
|
virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
|
||||||
|
|
||||||
|
virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue