1 2 #ifndef ADDRESSABLEITEMMODEL_H 3 #define ADDRESSABLEITEMMODEL_H 4 5 #include <QAbstractItemModel> 6 #include <QSortFilterProxyModel> 7 #include <QAbstractItemModel> 8 9 #include "core/CutterCommon.h" 10 11 class CUTTER_EXPORT AddressableItemModelI 12 { 13 public: 14 virtual RVA address(const QModelIndex &index) const = 0; 15 /** 16 * @brief Get name for item, optional. 17 * @param index item intex 18 * @return Item name or empty QString if item doesn't have short descriptive name. 19 */ name(const QModelIndex & index)20 virtual QString name(const QModelIndex &index) const { Q_UNUSED(index) return QString(); } 21 virtual QAbstractItemModel *asItemModel() = 0; 22 }; 23 24 template <class ParentModel = QAbstractItemModel> 25 class CUTTER_EXPORT AddressableItemModel : public ParentModel, public AddressableItemModelI 26 { 27 static_assert (std::is_base_of<QAbstractItemModel, ParentModel>::value, 28 "ParentModel needs to inherit from QAbstractItemModel"); 29 public: ParentModel(parent)30 explicit AddressableItemModel(QObject *parent = nullptr) : ParentModel(parent) {} ~AddressableItemModel()31 virtual ~AddressableItemModel() {} asItemModel()32 QAbstractItemModel *asItemModel() { return this; } 33 }; 34 35 class CUTTER_EXPORT AddressableFilterProxyModel : public AddressableItemModel<QSortFilterProxyModel> 36 { 37 using ParentClass = AddressableItemModel<QSortFilterProxyModel>; 38 public: 39 AddressableFilterProxyModel(AddressableItemModelI *sourceModel, QObject *parent); 40 41 RVA address(const QModelIndex &index) const override; 42 QString name(const QModelIndex &) const override; 43 void setSourceModel(AddressableItemModelI *sourceModel); 44 private: 45 void setSourceModel(QAbstractItemModel *sourceModel) override; // Don't use this directly 46 AddressableItemModelI *addressableSourceModel; 47 }; 48 49 #endif // ADDRESSABLEITEMMODEL_H 50