2017-12-19 18:05:57 +00:00
|
|
|
|
|
|
|
#include <QModelIndex>
|
|
|
|
|
2017-10-02 16:18:40 +00:00
|
|
|
#include "StringsWidget.h"
|
|
|
|
#include "ui_StringsWidget.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
StringsModel::StringsModel(QList<StringDescription> *strings, QObject *parent)
|
|
|
|
: QAbstractListModel(parent),
|
|
|
|
strings(strings)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-12-19 18:05:57 +00:00
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
int StringsModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return strings->count();
|
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
int StringsModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return Columns::COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant StringsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (index.row() >= strings->count())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
const StringDescription &str = strings->at(index.row());
|
2017-11-26 21:31:27 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case OFFSET:
|
|
|
|
return RAddressString(str.vaddr);
|
|
|
|
case STRING:
|
|
|
|
return str.string;
|
2018-02-09 14:22:45 +00:00
|
|
|
case TYPE:
|
2018-02-10 17:50:00 +00:00
|
|
|
return str.type.toUpper();
|
2018-02-09 14:22:45 +00:00
|
|
|
case LENGTH:
|
|
|
|
return str.length;
|
|
|
|
case SIZE:
|
|
|
|
return str.size;
|
2017-12-19 18:05:57 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
case StringDescriptionRole:
|
|
|
|
return QVariant::fromValue(str);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
QVariant StringsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case OFFSET:
|
|
|
|
return tr("Address");
|
|
|
|
case STRING:
|
|
|
|
return tr("String");
|
2018-02-09 14:22:45 +00:00
|
|
|
case TYPE:
|
|
|
|
return tr("Type");
|
|
|
|
case LENGTH:
|
|
|
|
return tr("Length");
|
|
|
|
case SIZE:
|
|
|
|
return tr("Size");
|
2017-12-19 18:05:57 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
void StringsModel::beginReload()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-12-19 18:05:57 +00:00
|
|
|
beginResetModel();
|
|
|
|
}
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
void StringsModel::endReload()
|
|
|
|
{
|
|
|
|
endResetModel();
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
StringsSortFilterProxyModel::StringsSortFilterProxyModel(StringsModel *source_model, QObject *parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2017-12-19 18:05:57 +00:00
|
|
|
setSourceModel(source_model);
|
2017-12-26 13:40:12 +00:00
|
|
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
2017-12-19 18:05:57 +00:00
|
|
|
}
|
2017-12-02 19:15:12 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
bool StringsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
|
|
|
StringDescription str = index.data(StringsModel::StringDescriptionRole).value<StringDescription>();
|
|
|
|
return str.string.contains(filterRegExp());
|
|
|
|
}
|
2017-12-02 19:15:12 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
bool StringsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
|
|
|
StringDescription left_str = left.data(StringsModel::StringDescriptionRole).value<StringDescription>();
|
|
|
|
StringDescription right_str = right.data(StringsModel::StringDescriptionRole).value<StringDescription>();
|
2017-12-02 19:15:12 +00:00
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
switch (left.column())
|
|
|
|
{
|
|
|
|
case StringsModel::OFFSET:
|
|
|
|
if (left_str.vaddr != right_str.vaddr)
|
|
|
|
return left_str.vaddr < right_str.vaddr;
|
2018-03-04 23:16:54 +00:00
|
|
|
case StringsModel::STRING: // sort by string
|
2017-12-19 18:05:57 +00:00
|
|
|
return left_str.string < right_str.string;
|
2018-03-04 23:16:54 +00:00
|
|
|
case StringsModel::TYPE: // sort by type
|
|
|
|
return left_str.type < right_str.type;
|
|
|
|
case StringsModel::SIZE: // sort by size
|
|
|
|
return left_str.size < right_str.size;
|
|
|
|
case StringsModel::LENGTH: // sort by length
|
|
|
|
return left_str.length < right_str.length;
|
2017-12-19 18:05:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
2017-12-19 18:05:57 +00:00
|
|
|
|
|
|
|
// fallback
|
|
|
|
return left_str.vaddr < right_str.vaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringsWidget::StringsWidget(QWidget *parent) :
|
|
|
|
QDockWidget(parent),
|
|
|
|
ui(new Ui::StringsWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
qhelpers::setVerticalScrollMode(ui->stringsTreeView);
|
|
|
|
|
2017-12-19 18:56:18 +00:00
|
|
|
// Ctrl-F to show/hide the filter entry
|
|
|
|
QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this);
|
|
|
|
connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
|
|
|
|
search_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
|
|
|
// Esc to clear the filter entry
|
2017-12-21 11:08:49 +00:00
|
|
|
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
2017-12-19 18:56:18 +00:00
|
|
|
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
|
|
|
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
model = new StringsModel(&strings, this);
|
|
|
|
proxy_model = new StringsSortFilterProxyModel(model, this);
|
|
|
|
ui->stringsTreeView->setModel(proxy_model);
|
|
|
|
ui->stringsTreeView->sortByColumn(StringsModel::OFFSET, Qt::AscendingOrder);
|
|
|
|
|
2017-12-19 18:56:18 +00:00
|
|
|
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)), proxy_model, SLOT(setFilterWildcard(const QString &)));
|
|
|
|
connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->stringsTreeView, SLOT(setFocus()));
|
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshStrings()));
|
|
|
|
}
|
|
|
|
|
|
|
|
StringsWidget::~StringsWidget() {}
|
|
|
|
|
|
|
|
void StringsWidget::on_stringsTreeView_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
StringDescription str = index.data(StringsModel::StringDescriptionRole).value<StringDescription>();
|
|
|
|
CutterCore::getInstance()->seek(str.vaddr);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 18:05:57 +00:00
|
|
|
void StringsWidget::refreshStrings()
|
2017-04-13 15:14:02 +00:00
|
|
|
{
|
2017-12-19 18:05:57 +00:00
|
|
|
model->beginReload();
|
|
|
|
strings = CutterCore::getInstance()->getAllStrings();
|
|
|
|
model->endReload();
|
|
|
|
|
|
|
|
ui->stringsTreeView->resizeColumnToContents(0);
|
|
|
|
ui->stringsTreeView->resizeColumnToContents(1);
|
2018-02-09 14:22:45 +00:00
|
|
|
if (ui->stringsTreeView->columnWidth(1) > 300)
|
|
|
|
ui->stringsTreeView->setColumnWidth(1, 300);
|
|
|
|
ui->stringsTreeView->resizeColumnToContents(2);
|
|
|
|
ui->stringsTreeView->resizeColumnToContents(3);
|
|
|
|
ui->stringsTreeView->resizeColumnToContents(4);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|