1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-02 21:09:40 +00:00
openmw/apps/opencs/model/world/idtable.hpp

123 lines
4.1 KiB
C++
Raw Normal View History

#ifndef CSM_WOLRD_IDTABLE_H
#define CSM_WOLRD_IDTABLE_H
2022-10-19 17:02:00 +00:00
#include <QModelIndex>
#include <QVariant>
#include <map>
#include <memory>
2022-10-19 17:02:00 +00:00
#include <string>
#include <utility>
2022-09-22 18:26:05 +00:00
#include <vector>
2022-09-22 18:26:05 +00:00
#include "columns.hpp"
#include "idtablebase.hpp"
#include "universalid.hpp"
2022-10-19 17:02:00 +00:00
class QObject;
2024-06-12 15:09:28 +00:00
namespace ESM
{
struct LandTexture;
}
namespace CSMWorld
{
class CollectionBase;
2015-03-14 01:42:46 +00:00
struct RecordBase;
2024-06-12 15:09:28 +00:00
template <typename ESXRecordT>
struct Record;
class IdTable : public IdTableBase
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2022-09-22 18:26:05 +00:00
private:
CollectionBase* mIdCollection;
2022-09-22 18:26:05 +00:00
// not implemented
IdTable(const IdTable&);
IdTable& operator=(const IdTable&);
2022-09-22 18:26:05 +00:00
public:
IdTable(CollectionBase* idCollection, unsigned int features = 0);
///< The ownership of \a idCollection is not transferred.
virtual ~IdTable() = default;
2022-09-22 18:26:05 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
2022-09-22 18:26:05 +00:00
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
2022-09-22 18:26:05 +00:00
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
2022-09-22 18:26:05 +00:00
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
2022-09-22 18:26:05 +00:00
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
2022-09-22 18:26:05 +00:00
Qt::ItemFlags flags(const QModelIndex& index) const override;
2022-09-22 18:26:05 +00:00
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
2022-09-22 18:26:05 +00:00
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
2022-09-22 18:26:05 +00:00
QModelIndex parent(const QModelIndex& index) const override;
2022-09-22 18:26:05 +00:00
void addRecord(const std::string& id, UniversalId::Type type = UniversalId::Type_None);
///< \param type Will be ignored, unless the collection supports multiple record types
2022-09-22 18:26:05 +00:00
void addRecordWithData(const std::string& id, const std::map<int, QVariant>& data,
UniversalId::Type type = UniversalId::Type_None);
///< \param type Will be ignored, unless the collection supports multiple record types
2022-09-22 18:26:05 +00:00
void cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, UniversalId::Type type = UniversalId::Type_None);
2022-09-22 18:26:05 +00:00
bool touchRecord(const std::string& id);
///< Will change the record state to modified, if it is not already.
2022-09-22 18:26:05 +00:00
std::string getId(int row) const;
2014-01-27 18:40:05 +00:00
2022-09-22 18:26:05 +00:00
QModelIndex getModelIndex(const std::string& id, int column) const override;
2022-09-22 18:26:05 +00:00
void setRecord(
const std::string& id, std::unique_ptr<RecordBase> record, UniversalId::Type type = UniversalId::Type_None);
///< Add record or overwrite existing record.
2022-09-22 18:26:05 +00:00
const RecordBase& getRecord(const std::string& id) const;
2012-12-06 13:56:04 +00:00
2022-09-22 18:26:05 +00:00
int searchColumnIndex(Columns::ColumnId id) const override;
///< Return index of column with the given \a id. If no such column exists, -1 is returned.
2012-12-06 13:56:04 +00:00
2022-09-22 18:26:05 +00:00
int findColumnIndex(Columns::ColumnId id) const override;
///< Return index of column with the given \a id. If no such column exists, an exception is
/// thrown.
2022-09-22 18:26:05 +00:00
void reorderRows(int baseIndex, const std::vector<int>& newOrder);
///< 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).
2022-09-22 18:26:05 +00:00
std::pair<UniversalId, std::string> view(int row) const override;
///< Return the UniversalId and the hint for viewing \a row. If viewing is not
/// supported by this table, return (UniversalId::Type_None, "").
2022-09-22 18:26:05 +00:00
/// Is \a id flagged as deleted?
bool isDeleted(const std::string& id) const override;
2022-09-22 18:26:05 +00:00
int getColumnId(int column) const override;
2014-03-08 14:27:43 +00:00
2022-09-22 18:26:05 +00:00
protected:
virtual CollectionBase* idCollection() const;
};
class LandTextureIdTable : public IdTable
{
2022-09-22 18:26:05 +00:00
public:
LandTextureIdTable(CollectionBase* idCollection, unsigned int features = 0);
2024-06-12 15:09:28 +00:00
const CSMWorld::Record<ESM::LandTexture>* searchRecord(std::uint16_t index, int plugin) const;
};
}
#endif