diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 102b348906..26287c6bdf 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -23,7 +23,7 @@ opencs_units (model/world opencs_units_noqt (model/world universalid data record idcollection commands columnbase scriptcontext cell refidcollection - refidadapter refiddata + refidadapter refiddata refidadapterimp ) opencs_hdrs_noqt (model/world diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 9172959bba..db6629aa09 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -327,6 +327,8 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) case ESM::REC_SPEL: mSpells.load (reader, base); break; case ESM::REC_CELL: mCells.load (reader, base); break; + case ESM::REC_STAT: mReferenceables.load (reader, base, UniversalId::Type_Static); break; + default: /// \todo throw an exception instead, once all records are implemented diff --git a/apps/opencs/model/world/refidadapter.hpp b/apps/opencs/model/world/refidadapter.hpp index bb9005b275..df0ceae706 100644 --- a/apps/opencs/model/world/refidadapter.hpp +++ b/apps/opencs/model/world/refidadapter.hpp @@ -1,4 +1,4 @@ -#ifndef CSM_WOLRD_REDIDADAPTER_H +#ifndef CSM_WOLRD_REFIDADAPTER_H #define CSM_WOLRD_REFIDADAPTER_H #include diff --git a/apps/opencs/model/world/refidadapterimp.cpp b/apps/opencs/model/world/refidadapterimp.cpp new file mode 100644 index 0000000000..5038797dd0 --- /dev/null +++ b/apps/opencs/model/world/refidadapterimp.cpp @@ -0,0 +1,49 @@ + +#include "refidadapterimp.hpp" + +#include + +#include + +#include "record.hpp" +#include "refiddata.hpp" +#include "universalid.hpp" + +CSMWorld::StaticRefIdAdapter::StaticRefIdAdapter (const RefIdColumn *id, const RefIdColumn *modified) +: mId (id), mModified (modified) +{} + +QVariant CSMWorld::StaticRefIdAdapter::getData (const RefIdColumn *column, const RefIdData& data, + int index) const +{ + const Record& record = static_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Static))); + + if (column==mId) + return QString::fromUtf8 (record.get().mId.c_str()); + + if (column==mModified) + { + if (record.mState==Record::State_Erased) + return static_cast (Record::State_Deleted); + + return static_cast (record.mState); + } + + return QVariant(); +} + +void CSMWorld::StaticRefIdAdapter::setData (const RefIdColumn *column, RefIdData& data, int index, + const QVariant& value) const +{ + Record& record = static_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Static))); + + if (column==mModified) + record.mState = static_cast (value.toInt()); +} + +std::string CSMWorld::StaticRefIdAdapter::getId (const RecordBase& record) const +{ + return dynamic_cast&> (record).get().mId; +} \ No newline at end of file diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp new file mode 100644 index 0000000000..c130e2f733 --- /dev/null +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -0,0 +1,28 @@ +#ifndef CSM_WOLRD_REFIDADAPTERIMP_H +#define CSM_WOLRD_REFIDADAPTERIMP_H + +#include "refidadapter.hpp" + +namespace CSMWorld +{ + class StaticRefIdAdapter : public RefIdAdapter + { + const RefIdColumn *mId; + const RefIdColumn *mModified; + + public: + + StaticRefIdAdapter (const RefIdColumn *id, const RefIdColumn *modified); + + virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int idnex) + const; + + virtual void setData (const RefIdColumn *column, RefIdData& data, int index, + const QVariant& value) const; + ///< If the data type does not match an exception is thrown. + + virtual std::string getId (const RecordBase& record) const; + }; +} + +#endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index a684b85c5b..8b46d649ff 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -129,6 +129,11 @@ void CSVDoc::View::setupWorldMenu() QAction *cells = new QAction (tr ("Cells"), this); connect (cells, SIGNAL (triggered()), this, SLOT (addCellsSubView())); world->addAction (cells); + + QAction *referenceables = new QAction (tr ("Referenceables"), this); + connect (referenceables, SIGNAL (triggered()), this, SLOT (addReferenceablesSubView())); + world->addAction (referenceables); + } void CSVDoc::View::setupUi() @@ -334,6 +339,11 @@ void CSVDoc::View::addCellsSubView() addSubView (CSMWorld::UniversalId::Type_Cells); } +void CSVDoc::View::addReferenceablesSubView() +{ + addSubView (CSMWorld::UniversalId::Type_Referenceables); +} + void CSVDoc::View::abortOperation (int type) { mDocument->abortOperation (type); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index a240d3b01d..9e1e94188e 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -135,6 +135,8 @@ namespace CSVDoc void addSpellsSubView(); void addCellsSubView(); + + void addReferenceablesSubView(); }; } diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 0ce3d3d6db..3d05f88608 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -27,6 +27,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Birthsigns, CSMWorld::UniversalId::Type_Spells, CSMWorld::UniversalId::Type_Cells, + CSMWorld::UniversalId::Type_Referenceables, CSMWorld::UniversalId::Type_None // end marker };