2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
2018-02-04 14:32:18 +00:00
|
|
|
#include "ResourcesWidget.h"
|
2020-07-25 08:32:44 +00:00
|
|
|
#include "ui_ListDockWidget.h"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/MainWindow.h"
|
2018-02-04 14:32:18 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
ResourcesModel::ResourcesModel(QList<ResourcesDescription> *resources, QObject *parent)
|
2021-01-24 14:50:13 +00:00
|
|
|
: AddressableItemModel<QAbstractListModel>(parent), resources(resources)
|
2018-02-04 14:32:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2020-04-15 16:20:57 +00:00
|
|
|
return res.name;
|
2018-03-21 20:32:32 +00:00
|
|
|
case VADDR:
|
2021-09-14 13:32:04 +00:00
|
|
|
return RzAddressString(res.vaddr);
|
2018-03-21 20:32:32 +00:00
|
|
|
case INDEX:
|
2019-09-01 21:30:25 +00:00
|
|
|
return QString::number(res.index);
|
2018-03-21 20:32:32 +00:00
|
|
|
case TYPE:
|
|
|
|
return res.type;
|
|
|
|
case SIZE:
|
|
|
|
return qhelpers::formatBytecount(res.size);
|
|
|
|
case LANG:
|
|
|
|
return res.lang;
|
2020-11-19 18:17:28 +00:00
|
|
|
case COMMENT:
|
|
|
|
return Core()->getCommentAt(res.vaddr);
|
2018-02-04 14:32:18 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2018-03-21 20:32:32 +00:00
|
|
|
}
|
2020-07-25 08:32:44 +00:00
|
|
|
case Qt::EditRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case NAME:
|
|
|
|
return res.name;
|
|
|
|
case VADDR:
|
|
|
|
return res.vaddr;
|
|
|
|
case INDEX:
|
|
|
|
return res.index;
|
|
|
|
case TYPE:
|
|
|
|
return res.type;
|
|
|
|
case SIZE:
|
|
|
|
return res.size;
|
|
|
|
case LANG:
|
|
|
|
return res.lang;
|
|
|
|
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");
|
2020-11-19 18:17:28 +00:00
|
|
|
case COMMENT:
|
|
|
|
return tr("Comment");
|
2018-02-04 14:32:18 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 21:30:25 +00:00
|
|
|
RVA ResourcesModel::address(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
const ResourcesDescription &res = resources->at(index.row());
|
|
|
|
return res.vaddr;
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:50:13 +00:00
|
|
|
ResourcesWidget::ResourcesWidget(MainWindow *main)
|
|
|
|
: ListDockWidget(main, ListDockWidget::SearchBarPolicy::HideByDefault)
|
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);
|
2019-09-01 21:30:25 +00:00
|
|
|
filterModel = new AddressableFilterProxyModel(model, this);
|
2020-07-25 08:32:44 +00:00
|
|
|
filterModel->setSortRole(Qt::EditRole);
|
2019-09-01 21:30:25 +00:00
|
|
|
setModels(filterModel);
|
|
|
|
|
2020-07-25 08:32:44 +00:00
|
|
|
ui->treeView->sortByColumn(0, Qt::AscendingOrder);
|
|
|
|
|
2019-09-01 21:30:25 +00:00
|
|
|
showCount(false);
|
2018-02-04 14:32:18 +00:00
|
|
|
|
|
|
|
// Configure widget
|
|
|
|
this->setWindowTitle(tr("Resources"));
|
|
|
|
|
2020-08-03 09:13:39 +00:00
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &ResourcesWidget::refreshResources);
|
2021-01-24 14:50:13 +00:00
|
|
|
connect(Core(), &CutterCore::commentsChanged, this,
|
|
|
|
[this]() { qhelpers::emitColumnChanged(model, ResourcesModel::COMMENT); });
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourcesWidget::refreshResources()
|
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
model->beginResetModel();
|
2018-02-04 14:32:18 +00:00
|
|
|
resources = Core()->getAllResources();
|
2018-10-10 11:33:55 +00:00
|
|
|
model->endResetModel();
|
2018-02-04 14:32:18 +00:00
|
|
|
}
|