2014-06-08 02:58:49 +02:00
|
|
|
#include "ItemListModel.hpp"
|
2015-04-24 19:09:21 +02:00
|
|
|
#include <engine/GameData.hpp>
|
2014-06-08 02:58:49 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
qint16 ItemListModel::getIDOf(unsigned int row) const {
|
2016-09-11 03:58:00 +02:00
|
|
|
if (row < world()->data->modelinfo.size()) {
|
2016-09-09 22:13:21 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
|
|
|
|
: QAbstractTableModel(parent), _world(world) {
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 17:38:36 +02:00
|
|
|
int ItemListModel::rowCount(const QModelIndex &) const {
|
2016-09-11 03:58:00 +02:00
|
|
|
return _world->data->modelinfo.size();
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 17:38:36 +02:00
|
|
|
int ItemListModel::columnCount(const QModelIndex &) const {
|
2016-09-09 22:13:21 +02:00
|
|
|
return 2;
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
QVariant ItemListModel::data(const QModelIndex &index, int role) const {
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
qint16 id = getIDOf(index.row());
|
|
|
|
if (id == -1) return QVariant::Invalid;
|
|
|
|
if (index.column() == 0) {
|
|
|
|
return id;
|
|
|
|
} else if (index.column() == 1) {
|
|
|
|
return QString::fromStdString("TODO");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant::Invalid;
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation,
|
|
|
|
int role) const {
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
|
|
|
if (section == 0) {
|
|
|
|
return "ID";
|
|
|
|
}
|
|
|
|
if (section == 1) {
|
|
|
|
return "Model";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant::Invalid;
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
2014-06-10 01:46:48 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
QModelIndex ItemListModel::index(int row, int column,
|
|
|
|
const QModelIndex &parent) const {
|
|
|
|
return hasIndex(row, column, parent)
|
|
|
|
? createIndex(row, column, getIDOf(row))
|
|
|
|
: QModelIndex();
|
2014-06-10 01:46:48 +02:00
|
|
|
}
|