switching editor id tables from QAbstractTableModel to QAbstractItemModel (in preparation for record types like containers)

actorid
Marc Zinnschlag 12 years ago
parent cd84b68e4b
commit d05508db52

@ -1,7 +1,7 @@
#include "commands.hpp" #include "commands.hpp"
#include <QAbstractTableModel> #include <QAbstractItemModel>
#include "idtableproxymodel.hpp" #include "idtableproxymodel.hpp"
#include "idtable.hpp" #include "idtable.hpp"

@ -3,7 +3,7 @@
#include <stdexcept> #include <stdexcept>
#include <QAbstractTableModel> #include <QAbstractItemModel>
#include <components/esm/esmreader.hpp> #include <components/esm/esmreader.hpp>
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
@ -12,7 +12,7 @@
#include "idtable.hpp" #include "idtable.hpp"
#include "columns.hpp" #include "columns.hpp"
void CSMWorld::Data::addModel (QAbstractTableModel *model, UniversalId::Type type1, void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1,
UniversalId::Type type2) UniversalId::Type type2)
{ {
mModels.push_back (model); mModels.push_back (model);
@ -42,7 +42,7 @@ CSMWorld::Data::Data()
CSMWorld::Data::~Data() CSMWorld::Data::~Data()
{ {
for (std::vector<QAbstractTableModel *>::iterator iter (mModels.begin()); iter!=mModels.end(); ++iter) for (std::vector<QAbstractItemModel *>::iterator iter (mModels.begin()); iter!=mModels.end(); ++iter)
delete *iter; delete *iter;
} }
@ -66,9 +66,9 @@ CSMWorld::IdCollection<ESM::GameSetting>& CSMWorld::Data::getGmsts()
return mGmsts; return mGmsts;
} }
QAbstractTableModel *CSMWorld::Data::getTableModel (const UniversalId& id) QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
{ {
std::map<UniversalId::Type, QAbstractTableModel *>::iterator iter = mModelIndex.find (id.getType()); std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
if (iter==mModelIndex.end()) if (iter==mModelIndex.end())
throw std::logic_error ("No table model available for " + id.toString()); throw std::logic_error ("No table model available for " + id.toString());

@ -12,7 +12,7 @@
#include "idcollection.hpp" #include "idcollection.hpp"
#include "universalid.hpp" #include "universalid.hpp"
class QAbstractTableModel; class QAbstractItemModel;
namespace CSMWorld namespace CSMWorld
{ {
@ -20,14 +20,14 @@ namespace CSMWorld
{ {
IdCollection<ESM::Global> mGlobals; IdCollection<ESM::Global> mGlobals;
IdCollection<ESM::GameSetting> mGmsts; IdCollection<ESM::GameSetting> mGmsts;
std::vector<QAbstractTableModel *> mModels; std::vector<QAbstractItemModel *> mModels;
std::map<UniversalId::Type, QAbstractTableModel *> mModelIndex; std::map<UniversalId::Type, QAbstractItemModel *> mModelIndex;
// not implemented // not implemented
Data (const Data&); Data (const Data&);
Data& operator= (const Data&); Data& operator= (const Data&);
void addModel (QAbstractTableModel *model, UniversalId::Type type1, void addModel (QAbstractItemModel *model, UniversalId::Type type1,
UniversalId::Type type2 = UniversalId::Type_None); UniversalId::Type type2 = UniversalId::Type_None);
public: public:
@ -44,7 +44,7 @@ namespace CSMWorld
IdCollection<ESM::GameSetting>& getGmsts(); IdCollection<ESM::GameSetting>& getGmsts();
QAbstractTableModel *getTableModel (const UniversalId& id); QAbstractItemModel *getTableModel (const UniversalId& id);
///< If no table model is available for \a id, an exception is thrown. ///< If no table model is available for \a id, an exception is thrown.
/// ///
/// \note The returned table may either be the model for the ID itself or the model that /// \note The returned table may either be the model for the ID itself or the model that

@ -96,6 +96,25 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren
return true; return true;
} }
QModelIndex CSMWorld::IdTable::index (int row, int column, const QModelIndex& parent) const
{
if (parent.isValid())
return QModelIndex();
if (row<0 || row>=mIdCollection->getSize())
return QModelIndex();
if (column<0 || column>=mIdCollection->getColumns())
return QModelIndex();
return createIndex (row, column);
}
QModelIndex CSMWorld::IdTable::parent (const QModelIndex& index) const
{
return QModelIndex();
}
void CSMWorld::IdTable::addRecord (const std::string& id) void CSMWorld::IdTable::addRecord (const std::string& id)
{ {
int index = mIdCollection->getSize(); int index = mIdCollection->getSize();

@ -1,14 +1,14 @@
#ifndef CSM_WOLRD_IDTABLE_H #ifndef CSM_WOLRD_IDTABLE_H
#define CSM_WOLRD_IDTABLE_H #define CSM_WOLRD_IDTABLE_H
#include <QAbstractTableModel> #include <QAbstractItemModel>
namespace CSMWorld namespace CSMWorld
{ {
class IdCollectionBase; class IdCollectionBase;
class RecordBase; class RecordBase;
class IdTable : public QAbstractTableModel class IdTable : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@ -39,6 +39,11 @@ namespace CSMWorld
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex()); virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex())
const;
virtual QModelIndex parent (const QModelIndex& index) const;
void addRecord (const std::string& id); void addRecord (const std::string& id);
QModelIndex getModelIndex (const std::string& id, int column) const; QModelIndex getModelIndex (const std::string& id, int column) const;

@ -3,7 +3,7 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QAbstractTableModel> #include <QAbstractItemModel>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QSpinBox> #include <QSpinBox>
#include <QLineEdit> #include <QLineEdit>
@ -24,7 +24,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
widget->setLayout (layout); widget->setLayout (layout);
QAbstractTableModel *model = document.getData().getTableModel (id); QAbstractItemModel *model = document.getData().getTableModel (id);
int columns = model->columnCount(); int columns = model->columnCount();

Loading…
Cancel
Save