2012-11-26 11:29:22 +00:00
|
|
|
#ifndef CSM_WOLRD_IDTABLE_H
|
|
|
|
#define CSM_WOLRD_IDTABLE_H
|
|
|
|
|
2013-11-14 10:39:14 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
#include "idtablebase.hpp"
|
2013-07-30 08:27:17 +00:00
|
|
|
#include "universalid.hpp"
|
2013-08-08 10:49:30 +00:00
|
|
|
#include "columns.hpp"
|
2013-07-30 08:27:17 +00:00
|
|
|
|
2012-11-26 11:29:22 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2013-06-17 09:42:02 +00:00
|
|
|
class CollectionBase;
|
2015-03-14 01:42:46 +00:00
|
|
|
struct RecordBase;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
class IdTable : public IdTableBase
|
2012-11-26 11:29:22 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2013-11-14 10:39:14 +00:00
|
|
|
private:
|
|
|
|
|
2013-06-17 09:42:02 +00:00
|
|
|
CollectionBase *mIdCollection;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
// not implemented
|
|
|
|
IdTable (const IdTable&);
|
|
|
|
IdTable& operator= (const IdTable&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-06-05 08:28:10 +00:00
|
|
|
IdTable (CollectionBase *idCollection, unsigned int features = 0);
|
2012-11-26 11:29:22 +00:00
|
|
|
///< The ownership of \a idCollection is not transferred.
|
|
|
|
|
|
|
|
virtual ~IdTable();
|
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual int rowCount (const QModelIndex & parent = QModelIndex()) const;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual int columnCount (const QModelIndex & parent = QModelIndex()) const;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
2012-11-29 13:45:34 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
2012-11-29 13:45:34 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual Qt::ItemFlags flags (const QModelIndex & index) const;
|
|
|
|
|
|
|
|
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
|
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex())
|
|
|
|
const;
|
|
|
|
|
|
|
|
virtual QModelIndex parent (const QModelIndex& index) const;
|
|
|
|
|
2013-07-30 08:27:17 +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
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2016-03-01 10:21:06 +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
|
|
|
|
|
2014-03-02 21:43:44 +00:00
|
|
|
void cloneRecord(const std::string& origin,
|
|
|
|
const std::string& destination,
|
2014-01-20 12:59:00 +00:00
|
|
|
UniversalId::Type type = UniversalId::Type_None);
|
2014-01-27 18:40:05 +00:00
|
|
|
|
2017-09-01 02:01:38 +00:00
|
|
|
bool touchRecord(const std::string& id);
|
|
|
|
///< Will change the record state to modified, if it is not already.
|
|
|
|
|
|
|
|
std::string getId(int row) const;
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
|
2012-12-06 13:56:04 +00:00
|
|
|
|
2015-04-24 20:06:11 +00:00
|
|
|
void setRecord (const std::string& id, const RecordBase& record,
|
|
|
|
UniversalId::Type type = UniversalId::Type_None);
|
2016-12-14 21:11:22 +00:00
|
|
|
///< Add record or overwrite existing record.
|
2012-12-06 13:56:04 +00:00
|
|
|
|
|
|
|
const RecordBase& getRecord (const std::string& id) const;
|
2013-08-08 10:49:30 +00:00
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
virtual int searchColumnIndex (Columns::ColumnId id) const;
|
2013-08-08 10:49:30 +00:00
|
|
|
///< Return index of column with the given \a id. If no such column exists, -1 is returned.
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
virtual int findColumnIndex (Columns::ColumnId id) const;
|
2013-08-08 10:49:30 +00:00
|
|
|
///< Return index of column with the given \a id. If no such column exists, an exception is
|
|
|
|
/// thrown.
|
2013-11-14 10:39:14 +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).
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
virtual std::pair<UniversalId, std::string> view (int row) const;
|
2014-03-02 21:43:44 +00:00
|
|
|
///< Return the UniversalId and the hint for viewing \a row. If viewing is not
|
|
|
|
/// supported by this table, return (UniversalId::Type_None, "").
|
2014-03-08 14:27:43 +00:00
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
/// Is \a id flagged as deleted?
|
|
|
|
virtual bool isDeleted (const std::string& id) const;
|
|
|
|
|
2015-03-29 13:28:11 +00:00
|
|
|
virtual int getColumnId(int column) const;
|
2015-04-09 09:11:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual CollectionBase *idCollection() const;
|
2012-11-26 11:29:22 +00:00
|
|
|
};
|
2017-08-25 23:51:30 +00:00
|
|
|
|
|
|
|
/// An IdTable customized to handle the more unique needs of LandTextureId's which behave
|
2017-09-04 23:31:09 +00:00
|
|
|
/// differently from other records. The major difference is that base records cannot be
|
|
|
|
/// modified.
|
2017-08-25 23:51:30 +00:00
|
|
|
class LandTextureIdTable : public IdTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-09-04 23:31:09 +00:00
|
|
|
struct ImportResults
|
|
|
|
{
|
|
|
|
using StringPair = std::pair<std::string,std::string>;
|
|
|
|
|
|
|
|
/// The newly added records
|
|
|
|
std::vector<std::string> createdRecords;
|
|
|
|
/// The 1st string is the original id, the 2nd is the mapped id
|
|
|
|
std::vector<StringPair> recordMapping;
|
|
|
|
};
|
|
|
|
|
2017-08-25 23:51:30 +00:00
|
|
|
LandTextureIdTable(CollectionBase* idCollection, unsigned int features=0);
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex& index, int role=Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
|
|
|
|
|
|
|
Qt::ItemFlags flags (const QModelIndex & index) const override;
|
2017-09-04 23:31:09 +00:00
|
|
|
|
|
|
|
/// Finds and maps/recreates the specified ids.
|
|
|
|
ImportResults importTextures(const std::vector<std::string>& ids);
|
2017-08-25 23:51:30 +00:00
|
|
|
};
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|