1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00
openrw/rwviewer/models/ObjectListModel.cpp

57 lines
1.8 KiB
C++
Raw Normal View History

#include "ObjectListModel.hpp"
2016-09-09 22:13:21 +02:00
ObjectListModel::ObjectListModel(GameData *dat, QObject *parent)
: QAbstractTableModel(parent), _gameData(dat) {
}
int ObjectListModel::rowCount(const QModelIndex &) const {
return _gameData->modelinfo.size();
}
int ObjectListModel::columnCount(const QModelIndex &) const {
2016-09-09 22:13:21 +02:00
return 3;
}
2016-09-09 22:13:21 +02:00
QVariant ObjectListModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
if (!index.isValid()) return QVariant::Invalid;
2016-09-09 22:13:21 +02:00
auto id = index.internalId();
if (index.column() == 0) {
return id;
} else if (index.column() == 1) {
auto object = _gameData->modelinfo[id].get();
return QString::fromStdString(
BaseModelInfo::getTypeName(object->type()));
2016-09-09 22:13:21 +02:00
} else if (index.column() == 2) {
auto object = _gameData->modelinfo[id].get();
return QString::fromStdString(object->name);
2016-09-09 22:13:21 +02:00
}
}
return QVariant::Invalid;
}
2016-09-09 22:13:21 +02:00
QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) {
case 0:
return "ID";
case 1:
return "Type";
case 2:
return "Model";
}
}
return QVariant::Invalid;
}
2016-09-09 22:13:21 +02:00
QModelIndex ObjectListModel::index(int row, int column,
const QModelIndex &parent) const {
auto it = _gameData->modelinfo.begin();
2016-09-09 22:13:21 +02:00
for (int i = 0; i < row; i++) it++;
auto id = it->second->id();
2016-09-09 22:13:21 +02:00
return hasIndex(row, column, parent) ? createIndex(row, column, id)
: QModelIndex();
}