QmlMaterial 0.1.0
Loading...
Searching...
No Matches
attached_property.hpp
1#pragma once
2
3#include <QList>
4#include <QMetaObject>
5#include <QObject>
6#include <QPointer>
7#include <qqmlregistration.h>
8
9#include "qml_material/export.hpp"
10
11class QQuickItem;
12
13namespace qml_material
14{
15
16class AttachedPropertyRegistry;
17
18class QML_MATERIAL_API AttachedPropertyNode : public QObject {
19 Q_OBJECT
20 QML_ANONYMOUS
21
22 Q_PROPERTY(QObject* inheritFrom READ inheritFrom WRITE setInheritFrom RESET resetInheritFrom
23 NOTIFY inheritFromChanged FINAL)
24
25public:
26 AttachedPropertyNode(QObject* target, const QMetaObject* attachedType);
27 ~AttachedPropertyNode() override;
28
29 QObject* target() const;
30
31 QObject* inheritFrom() const;
32 void setInheritFrom(QObject* source);
33 void resetInheritFrom();
34
35 AttachedPropertyNode* attachedParent() const;
36 QList<AttachedPropertyNode*> attachedChildren() const;
37
38 Q_SIGNAL void inheritFromChanged();
39
40protected:
41 void initializeAttachedProperty();
42 void propagateAttachedValues();
43
44 virtual void updateInheritedValues() = 0;
45
46private Q_SLOTS:
47 void refreshPropagation();
48
49private:
50 friend class AttachedPropertyRegistry;
51
52 QPointer<QObject> m_target;
53 QPointer<QObject> m_inherit_from;
54 QObject* m_registered_target { nullptr };
55 const QMetaObject* m_attached_type { nullptr };
56 AttachedPropertyRegistry* m_registry { nullptr };
57 QPointer<AttachedPropertyNode> m_attached_parent;
58 QList<QPointer<AttachedPropertyNode>> m_attached_children;
59 QPointer<QQuickItem> m_content_root;
60 QList<QMetaObject::Connection> m_target_connections;
61 QMetaObject::Connection m_registry_destroyed;
62 QMetaObject::Connection m_content_root_destroyed;
63 QMetaObject::Connection m_inherit_from_destroyed;
64 bool m_initialized { false };
65 bool m_cycle_warning_issued { false };
66 bool m_cross_engine_warning_issued { false };
67};
68
69} // namespace qml_material