Repository navigation
Expand file tree
/
Copy pathComponentConnector.cpp
More file actions
131 lines (110 loc) · 3.65 KB
/
Copy pathComponentConnector.cpp
File metadata and controls
131 lines (110 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "ComponentConnector.h"
#include "TestClass.h"
#include <QPainter>
ComponentConnector::ComponentConnector(QQuickItem *parent) :
QQuickItem(parent),
_targetObject(0)
{
setFlag(QQuickItem::ItemHasContents);
}
void ComponentConnector::componentComplete()
{
QQuickItem::componentComplete();
setWidth(360);
setHeight(360);
interrogateTarget();
}
QStringList ComponentConnector::customSlotNames() const
{
return _customSlots.keys();
}
QStringList ComponentConnector::customPropertyNames() const
{
return _customProperties.keys();
}
QStringList ComponentConnector::inheritedPropertyNames() const
{
return _inheritedProperties.keys();
}
QStringList ComponentConnector::customSignalNames() const
{
return _customSignals.keys();
}
QString ComponentConnector::componentName() const
{
if(_componentName.isNull() || _componentName.isEmpty())
return "Unnamed Component";
return _componentName;
}
QObject *ComponentConnector::targetObject() const
{
return _targetObject;
}
void ComponentConnector::setTargetObject(QObject *targetObject)
{
if (_targetObject != targetObject) {
_targetObject = targetObject;
interrogateTarget();
emit targetObjectChanged();
}
}
void ComponentConnector::setComponentName(QString value)
{
if(_componentName != value)
{
_componentName = value;
emit componentNameChanged(value);
}
}
/*!
* \brief ComponentConnector::interrogateTarget
*
* Finds all signals, slots and properties of the target class for inspection and adds them
* to the local properties of the ComponentConnector so they can be displayed in QML.
*
*/
void ComponentConnector::interrogateTarget()
{
//Clear old data (in case we had a previous target object)
_customSignals.clear();
_customSlots.clear();
_customProperties.clear();
_inheritedProperties.clear();
//Interrogate signals and slots
int startOfCustomMethods = _targetObject->metaObject()->methodOffset();
int methodCount = _targetObject->metaObject()->methodCount();
for(int i = startOfCustomMethods; i < methodCount; i++)
{
QMetaMethod currentMethod = _targetObject->metaObject()->method(i);
if(currentMethod.methodType() == QMetaMethod::Slot)
{
qDebug() << "Found slot:" << currentMethod.name();
_customSlots.insert(currentMethod.name(), currentMethod);
}
else if(currentMethod.methodType() == QMetaMethod::Signal)
{
qDebug() << "Found signal:" << currentMethod.name();
_customSignals.insert(currentMethod.name(), currentMethod);
}
}
//Interrogate custom and inherited properties
int startOfCustomProperties = _targetObject->metaObject()->propertyOffset();
int propertyCount = _targetObject->metaObject()->propertyCount();
for (int i = startOfCustomProperties; i < propertyCount; ++i)
{
QMetaProperty currentProperty = _targetObject->metaObject()->property(i);
qDebug() << "Found custom property: " << currentProperty.name();
_customProperties.insert(currentProperty.name(), currentProperty);
}
for (int i = 0; i < startOfCustomProperties; ++i)
{
QMetaProperty currentProperty = _targetObject->metaObject()->property(i);
qDebug() << "Found inherited property: " << currentProperty.name();
_inheritedProperties.insert(currentProperty.name(), currentProperty);
}
emit customSignalNamesChanged(customSignalNames());
emit customSlotNamesChanged(customSlotNames());
emit customPropertyNamesChanged(customPropertyNames());
emit inheritedPropertyNamesChanged(customPropertyNames());
update();
}