2013-05-06 12:11:55 +00:00
|
|
|
#ifndef CSM_WOLRD_REFIDCOLLECTION_H
|
|
|
|
#define CSM_WOLRD_REFIDCOLLECTION_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2013-05-11 15:34:18 +00:00
|
|
|
#include <deque>
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2015-04-09 09:11:19 +00:00
|
|
|
#include "columnbase.hpp"
|
|
|
|
#include "collectionbase.hpp"
|
2015-03-30 00:53:33 +00:00
|
|
|
#include "nestedcollection.hpp"
|
2013-05-06 12:11:55 +00:00
|
|
|
#include "refiddata.hpp"
|
|
|
|
|
2013-09-24 11:53:19 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMWriter;
|
|
|
|
}
|
|
|
|
|
2013-05-06 12:11:55 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
class RefIdAdapter;
|
2015-04-09 10:53:41 +00:00
|
|
|
struct NestedTableWrapperBase;
|
2015-04-12 08:29:42 +00:00
|
|
|
class NestedRefIdAdapterBase;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2015-04-02 09:19:15 +00:00
|
|
|
class RefIdColumn : public NestableColumn
|
2013-05-06 12:11:55 +00:00
|
|
|
{
|
|
|
|
bool mEditable;
|
|
|
|
bool mUserEditable;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
RefIdColumn (int columnId, Display displayType,
|
2014-06-17 20:02:20 +00:00
|
|
|
int flag = Flag_Table | Flag_Dialogue, bool editable = true,
|
2015-04-02 09:19:15 +00:00
|
|
|
bool userEditable = true);
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isEditable() const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isUserEditable() const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
};
|
|
|
|
|
2015-04-09 09:11:19 +00:00
|
|
|
class RefIdCollection : public CollectionBase, public NestedCollection
|
2013-05-06 12:11:55 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
RefIdData mData;
|
2013-05-11 15:34:18 +00:00
|
|
|
std::deque<RefIdColumn> mColumns;
|
2013-12-30 17:41:16 +00:00
|
|
|
std::map<UniversalId::Type, RefIdAdapter *> mAdapters;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2015-04-12 20:39:38 +00:00
|
|
|
std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > > mNestedAdapters;
|
2015-04-12 08:29:42 +00:00
|
|
|
|
2013-05-06 12:11:55 +00:00
|
|
|
private:
|
|
|
|
|
2015-04-11 01:26:29 +00:00
|
|
|
const RefIdAdapter& findAdapter (UniversalId::Type) const;
|
2013-05-06 12:11:55 +00:00
|
|
|
///< Throws an exception if no adaptor for \a Type can be found.
|
|
|
|
|
2015-04-12 22:03:30 +00:00
|
|
|
const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase &column, UniversalId::Type type) const;
|
2015-04-12 08:29:42 +00:00
|
|
|
|
2013-05-06 12:11:55 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
RefIdCollection();
|
|
|
|
|
|
|
|
virtual ~RefIdCollection();
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getSize() const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
std::string getId (int index) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getIndex (const std::string& id) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getColumns() const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
const ColumnBase& getColumn (int column) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
QVariant getData (int index, int column) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setData (int index, int column, const QVariant& data) override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void removeRows (int index, int count) override;
|
2014-07-17 10:41:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void cloneRecord(const std::string& origin,
|
2014-01-20 12:59:00 +00:00
|
|
|
const std::string& destination,
|
2020-10-16 18:18:54 +00:00
|
|
|
const UniversalId::Type type) override;
|
2014-01-27 18:40:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool touchRecord(const std::string& id) override;
|
2017-09-01 02:01:38 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void appendBlankRecord (const std::string& id, UniversalId::Type type) override;
|
2013-05-06 12:11:55 +00:00
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int searchId (const std::string& id) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
////< Search record with \a id.
|
|
|
|
/// \return index of record (if found) or -1 (not found)
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void replace (int index, const RecordBase& record) override;
|
2013-05-06 12:11:55 +00:00
|
|
|
///< If the record type does not match, an exception is thrown.
|
|
|
|
///
|
|
|
|
/// \attention \a record must not change the ID.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void appendRecord (const RecordBase& record, UniversalId::Type type) override;
|
2013-05-06 12:11:55 +00:00
|
|
|
///< If the record type does not match, an exception is thrown.
|
|
|
|
///
|
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
const RecordBase& getRecord (const std::string& id) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
const RecordBase& getRecord (int index) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
void load (ESM::ESMReader& reader, bool base, UniversalId::Type type);
|
2013-05-06 12:11:55 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getAppendIndex (const std::string& id, UniversalId::Type type) const override;
|
2013-05-06 12:11:55 +00:00
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
2013-09-19 10:11:27 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
std::vector<std::string> getIds (bool listDeleted) const override;
|
2013-09-19 10:11:27 +00:00
|
|
|
///< Return a sorted collection of all IDs
|
|
|
|
///
|
2013-09-19 11:42:19 +00:00
|
|
|
/// \param listDeleted include deleted record in the list
|
2013-09-24 11:53:19 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool reorderRows (int baseIndex, const std::vector<int>& newOrder) override;
|
2013-11-14 10:39:14 +00:00
|
|
|
///< Reorder the rows [baseIndex, baseIndex+newOrder.size()) according to the indices
|
|
|
|
/// given in \a newOrder (baseIndex+newOrder[0] specifies the new index of row baseIndex).
|
|
|
|
///
|
|
|
|
/// \return Success?
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
QVariant getNestedData(int row, int column, int subRow, int subColumn) const override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
NestedTableWrapperBase* nestedTable(int row, int column) const override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getNestedRowsCount(int row, int column) const override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getNestedColumnsCount(int row, int column) const override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
NestableColumn *getNestableColumn(int column) override;
|
2015-04-09 09:11:19 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void removeNestedRows(int row, int column, int subRow) override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void addNestedRow(int row, int col, int position) override;
|
2015-04-02 09:19:15 +00:00
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
void save (int index, ESM::ESMWriter& writer) const;
|
2013-12-30 12:23:16 +00:00
|
|
|
|
2014-07-17 10:41:43 +00:00
|
|
|
const RefIdData& getDataSet() const; //I can't figure out a better name for this one :(
|
2015-08-25 09:54:16 +00:00
|
|
|
void copyTo (int index, RefIdCollection& target) const;
|
2013-05-06 12:11:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|