diff --git a/apps/opencs/model/world/columnbase.cpp b/apps/opencs/model/world/columnbase.cpp index e81943843..c0a264a1f 100644 --- a/apps/opencs/model/world/columnbase.cpp +++ b/apps/opencs/model/world/columnbase.cpp @@ -3,6 +3,8 @@ #include "columns.hpp" +#include + CSMWorld::ColumnBase::ColumnBase (int columnId, Display displayType, int flags, bool canNest) : mColumnId (columnId), mDisplayType (displayType), mFlags (flags), mCanNest(canNest) {} @@ -28,3 +30,15 @@ bool CSMWorld::ColumnBase::canHaveNestedColumns() const { return mCanNest; } + +std::string CSMWorld::ColumnBase::getNestedColumnTitle(int columnNumber) const +{ + return Columns::getName (mDisplayType, columnNumber); +} + +void CSMWorld::ColumnBase::addNestedColumnDisplay(CSMWorld::ColumnBase::Display displayDefinition) +{ + assert (canHaveNestedColumns()); + + mNestedDisplayType.push_back(displayDefinition); +} diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index 164ca4302..0cd1f722f 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -2,6 +2,7 @@ #define CSM_WOLRD_COLUMNBASE_H #include +#include #include #include @@ -97,6 +98,7 @@ namespace CSMWorld int mColumnId; int mFlags; Display mDisplayType; + std::vector mNestedDisplayType; const bool mCanNest; ColumnBase (int columnId, Display displayType, int flag, bool canNest = false); @@ -110,6 +112,10 @@ namespace CSMWorld virtual std::string getTitle() const; + std::string getNestedColumnTitle(int columnNumber) const; + + virtual void addNestedColumnDisplay(Display displayDefinition); + virtual int getId() const; bool canHaveNestedColumns() const; diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp index 7410780e0..e39badeb5 100644 --- a/apps/opencs/model/world/columns.cpp +++ b/apps/opencs/model/world/columns.cpp @@ -216,6 +216,21 @@ std::string CSMWorld::Columns::getName (ColumnId column) return ""; } +std::string CSMWorld::Columns::getName(CSMWorld::ColumnBase::Display displayType, int columnNumber) +{ +//TODO, this is just temporary solution + switch (displayType) + { + case CSMWorld::ColumnBase::Display_NestedItemList: + if (columnNumber == 0) + return "ID"; + + if (columnNumber == 1) + return "Count"; + } + return "Do yourself a favor and take a look at the columns.cpp"; +} + int CSMWorld::Columns::getId (const std::string& name) { std::string name2 = Misc::StringUtils::lowerCase (name); diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index e824c4392..436ca1334 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -4,6 +4,8 @@ #include #include +#include "columnbase.hpp" + namespace CSMWorld { namespace Columns @@ -208,6 +210,8 @@ namespace CSMWorld std::string getName (ColumnId column); + std::string getName (ColumnBase::Display displayType, int columnNumber); + int getId (const std::string& name); ///< Will return -1 for an invalid name. diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 6aba322c1..fd2547ecf 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -1,5 +1,7 @@ #include "idtable.hpp" +#include + #include "collectionbase.hpp" #include "columnbase.hpp" @@ -70,6 +72,25 @@ QVariant CSMWorld::IdTable::headerData (int section, return QVariant(); } +QVariant CSMWorld::IdTable::nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role) const +{ + assert(mIdCollection->getColumn(section).canHaveNestedColumns()); + + if (orientation==Qt::Vertical) + return QVariant(); + + if (role==Qt::DisplayRole) + return tr (mIdCollection->getColumn(section).getNestedColumnTitle(subSection).c_str()); + + if (role==ColumnBase::Role_Flags) + return mIdCollection->getColumn (section).mFlags; + + if (role==ColumnBase::Role_Display) + return mIdCollection->getColumn (section).mNestedDisplayType.at(subSection); + + return QVariant(); +} + bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value, int role) { if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole) diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index 6dc6f3e33..29d1f134a 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -72,6 +72,8 @@ namespace CSMWorld virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual Qt::ItemFlags flags (const QModelIndex & index) const; diff --git a/apps/opencs/model/world/nestedtablemodel.cpp b/apps/opencs/model/world/nestedtablemodel.cpp index 9ae4bdfd3..534ec5d10 100644 --- a/apps/opencs/model/world/nestedtablemodel.cpp +++ b/apps/opencs/model/world/nestedtablemodel.cpp @@ -6,21 +6,20 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, ColumnBase::Display columnId, CSMWorld::IdTable* parentModel) - : mParentColumn(parent.column()) + : mParentColumn(parent.column()), + mMainModel(parentModel) { const int parentRow = parent.row(); mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8()); QAbstractProxyModel::setSourceModel(parentModel); - - setupHeaderVectors(columnId); } QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const { - const QModelIndex& testedParent = sourceModel()->parent(sourceIndex); - const QModelIndex& parent = dynamic_cast(sourceModel())->getModelIndex (mId, mParentColumn); + const QModelIndex& testedParent = mMainModel->parent(sourceIndex); + const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn); if (testedParent == parent) { return createIndex(sourceIndex.row(), sourceIndex.column()); @@ -34,36 +33,30 @@ QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceI QModelIndex CSMWorld::NestedTableModel::mapToSource(const QModelIndex& proxyIndex) const { - const QModelIndex& parent = dynamic_cast(sourceModel())->getModelIndex (mId, mParentColumn); - return sourceModel()->index(proxyIndex.row(), proxyIndex.column(), parent); + const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn); + return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent); } int CSMWorld::NestedTableModel::rowCount(const QModelIndex& index) const { assert (!index.isValid()); - CSMWorld::IdTable* table = dynamic_cast(sourceModel()); - - return table->rowCount(table->getModelIndex(mId, mParentColumn)); + return mMainModel->rowCount(mMainModel->getModelIndex(mId, mParentColumn)); } int CSMWorld::NestedTableModel::columnCount(const QModelIndex& parent) const { assert (!parent.isValid()); - CSMWorld::IdTable* table = dynamic_cast(sourceModel()); - - return table->columnCount(table->getModelIndex(mId, mParentColumn)); + return mMainModel->columnCount(mMainModel->getModelIndex(mId, mParentColumn)); } QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelIndex& parent) const { assert (!parent.isValid()); - CSMWorld::IdTable* table = dynamic_cast(sourceModel()); - - int rows = table->rowCount(parent); - int columns = table->columnCount(parent); + int rows = mMainModel->rowCount(parent); + int columns = mMainModel->columnCount(parent); if (row < 0 || row >= rows || @@ -85,34 +78,5 @@ QVariant CSMWorld::NestedTableModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation==Qt::Vertical) - return QVariant(); - - if (role==Qt::DisplayRole) - return tr (mHeaderTitle[section].c_str()); - - if (role==ColumnBase::Role_Flags) - return QVariant(); //TODO - - if (role==ColumnBase::Role_Display) - return mHeaderDisplay[section]; - - return QVariant(); -} - -void CSMWorld::NestedTableModel::setupHeaderVectors(ColumnBase::Display columnId) -{ - switch(columnId) - { - case ColumnBase::Display_NestedItemList: - mHeaderTitle.push_back("test1"); - mHeaderTitle.push_back("test2"); - - mHeaderDisplay.push_back(ColumnBase::Display_String); - mHeaderDisplay.push_back(ColumnBase::Display_Integer); - break; - - default: - assert(false); - } + return mMainModel->nestedHeaderData(mParentColumn, section, orientation, role); } diff --git a/apps/opencs/model/world/nestedtablemodel.hpp b/apps/opencs/model/world/nestedtablemodel.hpp index 80c7f5a8e..404051efc 100644 --- a/apps/opencs/model/world/nestedtablemodel.hpp +++ b/apps/opencs/model/world/nestedtablemodel.hpp @@ -22,9 +22,8 @@ namespace CSMWorld class NestedTableModel : public QAbstractProxyModel { const int mParentColumn; + IdTable* mMainModel; std::string mId; - std::vector mHeaderTitle; - std::vector mHeaderDisplay; public: NestedTableModel(const QModelIndex& parent, diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index a8fac216b..47c8ec800 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -168,6 +168,8 @@ CSMWorld::RefIdCollection::RefIdCollection() mColumns.push_back(RefIdColumn (Columns::ColumnId_ContainerContent, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue, true, true, true)); const RefIdColumn *content = &mColumns.back(); + (&mColumns.back())->addNestedColumnDisplay(CSMWorld::ColumnBase::Display_String); + (&mColumns.back())->addNestedColumnDisplay(CSMWorld::ColumnBase::Display_Integer); CreatureColumns creatureColumns (actorsColumns);