blob: d2e6a1a803d7cac7fee78b1ba920efa97091a8ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#pragma once
#include <qmetatype.h>
#include <QSortFilterProxyModel>
#include <qstandarditemmodel.h>
#include <QStyledItemDelegate>
#include <QTableView>
#include <QVector>
#include "binaryninjaapi.h"
#include "filter.h"
// Used to serialize into the item data for rendering with TokenDataDelegate.
struct TokenData
{
QVector<BinaryNinja::InstructionTextToken> tokens{};
TokenData() = default;
TokenData(const std::vector<BinaryNinja::InstructionTextToken> &tokens)
{
for (const auto &token: tokens)
this->tokens.push_back(token);
}
TokenData(const BinaryNinja::InstructionTextToken &token)
{
this->tokens.push_back(token);
}
QString toString() const
{
QStringList tokenStrings;
for (const auto &token: tokens)
{
tokenStrings.append(QString::fromStdString(token.text));
}
return tokenStrings.join("");
}
};
Q_DECLARE_METATYPE(TokenData)
class TokenDataDelegate final : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TokenDataDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent)
{
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
class AddressColorDelegate final : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit AddressColorDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent)
{
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
class GenericTextFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
GenericTextFilterModel(QObject *parent): QSortFilterProxyModel(parent)
{
}
~GenericTextFilterModel() override = default;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
};
|