More consistency nit pick.

This commit is contained in:
cc9cii 2015-03-30 16:41:55 +11:00
parent 29ef08bb75
commit 619b5206cd
8 changed files with 54 additions and 51 deletions

View file

@ -19,7 +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
idtablebase resourcetable nestedtablemodel idtablebase resourcetable nestedtableproxymodel
) )

View file

@ -51,7 +51,9 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const
parentAdress.second, parentAdress.second,
index.row(), index.row(),
index.column()); index.column());
} else { }
else
{
return mIdCollection->getData (index.row(), index.column()); 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)); CSMWorld::IdTable::index (parentAdress.second, mIdCollection->getColumns()-1));
return true; return true;
} else }
else
{ {
return false; return false;
} }
@ -149,7 +152,8 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren
{ {
dynamic_cast<NestedCollection*>(mIdCollection)->removeNestedRows(parent.row(), parent.column(), row+i); dynamic_cast<NestedCollection*>(mIdCollection)->removeNestedRows(parent.row(), parent.column(), row+i);
} }
} else }
else
{ {
beginRemoveRows (parent, row, row+count-1); beginRemoveRows (parent, row, row+count-1);

View file

@ -1,9 +1,9 @@
#include "nestedtablemodel.hpp" #include "nestedtableproxymodel.hpp"
#include <cassert> #include <cassert>
#include "idtable.hpp" #include "idtable.hpp"
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent, CSMWorld::NestedTableProxyModel::NestedTableProxyModel(const QModelIndex& parent,
ColumnBase::Display columnId, ColumnBase::Display columnId,
CSMWorld::IdTable* parentModel) CSMWorld::IdTable* parentModel)
: mParentColumn(parent.column()), : mParentColumn(parent.column()),
@ -14,10 +14,10 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8()); mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
QAbstractProxyModel::setSourceModel(parentModel); QAbstractProxyModel::setSourceModel(parentModel);
connect(mMainModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), connect(mMainModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsAboutToInserted(const QModelIndex &, int, int))); this, SLOT(forwardRowsAboutToInserted(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), connect(mMainModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsInserted(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)), connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(forwardRowsRemoved(const QModelIndex &, int, int))); this, SLOT(forwardRowsRemoved(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(resetStart(const QString&)), connect(mMainModel, SIGNAL(resetStart(const QString&)),
this, SLOT(forwardResetStart(const QString&))); this, SLOT(forwardResetStart(const QString&)));
@ -34,7 +34,7 @@ CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
this, SLOT(forwardResetEnd(const QString&))); 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& testedParent = mMainModel->parent(sourceIndex);
const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn); const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn);
@ -46,30 +46,29 @@ QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceI
{ {
return QModelIndex(); 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); const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn);
return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent); 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()); assert (!index.isValid());
return mMainModel->rowCount(mMainModel->getModelIndex(mId, mParentColumn)); 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()); assert (!parent.isValid());
return mMainModel->columnCount(mMainModel->getModelIndex(mId, mParentColumn)); 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()); assert (!parent.isValid());
@ -87,12 +86,12 @@ QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelI
return createIndex(row, column); return createIndex(row, column);
} }
QModelIndex CSMWorld::NestedTableModel::parent(const QModelIndex& index) const QModelIndex CSMWorld::NestedTableProxyModel::parent(const QModelIndex& index) const
{ {
return QModelIndex(); return QModelIndex();
} }
QVariant CSMWorld::NestedTableModel::headerData(int section, QVariant CSMWorld::NestedTableProxyModel::headerData(int section,
Qt::Orientation orientation, Qt::Orientation orientation,
int role) const 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); 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)); return mMainModel->flags(mMainModel->index(0, mParentColumn));
} }
std::string CSMWorld::NestedTableModel::getParentId() const std::string CSMWorld::NestedTableProxyModel::getParentId() const
{ {
return mId; return mId;
} }
int CSMWorld::NestedTableModel::getParentColumn() const int CSMWorld::NestedTableProxyModel::getParentColumn() const
{ {
return mParentColumn; return mParentColumn;
} }
CSMWorld::IdTable* CSMWorld::NestedTableModel::model() const CSMWorld::IdTable* CSMWorld::NestedTableProxyModel::model() const
{ {
return mMainModel; 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)) 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)) 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() && return (index.isValid() &&
index.column() == mParentColumn && index.column() == mParentColumn &&
mMainModel->data(mMainModel->index(index.row(), 0)).toString().toUtf8().constData() == mId); 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)) 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)) 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()) if (id.toUtf8() == mId.c_str())
beginResetModel(); beginResetModel();
} }
void CSMWorld::NestedTableModel::forwardResetEnd(const QString& id) void CSMWorld::NestedTableProxyModel::forwardResetEnd(const QString& id)
{ {
if (id.toUtf8() == mId.c_str()) if (id.toUtf8() == mId.c_str())
endResetModel(); endResetModel();

View file

@ -1,5 +1,5 @@
#ifndef CSM_WOLRD_NESTEDTABLEMODEL_H #ifndef CSM_WOLRD_NESTEDTABLEPROXYMODEL_H
#define CSM_WOLRD_NESTEDTABLEMODEL_H #define CSM_WOLRD_NESTEDTABLEPROXYMODEL_H
#include <vector> #include <vector>
@ -19,7 +19,7 @@ namespace CSMWorld
class RecordBase; class RecordBase;
class IdTable; class IdTable;
class NestedTableModel : public QAbstractProxyModel class NestedTableProxyModel : public QAbstractProxyModel
{ {
Q_OBJECT Q_OBJECT
@ -28,15 +28,15 @@ namespace CSMWorld
std::string mId; std::string mId;
public: public:
NestedTableModel(const QModelIndex& parent, NestedTableProxyModel(const QModelIndex& parent,
ColumnBase::Display displayType, ColumnBase::Display displayType,
IdTable* parentModel); IdTable* parentModel);
//parent is the parent of columns to work with. Columnid provides information about the column //parent is the parent of columns to work with. Columnid provides information about the column
std::string getParentId() const; std::string getParentId() const;
int getParentColumn() const; int getParentColumn() const;
CSMWorld::IdTable* model() const; CSMWorld::IdTable* model() const;
virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const; virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
@ -52,27 +52,27 @@ namespace CSMWorld
virtual QModelIndex parent(const QModelIndex& index) const; virtual QModelIndex parent(const QModelIndex& index) const;
virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) 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 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
virtual Qt::ItemFlags flags(const QModelIndex& index) const; virtual Qt::ItemFlags flags(const QModelIndex& index) const;
private: private:
void setupHeaderVectors(ColumnBase::Display columnId); void setupHeaderVectors(ColumnBase::Display columnId);
bool indexIsParent(const QModelIndex& index); bool indexIsParent(const QModelIndex& index);
private slots: private slots:
void forwardRowsAboutToInserted(const QModelIndex & parent, int first, int last); void forwardRowsAboutToInserted(const QModelIndex & parent, int first, int last);
void forwardRowsInserted(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 forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last);
void forwardRowsRemoved(const QModelIndex & parent, int first, int last); void forwardRowsRemoved(const QModelIndex & parent, int first, int last);
void forwardResetStart(const QString& id); void forwardResetStart(const QString& id);
void forwardResetEnd(const QString& id); void forwardResetEnd(const QString& id);
}; };
} }

