Merge lp:~kalikiana/dee-qt/deevarianttext into lp:dee-qt/0.2

Proposed by Michał Sawicz
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
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.

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Your changes to DeeListModel broke it for our use (rolesChanged isn't fired anymore).

review: Needs Fixing
lp:~kalikiana/dee-qt/deevarianttext updated
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#LibraryLocation-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#LibraryLocation-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

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

Subscribers

People subscribed via source and target branches