diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 2683f1a9e..3181eaa47 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -24,7 +24,7 @@ opencs_units (model/world opencs_units_noqt (model/world universalid data record idcollection commands columnbase scriptcontext cell refidcollection - refidadapter refiddata refidadapterimp ref + refidadapter refiddata refidadapterimp ref collectionbase ) opencs_hdrs_noqt (model/world diff --git a/apps/opencs/model/tools/mandatoryid.cpp b/apps/opencs/model/tools/mandatoryid.cpp index f9f2ca378..b99abec6d 100644 --- a/apps/opencs/model/tools/mandatoryid.cpp +++ b/apps/opencs/model/tools/mandatoryid.cpp @@ -1,9 +1,11 @@ #include "mandatoryid.hpp" -#include "../world/idcollection.hpp" +#include "../world/collectionbase.hpp" -CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection, +#include "../world/record.hpp" + +CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::CollectionBase& idCollection, const CSMWorld::UniversalId& collectionId, const std::vector& ids) : mIdCollection (idCollection), mCollectionId (collectionId), mIds (ids) {} diff --git a/apps/opencs/model/tools/mandatoryid.hpp b/apps/opencs/model/tools/mandatoryid.hpp index 14fcec204..342e2d754 100644 --- a/apps/opencs/model/tools/mandatoryid.hpp +++ b/apps/opencs/model/tools/mandatoryid.hpp @@ -10,7 +10,7 @@ namespace CSMWorld { - class IdCollectionBase; + class CollectionBase; } namespace CSMTools @@ -18,13 +18,13 @@ namespace CSMTools /// \brief Verify stage: make sure that records with specific IDs exist. class MandatoryIdStage : public Stage { - const CSMWorld::IdCollectionBase& mIdCollection; + const CSMWorld::CollectionBase& mIdCollection; CSMWorld::UniversalId mCollectionId; std::vector mIds; public: - MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection, const CSMWorld::UniversalId& collectionId, + MandatoryIdStage (const CSMWorld::CollectionBase& idCollection, const CSMWorld::UniversalId& collectionId, const std::vector& ids); virtual int setup(); diff --git a/apps/opencs/model/world/collectionbase.cpp b/apps/opencs/model/world/collectionbase.cpp new file mode 100644 index 000000000..932ea27b5 --- /dev/null +++ b/apps/opencs/model/world/collectionbase.cpp @@ -0,0 +1,6 @@ + +#include "collectionbase.hpp" + +CSMWorld::CollectionBase::CollectionBase() {} + +CSMWorld::CollectionBase::~CollectionBase() {} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp new file mode 100644 index 000000000..1a9b9deb7 --- /dev/null +++ b/apps/opencs/model/world/collectionbase.hpp @@ -0,0 +1,80 @@ +#ifndef CSM_WOLRD_COLLECTIONBASE_H +#define CSM_WOLRD_COLLECTIONBASE_H + +#include + +#include "universalid.hpp" + +class QVariant; + +namespace CSMWorld +{ + struct ColumnBase; + struct RecordBase; + + /// \brief Base class for record collections + class CollectionBase + { + // not implemented + CollectionBase (const CollectionBase&); + CollectionBase& operator= (const CollectionBase&); + + public: + + CollectionBase(); + + virtual ~CollectionBase(); + + virtual int getSize() const = 0; + + virtual std::string getId (int index) const = 0; + + virtual int getIndex (const std::string& id) const = 0; + + virtual int getColumns() const = 0; + + virtual const ColumnBase& getColumn (int column) const = 0; + + virtual QVariant getData (int index, int column) const = 0; + + virtual void setData (int index, int column, const QVariant& data) = 0; + +// Not in use. Temporarily removed so that the implementation of RefIdCollection can continue without +// these functions for now. +// virtual void merge() = 0; + ///< Merge modified into base. + +// virtual void purge() = 0; + ///< Remove records that are flagged as erased. + + virtual void removeRows (int index, int count) = 0; + + virtual void appendBlankRecord (const std::string& id, + UniversalId::Type type = UniversalId::Type_None) = 0; + ///< \param type Will be ignored, unless the collection supports multiple record types + + virtual int searchId (const std::string& id) const = 0; + ////< Search record with \a id. + /// \return index of record (if found) or -1 (not found) + + virtual void replace (int index, const RecordBase& record) = 0; + ///< If the record type does not match, an exception is thrown. + /// + /// \attention \a record must not change the ID. + ///< \param type Will be ignored, unless the collection supports multiple record types + + virtual void appendRecord (const RecordBase& record, + UniversalId::Type type = UniversalId::Type_None) = 0; + ///< If the record type does not match, an exception is thrown. + + virtual const RecordBase& getRecord (const std::string& id) const = 0; + + virtual const RecordBase& getRecord (int index) const = 0; + + virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0; + ///< \param type Will be ignored, unless the collection supports multiple record types + }; + +} + +#endif \ No newline at end of file diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp index 5ea953279..e8a5195fe 100644 --- a/apps/opencs/model/world/idcollection.cpp +++ b/apps/opencs/model/world/idcollection.cpp @@ -1,6 +1,3 @@ #include "idcollection.hpp" -CSMWorld::IdCollectionBase::IdCollectionBase() {} - -CSMWorld::IdCollectionBase::~IdCollectionBase() {} diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 193e4f8e2..158c4ccfc 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -16,77 +15,12 @@ #include #include "columnbase.hpp" -#include "universalid.hpp" + +#include "collectionbase.hpp" namespace CSMWorld { - class IdCollectionBase - { - // not implemented - IdCollectionBase (const IdCollectionBase&); - IdCollectionBase& operator= (const IdCollectionBase&); - - public: - - IdCollectionBase(); - - virtual ~IdCollectionBase(); - - virtual int getSize() const = 0; - - virtual std::string getId (int index) const = 0; - - virtual int getIndex (const std::string& id) const = 0; - - virtual int getColumns() const = 0; - - virtual const ColumnBase& getColumn (int column) const = 0; - - virtual QVariant getData (int index, int column) const = 0; - - virtual void setData (int index, int column, const QVariant& data) = 0; - -// Not in use. Temporarily removed so that the implementation of RefIdCollection can continue without -// these functions for now. -// virtual void merge() = 0; - ///< Merge modified into base. - -// virtual void purge() = 0; - ///< Remove records that are flagged as erased. - - virtual void removeRows (int index, int count) = 0; - - virtual void appendBlankRecord (const std::string& id, - UniversalId::Type type = UniversalId::Type_None) = 0; - ///< \param type Will be ignored, unless the collection supports multiple record types - - virtual int searchId (const std::string& id) const = 0; - ////< Search record with \a id. - /// \return index of record (if found) or -1 (not found) - - virtual void replace (int index, const RecordBase& record) = 0; - ///< If the record type does not match, an exception is thrown. - /// - /// \attention \a record must not change the ID. - ///< \param type Will be ignored, unless the collection supports multiple record types - - virtual void appendRecord (const RecordBase& record, - UniversalId::Type type = UniversalId::Type_None) = 0; - ///< If the record type does not match, an exception is thrown. - - virtual const RecordBase& getRecord (const std::string& id) const = 0; - - virtual const RecordBase& getRecord (int index) const = 0; - - virtual void load (ESM::ESMReader& reader, bool base, - UniversalId::Type type = UniversalId::Type_None) = 0; - ///< \param type Will be ignored, unless the collection supports multiple record types - - virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0; - ///< \param type Will be ignored, unless the collection supports multiple record types - }; - - ///< \brief Access to ID field in records + /// \brief Access to ID field in records template struct IdAccessor { @@ -109,7 +43,7 @@ namespace CSMWorld ///< \brief Collection of ID-based records template > - class IdCollection : public IdCollectionBase + class IdCollection : public CollectionBase { std::vector > mRecords; std::map mIndex; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 386ca8702..25258398b 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -1,9 +1,10 @@ #include "idtable.hpp" -#include "idcollection.hpp" +#include "collectionbase.hpp" +#include "columnbase.hpp" -CSMWorld::IdTable::IdTable (IdCollectionBase *idCollection) : mIdCollection (idCollection) +CSMWorld::IdTable::IdTable (CollectionBase *idCollection) : mIdCollection (idCollection) { } diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index de0dde56e..98bf6ad6d 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -5,14 +5,14 @@ namespace CSMWorld { - class IdCollectionBase; + class CollectionBase; class RecordBase; class IdTable : public QAbstractItemModel { Q_OBJECT - IdCollectionBase *mIdCollection; + CollectionBase *mIdCollection; // not implemented IdTable (const IdTable&); @@ -20,7 +20,7 @@ namespace CSMWorld public: - IdTable (IdCollectionBase *idCollection); + IdTable (CollectionBase *idCollection); ///< The ownership of \a idCollection is not transferred. virtual ~IdTable(); diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index e11fe0fc8..37210d989 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -3,6 +3,8 @@ #include +#include + #include "refidadapter.hpp" #include "refidadapterimp.hpp" diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index dc86c128c..7aaf55626 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -6,7 +6,7 @@ #include #include "columnbase.hpp" -#include "idcollection.hpp" +#include "collectionbase.hpp" #include "refiddata.hpp" namespace CSMWorld @@ -29,7 +29,7 @@ namespace CSMWorld virtual bool isUserEditable() const; }; - class RefIdCollection : public IdCollectionBase + class RefIdCollection : public CollectionBase { private: @@ -85,7 +85,7 @@ namespace CSMWorld virtual const RecordBase& getRecord (int index) const; - virtual void load (ESM::ESMReader& reader, bool base, UniversalId::Type type); + void load (ESM::ESMReader& reader, bool base, UniversalId::Type type); virtual int getAppendIndex (UniversalId::Type type) const; ///< \param type Will be ignored, unless the collection supports multiple record types