Merge lp:~zsombi/ubuntu-ui-toolkit/01-multiple-theme-engines into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Tim Peeters
Approved revision: 1448
Merged at revision: 1461
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/01-multiple-theme-engines
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 1386 lines (+616/-234)
23 files modified
modules/Ubuntu/Components/plugin/plugin.cpp (+3/-3)
modules/Ubuntu/Components/plugin/plugin.pro (+6/-4)
modules/Ubuntu/Components/plugin/ucdefaulttheme.cpp (+7/-7)
modules/Ubuntu/Components/plugin/ucdefaulttheme.h (+6/-6)
modules/Ubuntu/Components/plugin/ucdeprecatedtheme.cpp (+124/-0)
modules/Ubuntu/Components/plugin/ucdeprecatedtheme.h (+53/-0)
modules/Ubuntu/Components/plugin/uclistitem.cpp (+7/-4)
modules/Ubuntu/Components/plugin/uctheme.cpp (+57/-46)
modules/Ubuntu/Components/plugin/uctheme.h (+17/-10)
tests/resources/subtheming/Simple.qml (+45/-0)
tests/unit/tst_performance/StyledItemOldTheming.qml (+72/-0)
tests/unit/tst_performance/tst_performance.cpp (+4/-0)
tests/unit/tst_performance/tst_performance.pro (+2/-1)
tests/unit_x11/tst_components/tst_app_theming.qml (+54/-0)
tests/unit_x11/tst_components/tst_components.pro (+2/-2)
tests/unit_x11/tst_deprecated_theme_engine/Parent.qml (+14/-4)
tests/unit_x11/tst_deprecated_theme_engine/SimpleItem.qml (+20/-0)
tests/unit_x11/tst_deprecated_theme_engine/themes/CustomTheme/TestStyle.qml (+0/-1)
tests/unit_x11/tst_deprecated_theme_engine/themes/TestModule/TestTheme/TestStyle.qml (+0/-1)
tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.cpp (+113/-113)
tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.pro (+9/-2)
tests/unit_x11/tst_theme_engine/TestApp.qml (+0/-29)
tests/unit_x11/unit_x11.pro (+1/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/01-multiple-theme-engines
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Tim Peeters Approve
Review via email: mp+251942@code.launchpad.net

Commit message

Separating Theme context property from theme engine, giving the possibility to use the theming engine by multiple instances. Preparations for deprecation. Theming unit tests fixed.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1441. By Zsombor Egri

staging sync

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1442. By Zsombor Egri

staging sync

1443. By Zsombor Egri

Rename ThemeSettings to DefaultTheme

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

Update the copyright year in the files that you changed. At least plugin.cpp, ucdefaulttheme.cpp, ucdefaulttheme.h. Maybe more.

Revision history for this message
Tim Peeters (tpeeters) wrote :

The new Simple.qml also has (C) 2014.

Revision history for this message
Tim Peeters (tpeeters) wrote :

tests/resources/styleset/ <-- the name "styleset" is depreacted.

What is the goal of resources/styleset/Simple.qml? You are setting objectNames there as if it was used in some unit/AP test, but I don't see where you use it.

Revision history for this message
Tim Peeters (tpeeters) wrote :

795 === renamed directory 'tests/unit_x11/tst_theme_engine/AppTheme' => 'tests/unit_x11/tst_components/AppTheme'

why?

Revision history for this message
Tim Peeters (tpeeters) wrote :

836 + function test_0() {

Can you give this test a more useful name?

841 + function test_ambiance()
842 + {
843 + Theme.name = "Ubuntu.Components.Themes.Ambiance";
844 + }
845 +
846 + function test_reset()
847 + {
848 + Theme.name = undefined;
849 + }

These tests are setting values, but not checking anything with the new values.

review: Needs Fixing
Revision history for this message
Tim Peeters (tpeeters) wrote :

991 === modified file 'tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp'

Should this be renamed to tst_deprecated_theme_engine_test? Or will tests for the new themning go in there as well?

Revision history for this message
Zsombor Egri (zsombi) wrote :

> tests/resources/styleset/ <-- the name "styleset" is depreacted.
>
>
> What is the goal of resources/styleset/Simple.qml? You are setting objectNames
> there as if it was used in some unit/AP test, but I don't see where you use
> it.

I use this app to test the theming across this chain of MRs.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> 795 === renamed directory 'tests/unit_x11/tst_theme_engine/AppTheme' =>
> 'tests/unit_x11/tst_components/AppTheme'
>
> why?

The C++ tests have the plugin linked statically with them. This makes the UCDeprecatedTheme::instance() to be called once all over the tests. This means that the plugin won't function properly like it would on an Application. This causes crash on the auto-theming, as it tries to delete a theme's palette which wasn't created with the same QML engine. The whole idea to initialize the UCTheme and UCDeprecatedTheme in this way is bad.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> 836 + function test_0() {
>
> Can you give this test a more useful name?
>
>
> 841 + function test_ambiance()
> 842 + {
> 843 + Theme.name = "Ubuntu.Components.Themes.Ambiance";
> 844 + }
> 845 +
> 846 + function test_reset()
> 847 + {
> 848 + Theme.name = undefined;
> 849 + }
>
> These tests are setting values, but not checking anything with the new values.

Because those values will be set even though you'll get loads of binding loops on MainView. The test is actually to not to have any warnings when they're set. And there is no way to say no warnings, that's why we have that on the runtest.sh level.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> 991 === modified file
> 'tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp'
>
> Should this be renamed to tst_deprecated_theme_engine_test? Or will tests for
> the new themning go in there as well?

The new theming tests will go to a separate test module, and these will keep doing the old tests. Not sure whether it is worth renaming it, but I will.

1444. By Zsombor Egri

review comments applied

1445. By Zsombor Egri

staging sync

1446. By Zsombor Egri

funny branch divergence fix

Revision history for this message
Tim Peeters (tpeeters) wrote :

Thanks for the updates. Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1447. By Zsombor Egri

staging merge

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1448. By Zsombor Egri

CI kick

Revision history for this message
Tim Peeters (tpeeters) wrote :

should be good. let's see if it autolands.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
2--- modules/Ubuntu/Components/plugin/plugin.cpp 2015-03-04 19:07:58 +0000
3+++ modules/Ubuntu/Components/plugin/plugin.cpp 2015-04-02 11:34:06 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright 2012-2014 Canonical Ltd.
7+ * Copyright 2012-2015 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11@@ -13,7 +13,6 @@
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15- * Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
16 */
17
18 #include <QtQuick/private/qquickimagebase_p.h>
19@@ -23,6 +22,7 @@
20
21 #include "plugin.h"
22 #include "uctheme.h"
23+#include "ucdeprecatedtheme.h"
24
25 #include <QtQml/QQmlContext>
26 #include "i18n.h"
27@@ -207,7 +207,7 @@
28 // that can be accessed from any object
29 context->setContextProperty("QuickUtils", &QuickUtils::instance());
30
31- UCTheme::instance().registerToContext(context);
32+ UCDeprecatedTheme::instance().registerToContext(context);
33
34 context->setContextProperty("i18n", &UbuntuI18n::instance());
35 ContextPropertyChangeListener *i18nChangeListener =
36
37=== modified file 'modules/Ubuntu/Components/plugin/plugin.pro'
38--- modules/Ubuntu/Components/plugin/plugin.pro 2015-03-04 19:07:58 +0000
39+++ modules/Ubuntu/Components/plugin/plugin.pro 2015-04-02 11:34:06 +0000
40@@ -26,7 +26,6 @@
41
42 HEADERS += plugin.h \
43 uctheme.h \
44- ucthemesettings.h \
45 i18n.h \
46 listener.h \
47 ucscalingimageprovider.h \
48@@ -79,11 +78,12 @@
49 ucserviceproperties_p.h \
50 privates/listitemdragarea.h \
51 privates/listitemdraghandler.h \
52- ucnamespace.h
53+ ucnamespace.h \
54+ ucdeprecatedtheme.h \
55+ ucdefaulttheme.h
56
57 SOURCES += plugin.cpp \
58 uctheme.cpp \
59- ucthemesettings.cpp \
60 i18n.cpp \
61 listener.cpp \
62 ucscalingimageprovider.cpp \
63@@ -126,7 +126,9 @@
64 ucserviceproperties.cpp \
65 privates/listitemdragarea.cpp \
66 privates/listitemdraghandler.cpp \
67- ucnamespace.cpp
68+ ucnamespace.cpp \
69+ ucdeprecatedtheme.cpp \
70+ ucdefaulttheme.cpp
71
72 # adapters
73 SOURCES += adapters/alarmsadapter_organizer.cpp
74
75=== renamed file 'modules/Ubuntu/Components/plugin/ucthemesettings.cpp' => 'modules/Ubuntu/Components/plugin/ucdefaulttheme.cpp'
76--- modules/Ubuntu/Components/plugin/ucthemesettings.cpp 2015-01-20 10:33:29 +0000
77+++ modules/Ubuntu/Components/plugin/ucdefaulttheme.cpp 2015-04-02 11:34:06 +0000
78@@ -1,5 +1,5 @@
79 /*
80- * Copyright 2013 Canonical Ltd.
81+ * Copyright 2013-2015 Canonical Ltd.
82 *
83 * This program is free software; you can redistribute it and/or modify
84 * it under the terms of the GNU Lesser General Public License as published by
85@@ -17,7 +17,7 @@
86 * Florian Boucault <florian.boucault@canonical.com>
87 */
88
89-#include "ucthemesettings.h"
90+#include "ucdefaulttheme.h"
91 #include "uctheme.h"
92
93 #include <QDebug>
94@@ -34,7 +34,7 @@
95 const QString THEME_KEY("theme");
96 const QString DEFAULT_THEME("Ubuntu.Components.Themes.Ambiance");
97
98-UCThemeSettings::UCThemeSettings(QObject *parent) :
99+UCDefaultTheme::UCDefaultTheme(QObject *parent) :
100 QObject(parent),
101 m_settings(SETTINGS_FILE_FORMAT.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)), QSettings::IniFormat)
102 {
103@@ -51,11 +51,11 @@
104 }
105
106 QObject::connect(&m_settingsFileWatcher, &QFileSystemWatcher::fileChanged,
107- this, &UCThemeSettings::reloadSettings);
108+ this, &UCDefaultTheme::reloadSettings);
109 reloadSettings();
110 }
111
112-void UCThemeSettings::reloadSettings()
113+void UCDefaultTheme::reloadSettings()
114 {
115 m_settings.sync();
116 m_settingsFileWatcher.addPath(m_settings.fileName());
117@@ -67,12 +67,12 @@
118 }
119 }
120
121-QString UCThemeSettings::themeName() const
122+QString UCDefaultTheme::themeName() const
123 {
124 return m_themeName;
125 }
126
127-void UCThemeSettings::setThemeName(const QString &themeName)
128+void UCDefaultTheme::setThemeName(const QString &themeName)
129 {
130 if (themeName != m_themeName) {
131 m_themeName = themeName;
132
133=== renamed file 'modules/Ubuntu/Components/plugin/ucthemesettings.h' => 'modules/Ubuntu/Components/plugin/ucdefaulttheme.h'
134--- modules/Ubuntu/Components/plugin/ucthemesettings.h 2013-10-18 08:56:39 +0000
135+++ modules/Ubuntu/Components/plugin/ucdefaulttheme.h 2015-04-02 11:34:06 +0000
136@@ -1,5 +1,5 @@
137 /*
138- * Copyright 2013 Canonical Ltd.
139+ * Copyright 2013-2015 Canonical Ltd.
140 *
141 * This program is free software; you can redistribute it and/or modify
142 * it under the terms of the GNU Lesser General Public License as published by
143@@ -17,20 +17,20 @@
144 * Florian Boucault <florian.boucault@canonical.com>
145 */
146
147-#ifndef UCTHEMESETTINGS_H
148-#define UCTHEMESETTINGS_H
149+#ifndef UCDEFAULTTHEME_H
150+#define UCDEFAULTTHEME_H
151
152 #include <QtCore/QFileSystemWatcher>
153 #include <QtCore/QSettings>
154 #include <QtCore/QObject>
155
156-class UCThemeSettings : public QObject
157+class UCDefaultTheme : public QObject
158 {
159 Q_OBJECT
160
161 Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
162 public:
163- explicit UCThemeSettings(QObject *parent = 0);
164+ explicit UCDefaultTheme(QObject *parent = 0);
165
166 // getter/setters
167 QString themeName() const;
168@@ -47,4 +47,4 @@
169 QString m_themeName;
170 };
171
172-#endif // UCTHEMESETTINGS_H
173+#endif // UCDEFAULTTHEME_H
174
175=== added file 'modules/Ubuntu/Components/plugin/ucdeprecatedtheme.cpp'
176--- modules/Ubuntu/Components/plugin/ucdeprecatedtheme.cpp 1970-01-01 00:00:00 +0000
177+++ modules/Ubuntu/Components/plugin/ucdeprecatedtheme.cpp 2015-04-02 11:34:06 +0000
178@@ -0,0 +1,124 @@
179+/*
180+ * Copyright 2015 Canonical Ltd.
181+ *
182+ * This program is free software; you can redistribute it and/or modify
183+ * it under the terms of the GNU Lesser General Public License as published by
184+ * the Free Software Foundation; version 3.
185+ *
186+ * This program is distributed in the hope that it will be useful,
187+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
188+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189+ * GNU Lesser General Public License for more details.
190+ *
191+ * You should have received a copy of the GNU Lesser General Public License
192+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
193+ *
194+ * Authors: Zsombor Egri <zsombor.egri@canonical.com>
195+ */
196+
197+#include "ucdeprecatedtheme.h"
198+#include "uctheme.h"
199+#include "listener.h"
200+#include <QtQml/QQmlComponent>
201+#include <QtQml/QQmlContext>
202+#include <QtQml/QQmlInfo>
203+
204+/*!
205+ \qmltype Theme
206+ \instantiates UCTheme
207+ \inqmlmodule Ubuntu.Components 1.1
208+ \ingroup theming
209+ \brief The Theme class provides facilities to interact with the current theme.
210+
211+ A global instance is exposed as the \b Theme context property.
212+
213+ The theme defines the visual aspect of the Ubuntu components.
214+
215+ Example changing the current theme:
216+
217+ \qml
218+ import QtQuick 2.4
219+ import Ubuntu.Components 1.2
220+
221+ Item {
222+ Button {
223+ onClicked: Theme.name = "Ubuntu.Components.Themes.Ambiance"
224+ }
225+ }
226+ \endqml
227+
228+ Example creating a style component:
229+
230+ \qml
231+ import QtQuick 2.4
232+ import Ubuntu.Components 1.2
233+
234+ StyledItem {
235+ id: myItem
236+ style: Theme.createStyleComponent("MyItemStyle.qml", myItem)
237+ }
238+ \endqml
239+
240+ \sa {StyledItem}
241+*/
242+UCDeprecatedTheme::UCDeprecatedTheme(QObject *parent)
243+ : QObject(parent)
244+{
245+ connect(&UCTheme::defaultSet(), &UCTheme::nameChanged,
246+ this, &UCDeprecatedTheme::nameChanged);
247+ connect(&UCTheme::defaultSet(), &UCTheme::paletteChanged,
248+ this, &UCDeprecatedTheme::paletteChanged);
249+}
250+
251+/*!
252+ \qmlproperty string Theme::name
253+
254+ The name of the current theme.
255+*/
256+QString UCDeprecatedTheme::name() const
257+{
258+ return UCTheme::defaultSet().name();
259+}
260+void UCDeprecatedTheme::setName(const QString& name)
261+{
262+ UCTheme::defaultSet().setName(name);
263+}
264+void UCDeprecatedTheme::resetName()
265+{
266+ UCTheme::defaultSet().resetName();
267+}
268+
269+/*!
270+ \qmlproperty Palette Theme::palette
271+
272+ The palette of the current theme.
273+*/
274+QObject* UCDeprecatedTheme::palette()
275+{
276+ return UCTheme::defaultSet().palette();
277+}
278+
279+/*!
280+ \qmlmethod Component Theme::createStyleComponent(string styleName, object parent)
281+
282+ Returns an instance of the style component named \a styleName.
283+*/
284+QQmlComponent* UCDeprecatedTheme::createStyleComponent(const QString& styleName, QObject* parent)
285+{
286+ return UCTheme::defaultSet().createStyleComponent(styleName, parent);
287+}
288+
289+void UCDeprecatedTheme::registerToContext(QQmlContext* context)
290+{
291+ // add paths to engine search folder
292+ UCTheme::defaultSet().m_engine = context->engine();
293+ UCTheme::defaultSet().updateEnginePaths();
294+
295+ // register deprecated Theme property
296+ context->setContextProperty("Theme", this);
297+
298+ ContextPropertyChangeListener *themeChangeListener =
299+ new ContextPropertyChangeListener(context, "Theme");
300+ QObject::connect(this, SIGNAL(nameChanged()),
301+ themeChangeListener, SLOT(updateContextProperty()));
302+}
303
304=== added file 'modules/Ubuntu/Components/plugin/ucdeprecatedtheme.h'
305--- modules/Ubuntu/Components/plugin/ucdeprecatedtheme.h 1970-01-01 00:00:00 +0000
306+++ modules/Ubuntu/Components/plugin/ucdeprecatedtheme.h 2015-04-02 11:34:06 +0000
307@@ -0,0 +1,53 @@
308+/*
309+ * Copyright 2015 Canonical Ltd.
310+ *
311+ * This program is free software; you can redistribute it and/or modify
312+ * it under the terms of the GNU Lesser General Public License as published by
313+ * the Free Software Foundation; version 3.
314+ *
315+ * This program is distributed in the hope that it will be useful,
316+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
317+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
318+ * GNU Lesser General Public License for more details.
319+ *
320+ * You should have received a copy of the GNU Lesser General Public License
321+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
322+ *
323+ * Authors: Zsombor Egri <zsombor.egri@canonical.com>
324+ */
325+
326+#ifndef UCDEPRECATEDTHEME_H
327+#define UCDEPRECATEDTHEME_H
328+
329+#include <QtCore/QObject>
330+
331+class QQmlComponent;
332+class QQmlContext;
333+class UCTheme;
334+class UCDeprecatedTheme : public QObject
335+{
336+ Q_OBJECT
337+ Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
338+ Q_PROPERTY(QObject* palette READ palette NOTIFY paletteChanged)
339+public:
340+ static UCDeprecatedTheme& instance() {
341+ static UCDeprecatedTheme instance;
342+ return instance;
343+ }
344+ explicit UCDeprecatedTheme(QObject *parent = 0);
345+
346+ // getter/setters
347+ QString name() const;
348+ void setName(const QString& name);
349+ void resetName();
350+ QObject* palette();
351+
352+ Q_INVOKABLE QQmlComponent* createStyleComponent(const QString& styleName, QObject* parent);
353+ void registerToContext(QQmlContext* context);
354+
355+Q_SIGNALS:
356+ void nameChanged();
357+ void paletteChanged();
358+};
359+
360+#endif // UCDEPRECATEDTHEME_H
361
362=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp'
363--- modules/Ubuntu/Components/plugin/uclistitem.cpp 2015-03-03 13:47:48 +0000
364+++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2015-04-02 11:34:06 +0000
365@@ -15,7 +15,7 @@
366 */
367
368 #include "ucunits.h"
369-#include "uctheme.h"
370+#include "ucdeprecatedtheme.h"
371 #include "uclistitem.h"
372 #include "uclistitem_p.h"
373 #include "uclistitemactions.h"
374@@ -40,7 +40,8 @@
375 QColor getPaletteColor(const char *profile, const char *color)
376 {
377 QColor result;
378- QObject *palette = UCTheme::instance().palette();
379+ // FIXME: use theme when available
380+ QObject *palette = UCDeprecatedTheme::instance().palette();
381 if (palette) {
382 QObject *paletteProfile = palette->property(profile).value<QObject*>();
383 if (paletteProfile) {
384@@ -237,7 +238,8 @@
385 q, SLOT(_q_updateSwiping()), Qt::DirectConnection);
386
387 // catch theme changes
388- QObject::connect(&UCTheme::instance(), SIGNAL(nameChanged()), q, SLOT(_q_updateThemedData()));
389+ // FIXME: use theme when available
390+ QObject::connect(&UCDeprecatedTheme::instance(), SIGNAL(nameChanged()), q, SLOT(_q_updateThemedData()));
391 _q_updateThemedData();
392
393 // watch grid unit size change and set implicit size
394@@ -379,7 +381,8 @@
395 }
396 delete implicitStyleComponent;
397 Q_Q(UCListItem);
398- implicitStyleComponent = UCTheme::instance().createStyleComponent("ListItemStyle.qml", q);
399+ // FIXME: use theme when available
400+ implicitStyleComponent = UCDeprecatedTheme::instance().createStyleComponent("ListItemStyle.qml", q);
401 if (implicitStyleComponent) {
402 // set the objectnane for testing in tst_listitems.qml
403 implicitStyleComponent->setObjectName("ListItemThemeStyle");
404
405=== modified file 'modules/Ubuntu/Components/plugin/uctheme.cpp'
406--- modules/Ubuntu/Components/plugin/uctheme.cpp 2015-03-03 13:47:48 +0000
407+++ modules/Ubuntu/Components/plugin/uctheme.cpp 2015-04-02 11:34:06 +0000
408@@ -1,5 +1,5 @@
409 /*
410- * Copyright 2013 Canonical Ltd.
411+ * Copyright 2013-2015 Canonical Ltd.
412 *
413 * This program is free software; you can redistribute it and/or modify
414 * it under the terms of the GNU Lesser General Public License as published by
415@@ -36,7 +36,7 @@
416 #include <QtGui/QGuiApplication>
417 #include <QtGui/QFont>
418
419-/*!
420+/*
421 \qmltype Theme
422 \instantiates UCTheme
423 \inqmlmodule Ubuntu.Components 1.1
424@@ -111,20 +111,23 @@
425 return result;
426 }
427
428-UCTheme::UCTheme(QObject *parent) :
429- QObject(parent),
430- m_palette(NULL),
431- m_engine(NULL),
432- m_engineUpdated(false)
433-{
434- m_name = m_themeSettings.themeName();
435- QObject::connect(&m_themeSettings, &UCThemeSettings::themeNameChanged,
436- this, &UCTheme::onThemeNameChanged);
437- updateThemePaths();
438-
439- QObject::connect(this, SIGNAL(nameChanged()),
440- this, SLOT(loadPalette()), Qt::UniqueConnection);
441-
442+UCTheme::UCTheme(QObject *parent)
443+ : QObject(parent)
444+ , m_name(UCTheme::defaultSet().m_name)
445+ , m_palette(UCTheme::defaultSet().m_palette)
446+ , m_engine(UCTheme::defaultSet().m_engine)
447+ , m_defaultStyle(false)
448+{
449+ init();
450+}
451+
452+UCTheme::UCTheme(bool defaultStyle, QObject *parent)
453+ : QObject(parent)
454+ , m_palette(NULL)
455+ , m_engine(NULL)
456+ , m_defaultStyle(defaultStyle)
457+{
458+ init();
459 // set the default font
460 QFont defaultFont;
461 defaultFont.setFamily("Ubuntu");
462@@ -133,9 +136,17 @@
463 QGuiApplication::setFont(defaultFont);
464 }
465
466+void UCTheme::init()
467+{
468+ m_name = m_defaultTheme.themeName();
469+ QObject::connect(&m_defaultTheme, &UCDefaultTheme::themeNameChanged,
470+ this, &UCTheme::onThemeNameChanged);
471+ updateThemePaths();
472+}
473+
474 void UCTheme::updateEnginePaths()
475 {
476- if (!m_engine || m_engineUpdated) {
477+ if (!m_engine) {
478 return;
479 }
480
481@@ -145,13 +156,12 @@
482 m_engine->addImportPath(path);
483 }
484 }
485- m_engineUpdated = true;
486 }
487
488 void UCTheme::onThemeNameChanged()
489 {
490- if (m_themeSettings.themeName() != m_name) {
491- m_name = m_themeSettings.themeName();
492+ if (m_defaultTheme.themeName() != m_name) {
493+ m_name = m_defaultTheme.themeName();
494 updateThemePaths();
495 Q_EMIT nameChanged();
496 }
497@@ -186,7 +196,7 @@
498 }
499 }
500
501-/*!
502+/*
503 \qmlproperty string Theme::name
504
505 The name of the current theme.
506@@ -195,19 +205,29 @@
507 {
508 return m_name;
509 }
510-
511 void UCTheme::setName(const QString& name)
512 {
513- if (name != m_name) {
514- QObject::disconnect(&m_themeSettings, &UCThemeSettings::themeNameChanged,
515+ if (name == m_name) {
516+ return;
517+ }
518+ if (name.isEmpty()) {
519+ init();
520+ } else {
521+ QObject::disconnect(&m_defaultTheme, &UCDefaultTheme::themeNameChanged,
522 this, &UCTheme::onThemeNameChanged);
523 m_name = name;
524 updateThemePaths();
525- Q_EMIT nameChanged();
526 }
527+ updateEnginePaths();
528+ Q_EMIT nameChanged();
529+ loadPalette();
530+}
531+void UCTheme::resetName()
532+{
533+ setName(QString());
534 }
535
536-/*!
537+/*
538 \qmlproperty Palette Theme::palette
539
540 The palette of the current theme.
541@@ -248,7 +268,7 @@
542 return parentTheme;
543 }
544
545-/*!
546+/*
547 \qmlmethod Component Theme::createStyleComponent(string styleName, object parent)
548
549 Returns an instance of the style component named \a styleName.
550@@ -283,22 +303,6 @@
551 return component;
552 }
553
554-void UCTheme::registerToContext(QQmlContext* context)
555-{
556- // add paths to engine search folder
557- m_engine = context->engine();
558- updateEnginePaths();
559-
560- // register Theme
561- context->setContextProperty("Theme", this);
562-
563- ContextPropertyChangeListener *themeChangeListener =
564- new ContextPropertyChangeListener(context, "Theme");
565- QObject::connect(this, SIGNAL(nameChanged()),
566- themeChangeListener, SLOT(updateContextProperty()));
567-
568-}
569-
570 void UCTheme::loadPalette(bool notify)
571 {
572 if (!m_engine) {
573@@ -307,8 +311,15 @@
574 if (m_palette != NULL) {
575 delete m_palette;
576 }
577- m_palette = QuickUtils::instance().createQmlObject(styleUrl("Palette.qml"), m_engine);
578- if (notify) {
579- Q_EMIT paletteChanged();
580+ // theme may not have palette defined
581+ QUrl paletteUrl = styleUrl("Palette.qml");
582+ if (paletteUrl.isValid()) {
583+ m_palette = QuickUtils::instance().createQmlObject(paletteUrl, m_engine);
584+ if (notify) {
585+ Q_EMIT paletteChanged();
586+ }
587+ } else {
588+ // use the default palette if none defined
589+ m_palette = defaultSet().m_palette;
590 }
591 }
592
593=== modified file 'modules/Ubuntu/Components/plugin/uctheme.h'
594--- modules/Ubuntu/Components/plugin/uctheme.h 2014-11-24 15:08:26 +0000
595+++ modules/Ubuntu/Components/plugin/uctheme.h 2015-04-02 11:34:06 +0000
596@@ -1,5 +1,5 @@
597 /*
598- * Copyright 2013 Canonical Ltd.
599+ * Copyright 2013-2015 Canonical Ltd.
600 *
601 * This program is free software; you can redistribute it and/or modify
602 * it under the terms of the GNU Lesser General Public License as published by
603@@ -21,29 +21,31 @@
604 #define UCTHEME_H
605
606 #include <QtCore/QObject>
607+#include <QtCore/QPointer>
608 #include <QtCore/QUrl>
609 #include <QtCore/QString>
610 #include <QtQml/QQmlComponent>
611
612-#include "ucthemesettings.h"
613+#include "ucdefaulttheme.h"
614
615 class UCTheme : public QObject
616 {
617 Q_OBJECT
618
619- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
620+ Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
621 Q_PROPERTY(QObject* palette READ palette NOTIFY paletteChanged)
622 public:
623- static UCTheme& instance() {
624- static UCTheme instance;
625+ explicit UCTheme(QObject *parent = 0);
626+ static UCTheme &defaultSet()
627+ {
628+ static UCTheme instance(true);
629 return instance;
630 }
631
632- explicit UCTheme(QObject *parent = 0);
633-
634 // getter/setters
635 QString name() const;
636 void setName(const QString& name);
637+ void resetName();
638 QObject* palette();
639
640 Q_INVOKABLE QQmlComponent* createStyleComponent(const QString& styleName, QObject* parent);
641@@ -63,12 +65,17 @@
642 void loadPalette(bool notify = true);
643
644 private:
645+ UCTheme(bool defaultStyle, QObject *parent = 0);
646+ void init();
647+
648 QString m_name;
649- QObject* m_palette;
650+ QPointer<QObject> m_palette; // the palette might be from the default style if the theme doesn't define palette
651 QQmlEngine *m_engine;
652 QList<QUrl> m_themePaths;
653- UCThemeSettings m_themeSettings;
654- bool m_engineUpdated;
655+ UCDefaultTheme m_defaultTheme;
656+ bool m_defaultStyle:1;
657+
658+ friend class UCDeprecatedTheme;
659 };
660
661 #endif // UCTHEME_H
662
663=== added directory 'tests/resources/subtheming'
664=== added file 'tests/resources/subtheming/Simple.qml'
665--- tests/resources/subtheming/Simple.qml 1970-01-01 00:00:00 +0000
666+++ tests/resources/subtheming/Simple.qml 2015-04-02 11:34:06 +0000
667@@ -0,0 +1,45 @@
668+/*
669+ * Copyright 2015 Canonical Ltd.
670+ *
671+ * This program is free software; you can redistribute it and/or modify
672+ * it under the terms of the GNU Lesser General Public License as published by
673+ * the Free Software Foundation; version 3.
674+ *
675+ * This program is distributed in the hope that it will be useful,
676+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
677+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
678+ * GNU Lesser General Public License for more details.
679+ *
680+ * You should have received a copy of the GNU Lesser General Public License
681+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
682+ */
683+
684+import QtQuick 2.4
685+import Ubuntu.Components 1.2
686+
687+StyledItem {
688+ id: component1
689+ objectName: "TopItem"
690+ width: units.gu(50)
691+ height: units.gu(100)
692+
693+ Column {
694+ objectName: "Column"
695+ anchors.fill: parent
696+ TextField {
697+ objectName: "OuterText"
698+ property string styleName: Theme.name
699+ onStyleNameChanged: print(objectName, styleName)
700+ }
701+ StyledItem {
702+ objectName: "SuruDarkStyled"
703+ width: parent.width
704+ height: units.gu(10)
705+ TextField {
706+ objectName: "InnerText"
707+ property string styleName: Theme.name
708+ onStyleNameChanged: print(objectName, styleName)
709+ }
710+ }
711+ }
712+}
713
714=== added file 'tests/unit/tst_performance/StyledItemOldTheming.qml'
715--- tests/unit/tst_performance/StyledItemOldTheming.qml 1970-01-01 00:00:00 +0000
716+++ tests/unit/tst_performance/StyledItemOldTheming.qml 2015-04-02 11:34:06 +0000
717@@ -0,0 +1,72 @@
718+/*
719+ * Copyright 2015 Canonical Ltd.
720+ *
721+ * This program is free software; you can redistribute it and/or modify
722+ * it under the terms of the GNU Lesser General Public License as published by
723+ * the Free Software Foundation; version 3.
724+ *
725+ * This program is distributed in the hope that it will be useful,
726+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
727+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
728+ * GNU Lesser General Public License for more details.
729+ *
730+ * You should have received a copy of the GNU Lesser General Public License
731+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
732+ */
733+
734+import QtQuick 2.4
735+import Ubuntu.Components 1.2
736+
737+StyledItem {
738+ id: component1
739+ width: units.gu(50)
740+ height: units.gu(100)
741+
742+ property string newTheme
743+ onNewThemeChanged: Theme.name = newTheme
744+
745+ Column {
746+ anchors.fill: parent
747+ StyledItem {
748+ id: component2
749+ width: units.gu(40)
750+ height: units.gu(80)
751+
752+ StyledItem {
753+ id: component3
754+ width: units.gu(40)
755+ height: units.gu(80)
756+ Item {
757+ anchors.fill: parent
758+ StyledItem {
759+ id: component4
760+ width: units.gu(40)
761+ height: units.gu(80)
762+ }
763+ Loader {
764+ id: loader1
765+ width: units.gu(30)
766+ height: units.gu(30)
767+ sourceComponent: dynamicItem
768+ }
769+ }
770+ }
771+ }
772+ Component {
773+ id: dynamicItem
774+ Item {
775+ StyledItem {
776+ id: component5
777+ anchors.fill: parent
778+ }
779+ }
780+ }
781+
782+ Loader {
783+ id: loader2
784+ width: units.gu(30)
785+ height: units.gu(30)
786+ sourceComponent: dynamicItem
787+ }
788+ }
789+}
790
791=== modified file 'tests/unit/tst_performance/tst_performance.cpp'
792--- tests/unit/tst_performance/tst_performance.cpp 2015-03-02 13:49:13 +0000
793+++ tests/unit/tst_performance/tst_performance.cpp 2015-04-02 11:34:06 +0000
794@@ -69,6 +69,7 @@
795 QTest::addColumn<QString>("document");
796 QTest::addColumn<QUrl>("theme");
797
798+ QTest::newRow("old theming") << "StyledItemOldTheming.qml" << QUrl("Ubuntu.Components.Themes.SuruDark");
799 QTest::newRow("grid with Rectangle") << "RectangleGrid.qml" << QUrl();
800 QTest::newRow("grid with Text") << "TextGrid.qml" << QUrl();
801 QTest::newRow("grid with Label") << "LabelGrid.qml" << QUrl();
802@@ -95,6 +96,9 @@
803 QQuickItem *root = 0;
804 QBENCHMARK {
805 root = loadDocument(document);
806+ if (root && theme.isValid()) {
807+ root->setProperty("newTheme", theme.toString());
808+ }
809 }
810 if (root)
811 delete root;
812
813=== modified file 'tests/unit/tst_performance/tst_performance.pro'
814--- tests/unit/tst_performance/tst_performance.pro 2015-03-02 13:39:03 +0000
815+++ tests/unit/tst_performance/tst_performance.pro 2015-04-02 11:34:06 +0000
816@@ -25,4 +25,5 @@
817 ListItemsEmptyList.qml \
818 ListItemsBaseList.qml \
819 ListItemWithInlineActionsList.qml \
820- ListItemWithActionsList.qml
821+ ListItemWithActionsList.qml \
822+ StyledItemOldTheming.qml
823
824=== renamed directory 'tests/unit_x11/tst_theme_engine/AppTheme' => 'tests/unit_x11/tst_components/AppTheme'
825=== added file 'tests/unit_x11/tst_components/tst_app_theming.qml'
826--- tests/unit_x11/tst_components/tst_app_theming.qml 1970-01-01 00:00:00 +0000
827+++ tests/unit_x11/tst_components/tst_app_theming.qml 2015-04-02 11:34:06 +0000
828@@ -0,0 +1,54 @@
829+/*
830+ * Copyright 2015 Canonical Ltd.
831+ *
832+ * This program is free software; you can redistribute it and/or modify
833+ * it under the terms of the GNU Lesser General Public License as published by
834+ * the Free Software Foundation; version 3.
835+ *
836+ * This program is distributed in the hope that it will be useful,
837+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
838+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
839+ * GNU Lesser General Public License for more details.
840+ *
841+ * You should have received a copy of the GNU Lesser General Public License
842+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
843+ */
844+
845+import QtQuick 2.4
846+import Ubuntu.Components 1.2
847+import QtTest 1.0
848+import Ubuntu.Test 1.0
849+
850+MainView {
851+ id: main
852+ width: units.gu(40)
853+ height: units.gu(71)
854+
855+ Component.onCompleted: Theme.name = "AppTheme"
856+
857+ Label {
858+ id: testLabel
859+ }
860+
861+ UbuntuTestCase {
862+ name: "AppTheming"
863+ when: windowShown
864+
865+ function test_app_theme_defaults() {
866+ compare(main.backgroundColor, "#a21e1c", "Theme not loaded?");
867+ compare(testLabel.color, "#add8e6", "Label color not from application theme.");
868+ }
869+
870+ // the following tests should give binding loops which are captured by the runtest.sh
871+ // and will report failure if received
872+ function test_no_binding_loop_when_set_to_ambiance()
873+ {
874+ Theme.name = "Ubuntu.Components.Themes.Ambiance";
875+ }
876+
877+ function test_reset_theme_should_not_give_binding_loops()
878+ {
879+ Theme.name = undefined;
880+ }
881+ }
882+}
883
884=== modified file 'tests/unit_x11/tst_components/tst_components.pro'
885--- tests/unit_x11/tst_components/tst_components.pro 2015-03-24 16:51:39 +0000
886+++ tests/unit_x11/tst_components/tst_components.pro 2015-04-02 11:34:06 +0000
887@@ -7,5 +7,5 @@
888 SOURCES += tst_components.cpp tabsmodel.cpp
889 HEADERS += tabsmodel.h
890
891-OTHER_FILES += $$system(ls *.qml) \
892- tst_stress_alarmmodel.qml
893+OTHER_FILES += $$system(ls *.qml)
894+OTHER_FILES += $$system(ls AppTheme/*)
895
896=== renamed directory 'tests/unit_x11/tst_theme_engine' => 'tests/unit_x11/tst_deprecated_theme_engine'
897=== modified file 'tests/unit_x11/tst_deprecated_theme_engine/Parent.qml'
898--- tests/unit_x11/tst_theme_engine/Parent.qml 2015-03-03 13:20:06 +0000
899+++ tests/unit_x11/tst_deprecated_theme_engine/Parent.qml 2015-04-02 11:34:06 +0000
900@@ -1,5 +1,5 @@
901 /*
902- * Copyright 2013 Canonical Ltd.
903+ * Copyright 2013-2015 Canonical Ltd.
904 *
905 * This program is free software; you can redistribute it and/or modify
906 * it under the terms of the GNU Lesser General Public License as published by
907@@ -14,7 +14,17 @@
908 * along with this program. If not, see <http://www.gnu.org/licenses/>.
909 */
910
911-import QtQuick 2.0
912-
913-Item {
914+import QtQuick 2.4
915+import Ubuntu.Components 1.2
916+
917+StyledItem {
918+ id: item
919+ property string styleDocument
920+ onStyleDocumentChanged: style = Theme.createStyleComponent(styleDocument, item)
921+
922+ property string themeName
923+ onThemeNameChanged: Theme.name = themeName;
924+
925+ // make sure we start with Ambiance theme by invoking resetName()
926+ Component.onCompleted: Theme.name = undefined
927 }
928
929=== added file 'tests/unit_x11/tst_deprecated_theme_engine/SimpleItem.qml'
930--- tests/unit_x11/tst_deprecated_theme_engine/SimpleItem.qml 1970-01-01 00:00:00 +0000
931+++ tests/unit_x11/tst_deprecated_theme_engine/SimpleItem.qml 2015-04-02 11:34:06 +0000
932@@ -0,0 +1,20 @@
933+/*
934+ * Copyright 2015 Canonical Ltd.
935+ *
936+ * This program is free software; you can redistribute it and/or modify
937+ * it under the terms of the GNU Lesser General Public License as published by
938+ * the Free Software Foundation; version 3.
939+ *
940+ * This program is distributed in the hope that it will be useful,
941+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
942+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
943+ * GNU Lesser General Public License for more details.
944+ *
945+ * You should have received a copy of the GNU Lesser General Public License
946+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
947+ */
948+
949+import QtQuick 2.4
950+
951+Item {
952+}
953
954=== renamed directory 'tests/resources/themes' => 'tests/unit_x11/tst_deprecated_theme_engine/themes'
955=== modified file 'tests/unit_x11/tst_deprecated_theme_engine/themes/CustomTheme/TestStyle.qml'
956--- tests/resources/themes/CustomTheme/TestStyle.qml 2015-03-03 13:20:06 +0000
957+++ tests/unit_x11/tst_deprecated_theme_engine/themes/CustomTheme/TestStyle.qml 2015-04-02 11:34:06 +0000
958@@ -18,5 +18,4 @@
959 import TestTheme 1.0 as Parent
960
961 Parent.TestStyle {
962- Component.onCompleted: console.log("CUSTOMTHEME")
963 }
964
965=== modified file 'tests/unit_x11/tst_deprecated_theme_engine/themes/TestModule/TestTheme/TestStyle.qml'
966--- tests/resources/themes/TestModule/TestTheme/TestStyle.qml 2015-03-03 13:20:06 +0000
967+++ tests/unit_x11/tst_deprecated_theme_engine/themes/TestModule/TestTheme/TestStyle.qml 2015-04-02 11:34:06 +0000
968@@ -18,5 +18,4 @@
969 import Ubuntu.Components.Themes.Ambiance 0.1
970
971 Item {
972- Component.onCompleted: console.log("PARENT")
973 }
974
975=== renamed file 'tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp' => 'tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.cpp'
976--- tests/unit_x11/tst_theme_engine/tst_theme_enginetest.cpp 2014-12-04 07:18:58 +0000
977+++ tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.cpp 2015-04-02 11:34:06 +0000
978@@ -1,5 +1,5 @@
979 /*
980- * Copyright 2013 Canonical Ltd.
981+ * Copyright 2013-2015 Canonical Ltd.
982 *
983 * This program is free software; you can redistribute it and/or modify
984 * it under the terms of the GNU Lesser General Public License as published by
985@@ -18,14 +18,51 @@
986 #include <QtCore/QString>
987 #include <QtTest/QtTest>
988 #include <QtQml/QQmlEngine>
989+#include <QtQml/QQmlContext>
990 #include <QtQml/QQmlComponent>
991-#include "uctheme.h"
992+#include "ucdeprecatedtheme.h"
993 #include "uctestcase.h"
994 #include <private/qquicktext_p.h>
995
996 Q_DECLARE_METATYPE(QList<QQmlError>)
997
998-class tst_UCTheme : public QObject
999+class ThemeTestCase : public UbuntuTestCase
1000+{
1001+ Q_OBJECT
1002+public:
1003+ ThemeTestCase(const QString& file, QWindow* parent = 0)
1004+ : UbuntuTestCase(file, parent)
1005+ {
1006+ }
1007+
1008+ ~ThemeTestCase()
1009+ {
1010+ // restore theme before quitting
1011+ if (!rootContext()) {
1012+ return;
1013+ }
1014+ UCDeprecatedTheme *theme = rootContext()->contextProperty("Theme").value<UCDeprecatedTheme*>();
1015+ if (theme) {
1016+ theme->resetName();
1017+ } else {
1018+ qWarning() << "No theme instance found!";
1019+ }
1020+ }
1021+
1022+ void setTheme(const QString &theme)
1023+ {
1024+ rootObject()->setProperty("themeName", theme);
1025+ QTest::waitForEvents();
1026+ }
1027+
1028+ void setStyle(const QString &style)
1029+ {
1030+ rootObject()->setProperty("styleDocument", style);
1031+ QTest::waitForEvents();
1032+ }
1033+};
1034+
1035+class tst_UCDeprecatedTheme : public QObject
1036 {
1037 Q_OBJECT
1038 private:
1039@@ -44,171 +81,133 @@
1040 void testThemesRelativePathWithParentXDGDATA();
1041 void testThemesRelativePathWithParentNoVariablesSet();
1042 void testThemesRelativePathWithParentOneXDGPathSet();
1043- void testAppTheme();
1044 void testNoImportPathSet();
1045 void testBogusImportPathSet();
1046 void testMultipleImportPathsSet();
1047 };
1048
1049-void tst_UCTheme::initTestCase()
1050+void tst_UCDeprecatedTheme::initTestCase()
1051 {
1052 m_xdgDataPath = QLatin1String(getenv("XDG_DATA_DIRS"));
1053 }
1054
1055-void tst_UCTheme::cleanupTestCase()
1056+void tst_UCDeprecatedTheme::cleanupTestCase()
1057 {
1058 qputenv("XDG_DATA_DIRS", m_xdgDataPath.toLocal8Bit());
1059 }
1060
1061-void tst_UCTheme::testInstance()
1062+void tst_UCDeprecatedTheme::testInstance()
1063 {
1064- UCTheme::instance();
1065+ UCDeprecatedTheme::instance();
1066 }
1067
1068-void tst_UCTheme::testNameDefault()
1069+void tst_UCDeprecatedTheme::testNameDefault()
1070 {
1071- UCTheme theme;
1072+ UCDeprecatedTheme theme;
1073 QCOMPARE(theme.name(), QString("Ubuntu.Components.Themes.Ambiance"));
1074 }
1075
1076-void tst_UCTheme::testNameSet()
1077+void tst_UCDeprecatedTheme::testNameSet()
1078 {
1079 QTest::ignoreMessage(QtWarningMsg, "Theme not found: \"MyBeautifulTheme\"");
1080
1081- UCTheme theme;
1082+ UCDeprecatedTheme theme;
1083 theme.setName("MyBeautifulTheme");
1084 QCOMPARE(theme.name(), QString("MyBeautifulTheme"));
1085 }
1086
1087-void tst_UCTheme::testCreateStyleComponent()
1088+void tst_UCDeprecatedTheme::testCreateStyleComponent()
1089 {
1090 QFETCH(QString, styleName);
1091 QFETCH(QString, parentName);
1092 QFETCH(bool, success);
1093
1094- if (parentName.isEmpty())
1095+ if (parentName == "SimpleItem.qml")
1096 QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
1097 else if (styleName == "NotExistingTestStyle.qml")
1098- UbuntuTestCase::ignoreWarning(parentName, 19, 1, "QML Item: Warning: Style NotExistingTestStyle.qml not found in theme TestModule.TestTheme");
1099+ ThemeTestCase::ignoreWarning(parentName, 20, 1, "QML Parent: Warning: Style NotExistingTestStyle.qml not found in theme TestModule.TestTheme");
1100
1101 qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", ".");
1102
1103- UCTheme theme;
1104- theme.setName("TestModule.TestTheme");
1105- QQmlEngine engine;
1106- QQmlComponent parentComponent(&engine, parentName);
1107- QObject* parent = parentComponent.create();
1108- QQmlComponent* component = theme.createStyleComponent(styleName, parent);
1109-
1110- QCOMPARE(component != NULL, success);
1111+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase(parentName));
1112+ QVERIFY(view);
1113+ view->setTheme("TestModule.TestTheme");
1114+ view->setStyle(styleName);
1115+ QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
1116+ QCOMPARE(style != NULL, success);
1117 }
1118
1119-void tst_UCTheme::testCreateStyleComponent_data() {
1120+void tst_UCDeprecatedTheme::testCreateStyleComponent_data() {
1121 QTest::addColumn<QString>("styleName");
1122 QTest::addColumn<QString>("parentName");
1123 QTest::addColumn<bool>("success");
1124 QTest::newRow("Existing style") << "TestStyle.qml" << "Parent.qml" << true;
1125 QTest::newRow("Non existing style") << "NotExistingTestStyle.qml" << "Parent.qml" << false;
1126- QTest::newRow("No parent") << "TestStyle.qml" << "" << false;
1127 }
1128
1129-void tst_UCTheme::testThemesRelativePath()
1130+void tst_UCDeprecatedTheme::testThemesRelativePath()
1131 {
1132 qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "../tst_theme_engine");
1133
1134- UCTheme theme;
1135- theme.setName("TestModule.TestTheme");
1136- QQmlEngine engine;
1137- QQmlComponent parentComponent(&engine, "Parent.qml");
1138- QObject* parent = parentComponent.create();
1139- QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
1140-
1141- QCOMPARE(component != NULL, true);
1142- QCOMPARE(component->status(), QQmlComponent::Ready);
1143-}
1144-
1145-void tst_UCTheme::testThemesRelativePathWithParent()
1146-{
1147- QSKIP("https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1248982");
1148- qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "../../resources/themes:../../resources/themes/TestModule");
1149-
1150- UCTheme theme;
1151- theme.setName("CustomTheme");
1152- QQmlEngine engine;
1153- theme.registerToContext(engine.rootContext());
1154- QQmlComponent parentComponent(&engine, "Parent.qml");
1155- QObject* parent = parentComponent.create();
1156- QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
1157-
1158- QCOMPARE(component != NULL, true);
1159- QCOMPARE(component->status(), QQmlComponent::Ready);
1160-}
1161-
1162-void tst_UCTheme::testThemesRelativePathWithParentXDGDATA()
1163-{
1164- QSKIP("https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1248982");
1165+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1166+ QVERIFY(view);
1167+ view->setTheme("TestModule.TestTheme");
1168+ view->setStyle("TestStyle.qml");
1169+ QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
1170+ QCOMPARE(style != NULL, true);
1171+}
1172+
1173+void tst_UCDeprecatedTheme::testThemesRelativePathWithParent()
1174+{
1175+ qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "./themes:./themes/TestModule");
1176+
1177+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1178+ QVERIFY(view);
1179+ view->setTheme("CustomTheme");
1180+ view->setStyle("TestStyle.qml");
1181+ QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
1182+ QCOMPARE(style != NULL, true);
1183+}
1184+
1185+void tst_UCDeprecatedTheme::testThemesRelativePathWithParentXDGDATA()
1186+{
1187 qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "");
1188- qputenv("XDG_DATA_DIRS", "../../resources/themes:../../resources/themes/TestModule");
1189-
1190- UCTheme theme;
1191- theme.setName("CustomTheme");
1192- QQmlEngine engine;
1193- theme.registerToContext(engine.rootContext());
1194- QQmlComponent parentComponent(&engine, "Parent.qml");
1195- QObject* parent = parentComponent.create();
1196- QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
1197-
1198- QCOMPARE(component != NULL, true);
1199- QCOMPARE(component->status(), QQmlComponent::Ready);
1200+ qputenv("XDG_DATA_DIRS", "./themes:./themes/TestModule");
1201+
1202+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1203+ QVERIFY(view);
1204+ view->setTheme("CustomTheme");
1205+ view->setStyle("TestStyle.qml");
1206+ QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
1207+ QCOMPARE(style != NULL, true);
1208 }
1209
1210-void tst_UCTheme::testThemesRelativePathWithParentNoVariablesSet()
1211+void tst_UCDeprecatedTheme::testThemesRelativePathWithParentNoVariablesSet()
1212 {
1213- UbuntuTestCase::ignoreWarning("Parent.qml", 19, 1, "QML Item: Warning: Style TestStyle.qml not found in theme Ubuntu.Components.Themes.Ambiance");
1214+ ThemeTestCase::ignoreWarning("Parent.qml", 20, 1, "QML Parent: Warning: Style TestStyle.qml not found in theme Ubuntu.Components.Themes.Ambiance");
1215
1216 qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "");
1217 qputenv("XDG_DATA_DIRS", "");
1218
1219- UCTheme theme;
1220- QQmlEngine engine;
1221- qRegisterMetaType<QList <QQmlError> >();
1222- QSignalSpy spy(&engine, SIGNAL(warnings(QList<QQmlError>)));
1223- theme.registerToContext(engine.rootContext());
1224- QQmlComponent parentComponent(&engine, "Parent.qml");
1225- QObject* parent = parentComponent.create();
1226- QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
1227- // warning about TestStyle not defined in Ubuntu.Components.Themes.Ambiance should be shown
1228- QCOMPARE(spy.count(), 1);
1229- QCOMPARE(component == NULL, true);
1230+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1231+ QVERIFY(view);
1232+ view->setStyle("TestStyle.qml");
1233 }
1234
1235-void tst_UCTheme::testThemesRelativePathWithParentOneXDGPathSet()
1236+void tst_UCDeprecatedTheme::testThemesRelativePathWithParentOneXDGPathSet()
1237 {
1238 qputenv("UBUNTU_UI_TOOLKIT_THEMES_PATH", "");
1239 qputenv("XDG_DATA_DIRS", "../tst_theme_engine");
1240
1241- UCTheme theme;
1242- theme.setName("TestModule.TestTheme");
1243- QQmlEngine engine;
1244- QQmlComponent parentComponent(&engine, "Parent.qml");
1245- QObject* parent = parentComponent.create();
1246- QQmlComponent* component = theme.createStyleComponent("TestStyle.qml", parent);
1247-
1248- QCOMPARE(component != NULL, true);
1249- QCOMPARE(component->status(), QQmlComponent::Ready);
1250-}
1251-
1252-void tst_UCTheme::testAppTheme()
1253-{
1254- QScopedPointer<UbuntuTestCase> test(new UbuntuTestCase("TestApp.qml"));
1255- QColor backgroundColor = test->rootObject()->property("backgroundColor").value<QColor>();
1256- QCOMPARE(backgroundColor, QColor("#A21E1C"));
1257- QQuickText *label = test->findItem<QQuickText*>("test_label");
1258- QVERIFY(label);
1259- QCOMPARE(label->color(), QColor("lightblue"));
1260-}
1261-
1262-void tst_UCTheme::testNoImportPathSet()
1263+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1264+ QVERIFY(view);
1265+ view->setTheme("TestModule.TestTheme");
1266+ view->setStyle("TestStyle.qml");
1267+ QQmlComponent *style = view->rootObject()->property("style").value<QQmlComponent*>();
1268+ QCOMPARE(style != NULL, true);
1269+}
1270+
1271+void tst_UCDeprecatedTheme::testNoImportPathSet()
1272 {
1273 if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Ubuntu/Components").exists())
1274 QSKIP("This can only be tested if the UITK is installed");
1275@@ -217,11 +216,11 @@
1276 qputenv("XDG_DATA_DIRS", "");
1277 qputenv("QML2_IMPORT_PATH", "");
1278
1279- UCTheme theme;
1280+ UCDeprecatedTheme theme;
1281 QCOMPARE(theme.name(), QString("Ubuntu.Components.Themes.Ambiance"));
1282 }
1283
1284-void tst_UCTheme::testBogusImportPathSet()
1285+void tst_UCDeprecatedTheme::testBogusImportPathSet()
1286 {
1287 if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Ubuntu/Components").exists())
1288 QSKIP("This can only be tested if the UITK is installed");
1289@@ -230,11 +229,11 @@
1290 qputenv("XDG_DATA_DIRS", "");
1291 qputenv("QML2_IMPORT_PATH", "/no/plugins/here");
1292
1293- UCTheme theme;
1294+ UCDeprecatedTheme theme;
1295 QCOMPARE(theme.name(), QString("Ubuntu.Components.Themes.Ambiance"));
1296 }
1297
1298-void tst_UCTheme::testMultipleImportPathsSet()
1299+void tst_UCDeprecatedTheme::testMultipleImportPathsSet()
1300 {
1301 if (!QFile(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + "/Ubuntu/Components").exists())
1302 QSKIP("This can only be tested if the UITK is installed");
1303@@ -243,10 +242,11 @@
1304 qputenv("XDG_DATA_DIRS", "");
1305 qputenv("QML2_IMPORT_PATH", "/no/plugins/here:.");
1306
1307- UCTheme theme;
1308- theme.setName("TestModule.TestTheme");
1309+ QScopedPointer<ThemeTestCase> view(new ThemeTestCase("Parent.qml"));
1310+ QVERIFY(view);
1311+ view->setTheme("TestModule.TestTheme");
1312 }
1313
1314-QTEST_MAIN(tst_UCTheme)
1315+QTEST_MAIN(tst_UCDeprecatedTheme)
1316
1317-#include "tst_theme_enginetest.moc"
1318+#include "tst_deprecated_theme_engine.moc"
1319
1320=== renamed file 'tests/unit_x11/tst_theme_engine/tst_theme_engine.pro' => 'tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.pro'
1321--- tests/unit_x11/tst_theme_engine/tst_theme_engine.pro 2014-12-04 07:18:58 +0000
1322+++ tests/unit_x11/tst_deprecated_theme_engine/tst_deprecated_theme_engine.pro 2015-04-02 11:34:06 +0000
1323@@ -1,7 +1,14 @@
1324 include(../test-include.pri)
1325 QT += quick-private gui-private
1326-SOURCES += tst_theme_enginetest.cpp
1327+SOURCES += tst_deprecated_theme_engine.cpp
1328
1329 OTHER_FILES += \
1330 TestStyle.qml \
1331- TestApp.qml
1332+ TestApp.qml \
1333+ Parent.qml \
1334+ SimpleItem.qml \
1335+ themes/CustomTheme/TestStyle.qml \
1336+ themes/CustomTheme/parent_theme \
1337+ themes/TestModule/TestTheme/TestStyle.qml \
1338+ themes/TestModule/TestTheme/qmldir \
1339+ themes/TestModule/TestTheme/parent_theme
1340
1341=== removed file 'tests/unit_x11/tst_theme_engine/TestApp.qml'
1342--- tests/unit_x11/tst_theme_engine/TestApp.qml 2015-03-03 13:20:06 +0000
1343+++ tests/unit_x11/tst_theme_engine/TestApp.qml 1970-01-01 00:00:00 +0000
1344@@ -1,29 +0,0 @@
1345-/*
1346- * Copyright 2014 Canonical Ltd.
1347- *
1348- * This program is free software; you can redistribute it and/or modify
1349- * it under the terms of the GNU Lesser General Public License as published by
1350- * the Free Software Foundation; version 3.
1351- *
1352- * This program is distributed in the hope that it will be useful,
1353- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1354- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1355- * GNU Lesser General Public License for more details.
1356- *
1357- * You should have received a copy of the GNU Lesser General Public License
1358- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1359- */
1360-
1361-import QtQuick 2.0
1362-import Ubuntu.Components 1.1
1363-
1364-MainView {
1365- width: units.gu(40)
1366- height: units.gu(71)
1367-
1368- Component.onCompleted: Theme.name = "AppTheme"
1369-
1370- Label {
1371- objectName: "test_label"
1372- }
1373-}
1374
1375=== modified file 'tests/unit_x11/unit_x11.pro'
1376--- tests/unit_x11/unit_x11.pro 2015-02-18 11:39:07 +0000
1377+++ tests/unit_x11/unit_x11.pro 2015-04-02 11:34:06 +0000
1378@@ -8,7 +8,7 @@
1379 tst_inversemousearea \
1380 tst_recreateview \
1381 tst_statesaver \
1382- tst_theme_engine \
1383+ tst_deprecated_theme_engine \
1384 tst_orientation \
1385 tst_layouts \
1386 tst_mousefilters \

Subscribers

People subscribed via source and target branches