#ifndef SECTIONSWIDGET_H #define SECTIONSWIDGET_H #include #include #include #include "Cutter.h" #include "CutterDockWidget.h" class QSplitter; class QTreeView; class QAbstractItemView; class QResizeEvent; class MainWindow; namespace Ui { class SectionsWidget; } class SectionsModel : public QAbstractListModel { Q_OBJECT private: QList *sections; public: enum Column { NameColumn = 0, SizeColumn, AddressColumn, EndAddressColumn, ColumnCount }; enum Role { SectionDescriptionRole = Qt::UserRole }; SectionsModel(QList *sections, QObject *parent = Q_NULLPTR); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; void beginReloadSections(); void endReloadSections(); }; class SectionsProxyModel : public QSortFilterProxyModel { Q_OBJECT public: SectionsProxyModel(SectionsModel *sourceModel, QObject *parent = Q_NULLPTR); private slots: void onSourceModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles); protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; }; class SectionsWidget : public CutterDockWidget { Q_OBJECT public: explicit SectionsWidget(MainWindow *main, QAction *action = Q_NULLPTR); ~SectionsWidget(); protected: void resizeEvent(QResizeEvent *event) override; private slots: void refreshSections(); void showSectionsContextMenu(const QPoint &pt); void on_actionVertical_triggered(); void on_actionHorizontal_triggered(); void onSectionsDoubleClicked(const QModelIndex &index); private: std::unique_ptr ui; QList sections; SectionsModel *sectionsModel; SectionsProxyModel *sectionsProxyModel; QSplitter *splitter; QTreeView *sectionsTable; QAbstractItemView *sectionsPieChart; MainWindow *main; void setupViews(); }; #endif // SECTIONSWIDGET_H