on xenial help sign in
Added fake settings
74ee45eAndrea Cimitan
qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
20
20
21ScopeSetting {
21ScopeSetting {
22 id: root
22 id: root
23+ height: listItem.height
23
24
24 ListItem.Empty {
25 ListItem.Empty {
26+ id: listItem
25 onClicked: {
27 onClicked: {
26 control.checked = !control.checked
28 control.checked = !control.checked
27 updated(control.checked)
29 updated(control.checked)
qml/Dash/ScopeSettings/ScopeSettingList.qml+3−1
@@ -20,9 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
20
20
21ScopeSetting {
21ScopeSetting {
22 id: root
22 id: root
23+ height: listItem.height
23
24
24 ListItem.ItemSelector {
25 ListItem.ItemSelector {
25− id: control
26+ id: listItem
26 objectName: "control"
27 objectName: "control"
27 anchors {
28 anchors {
28 left: parent.left
29 left: parent.left
@@ -30,6 +31,7 @@ ScopeSetting {
30 }
31 }
31 text: widgetData.displayName
32 text: widgetData.displayName
32 model: widgetData.properties["values"]
33 model: widgetData.properties["values"]
34+ onHeightChanged: console.log("item", height)
33
35
34 onSelectedIndexChanged: root.updated(selectedIndex)
36 onSelectedIndexChanged: root.updated(selectedIndex)
35 }
37 }
qml/Dash/ScopeSettings/ScopeSettingNumber.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
20
20
21ScopeSetting {
21ScopeSetting {
22 id: root
22 id: root
23+ height: listItem.height
23
24
24 ListItem.Empty {
25 ListItem.Empty {
26+ id: listItem
25 onClicked: {
27 onClicked: {
26 control.focus = true;
28 control.focus = true;
27 control.selectAll();
29 control.selectAll();
qml/Dash/ScopeSettings/ScopeSettingString.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
20
20
21ScopeSetting {
21ScopeSetting {
22 id: root
22 id: root
23+ height: listItem.height
23
24
24 ListItem.Empty {
25 ListItem.Empty {
26+ id: listItem
25 onClicked: {
27 onClicked: {
26 control.focus = true;
28 control.focus = true;
27 control.selectAll();
29 control.selectAll();
qml/Dash/ScopeSettings/ScopeSettings.qml+1−1
@@ -23,7 +23,7 @@ ListView {
23
23
24 orientation: ListView.Vertical
24 orientation: ListView.Vertical
25
25
26− delegate: ScopeSettingWidgetFactory {
26+ delegate: ScopeSettingsWidgetFactory {
27 objectName: "scopeSettingItem" + index
27 objectName: "scopeSettingItem" + index
28 width: root.width
28 width: root.width
29 widgetData: model
29 widgetData: model
tests/mocks/Unity/CMakeLists.txt+2
@@ -23,6 +23,7 @@ set(UnityQML_SOURCES
23 fake_scope.cpp
23 fake_scope.cpp
24 fake_scopes.cpp
24 fake_scopes.cpp
25 fake_scopesoverview.cpp
25 fake_scopesoverview.cpp
26+ fake_settingsmodel.cpp
26 fake_categories.cpp
27 fake_categories.cpp
27 fake_navigation.cpp
28 fake_navigation.cpp
28 fake_resultsmodel.cpp
29 fake_resultsmodel.cpp
@@ -38,6 +39,7 @@ set(UnityQML_SOURCES
38 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h
39 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h
39 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
40 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
40 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopesInterface.h
41 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopesInterface.h
42+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/SettingsModelInterface.h
41)
43)
42
44
43add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
45add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
tests/mocks/Unity/fake_scope.cpp+3−1
@@ -22,6 +22,7 @@
22#include "fake_navigation.h"
22#include "fake_navigation.h"
23#include "fake_resultsmodel.h"
23#include "fake_resultsmodel.h"
24#include "fake_scopes.h"
24#include "fake_scopes.h"
25+#include "fake_settingsmodel.h"
25
26
26Scope::Scope(Scopes* parent) : Scope(QString(), QString(), false, parent)
27Scope::Scope(Scopes* parent) : Scope(QString(), QString(), false, parent)
27{
28{
@@ -39,6 +40,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
39 , m_previewRendererName("preview-generic")
40 , m_previewRendererName("preview-generic")
40 , m_categories(new Categories(categories, this))
41 , m_categories(new Categories(categories, this))
41 , m_openScope(nullptr)
42 , m_openScope(nullptr)
43+ , m_settings(new SettingsModel(this))
42{
44{
43}
45}
44
46
@@ -94,7 +96,7 @@ unity::shell::scopes::CategoriesInterface* Scope::categories() const
94
96
95unity::shell::scopes::SettingsModelInterface* Scope::settings() const
97unity::shell::scopes::SettingsModelInterface* Scope::settings() const
96{
98{
97− return nullptr;
99+ return m_settings;
98}
100}
99
101
100QString Scope::noResultsHint() const
102QString Scope::noResultsHint() const
tests/mocks/Unity/fake_scope.h+1
@@ -96,6 +96,7 @@ protected:
96
96
97 unity::shell::scopes::CategoriesInterface* m_categories;
97 unity::shell::scopes::CategoriesInterface* m_categories;
98 unity::shell::scopes::ScopeInterface* m_openScope;
98 unity::shell::scopes::ScopeInterface* m_openScope;
99+ unity::shell::scopes::SettingsModelInterface* m_settings;
99};
100};
100
101
101#endif // FAKE_SCOPE_H
102#endif // FAKE_SCOPE_H
tests/mocks/Unity/fake_settingsmodel.cppnew file+96
@@ -0,0 +1,96 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "fake_settingsmodel.h"
18+
19+SettingsModel::SettingsModel(QObject* parent) :
20+ SettingsModelInterface(parent) {
21+ {
22+ QVariantMap parameters;
23+ m_data << QSharedPointer<Data>(new Data("boolean-setting", "Boolean Setting", "boolean", parameters, true));
24+ }
25+ {
26+ QVariantMap parameters;
27+ parameters["values"] = QVariantList() << "First" << "Second" << "Third";
28+ m_data << QSharedPointer<Data>(new Data("list-setting", "List Setting", "list", parameters, 1));
29+ }
30+ {
31+ QVariantMap parameters;
32+ m_data << QSharedPointer<Data>(new Data("number-setting", "Number Setting", "number", parameters, 1.23));
33+ }
34+ {
35+ QVariantMap parameters;
36+ m_data << QSharedPointer<Data>(new Data("string-setting", "String Setting", "string", parameters, "flibble"));
37+ }
38+}
39+
40+QVariant SettingsModel::data(const QModelIndex& index, int role) const {
41+ int row = index.row();
42+ QVariant result;
43+
44+ if (row < m_data.size()) {
45+ auto data = m_data[row];
46+
47+ switch (role) {
48+ case Roles::RoleSettingId:
49+ result = data->id;
50+ break;
51+ case Roles::RoleDisplayName:
52+ result = data->displayName;
53+ break;
54+ case Roles::RoleType:
55+ result = data->type;
56+ break;
57+ case Roles::RoleProperties:
58+ result = data->properties;
59+ break;
60+ case Roles::RoleValue: {
61+ result = data->value;
62+ break;
63+ }
64+ default:
65+ break;
66+ }
67+ }
68+
69+ return result;
70+}
71+
72+bool SettingsModel::setData(const QModelIndex &index, const QVariant &value,
73+ int role) {
74+ int row = index.row();
75+ if (row < m_data.size()) {
76+ switch (role) {
77+ case SettingsModelInterface::RoleValue: {
78+ auto data = m_data[row];
79+ data->value = value;
80+ return true;
81+ }
82+ default:
83+ break;
84+ }
85+ }
86+
87+ return false;
88+}
89+
90+int SettingsModel::rowCount(const QModelIndex&) const {
91+ return count();
92+}
93+
94+int SettingsModel::count() const {
95+ return m_data.size();
96+}
tests/mocks/Unity/fake_settingsmodel.hnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef FAKE_SETTINGSMODEL_H
18+#define FAKE_SETTINGSMODEL_H
19+
20+#include <unity/shell/scopes/SettingsModelInterface.h>
21+
22+#include <QList>
23+#include <QSharedPointer>
24+
25+class SettingsModel: public unity::shell::scopes::SettingsModelInterface {
26+Q_OBJECT
27+
28+ struct Data {
29+ QString id;
30+ QString displayName;
31+ QString type;
32+ QVariant properties;
33+ QVariant value;
34+
35+ Data(QString const& id_, QString const& displayName_,
36+ QString const& type_, QVariant const& properties_,
37+ QVariant const& value_) :
38+ id(id_), displayName(displayName_), type(type_),
39+ properties(properties_), value(value_) {}
40+ };
41+
42+public:
43+ explicit SettingsModel(QObject* parent = 0);
44+ ~SettingsModel() = default;
45+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
46+ bool setData(const QModelIndex&index, const QVariant& value, int role = Qt::EditRole) override;
47+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
48+ int count() const override;
49+
50+protected:
51+ QList<QSharedPointer<Data>> m_data;
52+};
53+
54+#endif // FAKE_SETTINGSMODEL_H
tests/mocks/Unity/fake_unity_plugin.cpp+2
@@ -26,6 +26,7 @@
26#include "fake_previewmodel.h"
26#include "fake_previewmodel.h"
27#include "fake_previewwidgetmodel.h"
27#include "fake_previewwidgetmodel.h"
28#include "fake_resultsmodel.h"
28#include "fake_resultsmodel.h"
29+#include "fake_settingsmodel.h"
29
30
30// External
31// External
31#include <glib-object.h>
32#include <glib-object.h>
@@ -43,6 +44,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
43 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
44 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
44 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
45 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
45 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
46 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
47+ qmlRegisterUncreatableType<unity::shell::scopes::SettingsModelInterface>(uri, 0, 2, "Scope", "Can't create SettingsModel object in QML.");
46 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
48 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
47 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
49 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
48 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
50 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");