2017-09-25 12:55:41 +00:00
|
|
|
#include <QDockWidget>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QComboBox>
|
2017-03-29 10:18:37 +00:00
|
|
|
#include "flagswidget.h"
|
|
|
|
#include "ui_flagswidget.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-05-06 10:46:28 +00:00
|
|
|
FlagsModel::FlagsModel(QList<FlagDescription> *flags, QObject *parent)
|
2017-05-04 14:16:21 +00:00
|
|
|
: QAbstractListModel(parent),
|
|
|
|
flags(flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-06 10:46:28 +00:00
|
|
|
int FlagsModel::rowCount(const QModelIndex &) const
|
2017-05-04 14:16:21 +00:00
|
|
|
{
|
|
|
|
return flags->count();
|
|
|
|
}
|
|
|
|
|
2017-05-06 10:46:28 +00:00
|
|
|
int FlagsModel::columnCount(const QModelIndex &) const
|
2017-05-04 14:16:21 +00:00
|
|
|
{
|
|
|
|
return Columns::COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant FlagsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
if (index.row() >= flags->count())
|
2017-05-04 14:16:21 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
const FlagDescription &flag = flags->at(index.row());
|
|
|
|
|
2017-06-03 12:27:23 +00:00
|
|
|
switch (role)
|
2017-05-04 14:16:21 +00:00
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case SIZE:
|
|
|
|
return RSizeString(flag.size);
|
|
|
|
case OFFSET:
|
|
|
|
return RAddressString(flag.offset);
|
|
|
|
case NAME:
|
|
|
|
return flag.name;
|
2017-05-04 14:16:21 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-06-03 12:27:23 +00:00
|
|
|
}
|
|
|
|
case FlagDescriptionRole:
|
|
|
|
return QVariant::fromValue(flag);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-05-04 14:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant FlagsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
switch (role)
|
2017-05-04 14:16:21 +00:00
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case SIZE:
|
|
|
|
return tr("Size");
|
|
|
|
case OFFSET:
|
|
|
|
return tr("Offset");
|
|
|
|
case NAME:
|
|
|
|
return tr("Name");
|
2017-05-04 14:16:21 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-06-03 12:27:23 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
2017-05-04 14:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsModel::beginReloadFlags()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsModel::endReloadFlags()
|
|
|
|
{
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FlagsSortFilterProxyModel::FlagsSortFilterProxyModel(FlagsModel *source_model, QObject *parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
setSourceModel(source_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlagsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
|
|
|
|
return flag.name.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlagsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
|
|
|
FlagDescription left_flag = left.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
|
|
|
|
FlagDescription right_flag = right.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
|
|
|
|
|
2017-06-03 12:27:23 +00:00
|
|
|
switch (left.column())
|
2017-05-04 14:16:21 +00:00
|
|
|
{
|
2017-06-03 12:27:23 +00:00
|
|
|
case FlagsModel::SIZE:
|
|
|
|
if (left_flag.size != right_flag.size)
|
|
|
|
return left_flag.size < right_flag.size;
|
|
|
|
// fallthrough
|
|
|
|
case FlagsModel::OFFSET:
|
|
|
|
if (left_flag.offset != right_flag.offset)
|
|
|
|
return left_flag.offset < right_flag.offset;
|
|
|
|
// fallthrough
|
|
|
|
case FlagsModel::NAME:
|
|
|
|
return left_flag.name < right_flag.name;
|
|
|
|
default:
|
|
|
|
break;
|
2017-05-04 14:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fallback
|
|
|
|
return left_flag.offset < right_flag.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
FlagsWidget::FlagsWidget(MainWindow *main, QWidget *parent) :
|
2017-04-13 15:14:02 +00:00
|
|
|
DockWidget(parent),
|
|
|
|
ui(new Ui::FlagsWidget),
|
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-05-06 10:46:28 +00:00
|
|
|
flags_model = new FlagsModel(&flags, this);
|
2017-05-04 14:16:21 +00:00
|
|
|
flags_proxy_model = new FlagsSortFilterProxyModel(flags_model, this);
|
|
|
|
connect(ui->filterLineEdit, SIGNAL(textChanged(const QString &)), flags_proxy_model, SLOT(setFilterWildcard(const QString &)));
|
|
|
|
ui->flagsTreeView->setModel(flags_proxy_model);
|
|
|
|
ui->flagsTreeView->sortByColumn(FlagsModel::OFFSET, Qt::AscendingOrder);
|
2017-07-11 11:05:42 +00:00
|
|
|
|
|
|
|
connect(main->core, SIGNAL(flagsChanged()), this, SLOT(flagsChanged()));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 09:41:28 +00:00
|
|
|
FlagsWidget::~FlagsWidget() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
void FlagsWidget::setup()
|
|
|
|
{
|
|
|
|
setScrollMode();
|
|
|
|
|
|
|
|
refreshFlagspaces();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsWidget::refresh()
|
|
|
|
{
|
2017-05-04 14:16:21 +00:00
|
|
|
refreshFlagspaces();
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 14:16:21 +00:00
|
|
|
void FlagsWidget::on_flagsTreeView_doubleClicked(const QModelIndex &index)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-05-04 14:16:21 +00:00
|
|
|
FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
|
|
|
|
this->main->seek(flag.offset, flag.name, true);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsWidget::on_flagspaceCombo_currentTextChanged(const QString &arg1)
|
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(arg1);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
refreshFlags();
|
|
|
|
}
|
|
|
|
|
2017-07-11 11:05:42 +00:00
|
|
|
void FlagsWidget::flagsChanged()
|
|
|
|
{
|
|
|
|
refreshFlagspaces();
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
void FlagsWidget::refreshFlagspaces()
|
|
|
|
{
|
|
|
|
int cur_idx = ui->flagspaceCombo->currentIndex();
|
2017-05-03 09:09:57 +00:00
|
|
|
if (cur_idx < 0)
|
|
|
|
cur_idx = 0;
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
ui->flagspaceCombo->clear();
|
2017-05-03 09:09:57 +00:00
|
|
|
ui->flagspaceCombo->addItem(tr("(all)"));
|
|
|
|
|
|
|
|
for (auto i : main->core->getAllFlagspaces())
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2017-05-03 09:09:57 +00:00
|
|
|
ui->flagspaceCombo->addItem(i.name, QVariant::fromValue(i));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
if (cur_idx > 0)
|
|
|
|
ui->flagspaceCombo->setCurrentIndex(cur_idx);
|
|
|
|
|
|
|
|
refreshFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsWidget::refreshFlags()
|
|
|
|
{
|
2017-05-03 09:09:57 +00:00
|
|
|
QString flagspace;
|
|
|
|
|
|
|
|
QVariant flagspace_data = ui->flagspaceCombo->currentData();
|
2017-06-03 12:27:23 +00:00
|
|
|
if (flagspace_data.isValid())
|
2017-05-03 09:09:57 +00:00
|
|
|
flagspace = flagspace_data.value<FlagspaceDescription>().name;
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-05-04 14:16:21 +00:00
|
|
|
flags_model->beginReloadFlags();
|
|
|
|
flags = main->core->getAllFlags(flagspace);
|
|
|
|
flags_model->endReloadFlags();
|
2017-04-27 18:59:27 +00:00
|
|
|
|
2017-05-04 14:16:21 +00:00
|
|
|
ui->flagsTreeView->resizeColumnToContents(0);
|
|
|
|
ui->flagsTreeView->resizeColumnToContents(1);
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
// TODO: this is not a very good place for the following:
|
2017-05-04 14:16:21 +00:00
|
|
|
QStringList flagNames;
|
|
|
|
for (auto i : flags)
|
|
|
|
flagNames.append(i.name);
|
|
|
|
main->refreshOmniBar(flagNames);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlagsWidget::setScrollMode()
|
|
|
|
{
|
2017-05-04 14:16:21 +00:00
|
|
|
qhelpers::setVerticalScrollMode(ui->flagsTreeView);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|