1 #ifndef HEADERSWIDGET_H 2 #define HEADERSWIDGET_H 3 4 #include <memory> 5 6 #include "core/Cutter.h" 7 #include "ListDockWidget.h" 8 9 #include <QAbstractListModel> 10 #include <QSortFilterProxyModel> 11 12 class MainWindow; 13 class QTreeWidget; 14 15 namespace Ui { 16 class HeadersWidget; 17 } 18 19 20 class MainWindow; 21 class QTreeWidgetItem; 22 class HeadersWidget; 23 24 25 class HeadersModel: public AddressableItemModel<QAbstractListModel> 26 { 27 Q_OBJECT 28 29 friend HeadersWidget; 30 31 private: 32 QList<HeaderDescription> *headers; 33 34 public: 35 enum Column { OffsetColumn = 0, NameColumn, ValueColumn, CommentColumn, ColumnCount }; 36 enum Role { HeaderDescriptionRole = Qt::UserRole }; 37 38 HeadersModel(QList<HeaderDescription> *headers, QObject *parent = nullptr); 39 40 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 41 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 42 43 QVariant data(const QModelIndex &index, int role) const override; 44 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 45 46 RVA address(const QModelIndex &index) const override; 47 QString name(const QModelIndex &index) const override; 48 }; 49 50 51 52 class HeadersProxyModel : public AddressableFilterProxyModel 53 { 54 Q_OBJECT 55 56 public: 57 HeadersProxyModel(HeadersModel *sourceModel, QObject *parent = nullptr); 58 59 protected: 60 bool filterAcceptsRow(int row, const QModelIndex &parent) const override; 61 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 62 }; 63 64 65 66 class HeadersWidget : public ListDockWidget 67 { 68 Q_OBJECT 69 70 public: 71 explicit HeadersWidget(MainWindow *main); 72 ~HeadersWidget(); 73 74 private slots: 75 void refreshHeaders(); 76 77 private: 78 HeadersModel *headersModel; 79 HeadersProxyModel *headersProxyModel; 80 QList<HeaderDescription> headers; 81 }; 82 83 84 #endif // HEADERSWIDGET_H 85