2022-06-23 21:36:00 -04:00
|
|
|
#include "chunkmodel.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
2022-07-18 03:27:00 -04:00
|
|
|
#include <sitypes.h>
|
2022-06-23 21:36:00 -04:00
|
|
|
|
2022-07-11 04:48:50 -04:00
|
|
|
#define super Model
|
2022-06-23 21:36:00 -04:00
|
|
|
|
2022-06-27 12:44:50 -04:00
|
|
|
using namespace si;
|
|
|
|
|
2022-06-23 21:36:00 -04:00
|
|
|
ChunkModel::ChunkModel(QObject *parent) :
|
2022-07-11 04:48:50 -04:00
|
|
|
super{parent}
|
2022-06-23 21:36:00 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ChunkModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return kColCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ChunkModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2022-07-18 03:27:00 -04:00
|
|
|
Info *c = static_cast<Info*>(GetCoreFromIndex(index));
|
2022-06-23 21:36:00 -04:00
|
|
|
if (!c) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
|
|
|
switch (index.column()) {
|
|
|
|
case kColType:
|
|
|
|
// Convert 4-byte ID to QString
|
2022-07-18 03:27:00 -04:00
|
|
|
return QString::fromLatin1(reinterpret_cast<const char *>(&c->GetType()), sizeof(uint32_t));
|
2022-06-27 12:44:50 -04:00
|
|
|
case kColOffset:
|
2022-07-18 03:27:00 -04:00
|
|
|
return QStringLiteral("0x%1").arg(QString::number(c->GetOffset(), 16).toUpper());
|
2022-07-18 05:11:24 -04:00
|
|
|
case kColSize:
|
|
|
|
return QStringLiteral("0x%1").arg(QString::number(c->GetSize(), 16).toUpper());
|
2022-06-23 21:36:00 -04:00
|
|
|
case kColDesc:
|
2022-07-18 03:27:00 -04:00
|
|
|
return QString::fromUtf8(RIFF::GetTypeDescription(static_cast<RIFF::Type>(c->GetType())));
|
2022-07-04 02:33:56 -04:00
|
|
|
case kColObjectID:
|
2022-07-18 03:27:00 -04:00
|
|
|
uint32_t i = c->GetObjectID();
|
|
|
|
if (i != Info::NULL_OBJECT_ID) {
|
|
|
|
return QString::number(i);
|
2022-07-04 02:33:56 -04:00
|
|
|
}
|
|
|
|
break;
|
2022-06-23 21:36:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ChunkModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
switch (section) {
|
|
|
|
case kColType:
|
|
|
|
return tr("Type");
|
2022-06-27 12:44:50 -04:00
|
|
|
case kColOffset:
|
|
|
|
return tr("Offset");
|
2022-07-18 05:11:24 -04:00
|
|
|
case kColSize:
|
|
|
|
return tr("Size");
|
2022-06-23 21:36:00 -04:00
|
|
|
case kColDesc:
|
|
|
|
return tr("Description");
|
2022-07-04 02:33:56 -04:00
|
|
|
case kColObjectID:
|
|
|
|
return tr("Object ID");
|
2022-06-23 21:36:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super::headerData(section, orientation, role);
|
|
|
|
}
|