cutter/src/widgets/HeadersWidget.h

88 lines
1.8 KiB
C
Raw Normal View History

2018-05-21 17:34:41 +00:00
#ifndef HEADERSWIDGET_H
#define HEADERSWIDGET_H
#include <memory>
#include "core/Cutter.h"
2018-05-21 17:34:41 +00:00
#include "CutterDockWidget.h"
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
class MainWindow;
class QTreeWidget;
2018-09-30 20:00:53 +00:00
namespace Ui {
class HeadersWidget;
2018-05-21 17:34:41 +00:00
}
class MainWindow;
class QTreeWidgetItem;
class HeadersWidget;
2018-05-21 17:34:41 +00:00
class HeadersModel: public QAbstractListModel
{
Q_OBJECT
friend HeadersWidget;
2018-05-21 17:34:41 +00:00
private:
QList<HeaderDescription> *headers;
public:
enum Column { OffsetColumn = 0, NameColumn, ValueColumn, ColumnCount };
enum Role { HeaderDescriptionRole = Qt::UserRole };
HeadersModel(QList<HeaderDescription> *headers, QObject *parent = 0);
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;
};
class HeadersProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
HeadersProxyModel(HeadersModel *sourceModel, QObject *parent = nullptr);
protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
};
class HeadersWidget : public CutterDockWidget
{
Q_OBJECT
public:
explicit HeadersWidget(MainWindow *main, QAction *action = nullptr);
~HeadersWidget();
private slots:
void on_headersTreeView_doubleClicked(const QModelIndex &index);
void refreshHeaders();
private:
std::unique_ptr<Ui::HeadersWidget> ui;
HeadersModel *headersModel;
HeadersProxyModel *headersProxyModel;
QList<HeaderDescription> headers;
void setScrollMode();
};
#endif // HEADERSWIDGET_H