Update AMB with amb-qt(qml) plugins to latest
[AGL/meta-agl.git] / meta-ivi-common / recipes-automotive / automotive-message-broker / automotive-message-broker / 0008-Add-simple-Qt-QML-example.patch
1 From 7c452ae1228b01a3db697b5a74c9dee60dcfe352 Mon Sep 17 00:00:00 2001
2 From: Petr Nechaev <petr.nechaev@cogentembedded.com>
3 Date: Mon, 3 Aug 2015 14:17:40 +0300
4 Subject: [PATCH 8/9] Add simple Qt-QML example
5
6 The example requires qtdeclarative. It outputs values of basic vehicle
7 properties.
8 ---
9  plugins/dbus/amb-qt/CMakeLists.txt  |  6 +++++
10  plugins/dbus/amb-qt/Meter.qml       | 46 +++++++++++++++++++++++++++++++++++++
11  plugins/dbus/amb-qt/qtquicktest.cpp | 12 ++++++++++
12  plugins/dbus/amb-qt/qtquicktest.qml | 35 ++++++++++++++++++++++++++++
13  plugins/dbus/amb-qt/qtquicktest.qrc |  6 +++++
14  5 files changed, 105 insertions(+)
15  create mode 100644 plugins/dbus/amb-qt/Meter.qml
16  create mode 100644 plugins/dbus/amb-qt/qtquicktest.cpp
17  create mode 100644 plugins/dbus/amb-qt/qtquicktest.qml
18  create mode 100644 plugins/dbus/amb-qt/qtquicktest.qrc
19
20 diff --git a/plugins/dbus/amb-qt/CMakeLists.txt b/plugins/dbus/amb-qt/CMakeLists.txt
21 index 42b7fb4..99f691b 100644
22 --- a/plugins/dbus/amb-qt/CMakeLists.txt
23 +++ b/plugins/dbus/amb-qt/CMakeLists.txt
24 @@ -31,10 +31,16 @@ target_link_libraries(ambqtquick amb-qt ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY
25  add_executable(ambtestclient test.cpp)
26  target_link_libraries(ambtestclient amb amb-qt ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
27  
28 +qt5_add_resources(ambqtquicktest_RESOURCES qtquicktest.qrc)
29 +add_executable(ambqtquicktest qtquicktest.cpp ${ambqtquicktest_RESOURCES})
30 +target_link_libraries(ambqtquicktest amb amb-qt ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
31 +qt5_use_modules(ambqtquicktest Quick Core)
32 +
33  install (TARGETS amb-qt LIBRARY DESTINATION lib${LIB_SUFFIX})
34  
35  install (FILES ${ambqt_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/ COMPONENT Devel)
36  install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION ${LIB_INSTALL_DIR}/qt5/qml/amb COMPONENT Devel)
37  install (TARGETS ambqtquick DESTINATION ${LIB_INSTALL_DIR}/qt5/qml/amb)
38  install (TARGETS ambtestclient RUNTIME DESTINATION bin)
39 +install (TARGETS ambqtquicktest RUNTIME DESTINATION bin)
40  endif(qt_bindings)
41 diff --git a/plugins/dbus/amb-qt/Meter.qml b/plugins/dbus/amb-qt/Meter.qml
42 new file mode 100644
43 index 0000000..370e4da
44 --- /dev/null
45 +++ b/plugins/dbus/amb-qt/Meter.qml
46 @@ -0,0 +1,46 @@
47 +/*
48 +Copyright (C) 2015 Cogent Embedded Inc.
49 +
50 +This library is free software; you can redistribute it and/or
51 +modify it under the terms of the GNU Lesser General Public
52 +License as published by the Free Software Foundation; either
53 +version 2.1 of the License, or (at your option) any later version.
54 +
55 +This library is distributed in the hope that it will be useful,
56 +but WITHOUT ANY WARRANTY; without even the implied warranty of
57 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58 +Lesser General Public License for more details.
59 +
60 +You should have received a copy of the GNU Lesser General Public
61 +License along with this library; if not, write to the Free Software
62 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
63 +*/
64 +import QtQuick 2.0
65 +import amb 0.1
66 +
67 +Row {
68 +
69 +    property string name
70 +    onNameChanged: {
71 +        // we use objectName.propertyName format
72 +        var parts = name.split(".");
73 +        prop.objectName = parts[0];
74 +        prop.propertyName = parts.length >= 2 ? parts[1] : "Value";
75 +        prop.connect();
76 +    }
77 +
78 +    spacing: 10
79 +    Text {
80 +        text: parent.name
81 +        font.pointSize: 14
82 +        width: 300 // this is a guess
83 +    }
84 +    Text {
85 +        text: qsTr("%1").arg(prop.value)
86 +        font.pointSize: 14
87 +    }
88 +
89 +    AutomotivePropertyItem {
90 +        id: prop
91 +    }
92 +}
93 diff --git a/plugins/dbus/amb-qt/qtquicktest.cpp b/plugins/dbus/amb-qt/qtquicktest.cpp
94 new file mode 100644
95 index 0000000..4735d57
96 --- /dev/null
97 +++ b/plugins/dbus/amb-qt/qtquicktest.cpp
98 @@ -0,0 +1,12 @@
99 +#include <QGuiApplication>
100 +#include <QQmlApplicationEngine>
101 +
102 +int main(int argc, char *argv[])
103 +{
104 +       QGuiApplication app(argc, argv);
105 +
106 +       QQmlApplicationEngine engine;
107 +       engine.load(QUrl(QStringLiteral("qrc:/qtquicktest.qml")));
108 +
109 +       return app.exec();
110 +}
111 diff --git a/plugins/dbus/amb-qt/qtquicktest.qml b/plugins/dbus/amb-qt/qtquicktest.qml
112 new file mode 100644
113 index 0000000..70cd846
114 --- /dev/null
115 +++ b/plugins/dbus/amb-qt/qtquicktest.qml
116 @@ -0,0 +1,35 @@
117 +/*
118 +Copyright (C) 2015 Cogent Embedded Inc.
119 +
120 +This library is free software; you can redistribute it and/or
121 +modify it under the terms of the GNU Lesser General Public
122 +License as published by the Free Software Foundation; either
123 +version 2.1 of the License, or (at your option) any later version.
124 +
125 +This library is distributed in the hope that it will be useful,
126 +but WITHOUT ANY WARRANTY; without even the implied warranty of
127 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
128 +Lesser General Public License for more details.
129 +
130 +You should have received a copy of the GNU Lesser General Public
131 +License along with this library; if not, write to the Free Software
132 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
133 +*/
134 +import QtQuick 2.0
135 +import QtQuick.Window 2.0
136 +
137 +Window {
138 +    visible: true
139 +    width: 500
140 +    height: 400
141 +
142 +    Column {
143 +        anchors.fill: parent;
144 +
145 +        Meter { name: "VehicleSpeed.Speed"}
146 +        Meter { name: "EngineSpeed.Speed"}
147 +        Meter { name: "SteeringWheel.Angle"}
148 +        Meter { name: "ThrottlePosition.Value"}
149 +        Meter { name: "BrakeOperation.BrakePressure"}
150 +    }
151 +}
152 diff --git a/plugins/dbus/amb-qt/qtquicktest.qrc b/plugins/dbus/amb-qt/qtquicktest.qrc
153 new file mode 100644
154 index 0000000..998ec70
155 --- /dev/null
156 +++ b/plugins/dbus/amb-qt/qtquicktest.qrc
157 @@ -0,0 +1,6 @@
158 +<RCC>
159 +    <qresource prefix="/">
160 +        <file>qtquicktest.qml</file>
161 +        <file>Meter.qml</file>
162 +    </qresource>
163 +</RCC>
164 -- 
165 1.9.1
166