2022-07-03 23:45:57 -04:00
|
|
|
#include "objectmodel.h"
|
|
|
|
|
2022-07-11 04:48:50 -04:00
|
|
|
#include <object.h>
|
2022-07-10 23:51:49 -04:00
|
|
|
|
2022-07-11 04:48:50 -04:00
|
|
|
#define super Model
|
2022-07-03 23:45:57 -04:00
|
|
|
|
|
|
|
using namespace si;
|
|
|
|
|
|
|
|
ObjectModel::ObjectModel(QObject *parent) :
|
|
|
|
super{parent}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ObjectModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return kColCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ObjectModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2022-07-11 04:48:50 -04:00
|
|
|
Core *c = GetCoreFromIndex(index);
|
2022-07-03 23:45:57 -04:00
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
|
|
|
switch (index.column()) {
|
|
|
|
case kColIndex:
|
2022-07-11 04:48:50 -04:00
|
|
|
if (Object *o = dynamic_cast<Object*>(c)) {
|
2022-07-11 04:57:37 -04:00
|
|
|
if (!index.parent().isValid()) {
|
|
|
|
return tr("%1:%2").arg(QString::number(index.row()), QString::number(o->id()));
|
|
|
|
} else {
|
|
|
|
return QString::number(o->id());
|
|
|
|
}
|
2022-07-11 04:48:50 -04:00
|
|
|
}
|
|
|
|
break;
|
2022-07-03 23:45:57 -04:00
|
|
|
case kColName:
|
2022-07-11 04:48:50 -04:00
|
|
|
if (Object *o = dynamic_cast<Object*>(c)) {
|
|
|
|
return QString::fromStdString(o->name());
|
2022-07-03 23:45:57 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ObjectModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
switch (section) {
|
|
|
|
case kColIndex:
|
|
|
|
return tr("Index");
|
|
|
|
case kColName:
|
|
|
|
return tr("Name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super::headerData(section, orientation, role);
|
|
|
|
}
|