QmlMaterial 0.1.0
Loading...
Searching...
No Matches
header_data_model.hpp
1#pragma once
2
3#include <QAbstractTableModel>
4#include <QPointer>
5#include <qqmlregistration.h>
6#include "qml_material/export.hpp"
7
8namespace qml_material
9{
10class QML_MATERIAL_API HeaderDataModel : public QAbstractTableModel {
11 Q_OBJECT
12 QML_ELEMENT
13 Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY
14 sourceModelChanged FINAL)
15 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY
16 orientationChanged FINAL)
17public:
18 explicit HeaderDataModel(QObject* parent = nullptr);
19 QAbstractItemModel* sourceModel() const { return m_source; }
20 Qt::Orientation orientation() const { return m_orientation; }
21 void setSourceModel(QAbstractItemModel* source);
22 void setOrientation(Qt::Orientation orientation);
23 int rowCount(const QModelIndex& parent = {}) const override;
24 int columnCount(const QModelIndex& parent = {}) const override;
25 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
26 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
27 QHash<int, QByteArray> roleNames() const override;
28 Q_SIGNAL void sourceModelChanged();
29 Q_SIGNAL void orientationChanged();
30
31private:
32 bool validIndex(const QModelIndex& index) const;
33 void connectSource();
34 QPointer<QAbstractItemModel> m_source;
35 Qt::Orientation m_orientation = Qt::Horizontal;
36};
37} // namespace qml_material