~ubuntu-branches/ubuntu/trusty/autopilot-qt/trusty

« back to all changes in this revision

Viewing changes to driver/qtnode.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Thomi Richards, Timo Jyrinki, Christopher Lee
  • Date: 2014-03-03 04:42:27 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140303044227-opwfn6gohcxgy78a
Tags: 1.4+14.04.20140303-0ubuntu1
[ Thomi Richards ]
* Export QObject children of Qml items. (LP: #1269578)

[ Timo Jyrinki ]
* Fix tab/space whitespace in debian/control.

[ Christopher Lee ]
* Backing out recent change that introduces issues on devices.
* Re-implement (w/ fixes) exporting QObject children of Qml items
  (including non-visual items). (LP: #1269578)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <QDBusArgument>
19
19
 
20
20
// Marshall the NodeIntrospectionData data into a D-Bus argument
21
 
 QDBusArgument &operator<<(QDBusArgument &argument, const NodeIntrospectionData &node_data)
22
 
 {
23
 
     argument.beginStructure();
24
 
     argument << node_data.object_path << node_data.state;
25
 
     argument.endStructure();
26
 
     return argument;
27
 
 }
 
21
QDBusArgument &operator<<(QDBusArgument &argument, const NodeIntrospectionData &node_data)
 
22
{
 
23
    argument.beginStructure();
 
24
    argument << node_data.object_path << node_data.state;
 
25
    argument.endStructure();
 
26
    return argument;
 
27
}
28
28
 
29
 
 // Retrieve the NodeIntrospectionData data from the D-Bus argument
30
 
 const QDBusArgument &operator>>(const QDBusArgument &argument, NodeIntrospectionData &node_data)
31
 
 {
32
 
     argument.beginStructure();
33
 
     argument >> node_data.object_path >> node_data.state;
34
 
     argument.endStructure();
35
 
     return argument;
36
 
 }
 
29
// Retrieve the NodeIntrospectionData data from the D-Bus argument
 
30
const QDBusArgument &operator>>(const QDBusArgument &argument, NodeIntrospectionData &node_data)
 
31
{
 
32
    argument.beginStructure();
 
33
    argument >> node_data.object_path >> node_data.state;
 
34
    argument.endStructure();
 
35
    return argument;
 
36
}
37
37
 
38
38
const QByteArray AP_ID_NAME("_autopilot_id");
39
39
 
41
41
: object_(obj)
42
42
, parent_(parent)
43
43
{
 
44
    SetName(obj);
44
45
    std::string parent_path = parent ? parent->GetPath() : "";
45
46
    full_path_ = parent_path + "/" + GetName();
46
47
}
48
49
QtNode::QtNode(QObject* obj)
49
50
: object_(obj)
50
51
{
 
52
    SetName(obj);
51
53
    full_path_ = "/" + GetName();
52
54
}
53
55
 
65
67
    return data;
66
68
}
67
69
 
68
 
std::string QtNode::GetName() const
 
70
void QtNode::SetName(const QObject* object)
69
71
{
70
 
    QString name = object_->metaObject()->className();
71
 
 
 
72
    QString name = object->metaObject()->className();
72
73
    // QML type names get mangled by Qt - they get _QML_N or _QMLTYPE_N appended.
73
 
    //
74
74
    if (name.contains('_'))
75
75
        name = name.split('_').front();
76
 
    return name.toStdString();
 
76
    node_name_ = name.toStdString();
 
77
}
 
78
 
 
79
std::string QtNode::GetName() const
 
80
{
 
81
    return node_name_;
77
82
}
78
83
 
79
84
std::string QtNode::GetPath() const
99
104
 
100
105
bool QtNode::MatchStringProperty(const std::string& name, const std::string& value) const
101
106
{
102
 
    QVariantMap properties = GetNodeProperties(object_);
 
107
    QVariant property = GetNodeProperty(object_, name);
103
108
 
104
 
    QString qname = QString::fromStdString(name);
105
 
    if (! properties.contains(qname))
 
109
    if(!property.isValid())
106
110
        return false;
107
111
 
108
 
    QVariant object_value = qvariant_cast<QVariantList>(properties[qname]).at(1);
 
112
    // Need the value not the object type id
 
113
    QVariant object_value = qvariant_cast<QVariantList>(property).at(1);
109
114
    QVariant check_value(QString::fromStdString(value));
110
115
    if (check_value.canConvert(object_value.type()))
111
116
    {
121
126
    if (name == "id")
122
127
        return value == GetId();
123
128
 
124
 
    QVariantMap properties = GetNodeProperties(object_);
 
129
    QVariant property = GetNodeProperty(object_, name);
125
130
 
126
 
    QString qname = QString::fromStdString(name);
127
 
    if (! properties.contains(qname))
 
131
    if(!property.isValid())
128
132
        return false;
129
133
 
130
 
    QVariant object_value = qvariant_cast<QVariantList>(properties[qname]).at(1);
 
134
    // Need the value not the object type id
 
135
    QVariant object_value = qvariant_cast<QVariantList>(property).at(1);
131
136
    QVariant check_value(value);
132
137
    if (check_value.canConvert(object_value.type()))
133
138
    {
140
145
 
141
146
bool QtNode::MatchBooleanProperty(const std::string& name, bool value) const
142
147
{
143
 
    QVariantMap properties = GetNodeProperties(object_);
 
148
    QVariant property = GetNodeProperty(object_, name);
144
149
 
145
 
    QString qname = QString::fromStdString(name);
146
 
    if (! properties.contains(qname))
 
150
    if(!property.isValid())
147
151
        return false;
148
152
 
149
 
    QVariant object_value = qvariant_cast<QVariantList>(properties[qname]).at(1);
 
153
    // Need the value not the object type id
 
154
    QVariant object_value = qvariant_cast<QVariantList>(property).at(1);
150
155
    QVariant check_value(value);
151
156
 
152
157
    if (check_value.canConvert(object_value.type()))