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 QML_MATERIAL_API AttachedPropertyNode : public QObject {
17 Q_OBJECT
18 QML_ANONYMOUS
19
20 Q_PROPERTY(QObject* inheritFrom READ inheritFrom WRITE setInheritFrom RESET resetInheritFrom
21 NOTIFY inheritFromChanged FINAL)
22
23public:
24 AttachedPropertyNode(QObject* target, const QMetaObject* attachedType);
25 ~AttachedPropertyNode() override;
26
27 QObject* target() const;
28
29 QObject* inheritFrom() const;
30 void setInheritFrom(QObject* source);
31 void resetInheritFrom();
32
33 // Non-visual owners publish this again when their logical context changes.
34 void setInheritanceParent(QQuickItem*);
35
36 AttachedPropertyNode* attachedParent() const;
37 QList<AttachedPropertyNode*> attachedChildren() const;
38
39 Q_SIGNAL void inheritFromChanged();
40
41protected:
42 void initializeAttachedProperty();
43 void propagateAttachedValues();
44
45 virtual void updateInheritedValues() = 0;
46
47private Q_SLOTS:
48 void refreshPropagation();
49
50private:
51 AttachedPropertyNode* findParent();
52 bool acceptsParent(AttachedPropertyNode*) const;
53 void setAttachedParent(AttachedPropertyNode*);
54 void adoptAttachedChildren();
55 void connectTarget();
56 void disconnectTarget();
57
58 QPointer<QObject> m_target;
59 QPointer<QObject> m_inherit_from;
60 QPointer<QQuickItem> m_inheritance_parent;
61 const QMetaObject* m_attached_type { nullptr };
62 QPointer<AttachedPropertyNode> m_attached_parent;
63 QList<QPointer<AttachedPropertyNode>> m_attached_children;
64 QMetaObject::Connection m_parent_connection;
65 QMetaObject::Connection m_window_connection;
66 QMetaObject::Connection m_inherit_from_destroyed;
67 quint64 m_revision { 0 };
68 quint64 m_source_revision { 0 };
69 bool m_initialized { false };
70 bool m_destroying { false };
71 bool m_cycle_warning_issued { false };
72 bool m_cross_engine_warning_issued { false };
73};
74
75} // namespace qml_material