View file

@ -23,7 +23,7 @@
#include <QHeaderView> #include <QHeaderView>
#include <QDebug> #include <QDebug>
#include "../../model/world/nestedtablemodel.hpp" #include "../../model/world/nestedtableproxymodel.hpp"
#include "../../model/world/columnbase.hpp" #include "../../model/world/columnbase.hpp"
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../../model/world/columns.hpp" #include "../../model/world/columns.hpp"
@ -422,7 +422,7 @@ void CSVWorld::EditWidget::remake(int row)
if (mTable->hasChildren(mTable->index(row, i))) 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); NestedTable* table = new NestedTable(mDocument, mNestedModels.back(), this);

View file

@ -21,7 +21,7 @@ class QVBoxLayout;
namespace CSMWorld namespace CSMWorld
{ {
class IdTable; class IdTable;
class NestedTableModel; class NestedTableProxyModel;
} }
namespace CSMDoc namespace CSMDoc
@ -165,7 +165,7 @@ namespace CSVWorld
QWidget* mMainWidget; QWidget* mMainWidget;
CSMWorld::IdTable* mTable; CSMWorld::IdTable* mTable;
CSMDoc::Document& mDocument; CSMDoc::Document& mDocument;
std::vector<CSMWorld::NestedTableModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
public: public:

View file

@ -1,5 +1,5 @@
#include "nestedtable.hpp" #include "nestedtable.hpp"
#include "../../model/world/nestedtablemodel.hpp" #include "../../model/world/nestedtableproxymodel.hpp"
#include "../../model/world/universalid.hpp" #include "../../model/world/universalid.hpp"
#include "../../model/world/commands.hpp" #include "../../model/world/commands.hpp"
#include "util.hpp" #include "util.hpp"
@ -10,7 +10,7 @@
#include <QDebug> #include <QDebug>
CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document, CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
CSMWorld::NestedTableModel* model, CSMWorld::NestedTableProxyModel* model,
QWidget* parent) QWidget* parent)
: QTableView(parent), : QTableView(parent),
mUndoStack(document.getUndoStack()), mUndoStack(document.getUndoStack()),

View file

@ -10,7 +10,7 @@ class QContextMenuEvent;
namespace CSMWorld namespace CSMWorld
{ {
class NestedTableModel; class NestedTableProxyModel;
class UniversalId; class UniversalId;
} }
@ -28,11 +28,11 @@ namespace CSVWorld
QAction *mAddNewRowAction; QAction *mAddNewRowAction;
QAction *mRemoveRowAction; QAction *mRemoveRowAction;
QUndoStack& mUndoStack; QUndoStack& mUndoStack;
CSMWorld::NestedTableModel* mModel; CSMWorld::NestedTableProxyModel* mModel;
public: public:
NestedTable(CSMDoc::Document& document, NestedTable(CSMDoc::Document& document,
CSMWorld::NestedTableModel* model, CSMWorld::NestedTableProxyModel* model,
QWidget* parent = NULL); QWidget* parent = NULL);
protected: protected: