summaryrefslogtreecommitdiff
path: root/view/sharedcache/ui/symboltable.h
blob: 53c7187454d7d25ad241fa71d538ad243c9d7c64 (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
85
86
#pragma once

#include <sharedcacheapi.h>
#include "viewframe.h"
#include "animation.h"

#include <QTableView>
#include <QStandardItemModel>
#include "filter.h"

class SymbolTableView;

class SymbolTableModel : public QAbstractTableModel {
    Q_OBJECT

    SymbolTableView* m_parent;
    std::string m_filter;
    std::vector<SharedCacheAPI::CacheSymbol> m_preparedSymbols {};
    // the symbols we actually use.
    std::vector<SharedCacheAPI::CacheSymbol> m_modelSymbols {};

public:
    explicit SymbolTableModel(SymbolTableView* parent);

    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    int columnCount(const QModelIndex& parent = QModelIndex()) const override;
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    void updateSymbols(std::vector<SharedCacheAPI::CacheSymbol>&& symbols);

    void setFilter(std::string text);

    const SharedCacheAPI::CacheSymbol& symbolAt(int row) const;
};


class SymbolTableView : public QTableView, public FilterTarget
{
    Q_OBJECT
    friend class SymbolTableModel;

    SymbolTableModel* m_model;

public:
    SymbolTableView(QWidget* parent);
    virtual ~SymbolTableView() override;

    void scrollToFirstItem() override {
        if (model()->rowCount() > 0) {
            scrollTo(model()->index(0, 0));
        }
    }

    // Call this to populate the symbols from the given view.
    void populateSymbols(BinaryNinja::BinaryView& view);

    void scrollToCurrentItem() override {
        QModelIndex currentIndex = selectionModel()->currentIndex();
        if (currentIndex.isValid()) {
            scrollTo(currentIndex);
        }
    }

    void selectFirstItem() override {
        if (model()->rowCount() > 0) {
            QModelIndex firstIndex = model()->index(0, 0);
            selectionModel()->select(firstIndex, QItemSelectionModel::ClearAndSelect);
        }
    }

    void activateFirstItem() override {
        if (model()->rowCount() > 0) {
            QModelIndex firstIndex = model()->index(0, 0);
            setCurrentIndex(firstIndex);
            emit activated(firstIndex);
        }
    }

    SharedCacheAPI::CacheSymbol getSymbolAtRow(int row) const
    {
        return m_model->symbolAt(row);
    }

    void setFilter(const std::string& filter) override;
};