diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index c9ca60b33..5f9559257 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -19,7 +19,7 @@ opencs_hdrs_noqt (model/doc opencs_units (model/world idtable idtableproxymodel regionmap data commanddispatcher - idtablebase resourcetable nestedtablemodel + idtablebase resourcetable nestedtableproxymodel ) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 964b68cd1..c5061b93d 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -51,7 +51,9 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const parentAdress.second, index.row(), index.column()); - } else { + } + else + { return mIdCollection->getData (index.row(), index.column()); } } @@ -110,7 +112,8 @@ bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value CSMWorld::IdTable::index (parentAdress.second, mIdCollection->getColumns()-1)); return true; - } else + } + else { return false; } @@ -149,7 +152,8 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren { dynamic_cast(mIdCollection)->removeNestedRows(parent.row(), parent.column(), row+i); } - } else + } + else { beginRemoveRows (parent, row, row+count-1); diff --git a/apps/opencs/model/world/nestedtablemodel.cpp b/apps/opencs/model/world/nestedtableproxymodel.cpp similarity index 66% rename from apps/opencs/model/world/nestedtablemodel.cpp rename to apps/opencs/model/world/nestedtableproxymodel.cpp index 734047b8d..c098e0316 100644 --- a/apps/opencs/model/world/nestedtablemodel.cpp +++ b/apps/opencs/model/world/nestedtableproxymodel.cpp @@ -1,9 +1,9 @@ -#include "nestedtablemodel.hpp" +#include "nestedtableproxymodel.hpp" #include #include "idtable.hpp" -CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, +CSMWorld::NestedTableProxyModel::NestedTableProxyModel(const QModelIndex& parent, ColumnBase::Display columnId, CSMWorld::IdTable* parentModel) : mParentColumn(parent.column()), @@ -14,10 +14,10 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8()); QAbstractProxyModel::setSourceModel(parentModel); - + connect(mMainModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), this, SLOT(forwardRowsAboutToInserted(const QModelIndex &, int, int))); - + connect(mMainModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(forwardRowsInserted(const QModelIndex &, int, int))); @@ -26,7 +26,7 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(forwardRowsRemoved(const QModelIndex &, int, int))); - + connect(mMainModel, SIGNAL(resetStart(const QString&)), this, SLOT(forwardResetStart(const QString&))); @@ -34,7 +34,7 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, this, SLOT(forwardResetEnd(const QString&))); } -QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const +QModelIndex CSMWorld::NestedTableProxyModel::mapFromSource(const QModelIndex& sourceIndex) const { const QModelIndex& testedParent = mMainModel->parent(sourceIndex); const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn); @@ -46,30 +46,29 @@ QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceI { return QModelIndex(); } - } -QModelIndex CSMWorld::NestedTableModel::mapToSource(const QModelIndex& proxyIndex) const +QModelIndex CSMWorld::NestedTableProxyModel::mapToSource(const QModelIndex& proxyIndex) const { const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn); return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent); } -int CSMWorld::NestedTableModel::rowCount(const QModelIndex& index) const +int CSMWorld::NestedTableProxyModel::rowCount(const QModelIndex& index) const { assert (!index.isValid()); return mMainModel->rowCount(mMainModel->getModelIndex(mId, mParentColumn)); } -int CSMWorld::NestedTableModel::columnCount(const QModelIndex& parent) const +int CSMWorld::NestedTableProxyModel::columnCount(const QModelIndex& parent) const { assert (!parent.isValid()); return mMainModel->columnCount(mMainModel->getModelIndex(mId, mParentColumn)); } -QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelIndex& parent) const +QModelIndex CSMWorld::NestedTableProxyModel::index(int row, int column, const QModelIndex& parent) const { assert (!parent.isValid()); @@ -87,12 +86,12 @@ QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelI return createIndex(row, column); } -QModelIndex CSMWorld::NestedTableModel::parent(const QModelIndex& index) const +QModelIndex CSMWorld::NestedTableProxyModel::parent(const QModelIndex& index) const { return QModelIndex(); } -QVariant CSMWorld::NestedTableModel::headerData(int section, +QVariant CSMWorld::NestedTableProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -100,32 +99,32 @@ QVariant CSMWorld::NestedTableModel::headerData(int section, } -bool CSMWorld::NestedTableModel::setData ( const QModelIndex & index, const QVariant & value, int role) +bool CSMWorld::NestedTableProxyModel::setData ( const QModelIndex & index, const QVariant & value, int role) { return mMainModel->setData(mapToSource(index), value, role); } -Qt::ItemFlags CSMWorld::NestedTableModel::flags(const QModelIndex& index) const +Qt::ItemFlags CSMWorld::NestedTableProxyModel::flags(const QModelIndex& index) const { return mMainModel->flags(mMainModel->index(0, mParentColumn)); } -std::string CSMWorld::NestedTableModel::getParentId() const +std::string CSMWorld::NestedTableProxyModel::getParentId() const { return mId; } -int CSMWorld::NestedTableModel::getParentColumn() const +int CSMWorld::NestedTableProxyModel::getParentColumn() const { return mParentColumn; } -CSMWorld::IdTable* CSMWorld::NestedTableModel::model() const +CSMWorld::IdTable* CSMWorld::NestedTableProxyModel::model() const { return mMainModel; } -void CSMWorld::NestedTableModel::forwardRowsAboutToInserted(const QModelIndex& parent, int first, int last) +void CSMWorld::NestedTableProxyModel::forwardRowsAboutToInserted(const QModelIndex& parent, int first, int last) { if (indexIsParent(parent)) { @@ -133,7 +132,7 @@ void CSMWorld::NestedTableModel::forwardRowsAboutToInserted(const QModelIndex& p } } -void CSMWorld::NestedTableModel::forwardRowsInserted(const QModelIndex& parent, int first, int last) +void CSMWorld::NestedTableProxyModel::forwardRowsInserted(const QModelIndex& parent, int first, int last) { if (indexIsParent(parent)) { @@ -141,14 +140,14 @@ void CSMWorld::NestedTableModel::forwardRowsInserted(const QModelIndex& parent, } } -bool CSMWorld::NestedTableModel::indexIsParent(const QModelIndex& index) +bool CSMWorld::NestedTableProxyModel::indexIsParent(const QModelIndex& index) { return (index.isValid() && index.column() == mParentColumn && mMainModel->data(mMainModel->index(index.row(), 0)).toString().toUtf8().constData() == mId); } -void CSMWorld::NestedTableModel::forwardRowsAboutToRemoved(const QModelIndex& parent, int first, int last) +void CSMWorld::NestedTableProxyModel::forwardRowsAboutToRemoved(const QModelIndex& parent, int first, int last) { if (indexIsParent(parent)) { @@ -156,7 +155,7 @@ void CSMWorld::NestedTableModel::forwardRowsAboutToRemoved(const QModelIndex& pa } } -void CSMWorld::NestedTableModel::forwardRowsRemoved(const QModelIndex& parent, int first, int last) +void CSMWorld::NestedTableProxyModel::forwardRowsRemoved(const QModelIndex& parent, int first, int last) { if (indexIsParent(parent)) { @@ -164,13 +163,13 @@ void CSMWorld::NestedTableModel::forwardRowsRemoved(const QModelIndex& parent, i } } -void CSMWorld::NestedTableModel::forwardResetStart(const QString& id) +void CSMWorld::NestedTableProxyModel::forwardResetStart(const QString& id) { if (id.toUtf8() == mId.c_str()) beginResetModel(); } -void CSMWorld::NestedTableModel::forwardResetEnd(const QString& id) +void CSMWorld::NestedTableProxyModel::forwardResetEnd(const QString& id) { if (id.toUtf8() == mId.c_str()) endResetModel(); diff --git a/apps/opencs/model/world/nestedtablemodel.hpp b/apps/opencs/model/world/nestedtableproxymodel.hpp similarity index 89% rename from apps/opencs/model/world/nestedtablemodel.hpp rename to apps/opencs/model/world/nestedtableproxymodel.hpp index 5fea5c006..7ad8fc0c2 100644 --- a/apps/opencs/model/world/nestedtablemodel.hpp +++ b/apps/opencs/model/world/nestedtableproxymodel.hpp @@ -1,5 +1,5 @@ -#ifndef CSM_WOLRD_NESTEDTABLEMODEL_H -#define CSM_WOLRD_NESTEDTABLEMODEL_H +#ifndef CSM_WOLRD_NESTEDTABLEPROXYMODEL_H +#define CSM_WOLRD_NESTEDTABLEPROXYMODEL_H #include @@ -19,7 +19,7 @@ namespace CSMWorld class RecordBase; class IdTable; - class NestedTableModel : public QAbstractProxyModel + class NestedTableProxyModel : public QAbstractProxyModel { Q_OBJECT @@ -28,15 +28,15 @@ namespace CSMWorld std::string mId; public: - NestedTableModel(const QModelIndex& parent, + NestedTableProxyModel(const QModelIndex& parent, ColumnBase::Display displayType, IdTable* parentModel); //parent is the parent of columns to work with. Columnid provides information about the column std::string getParentId() const; - + int getParentColumn() const; - + CSMWorld::IdTable* model() const; virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const; @@ -52,27 +52,27 @@ namespace CSMWorld virtual QModelIndex parent(const QModelIndex& index) const; virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) const; - + virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); - + virtual Qt::ItemFlags flags(const QModelIndex& index) const; - + private: void setupHeaderVectors(ColumnBase::Display columnId); bool indexIsParent(const QModelIndex& index); - + private slots: void forwardRowsAboutToInserted(const QModelIndex & parent, int first, int last); - + void forwardRowsInserted(const QModelIndex & parent, int first, int last); void forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last); void forwardRowsRemoved(const QModelIndex & parent, int first, int last); - + void forwardResetStart(const QString& id); - + void forwardResetEnd(const QString& id); }; } diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 421e12c13..e26dcdc9b 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -23,7 +23,7 @@ #include #include -#include "../../model/world/nestedtablemodel.hpp" +#include "../../model/world/nestedtableproxymodel.hpp" #include "../../model/world/columnbase.hpp" #include "../../model/world/idtable.hpp" #include "../../model/world/columns.hpp" @@ -422,7 +422,7 @@ void CSVWorld::EditWidget::remake(int row) if (mTable->hasChildren(mTable->index(row, i))) { - mNestedModels.push_back(new CSMWorld::NestedTableModel (mTable->index(row, i), display, mTable)); + mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (mTable->index(row, i), display, mTable)); NestedTable* table = new NestedTable(mDocument, mNestedModels.back(), this); diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index 6ea79aa95..72acb1966 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -21,7 +21,7 @@ class QVBoxLayout; namespace CSMWorld { class IdTable; - class NestedTableModel; + class NestedTableProxyModel; } namespace CSMDoc @@ -165,7 +165,7 @@ namespace CSVWorld QWidget* mMainWidget; CSMWorld::IdTable* mTable; CSMDoc::Document& mDocument; - std::vector mNestedModels; //Plain, raw C pointers, deleted in the dtor + std::vector mNestedModels; //Plain, raw C pointers, deleted in the dtor public: diff --git a/apps/opencs/view/world/nestedtable.cpp b/apps/opencs/view/world/nestedtable.cpp index 14e079c98..1597c81a3 100644 --- a/apps/opencs/view/world/nestedtable.cpp +++ b/apps/opencs/view/world/nestedtable.cpp @@ -1,5 +1,5 @@ #include "nestedtable.hpp" -#include "../../model/world/nestedtablemodel.hpp" +#include "../../model/world/nestedtableproxymodel.hpp" #include "../../model/world/universalid.hpp" #include "../../model/world/commands.hpp" #include "util.hpp" @@ -10,7 +10,7 @@ #include CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document, - CSMWorld::NestedTableModel* model, + CSMWorld::NestedTableProxyModel* model, QWidget* parent) : QTableView(parent), mUndoStack(document.getUndoStack()), diff --git a/apps/opencs/view/world/nestedtable.hpp b/apps/opencs/view/world/nestedtable.hpp index 6b6b6aaba..f41ba4345 100644 --- a/apps/opencs/view/world/nestedtable.hpp +++ b/apps/opencs/view/world/nestedtable.hpp @@ -10,7 +10,7 @@ class QContextMenuEvent; namespace CSMWorld { - class NestedTableModel; + class NestedTableProxyModel; class UniversalId; } @@ -28,11 +28,11 @@ namespace CSVWorld QAction *mAddNewRowAction; QAction *mRemoveRowAction; QUndoStack& mUndoStack; - CSMWorld::NestedTableModel* mModel; + CSMWorld::NestedTableProxyModel* mModel; public: NestedTable(CSMDoc::Document& document, - CSMWorld::NestedTableModel* model, + CSMWorld::NestedTableProxyModel* model, QWidget* parent = NULL); protected: