2014-06-08 02:58:49 +02:00
|
|
|
#include "ItemListModel.hpp"
|
|
|
|
|
|
|
|
qint16 ItemListModel::getIDOf(unsigned int row) const
|
|
|
|
{
|
2014-09-17 04:13:02 +02:00
|
|
|
if( row < world()->objectTypes.size() )
|
|
|
|
{
|
|
|
|
return row;
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemListModel::ItemListModel(GameWorld *world, QObject *parent) :
|
|
|
|
QAbstractTableModel(parent), _world( world )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ItemListModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return _world->objectTypes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ItemListModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
2014-09-17 04:13:02 +02:00
|
|
|
return QString::fromStdString("TODO");
|
2014-06-08 02:58:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10 01:46:48 +02:00
|
|
|
|
|
|
|
QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex();
|
|
|
|
}
|