Merge lp:~kalikiana/dee-qt/deevarianttext into lp:dee-qt/0.2
- deevarianttext
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~kalikiana/dee-qt/deevarianttext |
Merge into: | lp:dee-qt/0.2 |
Prerequisite: | lp:~saviq/dee-qt/rename-libs |
Diff against target: |
995 lines (+586/-58) 18 files modified
.bzrignore (+15/-2) CMakeLists.txt (+9/-2) deelistmodel.cpp (+55/-22) deelistmodel.h (+7/-2) deeprivate.h (+23/-0) deevarianttext.cpp (+72/-0) deevarianttext.h (+49/-0) modules/Dee/CMakeLists.txt (+3/-1) modules/Dee/plugin.cpp (+2/-0) tests/CMakeLists.txt (+29/-1) tests/conversiontest.cpp (+1/-0) tests/deelistmodeltest.cpp (+40/-2) tests/deevarianttexttest.cpp (+58/-0) tests/qtquick1plugintest.cpp (+48/-0) tests/test_qtquick1.qml (+36/-11) tests/test_qtquick2.qml (+0/-15) tests/tst_deelistmodel.qml (+79/-0) tests/tst_deevarianttext.qml (+60/-0) |
To merge this branch: | bzr merge lp:~kalikiana/dee-qt/deevarianttext |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Sawicz | Needs Fixing | ||
Review via email: mp+137980@code.launchpad.net |
This proposal supersedes a proposal from 2012-12-04.
This proposal has been superseded by a proposal from 2013-03-14.
Commit message
Description of the change
- 98. By Cris Dywan
-
Fix running deevarianttexttest
- 99. By Cris Dywan
-
Add insertRemoveTest (needs improvement)
- 100. By Cris Dywan
-
Fixup insertRemoveTest
- 101. By Cris Dywan
-
Use QSignalSpy instead of manual callbacks to verify signals
- 102. By Cris Dywan
-
Expose append/ remove to QML to allow hosting new models
For now only in test models and no API to set the schema.
- 103. By Cris Dywan
-
Emit layoutChanged in addition to countChanged
- 104. By Cris Dywan
-
Use SignalSpy in QML - preliminary text delegate testing
- 105. By Cris Dywan
-
Use QT_INSTALL_QML (QtQuick2) instead of QT_INSTALL_IMPORTS (QtQuick1)
See http://
doc-snapshot. qt-project. org/5.0/ qtcore/ qlibraryinfo. html#LibraryLoc ation-enum - 106. By Cris Dywan
-
Drop delegate test, the approach is wrong
- 107. By Cris Dywan
-
Drop remaining pieces of delegate approach as well
Unmerged revisions
- 107. By Cris Dywan
-
Drop remaining pieces of delegate approach as well
- 106. By Cris Dywan
-
Drop delegate test, the approach is wrong
- 105. By Cris Dywan
-
Use QT_INSTALL_QML (QtQuick2) instead of QT_INSTALL_IMPORTS (QtQuick1)
See http://
doc-snapshot. qt-project. org/5.0/ qtcore/ qlibraryinfo. html#LibraryLoc ation-enum - 104. By Cris Dywan
-
Use SignalSpy in QML - preliminary text delegate testing
- 103. By Cris Dywan
-
Emit layoutChanged in addition to countChanged
- 102. By Cris Dywan
-
Expose append/ remove to QML to allow hosting new models
For now only in test models and no API to set the schema.
- 101. By Cris Dywan
-
Use QSignalSpy instead of manual callbacks to verify signals
- 100. By Cris Dywan
-
Fixup insertRemoveTest
- 99. By Cris Dywan
-
Add insertRemoveTest (needs improvement)
- 98. By Cris Dywan
-
Fix running deevarianttexttest
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2013-03-08 16:59:19 +0000 | |||
3 | +++ .bzrignore 2013-03-08 16:59:20 +0000 | |||
4 | @@ -2,7 +2,20 @@ | |||
5 | 2 | CMakeFiles | 2 | CMakeFiles |
6 | 3 | Makefile | 3 | Makefile |
7 | 4 | cmake_install.cmake | 4 | cmake_install.cmake |
8 | 5 | install_manifest.txt | ||
9 | 5 | libdee-qt.so* | 6 | libdee-qt.so* |
10 | 6 | libdee-qt5.so* | 7 | libdee-qt5.so* |
13 | 7 | moc_*.cxx | 8 | libQtDee.so* |
14 | 8 | install_manifest.txt | 9 | moc_*.cpp |
15 | 10 | *.moc | ||
16 | 11 | *_automoc.cpp | ||
17 | 12 | *.pc | ||
18 | 13 | CTestTestfile.cmake | ||
19 | 14 | *Test.log | ||
20 | 15 | Testing | ||
21 | 16 | conversiontest | ||
22 | 17 | deelistmodeltest | ||
23 | 18 | deevarianttexttest | ||
24 | 19 | plugintest | ||
25 | 20 | test-helper | ||
26 | 21 | *-xunit.xml | ||
27 | 9 | 22 | ||
28 | === modified file 'CMakeLists.txt' | |||
29 | --- CMakeLists.txt 2013-03-08 16:59:19 +0000 | |||
30 | +++ CMakeLists.txt 2013-03-08 16:59:20 +0000 | |||
31 | @@ -18,7 +18,7 @@ | |||
32 | 18 | set(OUR_QT_INCLUDES ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) | 18 | set(OUR_QT_INCLUDES ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) |
33 | 19 | set(OUR_QT_CORE_LIB ${Qt5Core_LIBRARIES}) | 19 | set(OUR_QT_CORE_LIB ${Qt5Core_LIBRARIES}) |
34 | 20 | set(OUR_QT_DBUS_LIB ${Qt5DBus_LIBRARIES}) | 20 | set(OUR_QT_DBUS_LIB ${Qt5DBus_LIBRARIES}) |
36 | 21 | set(QT_PKGCONFIG_DEPENDENCIES "QtCore") | 21 | set(QT_PKGCONFIG_DEPENDENCIES "QtCore QtQuick") |
37 | 22 | else () | 22 | else () |
38 | 23 | message("Building Qt4 version") | 23 | message("Building Qt4 version") |
39 | 24 | 24 | ||
40 | @@ -43,6 +43,12 @@ | |||
41 | 43 | # Sources | 43 | # Sources |
42 | 44 | set(DEE_QT_SRCS | 44 | set(DEE_QT_SRCS |
43 | 45 | deelistmodel.cpp | 45 | deelistmodel.cpp |
44 | 46 | deevarianttext.cpp | ||
45 | 47 | ) | ||
46 | 48 | |||
47 | 49 | ## QtDeeQml | ||
48 | 50 | set(QtDeeQml_SRCS | ||
49 | 51 | plugin.cpp | ||
50 | 46 | ) | 52 | ) |
51 | 47 | 53 | ||
52 | 48 | # Build | 54 | # Build |
53 | @@ -69,6 +75,7 @@ | |||
54 | 69 | # Unit-Test | 75 | # Unit-Test |
55 | 70 | enable_testing() | 76 | enable_testing() |
56 | 71 | 77 | ||
57 | 78 | add_custom_target(check COMMAND "env" "CTEST_OUTPUT_ON_FAILURE=1" "${CMAKE_CTEST_COMMAND}") | ||
58 | 72 | add_subdirectory(modules) | 79 | add_subdirectory(modules) |
59 | 73 | add_subdirectory(tests) | 80 | add_subdirectory(tests) |
60 | 74 | 81 | ||
61 | @@ -79,7 +86,7 @@ | |||
62 | 79 | LIBRARY DESTINATION lib${LIB_SUFFIX} | 86 | LIBRARY DESTINATION lib${LIB_SUFFIX} |
63 | 80 | ) | 87 | ) |
64 | 81 | 88 | ||
66 | 82 | install(FILES deelistmodel.h | 89 | install(FILES deelistmodel.h deevarianttext.h |
67 | 83 | DESTINATION ${INCLUDE_INSTALL_DIR} | 90 | DESTINATION ${INCLUDE_INSTALL_DIR} |
68 | 84 | ) | 91 | ) |
69 | 85 | 92 | ||
70 | 86 | 93 | ||
71 | === modified file 'deelistmodel.cpp' | |||
72 | --- deelistmodel.cpp 2012-11-21 10:30:50 +0000 | |||
73 | +++ deelistmodel.cpp 2013-03-08 16:59:20 +0000 | |||
74 | @@ -17,17 +17,20 @@ | |||
75 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
76 | 18 | */ | 18 | */ |
77 | 19 | 19 | ||
78 | 20 | #include <QCoreApplication> | ||
79 | 20 | #include <QtCore/QHash> | 21 | #include <QtCore/QHash> |
80 | 21 | #include <QtCore/QByteArray> | 22 | #include <QtCore/QByteArray> |
81 | 23 | #include <QDebug> | ||
82 | 22 | 24 | ||
83 | 23 | #include <dee.h> | 25 | #include <dee.h> |
84 | 24 | #include <glib-object.h> | ||
85 | 25 | 26 | ||
86 | 26 | #include "deelistmodel.h" | 27 | #include "deelistmodel.h" |
87 | 28 | #include "deeprivate.h" | ||
88 | 27 | 29 | ||
90 | 28 | static QVariant | 30 | QVariant |
91 | 29 | QVariantFromGVariant(GVariant *value) | 31 | QVariantFromGVariant(GVariant *value) |
92 | 30 | { | 32 | { |
93 | 33 | Q_ASSERT(value); | ||
94 | 31 | switch (g_variant_classify(value)) { | 34 | switch (g_variant_classify(value)) { |
95 | 32 | case G_VARIANT_CLASS_BOOLEAN: | 35 | case G_VARIANT_CLASS_BOOLEAN: |
96 | 33 | return QVariant((bool) g_variant_get_boolean(value)); | 36 | return QVariant((bool) g_variant_get_boolean(value)); |
97 | @@ -62,13 +65,14 @@ | |||
98 | 62 | } | 65 | } |
99 | 63 | return array; | 66 | return array; |
100 | 64 | } | 67 | } |
101 | 68 | case G_VARIANT_CLASS_VARIANT: | ||
102 | 69 | return QVariant(QVariantFromGVariant(g_variant_get_variant(value))); | ||
103 | 65 | default: | 70 | default: |
104 | 66 | /* Fallback on an empty QVariant. | 71 | /* Fallback on an empty QVariant. |
105 | 67 | FIXME: Missing conversion of following GVariant types: | 72 | FIXME: Missing conversion of following GVariant types: |
106 | 68 | - G_VARIANT_CLASS_HANDLE | 73 | - G_VARIANT_CLASS_HANDLE |
107 | 69 | - G_VARIANT_CLASS_OBJECT_PATH | 74 | - G_VARIANT_CLASS_OBJECT_PATH |
108 | 70 | - G_VARIANT_CLASS_SIGNATURE | 75 | - G_VARIANT_CLASS_SIGNATURE |
109 | 71 | - G_VARIANT_CLASS_VARIANT | ||
110 | 72 | - G_VARIANT_CLASS_MAYBE | 76 | - G_VARIANT_CLASS_MAYBE |
111 | 73 | - G_VARIANT_CLASS_DICT_ENTRY | 77 | - G_VARIANT_CLASS_DICT_ENTRY |
112 | 74 | */ | 78 | */ |
113 | @@ -84,7 +88,6 @@ | |||
114 | 84 | void connectToDeeModel(); | 88 | void connectToDeeModel(); |
115 | 85 | void connectToDeeModel(DeeModel *model); | 89 | void connectToDeeModel(DeeModel *model); |
116 | 86 | void disconnectFromDeeModel(); | 90 | void disconnectFromDeeModel(); |
117 | 87 | void createRoles(); | ||
118 | 88 | bool synchronized() const; | 91 | bool synchronized() const; |
119 | 89 | 92 | ||
120 | 90 | /* GObject signal handlers for m_deeModel */ | 93 | /* GObject signal handlers for m_deeModel */ |
121 | @@ -132,16 +135,27 @@ | |||
122 | 132 | if (!m_name.isEmpty()) | 135 | if (!m_name.isEmpty()) |
123 | 133 | { | 136 | { |
124 | 134 | m_deeModel = dee_shared_model_new(m_name.toUtf8().data()); | 137 | m_deeModel = dee_shared_model_new(m_name.toUtf8().data()); |
125 | 138 | // FIXME expose property to set schema in QML | ||
126 | 139 | bool ownSchema = m_name.contains(".test"); | ||
127 | 140 | if (ownSchema) | ||
128 | 141 | dee_model_set_schema(m_deeModel, "b", NULL); | ||
129 | 135 | g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent); | 142 | g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent); |
130 | 136 | g_signal_connect(m_deeModel, "row-added", G_CALLBACK(onRowAdded), m_parent); | 143 | g_signal_connect(m_deeModel, "row-added", G_CALLBACK(onRowAdded), m_parent); |
131 | 137 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); | 144 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); |
132 | 138 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); | 145 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); |
133 | 146 | if (ownSchema) | ||
134 | 147 | { | ||
135 | 148 | // Doc says we need to be synchronized before doing anything | ||
136 | 149 | while(!dee_shared_model_is_synchronized(DEE_SHARED_MODEL(m_deeModel))) | ||
137 | 150 | qApp->processEvents(); | ||
138 | 151 | } | ||
139 | 139 | } | 152 | } |
140 | 140 | } | 153 | } |
141 | 141 | 154 | ||
142 | 142 | void | 155 | void |
143 | 143 | DeeListModelPrivate::connectToDeeModel(DeeModel *model) | 156 | DeeListModelPrivate::connectToDeeModel(DeeModel *model) |
144 | 144 | { | 157 | { |
145 | 158 | m_parent->beginResetModel(); | ||
146 | 145 | disconnectFromDeeModel(); | 159 | disconnectFromDeeModel(); |
147 | 146 | 160 | ||
148 | 147 | m_deeModel = (DeeModel*)g_object_ref (model); | 161 | m_deeModel = (DeeModel*)g_object_ref (model); |
149 | @@ -150,15 +164,15 @@ | |||
150 | 150 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); | 164 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); |
151 | 151 | if (synchronized()) | 165 | if (synchronized()) |
152 | 152 | { | 166 | { |
153 | 153 | createRoles(); | ||
154 | 154 | m_count = dee_model_get_n_rows(m_deeModel); | 167 | m_count = dee_model_get_n_rows(m_deeModel); |
155 | 155 | m_parent->reset(); | ||
156 | 156 | Q_EMIT m_parent->countChanged(); | 168 | Q_EMIT m_parent->countChanged(); |
157 | 169 | Q_EMIT m_parent->layoutChanged(); | ||
158 | 157 | } | 170 | } |
159 | 158 | else | 171 | else |
160 | 159 | { | 172 | { |
161 | 160 | g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent); | 173 | g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent); |
162 | 161 | } | 174 | } |
163 | 175 | m_parent->endResetModel(); | ||
164 | 162 | } | 176 | } |
165 | 163 | 177 | ||
166 | 164 | bool | 178 | bool |
167 | @@ -175,25 +189,43 @@ | |||
168 | 175 | } | 189 | } |
169 | 176 | } | 190 | } |
170 | 177 | 191 | ||
173 | 178 | void | 192 | QHash<int, QByteArray> |
174 | 179 | DeeListModelPrivate::createRoles() | 193 | DeeListModel::roleNames() |
175 | 180 | { | 194 | { |
176 | 181 | if (m_deeModel == NULL) { | ||
177 | 182 | return; | ||
178 | 183 | } | ||
179 | 184 | |||
180 | 185 | QHash<int, QByteArray> roles; | 195 | QHash<int, QByteArray> roles; |
181 | 196 | |||
182 | 197 | qDebug() << "m_deeModel" << d->m_deeModel; | ||
183 | 198 | if (d->m_deeModel == NULL) { | ||
184 | 199 | return roles; | ||
185 | 200 | } | ||
186 | 201 | |||
187 | 186 | QString column; | 202 | QString column; |
189 | 187 | guint n_columns = dee_model_get_n_columns(m_deeModel); | 203 | guint n_columns = dee_model_get_n_columns(d->m_deeModel); |
190 | 188 | 204 | ||
191 | 189 | for (unsigned int index=0; index<n_columns; index++) | 205 | for (unsigned int index=0; index<n_columns; index++) |
192 | 190 | { | 206 | { |
193 | 191 | column = QString("column_%1").arg(index); | 207 | column = QString("column_%1").arg(index); |
199 | 192 | roles[index] = column.toAscii(); | 208 | roles[index] = column.toUtf8(); |
200 | 193 | } | 209 | } |
201 | 194 | 210 | return roles; | |
202 | 195 | m_parent->setRoleNames(roles); | 211 | } |
203 | 196 | Q_EMIT m_parent->roleNamesChanged(roles); | 212 | |
204 | 213 | void DeeListModel::append(const QString & data) | ||
205 | 214 | { | ||
206 | 215 | GVariant* gvariant = g_variant_parse(NULL, "false", NULL, NULL, NULL); | ||
207 | 216 | if (!gvariant) | ||
208 | 217 | { | ||
209 | 218 | qDebug() << "Failed to append " << data << " (invalid) to model"; | ||
210 | 219 | return; | ||
211 | 220 | } | ||
212 | 221 | DeeModelIter* iter = dee_model_insert (d->m_deeModel, 0, &gvariant); | ||
213 | 222 | g_variant_unref(gvariant); | ||
214 | 223 | } | ||
215 | 224 | |||
216 | 225 | void DeeListModel::remove(int index) | ||
217 | 226 | { | ||
218 | 227 | DeeModelIter* iter = dee_model_get_iter_at_row (d->m_deeModel, index); | ||
219 | 228 | dee_model_remove(d->m_deeModel, iter); | ||
220 | 197 | } | 229 | } |
221 | 198 | 230 | ||
222 | 199 | void | 231 | void |
223 | @@ -201,11 +233,12 @@ | |||
224 | 201 | GParamSpec *pspec, | 233 | GParamSpec *pspec, |
225 | 202 | DeeListModel *model) | 234 | DeeListModel *model) |
226 | 203 | { | 235 | { |
228 | 204 | model->d->createRoles(); | 236 | model->beginResetModel(); |
229 | 205 | model->d->m_count = dee_model_get_n_rows(model->d->m_deeModel); | 237 | model->d->m_count = dee_model_get_n_rows(model->d->m_deeModel); |
230 | 206 | model->synchronizedChanged(model->synchronized()); | 238 | model->synchronizedChanged(model->synchronized()); |
231 | 207 | model->reset(); | ||
232 | 208 | Q_EMIT model->countChanged(); | 239 | Q_EMIT model->countChanged(); |
233 | 240 | Q_EMIT model->layoutChanged(); | ||
234 | 241 | model->endResetModel(); | ||
235 | 209 | } | 242 | } |
236 | 210 | 243 | ||
237 | 211 | void | 244 | void |
238 | @@ -228,6 +261,7 @@ | |||
239 | 228 | model->beginInsertRows(QModelIndex(), position, position); | 261 | model->beginInsertRows(QModelIndex(), position, position); |
240 | 229 | model->endInsertRows(); | 262 | model->endInsertRows(); |
241 | 230 | Q_EMIT model->countChanged(); | 263 | Q_EMIT model->countChanged(); |
242 | 264 | Q_EMIT model->layoutChanged(); | ||
243 | 231 | } | 265 | } |
244 | 232 | 266 | ||
245 | 233 | void | 267 | void |
246 | @@ -255,6 +289,7 @@ | |||
247 | 255 | model->beginRemoveRows(QModelIndex(), position, position); | 289 | model->beginRemoveRows(QModelIndex(), position, position); |
248 | 256 | model->endRemoveRows(); | 290 | model->endRemoveRows(); |
249 | 257 | Q_EMIT model->countChanged(); | 291 | Q_EMIT model->countChanged(); |
250 | 292 | Q_EMIT model->layoutChanged(); | ||
251 | 258 | } | 293 | } |
252 | 259 | 294 | ||
253 | 260 | void | 295 | void |
254 | @@ -271,8 +306,6 @@ | |||
255 | 271 | Q_EMIT model->dataChanged(index, index); | 306 | Q_EMIT model->dataChanged(index, index); |
256 | 272 | } | 307 | } |
257 | 273 | 308 | ||
258 | 274 | |||
259 | 275 | |||
260 | 276 | DeeListModel::DeeListModel(QObject *parent) : | 309 | DeeListModel::DeeListModel(QObject *parent) : |
261 | 277 | QAbstractListModel(parent), d(new DeeListModelPrivate(this)) | 310 | QAbstractListModel(parent), d(new DeeListModelPrivate(this)) |
262 | 278 | { | 311 | { |
263 | 279 | 312 | ||
264 | === modified file 'deelistmodel.h' | |||
265 | --- deelistmodel.h 2012-01-31 17:49:00 +0000 | |||
266 | +++ deelistmodel.h 2013-03-08 16:59:20 +0000 | |||
267 | @@ -20,11 +20,12 @@ | |||
268 | 20 | #ifndef DEELISTMODEL_H | 20 | #ifndef DEELISTMODEL_H |
269 | 21 | #define DEELISTMODEL_H | 21 | #define DEELISTMODEL_H |
270 | 22 | 22 | ||
271 | 23 | #include <QtCore/QObject> | ||
272 | 23 | #include <QtCore/QAbstractListModel> | 24 | #include <QtCore/QAbstractListModel> |
273 | 24 | 25 | ||
274 | 25 | class DeeListModelPrivate; | 26 | class DeeListModelPrivate; |
275 | 26 | typedef struct _DeeModel DeeModel; | 27 | typedef struct _DeeModel DeeModel; |
277 | 27 | class __attribute__ ((visibility ("default"))) DeeListModel : public QAbstractListModel | 28 | class Q_DECL_EXPORT DeeListModel : public QAbstractListModel |
278 | 28 | { | 29 | { |
279 | 29 | friend class DeeListModelPrivate; | 30 | friend class DeeListModelPrivate; |
280 | 30 | 31 | ||
281 | @@ -45,6 +46,10 @@ | |||
282 | 45 | QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; | 46 | QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; |
283 | 46 | int rowCount(const QModelIndex & parent = QModelIndex()) const; | 47 | int rowCount(const QModelIndex & parent = QModelIndex()) const; |
284 | 47 | 48 | ||
285 | 49 | /* Modification of the model */ | ||
286 | 50 | Q_INVOKABLE void append(const QString & data); | ||
287 | 51 | Q_INVOKABLE void remove(int index); | ||
288 | 52 | |||
289 | 48 | /* getters */ | 53 | /* getters */ |
290 | 49 | QString name() const; | 54 | QString name() const; |
291 | 50 | bool synchronized() const; | 55 | bool synchronized() const; |
292 | @@ -52,11 +57,11 @@ | |||
293 | 52 | /* setters */ | 57 | /* setters */ |
294 | 53 | void setName(const QString& name); | 58 | void setName(const QString& name); |
295 | 54 | void setModel(DeeModel* model); | 59 | void setModel(DeeModel* model); |
296 | 60 | QHash<int, QByteArray> roleNames(); | ||
297 | 55 | 61 | ||
298 | 56 | Q_SIGNALS: | 62 | Q_SIGNALS: |
299 | 57 | void nameChanged(const QString&); | 63 | void nameChanged(const QString&); |
300 | 58 | void synchronizedChanged(bool); | 64 | void synchronizedChanged(bool); |
301 | 59 | void roleNamesChanged(const QHash<int,QByteArray> &); | ||
302 | 60 | void countChanged(); | 65 | void countChanged(); |
303 | 61 | 66 | ||
304 | 62 | private: | 67 | private: |
305 | 63 | 68 | ||
306 | === added file 'deeprivate.h' | |||
307 | --- deeprivate.h 1970-01-01 00:00:00 +0000 | |||
308 | +++ deeprivate.h 2013-03-08 16:59:20 +0000 | |||
309 | @@ -0,0 +1,23 @@ | |||
310 | 1 | /* | ||
311 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
312 | 3 | * | ||
313 | 4 | * Authors: | ||
314 | 5 | * Christian Dywan <christian.dywan@canonical.com> | ||
315 | 6 | * | ||
316 | 7 | * This program is free software; you can redistribute it and/or modify | ||
317 | 8 | * it under the terms of the GNU General Public License as published by | ||
318 | 9 | * the Free Software Foundation; version 3. | ||
319 | 10 | * | ||
320 | 11 | * This program is distributed in the hope that it will be useful, | ||
321 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
322 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
323 | 14 | * GNU General Public License for more details. | ||
324 | 15 | * | ||
325 | 16 | * You should have received a copy of the GNU General Public License | ||
326 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
327 | 18 | */ | ||
328 | 19 | |||
329 | 20 | #include <glib-object.h> | ||
330 | 21 | |||
331 | 22 | QVariant QVariantFromGVariant(GVariant *value); | ||
332 | 23 | |||
333 | 0 | 24 | ||
334 | === added file 'deevarianttext.cpp' | |||
335 | --- deevarianttext.cpp 1970-01-01 00:00:00 +0000 | |||
336 | +++ deevarianttext.cpp 2013-03-08 16:59:20 +0000 | |||
337 | @@ -0,0 +1,72 @@ | |||
338 | 1 | /* | ||
339 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
340 | 3 | * | ||
341 | 4 | * Authors: | ||
342 | 5 | * Christian Dywan <christian.dywan@canonical.com> | ||
343 | 6 | * | ||
344 | 7 | * This program is free software; you can redistribute it and/or modify | ||
345 | 8 | * it under the terms of the GNU General Public License as published by | ||
346 | 9 | * the Free Software Foundation; version 3. | ||
347 | 10 | * | ||
348 | 11 | * This program is distributed in the hope that it will be useful, | ||
349 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
350 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
351 | 14 | * GNU General Public License for more details. | ||
352 | 15 | * | ||
353 | 16 | * You should have received a copy of the GNU General Public License | ||
354 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
355 | 18 | */ | ||
356 | 19 | |||
357 | 20 | #include <QDebug> | ||
358 | 21 | |||
359 | 22 | #include "deevarianttext.h" | ||
360 | 23 | #include "deeprivate.h" | ||
361 | 24 | |||
362 | 25 | DeeVariantText::DeeVariantText(QObject *parent) : | ||
363 | 26 | m_text(""), | ||
364 | 27 | m_value(QVariant()), | ||
365 | 28 | m_type("") | ||
366 | 29 | { | ||
367 | 30 | } | ||
368 | 31 | |||
369 | 32 | void | ||
370 | 33 | DeeVariantText::setText(const QString& text) | ||
371 | 34 | { | ||
372 | 35 | if (m_text == text) | ||
373 | 36 | return; | ||
374 | 37 | |||
375 | 38 | m_text = text; | ||
376 | 39 | GVariant *gvariant = g_variant_parse(NULL, text.toUtf8(), NULL, NULL, NULL); | ||
377 | 40 | if (!gvariant) | ||
378 | 41 | { | ||
379 | 42 | qDebug() << "Failed to parse " << text << " to QVariant"; | ||
380 | 43 | m_value = QVariant(); | ||
381 | 44 | m_type = ""; | ||
382 | 45 | } | ||
383 | 46 | else | ||
384 | 47 | { | ||
385 | 48 | m_value = QVariantFromGVariant(gvariant); | ||
386 | 49 | m_type = g_variant_get_type_string(gvariant); | ||
387 | 50 | } | ||
388 | 51 | Q_EMIT textChanged(text); | ||
389 | 52 | Q_EMIT valueChanged(m_value); | ||
390 | 53 | } | ||
391 | 54 | |||
392 | 55 | QString | ||
393 | 56 | DeeVariantText::getText() | ||
394 | 57 | { | ||
395 | 58 | return m_text; | ||
396 | 59 | } | ||
397 | 60 | |||
398 | 61 | QVariant | ||
399 | 62 | DeeVariantText::getValue() | ||
400 | 63 | { | ||
401 | 64 | return m_value; | ||
402 | 65 | } | ||
403 | 66 | |||
404 | 67 | QVariant | ||
405 | 68 | DeeVariantText::getType() | ||
406 | 69 | { | ||
407 | 70 | return m_type; | ||
408 | 71 | } | ||
409 | 72 | |||
410 | 0 | 73 | ||
411 | === added file 'deevarianttext.h' | |||
412 | --- deevarianttext.h 1970-01-01 00:00:00 +0000 | |||
413 | +++ deevarianttext.h 2013-03-08 16:59:20 +0000 | |||
414 | @@ -0,0 +1,49 @@ | |||
415 | 1 | /* | ||
416 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
417 | 3 | * | ||
418 | 4 | * Authors: | ||
419 | 5 | * Christian Dywan <christian.dywan@canonical.com> | ||
420 | 6 | * | ||
421 | 7 | * This program is free software; you can redistribute it and/or modify | ||
422 | 8 | * it under the terms of the GNU General Public License as published by | ||
423 | 9 | * the Free Software Foundation; version 3. | ||
424 | 10 | * | ||
425 | 11 | * This program is distributed in the hope that it will be useful, | ||
426 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
427 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
428 | 14 | * GNU General Public License for more details. | ||
429 | 15 | * | ||
430 | 16 | * You should have received a copy of the GNU General Public License | ||
431 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
432 | 18 | */ | ||
433 | 19 | |||
434 | 20 | #ifndef DEEVARIANTTEXT_H | ||
435 | 21 | #define DEEVARIANTTEXT_H | ||
436 | 22 | |||
437 | 23 | #include <QtCore/QObject> | ||
438 | 24 | #include <QtCore/QVariant> | ||
439 | 25 | |||
440 | 26 | class Q_DECL_EXPORT DeeVariantText : public QObject { | ||
441 | 27 | Q_OBJECT | ||
442 | 28 | Q_PROPERTY(QString text READ getText WRITE setText NOTIFY textChanged) | ||
443 | 29 | Q_PROPERTY(QVariant value READ getValue NOTIFY valueChanged) | ||
444 | 30 | public: | ||
445 | 31 | DeeVariantText(QObject* parent = 0); | ||
446 | 32 | ~DeeVariantText() { } | ||
447 | 33 | |||
448 | 34 | QString getText(); | ||
449 | 35 | QVariant getValue(); | ||
450 | 36 | QVariant getType(); | ||
451 | 37 | void setText(const QString& text); | ||
452 | 38 | Q_SIGNALS: | ||
453 | 39 | void textChanged(const QString& text); | ||
454 | 40 | void valueChanged(const QVariant& value); | ||
455 | 41 | private: | ||
456 | 42 | Q_DISABLE_COPY(DeeVariantText) | ||
457 | 43 | QString m_text; | ||
458 | 44 | QVariant m_value; | ||
459 | 45 | QString m_type; | ||
460 | 46 | }; | ||
461 | 47 | |||
462 | 48 | #endif // DEEVARIANTTEXT_H | ||
463 | 49 | |||
464 | 0 | 50 | ||
465 | === modified file 'modules/Dee/CMakeLists.txt' | |||
466 | --- modules/Dee/CMakeLists.txt 2013-03-08 16:59:19 +0000 | |||
467 | +++ modules/Dee/CMakeLists.txt 2013-03-08 16:59:20 +0000 | |||
468 | @@ -4,7 +4,8 @@ | |||
469 | 4 | set(OUR_QT_QUICK_LIB ${Qt5Quick_LIBRARIES}) | 4 | set(OUR_QT_QUICK_LIB ${Qt5Quick_LIBRARIES}) |
470 | 5 | 5 | ||
471 | 6 | get_target_property(QMAKE_EXECUTABLE Qt5::qmake LOCATION) | 6 | get_target_property(QMAKE_EXECUTABLE Qt5::qmake LOCATION) |
473 | 7 | exec_program(${QMAKE_EXECUTABLE} ARGS "-query QT_INSTALL_IMPORTS" OUTPUT_VARIABLE QT_IMPORTS_DIR) | 7 | # See http://doc-snapshot.qt-project.org/5.0/qtcore/qlibraryinfo.html#LibraryLocation-enum |
474 | 8 | exec_program(${QMAKE_EXECUTABLE} ARGS "-query QT_INSTALL_QML" OUTPUT_VARIABLE QT_IMPORTS_DIR) | ||
475 | 8 | file(TO_CMAKE_PATH "${QT_IMPORTS_DIR}" QT_IMPORTS_DIR) | 9 | file(TO_CMAKE_PATH "${QT_IMPORTS_DIR}" QT_IMPORTS_DIR) |
476 | 9 | 10 | ||
477 | 10 | set(OUR_QT_QUICK_INCLUDE ${Qt5Quick_INCLUDE_DIRS}) | 11 | set(OUR_QT_QUICK_INCLUDE ${Qt5Quick_INCLUDE_DIRS}) |
478 | @@ -21,6 +22,7 @@ | |||
479 | 21 | ) | 22 | ) |
480 | 22 | 23 | ||
481 | 23 | add_library(DeePlugin SHARED ${DeePlugin_SRCS}) | 24 | add_library(DeePlugin SHARED ${DeePlugin_SRCS}) |
482 | 25 | add_dependencies(check DeePlugin) | ||
483 | 24 | 26 | ||
484 | 25 | target_link_libraries(DeePlugin | 27 | target_link_libraries(DeePlugin |
485 | 26 | ${DEE_QT_LIBNAME} | 28 | ${DEE_QT_LIBNAME} |
486 | 27 | 29 | ||
487 | === modified file 'modules/Dee/plugin.cpp' | |||
488 | --- modules/Dee/plugin.cpp 2013-03-08 16:59:19 +0000 | |||
489 | +++ modules/Dee/plugin.cpp 2013-03-08 16:59:20 +0000 | |||
490 | @@ -18,6 +18,7 @@ | |||
491 | 18 | */ | 18 | */ |
492 | 19 | 19 | ||
493 | 20 | #include "deelistmodel.h" | 20 | #include "deelistmodel.h" |
494 | 21 | #include "deevarianttext.h" | ||
495 | 21 | #include "plugin.h" | 22 | #include "plugin.h" |
496 | 22 | #if WITHQT5 | 23 | #if WITHQT5 |
497 | 23 | #include <qqml.h> | 24 | #include <qqml.h> |
498 | @@ -28,6 +29,7 @@ | |||
499 | 28 | void DeePlugin::registerTypes(const char *uri) | 29 | void DeePlugin::registerTypes(const char *uri) |
500 | 29 | { | 30 | { |
501 | 30 | qmlRegisterType<DeeListModel>(uri, 3, 0, "DeeListModel"); | 31 | qmlRegisterType<DeeListModel>(uri, 3, 0, "DeeListModel"); |
502 | 32 | qmlRegisterType<DeeVariantText>(uri, 3, 0, "DeeVariantText"); | ||
503 | 31 | } | 33 | } |
504 | 32 | 34 | ||
505 | 33 | #if !WITHQT5 | 35 | #if !WITHQT5 |
506 | 34 | 36 | ||
507 | === modified file 'tests/CMakeLists.txt' | |||
508 | --- tests/CMakeLists.txt 2013-03-08 16:59:19 +0000 | |||
509 | +++ tests/CMakeLists.txt 2013-03-08 16:59:20 +0000 | |||
510 | @@ -5,25 +5,53 @@ | |||
511 | 5 | else () | 5 | else () |
512 | 6 | set(OUR_QT_TEST_LIB ${QT_QTTEST_LIBRARIES}) | 6 | set(OUR_QT_TEST_LIB ${QT_QTTEST_LIBRARIES}) |
513 | 7 | set(OUR_QT_TEST_INCLUDES ${QT_QTTEST_INCLUDE_DIR}) | 7 | set(OUR_QT_TEST_INCLUDES ${QT_QTTEST_INCLUDE_DIR}) |
514 | 8 | set(OUR_QT_QUICK_LIB ${QT_QTDECLARATIVE_LIBRARIES}) | ||
515 | 9 | set(OUR_QT_QUICK_INCLUDE ${QT_QTDECLARATIVE_INCLUDE_DIR}) | ||
516 | 10 | endif () | ||
517 | 11 | |||
518 | 12 | if (WITHQT5) | ||
519 | 13 | add_test(NAME plugintest COMMAND "qmltestrunner" "-import" "../modules" "-xunitxml" "-o" "plugintest-xunit.xml" "-input" "${CMAKE_CURRENT_SOURCE_DIR}") | ||
520 | 14 | else () | ||
521 | 15 | add_executable(plugintest qtquick1plugintest.cpp) | ||
522 | 16 | target_link_libraries(plugintest ${OUR_QT_TEST_LIB} ${OUR_QT_QUICK_LIB}) | ||
523 | 17 | set_target_properties(plugintest PROPERTIES COMPILE_FLAGS -fPIC) | ||
524 | 18 | add_test(NAME plugintest WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/plugintest" "-p" "-xunitxml" "-p" "-o" "-p" "${CMAKE_CURRENT_BINARY_DIR}/plugintest-xunit.xml") | ||
525 | 19 | set_property(TEST plugintest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | ||
526 | 20 | set_property(TEST plugintest PROPERTY ENVIRONMENT "QT_GRAPHICSSYSTEM=raster") | ||
527 | 21 | set_property(TEST plugintest PROPERTY ENVIRONMENT "QML_IMPORT_PATH=${CMAKE_CURRENT_BINARY_DIR}/../modules") | ||
528 | 22 | add_dependencies(check plugintest) | ||
529 | 8 | endif () | 23 | endif () |
530 | 9 | 24 | ||
531 | 10 | include_directories( | 25 | include_directories( |
532 | 11 | ${CMAKE_CURRENT_BINARY_DIR} | 26 | ${CMAKE_CURRENT_BINARY_DIR} |
533 | 12 | ${OUR_QT_TEST_INCLUDES} | 27 | ${OUR_QT_TEST_INCLUDES} |
534 | 28 | ${OUR_QT_QUICK_INCLUDE} | ||
535 | 13 | ) | 29 | ) |
536 | 14 | 30 | ||
537 | 15 | add_executable(conversiontest conversiontest.cpp) | 31 | add_executable(conversiontest conversiontest.cpp) |
539 | 16 | target_link_libraries(conversiontest ${OUR_QT_TEST_LIB} ${DEE_QT_LIBNAME}) | 32 | target_link_libraries(conversiontest ${OUR_QT_WIDGETS_LIB} ${OUR_QT_TEST_LIB} ${OUR_QT_QUICK_LIB} ${DEE_QT_LIBNAME}) |
540 | 17 | set_target_properties(conversiontest PROPERTIES COMPILE_FLAGS -fPIC) | 33 | set_target_properties(conversiontest PROPERTIES COMPILE_FLAGS -fPIC) |
541 | 18 | add_test(NAME conversiontest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-p" "-xunitxml" "-p" "-o" "-p" "conversiontest-xunit.xml") | 34 | add_test(NAME conversiontest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-p" "-xunitxml" "-p" "-o" "-p" "conversiontest-xunit.xml") |
542 | 19 | set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | 35 | set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") |
543 | 36 | set_property(TEST conversiontest PROPERTY ENVIRONMENT "QT_QPA_PLATFORM=minimal") | ||
544 | 37 | add_dependencies(check conversiontest) | ||
545 | 20 | 38 | ||
546 | 21 | add_executable(test-helper test-helper.cpp) | 39 | add_executable(test-helper test-helper.cpp) |
547 | 22 | target_link_libraries(test-helper ${OUR_QT_CORE_LIB} ${OUR_QT_DBUS_LIB} ${DEE_LDFLAGS}) | 40 | target_link_libraries(test-helper ${OUR_QT_CORE_LIB} ${OUR_QT_DBUS_LIB} ${DEE_LDFLAGS}) |
548 | 23 | set_target_properties(test-helper PROPERTIES COMPILE_FLAGS -fPIC) | 41 | set_target_properties(test-helper PROPERTIES COMPILE_FLAGS -fPIC) |
549 | 42 | add_dependencies(conversiontest ${DEE_QT_LIBNAME} test-helper) | ||
550 | 24 | 43 | ||
551 | 25 | add_executable(deelistmodeltest deelistmodeltest.cpp) | 44 | add_executable(deelistmodeltest deelistmodeltest.cpp) |
552 | 26 | target_link_libraries(deelistmodeltest ${OUR_QT_TEST_LIB} ${OUR_QT_DBUS_LIB} ${DEE_QT_LIBNAME}) | 45 | target_link_libraries(deelistmodeltest ${OUR_QT_TEST_LIB} ${OUR_QT_DBUS_LIB} ${DEE_QT_LIBNAME}) |
553 | 27 | set_target_properties(deelistmodeltest PROPERTIES COMPILE_FLAGS -fPIC) | 46 | set_target_properties(deelistmodeltest PROPERTIES COMPILE_FLAGS -fPIC) |
554 | 28 | add_test(NAME deelistmodeltest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/test-helper" "--task" "${CMAKE_CURRENT_BINARY_DIR}/deelistmodeltest" "-p" "-xunitxml" "-p" "-o" "-p" "deelistmodeltest-xunit.xml") | 47 | add_test(NAME deelistmodeltest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/test-helper" "--task" "${CMAKE_CURRENT_BINARY_DIR}/deelistmodeltest" "-p" "-xunitxml" "-p" "-o" "-p" "deelistmodeltest-xunit.xml") |
555 | 29 | set_property(TEST deelistmodeltest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | 48 | set_property(TEST deelistmodeltest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") |
556 | 49 | add_dependencies(check deelistmodeltest) | ||
557 | 50 | |||
558 | 51 | add_executable(deevarianttexttest deevarianttexttest.cpp) | ||
559 | 52 | target_link_libraries(deevarianttexttest ${OUR_QT_TEST_LIB} ${OUR_QT_DBUS_LIB} ${DEE_QT_LIBNAME}) | ||
560 | 53 | set_target_properties(deevarianttexttest PROPERTIES COMPILE_FLAGS -fPIC) | ||
561 | 54 | add_test(NAME deevarianttexttest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/deevarianttexttest" "-p" "-xunitxml" "-p" "-o" "-p" "deevarianttexttest-xunit.xml") | ||
562 | 55 | set_property(TEST deevarianttexttest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | ||
563 | 56 | add_dependencies(check deevarianttexttest) | ||
564 | 57 | |||
565 | 30 | 58 | ||
566 | === modified file 'tests/conversiontest.cpp' | |||
567 | --- tests/conversiontest.cpp 2012-11-21 12:09:44 +0000 | |||
568 | +++ tests/conversiontest.cpp 2013-03-08 16:59:20 +0000 | |||
569 | @@ -18,6 +18,7 @@ | |||
570 | 18 | #include <QObject> | 18 | #include <QObject> |
571 | 19 | 19 | ||
572 | 20 | #include "deelistmodel.h" | 20 | #include "deelistmodel.h" |
573 | 21 | #include "deevarianttext.h" | ||
574 | 21 | 22 | ||
575 | 22 | #include <dee.h> | 23 | #include <dee.h> |
576 | 23 | 24 | ||
577 | 24 | 25 | ||
578 | === modified file 'tests/deelistmodeltest.cpp' | |||
579 | --- tests/deelistmodeltest.cpp 2012-11-21 12:22:10 +0000 | |||
580 | +++ tests/deelistmodeltest.cpp 2013-03-08 16:59:20 +0000 | |||
581 | @@ -80,9 +80,11 @@ | |||
582 | 80 | 80 | ||
583 | 81 | DeeListModel model_qt; | 81 | DeeListModel model_qt; |
584 | 82 | QCOMPARE(model_qt.count(), 0); | 82 | QCOMPARE(model_qt.count(), 0); |
585 | 83 | QSignalSpy modelReset(&model_qt, SIGNAL(modelReset())); | ||
586 | 83 | 84 | ||
587 | 84 | model_qt.setModel(model); | 85 | model_qt.setModel(model); |
588 | 85 | QCOMPARE(model_qt.synchronized(), (bool)dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model))); | 86 | QCOMPARE(model_qt.synchronized(), (bool)dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model))); |
589 | 87 | QCOMPARE(modelReset.count(), 1); | ||
590 | 86 | } | 88 | } |
591 | 87 | 89 | ||
592 | 88 | void setExistingModelTest() | 90 | void setExistingModelTest() |
593 | @@ -90,10 +92,12 @@ | |||
594 | 90 | DeeModel* model = dee_shared_model_new("com.deeqt.test.model"); | 92 | DeeModel* model = dee_shared_model_new("com.deeqt.test.model"); |
595 | 91 | 93 | ||
596 | 92 | DeeListModel model_qt; | 94 | DeeListModel model_qt; |
597 | 95 | QSignalSpy modelReset(&model_qt, SIGNAL(modelReset())); | ||
598 | 93 | QCOMPARE(model_qt.count(), 0); | 96 | QCOMPARE(model_qt.count(), 0); |
599 | 94 | 97 | ||
600 | 95 | model_qt.setModel(model); | 98 | model_qt.setModel(model); |
601 | 96 | QCOMPARE(model_qt.synchronized(), false); | 99 | QCOMPARE(model_qt.synchronized(), false); |
602 | 100 | QCOMPARE(modelReset.count(), 1); | ||
603 | 97 | 101 | ||
604 | 98 | while(!model_qt.synchronized()) | 102 | while(!model_qt.synchronized()) |
605 | 99 | qApp->processEvents(); | 103 | qApp->processEvents(); |
606 | @@ -102,12 +106,46 @@ | |||
607 | 102 | QCOMPARE(model_qt.roleNames().count(), 1); | 106 | QCOMPARE(model_qt.roleNames().count(), 1); |
608 | 103 | QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0")); | 107 | QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0")); |
609 | 104 | } | 108 | } |
611 | 105 | 109 | ||
612 | 110 | void insertRemoveTest() | ||
613 | 111 | { | ||
614 | 112 | /* TODO: "ReferenceError: column_0 is not defined" */ | ||
615 | 113 | DeeModel* model = dee_shared_model_new("com.deeqt.test.model"); | ||
616 | 114 | |||
617 | 115 | DeeListModel model_qt; | ||
618 | 116 | QSignalSpy modelReset(&model_qt, SIGNAL(modelReset())); | ||
619 | 117 | QSignalSpy layoutChanged(&model_qt, SIGNAL(layoutChanged())); | ||
620 | 118 | QSignalSpy rowsInserted(&model_qt, SIGNAL(rowsInserted(const QModelIndex&, int, int))); | ||
621 | 119 | QSignalSpy rowsRemoved(&model_qt, SIGNAL(rowsRemoved(const QModelIndex&, int, int))); | ||
622 | 120 | QCOMPARE(model_qt.count(), 0); | ||
623 | 121 | |||
624 | 122 | model_qt.setModel(model); | ||
625 | 123 | QCOMPARE(model_qt.synchronized(), false); | ||
626 | 124 | QCOMPARE(modelReset.count(), 1); | ||
627 | 125 | |||
628 | 126 | while(!model_qt.synchronized()) | ||
629 | 127 | qApp->processEvents(); | ||
630 | 128 | QCOMPARE(model_qt.synchronized(), true); | ||
631 | 129 | QCOMPARE(layoutChanged.count(), 1); | ||
632 | 130 | |||
633 | 131 | GVariant* b = g_variant_parse(NULL, "false", NULL, NULL, NULL); | ||
634 | 132 | Q_ASSERT(b); | ||
635 | 133 | DeeModelIter* iter = dee_model_insert (model, 0, &b); | ||
636 | 134 | g_variant_unref(b); | ||
637 | 135 | QCOMPARE(rowsInserted.count(), 1); | ||
638 | 136 | QCOMPARE(model_qt.rowCount(), 1); | ||
639 | 137 | QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0")); | ||
640 | 138 | |||
641 | 139 | dee_model_remove(model, iter); | ||
642 | 140 | QCOMPARE(rowsRemoved.count(), 1); | ||
643 | 141 | QCOMPARE(model_qt.rowCount(), 0); | ||
644 | 142 | QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0")); | ||
645 | 143 | } | ||
646 | 144 | |||
647 | 106 | void cleanupTestCase() | 145 | void cleanupTestCase() |
648 | 107 | { | 146 | { |
649 | 108 | tell_service_to_exit(); | 147 | tell_service_to_exit(); |
650 | 109 | } | 148 | } |
651 | 110 | |||
652 | 111 | }; | 149 | }; |
653 | 112 | 150 | ||
654 | 113 | QTEST_MAIN(DeeListModelTest) | 151 | QTEST_MAIN(DeeListModelTest) |
655 | 114 | 152 | ||
656 | === added file 'tests/deevarianttexttest.cpp' | |||
657 | --- tests/deevarianttexttest.cpp 1970-01-01 00:00:00 +0000 | |||
658 | +++ tests/deevarianttexttest.cpp 2013-03-08 16:59:20 +0000 | |||
659 | @@ -0,0 +1,58 @@ | |||
660 | 1 | /* | ||
661 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
662 | 3 | * | ||
663 | 4 | * This program is free software; you can redistribute it and/or modify | ||
664 | 5 | * it under the terms of the GNU General Public License as published by | ||
665 | 6 | * the Free Software Foundation; version 3. | ||
666 | 7 | * | ||
667 | 8 | * This program is distributed in the hope that it will be useful, | ||
668 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
669 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
670 | 11 | * GNU General Public License for more details. | ||
671 | 12 | * | ||
672 | 13 | * You should have received a copy of the GNU General Public License | ||
673 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
674 | 15 | */ | ||
675 | 16 | |||
676 | 17 | #include <QtTest> | ||
677 | 18 | #include <QObject> | ||
678 | 19 | |||
679 | 20 | #include "deevarianttext.h" | ||
680 | 21 | |||
681 | 22 | #include <dee.h> | ||
682 | 23 | |||
683 | 24 | class DeeVariantTextTest : public QObject | ||
684 | 25 | { | ||
685 | 26 | Q_OBJECT | ||
686 | 27 | |||
687 | 28 | private Q_SLOTS: | ||
688 | 29 | void initTestCase() | ||
689 | 30 | { | ||
690 | 31 | g_type_init(); | ||
691 | 32 | } | ||
692 | 33 | |||
693 | 34 | void GVariantParseTest() | ||
694 | 35 | { | ||
695 | 36 | QHash<QString, QVariant> hash; | ||
696 | 37 | hash["[[1, 2, 3], [4, 5, 6]]"] = "aai"; | ||
697 | 38 | hash["[[1, 2, 3], [4, 5, 6.0]]"] = "aad"; | ||
698 | 39 | hash["[\"hello\", nothing]"] = "ams"; | ||
699 | 40 | hash["{1: \"one\", 2: \"two\", 3: \"three\"}"] = "a{is}"; | ||
700 | 41 | hash["[just 3, nothing]"] = "ami"; | ||
701 | 42 | // hash["{\"title\": <\"frobit\">, \"enabled\": <true>, width: <800>}"] = ""; | ||
702 | 43 | hash["@ms \"\""] = "ms"; | ||
703 | 44 | QHashIterator<QString, QVariant> i(hash); | ||
704 | 45 | while (i.hasNext()) { | ||
705 | 46 | i.next(); | ||
706 | 47 | QString input(i.key()); | ||
707 | 48 | DeeVariantText dvariant; | ||
708 | 49 | dvariant.setText(input); | ||
709 | 50 | QCOMPARE(dvariant.getText(), input); | ||
710 | 51 | QCOMPARE(dvariant.getType(), i.value()); | ||
711 | 52 | } | ||
712 | 53 | } | ||
713 | 54 | }; | ||
714 | 55 | |||
715 | 56 | QTEST_MAIN(DeeVariantTextTest) | ||
716 | 57 | |||
717 | 58 | #include "deevarianttexttest.moc" | ||
718 | 0 | 59 | ||
719 | === added file 'tests/qtquick1plugintest.cpp' | |||
720 | --- tests/qtquick1plugintest.cpp 1970-01-01 00:00:00 +0000 | |||
721 | +++ tests/qtquick1plugintest.cpp 2013-03-08 16:59:20 +0000 | |||
722 | @@ -0,0 +1,48 @@ | |||
723 | 1 | /* | ||
724 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
725 | 3 | * | ||
726 | 4 | * This program is free software; you can redistribute it and/or modify | ||
727 | 5 | * it under the terms of the GNU General Public License as published by | ||
728 | 6 | * the Free Software Foundation; version 3. | ||
729 | 7 | * | ||
730 | 8 | * This program is distributed in the hope that it will be useful, | ||
731 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
732 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
733 | 11 | * GNU General Public License for more details. | ||
734 | 12 | * | ||
735 | 13 | * You should have received a copy of the GNU General Public License | ||
736 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
737 | 15 | */ | ||
738 | 16 | |||
739 | 17 | #include <QtTest> | ||
740 | 18 | #include <QObject> | ||
741 | 19 | #include <QtDeclarative> | ||
742 | 20 | |||
743 | 21 | class PluginTest : public QObject | ||
744 | 22 | { | ||
745 | 23 | Q_OBJECT | ||
746 | 24 | |||
747 | 25 | private Q_SLOTS: | ||
748 | 26 | void initTestCase() | ||
749 | 27 | { | ||
750 | 28 | } | ||
751 | 29 | |||
752 | 30 | void GVariantQMLTest() | ||
753 | 31 | { | ||
754 | 32 | // Dummy argc/v to avoid GCC confusing int with Display* on some systems | ||
755 | 33 | int argc = 0; | ||
756 | 34 | char *argv[0]; | ||
757 | 35 | QApplication app(argc, argv); | ||
758 | 36 | QDeclarativeView view; | ||
759 | 37 | view.setSource(QUrl::fromLocalFile("test_qtquick1.qml")); | ||
760 | 38 | Q_ASSERT(view.errors().empty()); | ||
761 | 39 | QObject *text2 = view.rootObject()->findChild<QObject*>("text2"); | ||
762 | 40 | Q_ASSERT(text2); | ||
763 | 41 | QVariant text2text(text2->metaObject()->property(text2->metaObject()->indexOfProperty("text")).read(text2)); | ||
764 | 42 | QCOMPARE(text2text.toString(), QString("4,1.1,0.1,0,0.3,3.6")); | ||
765 | 43 | } | ||
766 | 44 | }; | ||
767 | 45 | |||
768 | 46 | QTEST_MAIN(PluginTest) | ||
769 | 47 | |||
770 | 48 | #include "qtquick1plugintest.moc" | ||
771 | 0 | 49 | ||
772 | === modified file 'tests/test_qtquick1.qml' | |||
773 | --- tests/test_qtquick1.qml 2013-03-08 16:59:19 +0000 | |||
774 | +++ tests/test_qtquick1.qml 2013-03-08 16:59:20 +0000 | |||
775 | @@ -1,15 +1,40 @@ | |||
776 | 1 | import QtQuick 1.0 | 1 | import QtQuick 1.0 |
777 | 2 | import Dee 3.0 | 2 | import Dee 3.0 |
778 | 3 | 3 | ||
790 | 4 | ListView { | 4 | Item { |
791 | 5 | width: 200 | 5 | |
792 | 6 | height: 200 | 6 | ListView { |
793 | 7 | delegate: Text { | 7 | width: 200 |
794 | 8 | x: 66 | 8 | height: 200 |
795 | 9 | y: 93 | 9 | delegate: Text { |
796 | 10 | text: column_4 | 10 | x: 66 |
797 | 11 | } | 11 | y: 93 |
798 | 12 | model: DeeListModel { | 12 | text: column_4 |
799 | 13 | name: "com.canonical.Unity.Lens.applications.T1313498309.Results" | 13 | } |
800 | 14 | } | 14 | model: DeeListModel { |
801 | 15 | name: "com.canonical.Unity.Lens.applications.T1313498309.Results" | ||
802 | 16 | } | ||
803 | 17 | } | ||
804 | 18 | |||
805 | 19 | DeeVariantText { | ||
806 | 20 | id: arrayOfInt | ||
807 | 21 | text: "[[1, 2, 3], [4, 5, 6]]" | ||
808 | 22 | Component.onCompleted: { | ||
809 | 23 | arrayOfInt.text = "[[4, 1.1, .1], [0, 0.3, 3.6]]" | ||
810 | 24 | } | ||
811 | 25 | onTextChanged: { | ||
812 | 26 | text2.text = arrayOfInt.value.toString() | ||
813 | 27 | } | ||
814 | 28 | } | ||
815 | 29 | |||
816 | 30 | Text { | ||
817 | 31 | text: arrayOfInt.value.toString() | ||
818 | 32 | } | ||
819 | 33 | |||
820 | 34 | Text { | ||
821 | 35 | id: text2 | ||
822 | 36 | objectName: "text2" | ||
823 | 37 | } | ||
824 | 38 | |||
825 | 15 | } | 39 | } |
826 | 40 | |||
827 | 16 | 41 | ||
828 | === removed file 'tests/test_qtquick2.qml' | |||
829 | --- tests/test_qtquick2.qml 2013-03-08 16:59:19 +0000 | |||
830 | +++ tests/test_qtquick2.qml 1970-01-01 00:00:00 +0000 | |||
831 | @@ -1,15 +0,0 @@ | |||
832 | 1 | import QtQuick 2.0 | ||
833 | 2 | import Dee 3.0 | ||
834 | 3 | |||
835 | 4 | ListView { | ||
836 | 5 | width: 200 | ||
837 | 6 | height: 200 | ||
838 | 7 | delegate: Text { | ||
839 | 8 | x: 66 | ||
840 | 9 | y: 93 | ||
841 | 10 | text: column_4 | ||
842 | 11 | } | ||
843 | 12 | model: DeeListModel { | ||
844 | 13 | name: "com.canonical.Unity.Lens.applications.T1313498309.Results" | ||
845 | 14 | } | ||
846 | 15 | } | ||
847 | 16 | 0 | ||
848 | === added file 'tests/tst_deelistmodel.qml' | |||
849 | --- tests/tst_deelistmodel.qml 1970-01-01 00:00:00 +0000 | |||
850 | +++ tests/tst_deelistmodel.qml 2013-03-08 16:59:20 +0000 | |||
851 | @@ -0,0 +1,79 @@ | |||
852 | 1 | import QtQuick 2.0 | ||
853 | 2 | import QtTest 1.0 | ||
854 | 3 | import Dee 3.0 | ||
855 | 4 | |||
856 | 5 | TestCase { | ||
857 | 6 | name: "DeeListModel" | ||
858 | 7 | |||
859 | 8 | function test_1_initialModel () { | ||
860 | 9 | compare(myModel.count, 0) | ||
861 | 10 | compare(myView.count, 0) | ||
862 | 11 | } | ||
863 | 12 | |||
864 | 13 | function test_1_modelAssigned () { | ||
865 | 14 | myModel.name = "com.dee.qml.model.test1" | ||
866 | 15 | countChanged.wait() | ||
867 | 16 | compare(myModel.name, "com.dee.qml.model.test1") | ||
868 | 17 | compare(myModel.count, 0) | ||
869 | 18 | compare(myView.count, 0) | ||
870 | 19 | } | ||
871 | 20 | |||
872 | 21 | function test_2_modelAppend () { | ||
873 | 22 | myModel.name = "com.dee.qml.model.test2" | ||
874 | 23 | countChanged.wait() | ||
875 | 24 | compare(myModel.count, 0, "model empty") | ||
876 | 25 | myModel.append("[5.95,\"Pizza\"]") | ||
877 | 26 | countChanged.wait() | ||
878 | 27 | compare(myModel.count, 1, "model: one row more") | ||
879 | 28 | compare(myView.count, myModel.count, "model count matches listview") | ||
880 | 29 | } | ||
881 | 30 | |||
882 | 31 | function test_3_modelRemove () { | ||
883 | 32 | myModel.name = "com.dee.qml.model.test3" | ||
884 | 33 | countChanged.wait() | ||
885 | 34 | compare(myModel.count, 0, "model empty") | ||
886 | 35 | myModel.append("[0.99,\"Grean Tea, Sencha\"]") | ||
887 | 36 | myModel.append("[0.89,\"Black Tea, Oolong\"]") | ||
888 | 37 | countChanged.wait() | ||
889 | 38 | compare(myModel.count, 2, "two rows more") | ||
890 | 39 | compare(myView.count, myModel.count, "model count matches listview") | ||
891 | 40 | myModel.remove(0) | ||
892 | 41 | countChanged.wait() | ||
893 | 42 | compare(myModel.count, 1, "one row less") | ||
894 | 43 | } | ||
895 | 44 | |||
896 | 45 | function test_4_roleDefined () { | ||
897 | 46 | myModel.name = "com.dee.qml.model.test4" | ||
898 | 47 | countChanged.wait() | ||
899 | 48 | compare(myModel.count, 0, "model empty") | ||
900 | 49 | myModel.append("[5.95,\"Pizza\"]") | ||
901 | 50 | countChanged.wait() | ||
902 | 51 | compare(myModel.count, 1, "one row more") | ||
903 | 52 | } | ||
904 | 53 | |||
905 | 54 | SignalSpy { | ||
906 | 55 | id: countChanged | ||
907 | 56 | target: myModel | ||
908 | 57 | signalName: "countChanged" | ||
909 | 58 | } | ||
910 | 59 | |||
911 | 60 | ListView { | ||
912 | 61 | id: myView | ||
913 | 62 | |||
914 | 63 | width: 200 | ||
915 | 64 | height: 200 | ||
916 | 65 | delegate: Text { | ||
917 | 66 | id: myTextDelegate | ||
918 | 67 | x: 66 | ||
919 | 68 | y: 93 | ||
920 | 69 | text: "" // column_0 | ||
921 | 70 | } | ||
922 | 71 | |||
923 | 72 | model: DeeListModel { | ||
924 | 73 | id: myModel | ||
925 | 74 | name: "com.dee.qml.model.test0" | ||
926 | 75 | property string myColumnValue: "" | ||
927 | 76 | } | ||
928 | 77 | } | ||
929 | 78 | } | ||
930 | 79 | |||
931 | 0 | 80 | ||
932 | === added file 'tests/tst_deevarianttext.qml' | |||
933 | --- tests/tst_deevarianttext.qml 1970-01-01 00:00:00 +0000 | |||
934 | +++ tests/tst_deevarianttext.qml 2013-03-08 16:59:20 +0000 | |||
935 | @@ -0,0 +1,60 @@ | |||
936 | 1 | import QtQuick 2.0 | ||
937 | 2 | import QtTest 1.0 | ||
938 | 3 | import Dee 3.0 | ||
939 | 4 | |||
940 | 5 | TestCase { | ||
941 | 6 | name: "DeeVariantText" | ||
942 | 7 | |||
943 | 8 | function test_1_initialText () { | ||
944 | 9 | compare(arrayOfStr.value.toString(),"bar,foo") | ||
945 | 10 | } | ||
946 | 11 | |||
947 | 12 | function test_3_textAssigned () { | ||
948 | 13 | arrayOfInt.text = "[[4, 1.1, .1], [0, 0.3, 3.6]]" | ||
949 | 14 | compare(arrayOfInt.value.toString(),"4,1.1,0.1,0,0.3,3.6") | ||
950 | 15 | } | ||
951 | 16 | |||
952 | 17 | function test_4_textChanged () { | ||
953 | 18 | arrayOfInt.didChange = false | ||
954 | 19 | arrayOfInt.text = "@ams [nothing]" | ||
955 | 20 | compare(arrayOfInt.didChange,true) | ||
956 | 21 | } | ||
957 | 22 | |||
958 | 23 | function test_5_textNotChanged () { | ||
959 | 24 | arrayOfInt.text = "@ams [nothing]" | ||
960 | 25 | arrayOfInt.didChange = false | ||
961 | 26 | arrayOfInt.text = "@ams [nothing]" | ||
962 | 27 | compare(arrayOfInt.didChange,false) | ||
963 | 28 | } | ||
964 | 29 | |||
965 | 30 | function test_6_invalid () { | ||
966 | 31 | arrayOfInt.text = "[nothing]" | ||
967 | 32 | compare(arrayOfInt.value,undefined) | ||
968 | 33 | } | ||
969 | 34 | |||
970 | 35 | function test_7_unicode () { | ||
971 | 36 | arrayOfStr.text = "[\"١٢٣٤٥٦٧٨٩٠\", \"道具箱\", \"Котята\"]" | ||
972 | 37 | compare(arrayOfStr.value.toString(),"١٢٣٤٥٦٧٨٩٠,道具箱,Котята") | ||
973 | 38 | } | ||
974 | 39 | |||
975 | 40 | function test_8_gvariant () { | ||
976 | 41 | arrayOfStr.text = "[<\"test\">, <\"test2\">]" | ||
977 | 42 | compare(arrayOfStr.value.toString(), "test,test2") | ||
978 | 43 | } | ||
979 | 44 | |||
980 | 45 | DeeVariantText { | ||
981 | 46 | id: arrayOfStr | ||
982 | 47 | text: "[\"bar\", \"foo\"]" | ||
983 | 48 | } | ||
984 | 49 | |||
985 | 50 | DeeVariantText { | ||
986 | 51 | id: arrayOfInt | ||
987 | 52 | text: "[[1, 2, 3], [4, 5, 6]]" | ||
988 | 53 | property bool didChange: false | ||
989 | 54 | onTextChanged: { | ||
990 | 55 | didChange = true | ||
991 | 56 | } | ||
992 | 57 | } | ||
993 | 58 | |||
994 | 59 | } | ||
995 | 60 |
Your changes to DeeListModel broke it for our use (rolesChanged isn't fired anymore).