~canonical-platform-qa/autopilot-qt/wily_fix-unittests

« back to all changes in this revision

Viewing changes to driver/introspection.cpp

  • Committer: CI bot
  • Author(s): Timo Jyrinki
  • Date: 2014-03-12 13:51:19 UTC
  • mfrom: (80.1.1 autopilot-qt)
  • Revision ID: ps-jenkins@lists.canonical.com-20140312135119-rtoj0tkh2oku1u8o
Apply the revert that is in archives now, and rebuild against Qt 5.2.1. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
51
50
 
52
51
QList<NodeIntrospectionData> Introspect(QString const& query_string)
53
52
{
59
58
    }
60
59
 
61
60
    return state;
 
61
 
62
62
}
63
63
 
64
64
 
128
128
            QMetaProperty prop = meta->property(i);
129
129
            if (!prop.isValid())
130
130
            {
131
 
                qDebug() << "Property at index" << i << "is not valid!";
 
131
                qDebug() << "Property at index" << i << "Is not valid!";
132
132
                continue;
133
133
            }
134
134
            QVariant object_property = PackProperty(prop.read(obj));
150
150
        meta = meta->superClass();
151
151
    } while(meta);
152
152
 
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);
156
154
 
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;
161
 
 
162
 
    return object_properties;
163
 
}
164
 
 
165
 
QVariant GetNodeProperty(QObject* obj, const std::string& property_name)
166
 
{
167
 
    if(property_name == "globalRect")
168
 
        return GetGlobalRect(obj);
169
 
 
170
 
    if(property_name == "Children")
171
 
        return GetChildrenNames(obj);
172
 
 
173
 
    QVariant dynamic_property = obj->property(property_name.c_str());
174
 
    if (dynamic_property.isValid())
175
 
    {
176
 
        return PackProperty(dynamic_property);
177
 
    }
178
 
    else
179
 
    {
180
 
        const QMetaObject* meta = obj->metaObject();
181
 
        int property_index = meta->indexOfProperty(property_name.c_str());
182
 
        if(property_index != -1)
183
 
        {
184
 
            QMetaProperty prop = meta->property(property_index);
185
 
            if(prop.isValid())
186
 
                return PackProperty(prop.read(obj));
187
 
            else
188
 
                qDebug() << "Property " << QString::fromStdString(property_name)
189
 
                         << " is not valid.";
190
 
        }
191
 
    }
192
 
 
193
 
    return QVariant();
194
 
}
195
 
 
196
 
QVariant GetChildrenNames(QObject* obj)
197
 
{
198
156
    QStringList children = GetNodeChildNames(obj);
199
157
    if (!children.empty())
200
 
        return PackProperty(children);
201
 
    else
202
 
        return QVariant();
 
158
        object_properties["Children"] = PackProperty(children);
 
159
 
 
160
    return object_properties;
203
161
}
204
162
 
205
 
QVariant GetGlobalRect(QObject* obj)
 
163
 
 
164
void AddCustomProperties(QObject* obj, QVariantMap &properties)
206
165
{
207
166
    // Add any custom properties we need to the given QObject.
208
167
    // Add GlobalRect support for QWidget-derived classes
211
170
    {
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);
215
174
    }
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);
229
188
    }
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))
233
192
    {
234
193
        QQuickWindow *view = i->window();
235
 
        if(view)
236
 
        {
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()
241
 
                );
242
 
 
243
 
            return PackProperty(global_rect);
244
 
        }
 
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);
245
198
    }
246
199
#endif
247
 
 
248
 
    // Default to returning invalid QVariant
249
 
    return QVariant();
250
200
}
251
201
 
252
202
QVariant PackProperty(QVariant const& prop)