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>
|
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
#include <QAbstractItemModel>
|
2012-11-26 11:29:22 +00:00
|
|
|
|
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;
|
2012-12-06 13:56:04 +00:00
|
|
|
class RecordBase;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
class IdTable : public QAbstractItemModel
|
2012-11-26 11:29:22 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2013-11-14 10:39:14 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum Reordering
|
|
|
|
{
|
|
|
|
Reordering_None,
|
|
|
|
Reordering_WithinTopic
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-06-17 09:42:02 +00:00
|
|
|
CollectionBase *mIdCollection;
|
2013-11-14 10:39:14 +00:00
|
|
|
Reordering mReordering;
|
2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
// not implemented
|
|
|
|
IdTable (const IdTable&);
|
|
|
|
IdTable& operator= (const IdTable&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-11-14 10:39:14 +00:00
|
|
|
IdTable (CollectionBase *idCollection, Reordering reordering = Reordering_WithinTopic);
|
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
|
|
|
|
|
|
|
QModelIndex getModelIndex (const std::string& id, int column) const;
|
2012-12-06 13:56:04 +00:00
|
|
|
|
2013-04-29 15:52:01 +00:00
|
|
|
void setRecord (const std::string& id, const RecordBase& record);
|
2012-12-06 13:56:04 +00:00
|
|
|
///< Add record or overwrite existing recrod.
|
|
|
|
|
|
|
|
const RecordBase& getRecord (const std::string& id) const;
|
2013-08-08 10:49:30 +00: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-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).
|
|
|
|
|
|
|
|
Reordering getReordering() const;
|
2012-11-26 11:29:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|