on xenial help sign in
Added fake settings
commit74ee45e40c70f173fbd25a4e2c41dca95e64b104 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateTue 12 Aug 2014, 13:09 (12 years ago) parentbde3de3
11 files changed+168−3
qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+2 qml/Dash/ScopeSettings/ScopeSettingList.qml+3−1 qml/Dash/ScopeSettings/ScopeSettingNumber.qml+2 qml/Dash/ScopeSettings/ScopeSettingString.qml+2 qml/Dash/ScopeSettings/ScopeSettings.qml+1−1 tests/mocks/Unity/CMakeLists.txt+2 tests/mocks/Unity/fake_scope.cpp+3−1 tests/mocks/Unity/fake_scope.h+1 tests/mocks/Unity/fake_settingsmodel.cpp+96 tests/mocks/Unity/fake_settingsmodel.h+54 tests/mocks/Unity/fake_unity_plugin.cpp+2
qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
2020
2121ScopeSetting {
2222 id: root
23+ height: listItem.height
2324
2425 ListItem.Empty {
26+ id: listItem
2527 onClicked: {
2628 control.checked = !control.checked
2729 updated(control.checked)
qml/Dash/ScopeSettings/ScopeSettingList.qml+3−1
@@ -20,9 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
2020
2121ScopeSetting {
2222 id: root
23+ height: listItem.height
2324
2425 ListItem.ItemSelector {
25− id: control
26+ id: listItem
2627 objectName: "control"
2728 anchors {
2829 left: parent.left
@@ -30,6 +31,7 @@ ScopeSetting {
3031 }
3132 text: widgetData.displayName
3233 model: widgetData.properties["values"]
34+ onHeightChanged: console.log("item", height)
3335
3436 onSelectedIndexChanged: root.updated(selectedIndex)
3537 }
qml/Dash/ScopeSettings/ScopeSettingNumber.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
2020
2121ScopeSetting {
2222 id: root
23+ height: listItem.height
2324
2425 ListItem.Empty {
26+ id: listItem
2527 onClicked: {
2628 control.focus = true;
2729 control.selectAll();
qml/Dash/ScopeSettings/ScopeSettingString.qml+2
@@ -20,8 +20,10 @@ import Ubuntu.Components.ListItems 1.0 as ListItem
2020
2121ScopeSetting {
2222 id: root
23+ height: listItem.height
2324
2425 ListItem.Empty {
26+ id: listItem
2527 onClicked: {
2628 control.focus = true;
2729 control.selectAll();
qml/Dash/ScopeSettings/ScopeSettings.qml+1−1
@@ -23,7 +23,7 @@ ListView {
2323
2424 orientation: ListView.Vertical
2525
26− delegate: ScopeSettingWidgetFactory {
26+ delegate: ScopeSettingsWidgetFactory {
2727 objectName: "scopeSettingItem" + index
2828 width: root.width
2929 widgetData: model
tests/mocks/Unity/CMakeLists.txt+2
@@ -23,6 +23,7 @@ set(UnityQML_SOURCES
2323 fake_scope.cpp
2424 fake_scopes.cpp
2525 fake_scopesoverview.cpp
26+ fake_settingsmodel.cpp
2627 fake_categories.cpp
2728 fake_navigation.cpp
2829 fake_resultsmodel.cpp
@@ -38,6 +39,7 @@ set(UnityQML_SOURCES
3839 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h
3940 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
4041 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopesInterface.h
42+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/SettingsModelInterface.h
4143)
4244
4345add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
tests/mocks/Unity/fake_scope.cpp+3−1
@@ -22,6 +22,7 @@
2222#include "fake_navigation.h"
2323#include "fake_resultsmodel.h"
2424#include "fake_scopes.h"
25+#include "fake_settingsmodel.h"
2526
2627Scope::Scope(Scopes* parent) : Scope(QString(), QString(), false, parent)
2728{
@@ -39,6 +40,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
3940 , m_previewRendererName("preview-generic")
4041 , m_categories(new Categories(categories, this))
4142 , m_openScope(nullptr)
43+ , m_settings(new SettingsModel(this))
4244{
4345}
4446
@@ -94,7 +96,7 @@ unity::shell::scopes::CategoriesInterface* Scope::categories() const
9496
9597unity::shell::scopes::SettingsModelInterface* Scope::settings() const
9698{
97− return nullptr;
99+ return m_settings;
98100}
99101
100102QString Scope::noResultsHint() const
tests/mocks/Unity/fake_scope.h+1
@@ -96,6 +96,7 @@ protected:
9696
9797 unity::shell::scopes::CategoriesInterface* m_categories;
9898 unity::shell::scopes::ScopeInterface* m_openScope;
99+ unity::shell::scopes::SettingsModelInterface* m_settings;
99100};
100101
101102#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 @@
2626#include "fake_previewmodel.h"
2727#include "fake_previewwidgetmodel.h"
2828#include "fake_resultsmodel.h"
29+#include "fake_settingsmodel.h"
2930
3031// External
3132#include <glib-object.h>
@@ -43,6 +44,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4344 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
4445 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
4546 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.");
4648 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
4749 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4850 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");