46
46
QVariant IntrospectNode(QObject* obj);
47
47
QString GetNodeName(QObject* obj);
48
48
QStringList GetNodeChildNames(QObject* obj);
49
QVariant GetGlobalRect(QObject* obj);
50
QVariant GetChildrenNames(QObject* obj);
49
void AddCustomProperties(QObject* obj, QVariantMap& properties);
52
51
QList<NodeIntrospectionData> Introspect(QString const& query_string)
128
128
QMetaProperty prop = meta->property(i);
129
129
if (!prop.isValid())
131
qDebug() << "Property at index" << i << "is not valid!";
131
qDebug() << "Property at index" << i << "Is not valid!";
134
134
QVariant object_property = PackProperty(prop.read(obj));
150
150
meta = meta->superClass();
153
QVariant global_rect_property = GetNodeProperty(obj, "globalRect");
154
if(global_rect_property.isValid())
155
object_properties["globalRect"] = global_rect_property;
153
AddCustomProperties(obj, object_properties);
157
155
// add the 'Children' pseudo-property:
158
QVariant children_property = GetNodeProperty(obj, "Children");
159
if(children_property.isValid())
160
object_properties["Children"] = children_property;
162
return object_properties;
165
QVariant GetNodeProperty(QObject* obj, const std::string& property_name)
167
if(property_name == "globalRect")
168
return GetGlobalRect(obj);
170
if(property_name == "Children")
171
return GetChildrenNames(obj);
173
QVariant dynamic_property = obj->property(property_name.c_str());
174
if (dynamic_property.isValid())
176
return PackProperty(dynamic_property);
180
const QMetaObject* meta = obj->metaObject();
181
int property_index = meta->indexOfProperty(property_name.c_str());
182
if(property_index != -1)
184
QMetaProperty prop = meta->property(property_index);
186
return PackProperty(prop.read(obj));
188
qDebug() << "Property " << QString::fromStdString(property_name)
196
QVariant GetChildrenNames(QObject* obj)
198
156
QStringList children = GetNodeChildNames(obj);
199
157
if (!children.empty())
200
return PackProperty(children);
158
object_properties["Children"] = PackProperty(children);
160
return object_properties;
205
QVariant GetGlobalRect(QObject* obj)
164
void AddCustomProperties(QObject* obj, QVariantMap &properties)
207
166
// Add any custom properties we need to the given QObject.
208
167
// Add GlobalRect support for QWidget-derived classes
212
171
QRect r = w->rect();
213
172
r = QRect(w->mapToGlobal(r.topLeft()), r.size());
214
return PackProperty(r);
173
properties["globalRect"] = PackProperty(r);
216
175
// ...and support for QGraphicsItem-derived classes.
217
176
else if (QGraphicsItem *i = qobject_cast<QGraphicsItem*>(obj))
225
184
QRect global_rect = QRect(
226
185
view->mapToGlobal(scene_rect.topLeft()),
227
186
scene_rect.size());
228
return PackProperty(global_rect);
187
properties["globalRect"] = PackProperty(global_rect);
230
189
#ifdef QT5_SUPPORT
231
190
// ... and support for QQuickItems (aka. Qt5 Declarative items)
232
191
else if (QQuickItem *i = qobject_cast<QQuickItem*>(obj))
234
193
QQuickWindow *view = i->window();
237
QRectF bounding_rect = i->boundingRect();
238
bounding_rect = i->mapRectToScene(bounding_rect);
239
QRect global_rect = QRect(
240
view->mapToGlobal(bounding_rect.toRect().topLeft()), bounding_rect.size().toSize()
243
return PackProperty(global_rect);
194
QRectF bounding_rect = i->boundingRect();
195
bounding_rect = i->mapRectToScene(bounding_rect);
196
QRect global_rect = QRect(view->mapToGlobal(bounding_rect.toRect().topLeft()), bounding_rect.size().toSize());
197
properties["globalRect"] = PackProperty(global_rect);
248
// Default to returning invalid QVariant
252
202
QVariant PackProperty(QVariant const& prop)