2018-02-04 17:27:48 +00:00
|
|
|
#include "utils/Helpers.h"
|
2018-02-04 14:32:18 +00:00
|
|
|
#include "ResourcesWidget.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
#include "MainWindow.h"
|
2018-02-04 14:32:18 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
ResourcesModel::ResourcesModel(QList<ResourcesDescription> *resources, QObject *parent)
|
|
|
|
: QAbstractListModel(parent),
|
|
|
|
resources(resources)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResourcesModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return resources->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResourcesModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return Columns::COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ResourcesModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2018-02-09 13:19:36 +00:00
|
|
|
const ResourcesDescription &res = resources->at(index.row());
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case NAME:
|
|
|
|
return res.name;
|
|
|
|
case VADDR:
|
|
|
|
return RAddressString(res.vaddr);
|
|
|
|
case INDEX:
|
|
|
|
return res.index;
|
|
|
|
case TYPE:
|
|
|
|
return res.type;
|
|
|
|
case SIZE:
|
|
|
|
return qhelpers::formatBytecount(res.size);
|
|
|
|
case LANG:
|
|
|
|
return res.lang;
|
2018-02-04 14:32:18 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2018-03-21 20:32:32 +00:00
|
|
|
}
|
|
|
|
case Qt::UserRole:
|
|
|
|
return QVariant::fromValue(res);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ResourcesModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (role) {
|
2018-02-04 14:32:18 +00:00
|
|
|
case Qt::DisplayRole:
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (section) {
|
2018-02-04 14:32:18 +00:00
|
|
|
case NAME:
|
|
|
|
return tr("Name");
|
|
|
|
case VADDR:
|
|
|
|
return tr("Vaddr");
|
|
|
|
case INDEX:
|
|
|
|
return tr("Index");
|
|
|
|
case TYPE:
|
|
|
|
return tr("Type");
|
|
|
|
case SIZE:
|
|
|
|
return tr("Size");
|
|
|
|
case LANG:
|
|
|
|
return tr("Lang");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcesModel::beginReload()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcesModel::endReload()
|
|
|
|
{
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
ResourcesWidget::ResourcesWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action)
|
2018-02-04 14:32:18 +00:00
|
|
|
{
|
2018-03-03 17:48:39 +00:00
|
|
|
setObjectName("ResourcesWidget");
|
|
|
|
|
2018-02-04 14:32:18 +00:00
|
|
|
model = new ResourcesModel(&resources, this);
|
|
|
|
|
|
|
|
// Configure widget
|
|
|
|
this->setWindowTitle(tr("Resources"));
|
|
|
|
|
|
|
|
// Add resources tree view
|
|
|
|
view = new QTreeView(this);
|
|
|
|
view->setModel(model);
|
|
|
|
view->show();
|
|
|
|
this->setWidget(view);
|
|
|
|
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshResources()));
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this,
|
|
|
|
SLOT(onDoubleClicked(const QModelIndex &)));
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcesWidget::refreshResources()
|
|
|
|
{
|
|
|
|
model->beginReload();
|
|
|
|
resources = Core()->getAllResources();
|
|
|
|
model->endReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcesWidget::onDoubleClicked(const QModelIndex &index)
|
|
|
|
{
|
2018-04-23 07:54:06 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
2018-02-09 13:19:36 +00:00
|
|
|
ResourcesDescription res = index.data(Qt::UserRole).value<ResourcesDescription>();
|
2018-04-12 06:33:30 +00:00
|
|
|
Core()->seek(res.vaddr);
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|