1 #ifndef FLAGSWIDGET_H 2 #define FLAGSWIDGET_H 3 4 #include <memory> 5 6 #include <QAbstractItemModel> 7 #include <QSortFilterProxyModel> 8 #include <QStandardItemModel> 9 10 #include "core/Cutter.h" 11 #include "CutterDockWidget.h" 12 #include "CutterTreeWidget.h" 13 #include "AddressableItemList.h" 14 #include "AddressableItemModel.h" 15 16 class MainWindow; 17 class QTreeWidgetItem; 18 class FlagsWidget; 19 20 21 class FlagsModel: public AddressableItemModel<QAbstractListModel> 22 { 23 friend FlagsWidget; 24 25 private: 26 QList<FlagDescription> *flags; 27 28 public: 29 enum Columns { OFFSET = 0, SIZE, NAME, REALNAME, COMMENT, COUNT }; 30 static const int FlagDescriptionRole = Qt::UserRole; 31 32 FlagsModel(QList<FlagDescription> *flags, QObject *parent = nullptr); 33 34 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 35 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 36 37 QVariant data(const QModelIndex &index, int role) const override; 38 QVariant headerData(int section, Qt::Orientation orientation, 39 int role = Qt::DisplayRole) const override; 40 41 RVA address(const QModelIndex &index) const override; 42 QString name(const QModelIndex &index) const override; 43 44 const FlagDescription *description(QModelIndex index) const; 45 }; 46 47 48 49 class FlagsSortFilterProxyModel : public AddressableFilterProxyModel 50 { 51 Q_OBJECT 52 53 public: 54 FlagsSortFilterProxyModel(FlagsModel *source_model, QObject *parent = nullptr); 55 56 protected: 57 bool filterAcceptsRow(int row, const QModelIndex &parent) const override; 58 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 59 }; 60 61 62 63 namespace Ui { 64 class FlagsWidget; 65 } 66 67 class FlagsWidget : public CutterDockWidget 68 { 69 Q_OBJECT 70 71 public: 72 explicit FlagsWidget(MainWindow *main); 73 ~FlagsWidget(); 74 75 private slots: 76 void on_flagspaceCombo_currentTextChanged(const QString &arg1); 77 78 void on_actionRename_triggered(); 79 void on_actionDelete_triggered(); 80 81 void flagsChanged(); 82 void refreshFlagspaces(); 83 84 private: 85 std::unique_ptr<Ui::FlagsWidget> ui; 86 MainWindow *main; 87 88 bool disableFlagRefresh = false; 89 FlagsModel *flags_model; 90 FlagsSortFilterProxyModel *flags_proxy_model; 91 QList<FlagDescription> flags; 92 CutterTreeWidget *tree; 93 94 void refreshFlags(); 95 void setScrollMode(); 96 }; 97 98 #endif // FLAGSWIDGET_H 99