2013-06-17 11:42:02 +02:00
|
|
|
#ifndef CSM_WOLRD_COLLECTIONBASE_H
|
|
|
|
#define CSM_WOLRD_COLLECTIONBASE_H
|
|
|
|
|
2021-07-23 14:21:21 +10:00
|
|
|
#include <memory>
|
2013-06-17 11:42:02 +02:00
|
|
|
#include <string>
|
2021-09-04 18:07:23 +02:00
|
|
|
#include <string_view>
|
2013-11-14 11:39:14 +01:00
|
|
|
#include <vector>
|
2013-06-17 11:42:02 +02:00
|
|
|
|
2013-09-27 15:04:09 +02:00
|
|
|
#include "columns.hpp"
|
2013-06-17 11:42:02 +02:00
|
|
|
#include "universalid.hpp"
|
|
|
|
|
|
|
|
class QVariant;
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
2023-02-15 23:19:51 +01:00
|
|
|
class RefId;
|
2022-10-06 19:39:46 +02:00
|
|
|
}
|
|
|
|
|
2013-06-17 11:42:02 +02:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
struct ColumnBase;
|
|
|
|
struct RecordBase;
|
|
|
|
|
|
|
|
/// \brief Base class for record collections
|
2013-06-17 13:03:32 +02:00
|
|
|
///
|
|
|
|
/// \attention Modifying records through the interface does not update connected views.
|
|
|
|
/// Such modifications should be done through the table model interface instead unless no views
|
|
|
|
/// are connected to the model or special precautions have been taken to send update signals
|
|
|
|
/// manually.
|
2013-06-17 11:42:02 +02:00
|
|
|
class CollectionBase
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2023-05-29 13:37:19 +02:00
|
|
|
CollectionBase() = default;
|
|
|
|
CollectionBase(const CollectionBase&) = delete;
|
|
|
|
CollectionBase& operator=(const CollectionBase&) = delete;
|
|
|
|
virtual ~CollectionBase() = default;
|
2013-06-17 11:42:02 +02:00
|
|
|
|
|
|
|
virtual int getSize() const = 0;
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual ESM::RefId getId(int index) const = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual int getIndex(const ESM::RefId& id) const = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual int searchId(const ESM::RefId& id) const = 0;
|
|
|
|
////< Search record with \a id.
|
|
|
|
/// \return index of record (if found) or -1 (not found)
|
|
|
|
|
2021-07-23 14:21:21 +10:00
|
|
|
virtual void replace(int index, std::unique_ptr<RecordBase> record) = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
///< 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
|
|
|
|
|
2021-07-23 14:21:21 +10:00
|
|
|
virtual void appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type = UniversalId::Type_None)
|
2013-06-17 11:42:02 +02:00
|
|
|
= 0;
|
|
|
|
///< If the record type does not match, an exception is thrown.
|
|
|
|
|
2022-10-18 09:26:55 +02:00
|
|
|
virtual void cloneRecord(const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
2014-01-27 13:08:14 +01:00
|
|
|
= 0;
|
2014-01-27 19:40:05 +01:00
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual bool touchRecord(const ESM::RefId& id) = 0;
|
2017-08-31 22:01:38 -04:00
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual const RecordBase& getRecord(const ESM::RefId& id) const = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
|
|
|
|
virtual const RecordBase& getRecord(int index) const = 0;
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual int getAppendIndex(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) const = 0;
|
2013-06-17 11:42:02 +02:00
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
virtual std::vector<ESM::RefId> getIds(bool listDeleted = true) const = 0;
|
2013-09-19 12:11:27 +02:00
|
|
|
///< Return a sorted collection of all IDs
|
|
|
|
///
|
2013-09-19 13:42:19 +02:00
|
|
|
/// \param listDeleted include deleted record in the list
|
2013-09-27 15:04:09 +02:00
|
|
|
|
2013-11-14 11:39:14 +01:00
|
|
|
virtual bool reorderRows(int baseIndex, const std::vector<int>& newOrder) = 0;
|
|
|
|
///< 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?
|
|
|
|
|
2021-07-23 16:05:58 +10:00
|
|
|
virtual int getInsertIndex(
|
2023-02-16 21:37:33 +01:00
|
|
|
const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const;
|
2021-07-23 16:05:58 +10:00
|
|
|
///< Works like getAppendIndex unless an overloaded method uses the record pointer
|
|
|
|
/// to get additional info about the record that results in an alternative index.
|
|
|
|
|
2013-09-27 15:04:09 +02:00
|
|
|
int searchColumnIndex(Columns::ColumnId id) const;
|
|
|
|
///< Return index of column with the given \a id. If no such column exists, -1 is returned.
|
|
|
|
|
|
|
|
int findColumnIndex(Columns::ColumnId id) const;
|
|
|
|
///< Return index of column with the given \a id. If no such column exists, an exception is
|
|
|
|
/// thrown.
|
2013-09-19 12:11:27 +02:00
|
|
|
};
|
2013-06-17 11:42:02 +02:00
|
|
|
}
|
|
|
|
|
2015-03-11 10:54:45 -04:00
|
|
|
#endif
|