1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 13:53:55 +00:00
openmw/apps/opencs/model/world/refidcollection.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 lines
5.1 KiB
C++
Raw Normal View History

#ifndef CSM_WOLRD_REFIDCOLLECTION_H
#define CSM_WOLRD_REFIDCOLLECTION_H
2022-10-19 17:02:00 +00:00
#include <QVariant>
#include <deque>
#include <map>
2022-10-19 17:02:00 +00:00
#include <memory>
#include <string>
#include <string_view>
2022-10-19 17:02:00 +00:00
#include <utility>
#include <vector>
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/world/universalid.hpp>
#include "collectionbase.hpp"
#include "columnbase.hpp"
#include "nestedcollection.hpp"
#include "refiddata.hpp"
2013-09-24 11:53:19 +00:00
namespace ESM
{
2022-10-19 17:02:00 +00:00
class ESMReader;
2013-09-24 11:53:19 +00:00
class ESMWriter;
}
namespace CSMWorld
{
class RefIdAdapter;
2022-10-19 17:02:00 +00:00
struct RecordBase;
2015-04-09 10:53:41 +00:00
struct NestedTableWrapperBase;
class NestedRefIdAdapterBase;
class RefIdColumn : public NestableColumn
{
bool mEditable;
bool mUserEditable;
2022-09-22 18:26:05 +00:00
public:
RefIdColumn(int columnId, Display displayType, int flag = Flag_Table | Flag_Dialogue, bool editable = true,
bool userEditable = true);
bool isEditable() const override;
bool isUserEditable() const override;
};
class RefIdCollection : public CollectionBase, public NestedCollection
{
private:
RefIdData mData;
std::deque<RefIdColumn> mColumns;
2013-12-30 17:41:16 +00:00
std::map<UniversalId::Type, RefIdAdapter*> mAdapters;
2015-04-11 01:26:29 +00:00
std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*>>> mNestedAdapters;
private:
const RefIdAdapter& findAdapter(UniversalId::Type) const;
///< Throws an exception if no adaptor for \a Type can be found.
const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase& column, UniversalId::Type type) const;
2022-09-22 18:26:05 +00:00
public:
RefIdCollection();
~RefIdCollection() override;
int getSize() const override;
ESM::RefId getId(int index) const override;
int getIndex(const ESM::RefId& id) const override;
int getColumns() const override;
const ColumnBase& getColumn(int column) const override;
QVariant getData(int index, int column) const override;
void setData(int index, int column, const QVariant& data) override;
void removeRows(int index, int count) override;
2014-07-17 10:41:43 +00:00
void cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type) override;
2014-01-27 18:40:05 +00:00
bool touchRecord(const ESM::RefId& id) override;
void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type) override;
///< \param type Will be ignored, unless the collection supports multiple record types
int searchId(std::string_view id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
int searchId(const ESM::RefId& id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
void replace(int index, std::unique_ptr<RecordBase> record) override;
///< If the record type does not match, an exception is thrown.
///
/// \attention \a record must not change the ID.
void appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type) override;
///< If the record type does not match, an exception is thrown.
///
///< \param type Will be ignored, unless the collection supports multiple record types
const RecordBase& getRecord(const ESM::RefId& id) const override;
const RecordBase& getRecord(int index) const override;
2013-12-30 17:41:16 +00:00
void load(ESM::ESMReader& reader, bool base, UniversalId::Type type);
int getAppendIndex(const ESM::RefId& id, UniversalId::Type type) const override;
///< \param type Will be ignored, unless the collection supports multiple record types
std::vector<ESM::RefId> getIds(bool listDeleted) const override;
///< Return a sorted collection of all IDs
///
/// \param listDeleted include deleted record in the list
2013-09-24 11:53:19 +00:00
bool reorderRows(int baseIndex, const std::vector<int>& newOrder) override;
///< 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?
QVariant getNestedData(int row, int column, int subRow, int subColumn) const override;
NestedTableWrapperBase* nestedTable(int row, int column) const override;
void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) override;
int getNestedRowsCount(int row, int column) const override;
int getNestedColumnsCount(int row, int column) const override;
NestableColumn* getNestableColumn(int column) override;
void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) override;
void removeNestedRows(int row, int column, int subRow) override;
void addNestedRow(int row, int col, int position) override;
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;
};
}
#endif