1 #ifndef CSM_WOLRD_REFIDCOLLECTION_H 2 #define CSM_WOLRD_REFIDCOLLECTION_H 3 4 #include <vector> 5 #include <map> 6 #include <deque> 7 8 #include "columnbase.hpp" 9 #include "collectionbase.hpp" 10 #include "nestedcollection.hpp" 11 #include "refiddata.hpp" 12 13 namespace ESM 14 { 15 class ESMWriter; 16 } 17 18 namespace CSMWorld 19 { 20 class RefIdAdapter; 21 struct NestedTableWrapperBase; 22 class NestedRefIdAdapterBase; 23 24 class RefIdColumn : public NestableColumn 25 { 26 bool mEditable; 27 bool mUserEditable; 28 29 public: 30 31 RefIdColumn (int columnId, Display displayType, 32 int flag = Flag_Table | Flag_Dialogue, bool editable = true, 33 bool userEditable = true); 34 35 bool isEditable() const override; 36 37 bool isUserEditable() const override; 38 }; 39 40 class RefIdCollection : public CollectionBase, public NestedCollection 41 { 42 private: 43 44 RefIdData mData; 45 std::deque<RefIdColumn> mColumns; 46 std::map<UniversalId::Type, RefIdAdapter *> mAdapters; 47 48 std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > > mNestedAdapters; 49 50 private: 51 52 const RefIdAdapter& findAdapter (UniversalId::Type) const; 53 ///< Throws an exception if no adaptor for \a Type can be found. 54 55 const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase &column, UniversalId::Type type) const; 56 57 public: 58 59 RefIdCollection(); 60 61 virtual ~RefIdCollection(); 62 63 int getSize() const override; 64 65 std::string getId (int index) const override; 66 67 int getIndex (const std::string& id) const override; 68 69 int getColumns() const override; 70 71 const ColumnBase& getColumn (int column) const override; 72 73 QVariant getData (int index, int column) const override; 74 75 void setData (int index, int column, const QVariant& data) override; 76 77 void removeRows (int index, int count) override; 78 79 void cloneRecord(const std::string& origin, 80 const std::string& destination, 81 const UniversalId::Type type) override; 82 83 bool touchRecord(const std::string& id) override; 84 85 void appendBlankRecord (const std::string& id, UniversalId::Type type) override; 86 ///< \param type Will be ignored, unless the collection supports multiple record types 87 88 int searchId (const std::string& id) const override; 89 ////< Search record with \a id. 90 /// \return index of record (if found) or -1 (not found) 91 92 void replace (int index, const RecordBase& record) override; 93 ///< If the record type does not match, an exception is thrown. 94 /// 95 /// \attention \a record must not change the ID. 96 97 void appendRecord (const RecordBase& record, UniversalId::Type type) override; 98 ///< If the record type does not match, an exception is thrown. 99 /// 100 ///< \param type Will be ignored, unless the collection supports multiple record types 101 102 const RecordBase& getRecord (const std::string& id) const override; 103 104 const RecordBase& getRecord (int index) const override; 105 106 void load (ESM::ESMReader& reader, bool base, UniversalId::Type type); 107 108 int getAppendIndex (const std::string& id, UniversalId::Type type) const override; 109 ///< \param type Will be ignored, unless the collection supports multiple record types 110 111 std::vector<std::string> getIds (bool listDeleted) const override; 112 ///< Return a sorted collection of all IDs 113 /// 114 /// \param listDeleted include deleted record in the list 115 116 bool reorderRows (int baseIndex, const std::vector<int>& newOrder) override; 117 ///< Reorder the rows [baseIndex, baseIndex+newOrder.size()) according to the indices 118 /// given in \a newOrder (baseIndex+newOrder[0] specifies the new index of row baseIndex). 119 /// 120 /// \return Success? 121 122 QVariant getNestedData(int row, int column, int subRow, int subColumn) const override; 123 124 NestedTableWrapperBase* nestedTable(int row, int column) const override; 125 126 void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) override; 127 128 int getNestedRowsCount(int row, int column) const override; 129 130 int getNestedColumnsCount(int row, int column) const override; 131 132 NestableColumn *getNestableColumn(int column) override; 133 134 void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) override; 135 136 void removeNestedRows(int row, int column, int subRow) override; 137 138 void addNestedRow(int row, int col, int position) override; 139 140 void save (int index, ESM::ESMWriter& writer) const; 141 142 const RefIdData& getDataSet() const; //I can't figure out a better name for this one :( 143 void copyTo (int index, RefIdCollection& target) const; 144 }; 145 } 146 147 #endif 148