1 #ifndef SEARCHWIDGET_H
2 #define SEARCHWIDGET_H
3 
4 #include <memory>
5 
6 #include <QAbstractItemModel>
7 #include <QSortFilterProxyModel>
8 
9 #include "core/Cutter.h"
10 #include "CutterDockWidget.h"
11 #include "AddressableItemList.h"
12 
13 class MainWindow;
14 class QTreeWidgetItem;
15 class SearchWidget;
16 
17 
18 class SearchModel: public AddressableItemModel<QAbstractListModel>
19 {
20     Q_OBJECT
21 
22     friend SearchWidget;
23 
24 private:
25     QList<SearchDescription> *search;
26 
27 public:
28     enum Columns { OFFSET = 0, SIZE, CODE, DATA, COMMENT, COUNT };
29     static const int SearchDescriptionRole = Qt::UserRole;
30 
31     SearchModel(QList<SearchDescription> *search, QObject *parent = nullptr);
32 
33     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
34     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
35 
36     QVariant data(const QModelIndex &index, int role) const override;
37     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
38 
39     RVA address(const QModelIndex &index) const override;
40 };
41 
42 
43 
44 class SearchSortFilterProxyModel : public AddressableFilterProxyModel
45 {
46     Q_OBJECT
47 
48 public:
49     SearchSortFilterProxyModel(SearchModel *source_model, QObject *parent = nullptr);
50 
51 protected:
52     bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
53     bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
54 };
55 
56 
57 
58 namespace Ui {
59 class SearchWidget;
60 }
61 
62 class SearchWidget : public CutterDockWidget
63 {
64     Q_OBJECT
65 
66 public:
67     explicit SearchWidget(MainWindow *main);
68     ~SearchWidget();
69 
70 private slots:
71     void on_searchInCombo_currentIndexChanged(int index);
72     void searchChanged();
73     void updateSearchBoundaries();
74     void refreshSearchspaces();
75 
76 private:
77     std::unique_ptr<Ui::SearchWidget> ui;
78 
79     SearchModel *search_model;
80     SearchSortFilterProxyModel *search_proxy_model;
81     QList<SearchDescription> search;
82 
83     void refreshSearch();
84     void checkSearchResultEmpty();
85     void setScrollMode();
86     void updatePlaceholderText(int index);
87 };
88 
89 #endif // SEARCHWIDGET_H
90