QmlMaterial 0.1.0
Loading...
Searching...
No Matches
header_list_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 HeaderListModel : public QAbstractTableModel {
11 Q_OBJECT
12 QML_ELEMENT
13 Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged FINAL)
14 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY
15 orientationChanged FINAL)
16public:
17 explicit HeaderListModel(QObject* parent = nullptr);
18 QVariant source() const;
19 void setSource(const QVariant& source);
20 bool trySetSource(const QVariant& source);
21 Qt::Orientation orientation() const { return m_orientation; }
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 QHash<int, QByteArray> roleNames() const override;
27 Q_SIGNAL void sourceChanged();
28 Q_SIGNAL void orientationChanged();
29
30private:
31 int count() const;
32 QModelIndex sectionIndex(int section) const;
33 void connectSource();
34 QVariant m_source;
35 QPointer<QAbstractItemModel> m_model;
36 QVariantList m_values;
37 QHash<int, QByteArray> m_roles;
38 Qt::Orientation m_orientation = Qt::Horizontal;
39 int m_integerCount = 0;
40};
41} // namespace qml_material