on xenial help sign in
Use Interface classes from unity-api
commitc7548f53290ec0f745504c8cfdefb936975e3bd9 authorAlbert Astals <albert.astals@canonical.com> dateThu 22 May 2014, 17:59 (12 years ago) parent1564e3362b732b
27 files changed+131−380
qml/Components/PageHeader.qml+1−1 qml/Dash/CardCarousel.qml+2−2 qml/Dash/CardFilterGrid.qml+2−2 qml/Dash/DashContent.qml+1−1 qml/Dash/DashRenderer.qml+3−4 qml/Dash/GenericScopeView.qml+2−3 qml/Dash/PreviewListView.qml+2−2 qml/ScopeTool.qml+1−1 tests/mocks/Unity/CMakeLists.txt+8 tests/mocks/Unity/fake_categories.cpp+6−22 tests/mocks/Unity/fake_categories.h+5−18 tests/mocks/Unity/fake_previewmodel.cpp+2−15 tests/mocks/Unity/fake_previewmodel.h+7−25 tests/mocks/Unity/fake_previewstack.cpp+3−11 tests/mocks/Unity/fake_previewstack.h+6−17 tests/mocks/Unity/fake_previewwidgetmodel.cpp+2−10 tests/mocks/Unity/fake_previewwidgetmodel.h+3−12 tests/mocks/Unity/fake_resultsmodel.cpp+1−44 tests/mocks/Unity/fake_resultsmodel.h+5−37 tests/mocks/Unity/fake_scope.cpp+3−14 tests/mocks/Unity/fake_scope.h+26−72 tests/mocks/Unity/fake_scopes.cpp+11−22 tests/mocks/Unity/fake_scopes.h+7−24 tests/mocks/Unity/fake_unity_plugin.cpp+3−2 tests/qmltests/Components/tst_PageHeaderLabel.qml+4−4 tests/qmltests/Dash/tst_DashContent.qml+5−5 tests/qmltests/Dash/tst_GenericScopeView.qml+10−10
qml/Components/PageHeader.qml+1−1
@@ -25,7 +25,7 @@ Item {
2525 property bool searchEntryEnabled: false
2626 property alias searchQuery: searchField.text
2727 property ListModel searchHistory
28− property Scope scope
28+ property var scope: null
2929 property alias childItem: itemContainer.children
3030 property alias showBackButton: backButton.visible
3131
qml/Dash/CardCarousel.qml+2−2
@@ -42,8 +42,8 @@ DashRenderer {
4242 cacheBuffer: 1404 // 18px * 13gu * 6
4343 model: cardCarousel.model
4444
45− onClicked: cardCarousel.clicked(index, itemY)
46− onPressAndHold: cardCarousel.pressAndHold(index, itemY)
45+ onClicked: cardCarousel.clicked(index, null)
46+ onPressAndHold: cardCarousel.pressAndHold(index)
4747
4848 property real fontScale: 1 / selectedItemScaleFactor
4949 property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
qml/Dash/CardFilterGrid.qml+2−2
@@ -64,8 +64,8 @@ DashRenderer {
6464 }
6565 Connections {
6666 target: loader.item
67− onClicked: genericFilterGrid.clicked(index, item.y)
68− onPressAndHold: genericFilterGrid.pressAndHold(index, item.y)
67+ onClicked: genericFilterGrid.clicked(index, result)
68+ onPressAndHold: genericFilterGrid.pressAndHold(index)
6969 }
7070 }
7171 }
qml/Dash/DashContent.qml+1−1
@@ -138,7 +138,7 @@ Item {
138138
139139 readonly property bool moving: item ? item.moving : false
140140 readonly property var categoryView: item ? item.categoryView : null
141− readonly property Scope theScope: scope
141+ readonly property var theScope: scope
142142
143143 // these are needed for autopilot tests
144144 readonly property string scopeId: scope.id
qml/Dash/DashRenderer.qml+3−4
@@ -50,13 +50,12 @@ Item {
5050
5151 /// Emitted when the user clicked on an item
5252 /// @param index is the index of the clicked item
53− /// @param itemY is y of the clicked delegate
54− signal clicked(int index, real itemY)
53+ /// @param result result model of the cliked item, used for activation
54+ signal clicked(int index, var result)
5555
5656 /// Emitted when the user pressed and held on an item
5757 /// @param index is the index of the held item
58− /// @param itemY is y of the held delegate
59− signal pressAndHold(int index, real itemY)
58+ signal pressAndHold(int index)
6059
6160 function setFilter(filter, animate) {
6261 }
qml/Dash/GenericScopeView.qml+2−3
@@ -25,7 +25,7 @@ import "../Components/ListItems" as ListItems
2525FocusScope {
2626 id: scopeView
2727
28− property Scope scope: null
28+ property var scope: null
2929 property SortFilterProxyModel categories: categoryFilter
3030 property bool isCurrent: false
3131 property alias moving: categoryView.moving
@@ -187,8 +187,7 @@ FocusScope {
187187 // TODO Technically it is possible that calling activate() will make the scope emit
188188 // previewRequested so that we show a preview but there's no scope that does that yet
189189 // so it's not implemented
190− var item = target.model.get(index);
191− scopeView.scope.activate(item.result)
190+ scopeView.scope.activate(result)
192191 } else {
193192 previewListView.model = target.model;
194193 previewListView.currentIndex = -1
qml/Dash/PreviewListView.qml+2−2
@@ -23,7 +23,7 @@ import "Previews" as Previews
2323Item {
2424 id: root
2525
26− property Scope scope: null
26+ property var scope: null
2727 property var pageHeader: null
2828
2929 property alias open: previewListView.open
@@ -116,7 +116,7 @@ Item {
116116
117117 previewModel: {
118118 var previewStack = root.scope.preview(result);
119− return previewStack.get(0);
119+ return previewStack.getPreviewModel(0);
120120 }
121121 }
122122
qml/ScopeTool.qml+1−1
@@ -74,7 +74,7 @@ Rectangle {
7474
7575 model: filteredScopes
7676 searchHistory: SearchHistoryModel { }
77− property Scope scope: scopes.get(currentIndex)
77+ property var scope: scopes.getScope(currentIndex)
7878
7979 anchors {
8080 top: parent.top
tests/mocks/Unity/CMakeLists.txt+8
@@ -6,6 +6,7 @@ add_subdirectory(Notifications)
66pkg_search_module(DEE dee-1.0 REQUIRED)
77pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
88pkg_search_module(DEEQT libdee-qt5 REQUIRED)
9+pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=1)
910
1011include_directories(
1112 ${CMAKE_CURRENT_BINARY_DIR}
@@ -27,6 +28,13 @@ set(UnityQML_SOURCES
2728 fake_previewstack.cpp
2829 fake_previewwidgetmodel.cpp
2930 fake_unity_plugin.cpp
31+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
32+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
33+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
34+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
35+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h
36+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
37+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopesInterface.h
3038)
3139
3240add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
tests/mocks/Unity/fake_categories.cpp+6−22
@@ -22,24 +22,9 @@
2222#include "fake_resultsmodel.h"
2323
2424Categories::Categories(int category_count, QObject* parent)
25− : QAbstractListModel(parent)
25+ : unity::shell::scopes::CategoriesInterface(parent)
2626 , m_category_count(category_count)
2727{
28− m_roles[Categories::RoleCategoryId] = "categoryId";
29− m_roles[Categories::RoleName] = "name";
30− m_roles[Categories::RoleIcon] = "icon";
31− m_roles[Categories::RoleRawRendererTemplate] = "rawRendererTemplate";
32− m_roles[Categories::RoleRenderer] = "renderer";
33− m_roles[Categories::RoleComponents] = "components";
34− m_roles[Categories::RoleProgressSource] = "progressSource";
35− m_roles[Categories::RoleResults] = "results";
36− m_roles[Categories::RoleCount] = "count";
37−}
38−
39−QHash<int, QByteArray>
40−Categories::roleNames() const
41−{
42− return m_roles;
4328}
4429
4530int Categories::rowCount(const QModelIndex& /*parent*/) const
@@ -65,6 +50,11 @@ void Categories::addSpecialCategory(QString const& categoryId, QString const& na
6550 }
6651}
6752
53+bool Categories::overrideCategoryJson(QString const& categoryId, QString const& json)
54+{
55+ qFatal("Using un-implemented Categories::overrideCategoryJson");
56+}
57+
6858void Categories::countChanged()
6959{
7060 QObject* countObject = sender();
@@ -126,9 +116,6 @@ Categories::data(const QModelIndex& index, int role) const
126116 map["title"] = "HOLA";
127117 return map;
128118 }
129− case RoleProgressSource:
130− qFatal("Using un-implemented RoleProgressSource Categories role");
131− return QVariant();
132119 case RoleResults:
133120 return QVariant();
134121 case RoleCount:
@@ -172,9 +159,6 @@ Categories::data(const QModelIndex& index, int role) const
172159 map["subtitle"] = "HOLA";
173160 return map;
174161 }
175− case RoleProgressSource:
176− qFatal("Using un-implemented RoleProgressSource Categories role");
177− return QVariant();
178162 case RoleResults:
179163 return QVariant::fromValue(resultsModel);
180164 case RoleCount:
tests/mocks/Unity/fake_categories.h+5−18
@@ -17,44 +17,31 @@
1717#ifndef FAKE_CATEGORIES_H
1818#define FAKE_CATEGORIES_H
1919
20+#include <unity/shell/scopes/CategoriesInterface.h>
21+
2022// Qt
21−#include <QAbstractListModel>
2223#include <QList>
2324
2425class ResultsModel;
2526
26−class Categories : public QAbstractListModel
27+class Categories : public unity::shell::scopes::CategoriesInterface
2728{
2829 Q_OBJECT
2930
30− Q_ENUMS(Roles)
31−
3231public:
3332 Categories(int category_count, QObject* parent = 0);
34− enum Roles {
35− RoleCategoryId,
36− RoleName,
37− RoleIcon,
38− RoleRawRendererTemplate,
39− RoleRenderer,
40− RoleComponents,
41− RoleProgressSource, // maybe
42− RoleResults,
43− RoleCount
44− };
4533
4634 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
47− QHash<int, QByteArray> roleNames() const override;
4835 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4936
50− Q_INVOKABLE void addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject);
37+ Q_INVOKABLE void addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject) override;
38+ Q_INVOKABLE bool overrideCategoryJson(QString const& categoryId, QString const& json) override;
5139
5240private Q_SLOTS:
5341 void countChanged();
5442
5543private:
5644 mutable QHash<int, ResultsModel*> m_resultsModels;
57− QHash<int, QByteArray> m_roles;
5845 int m_category_count;
5946
6047 struct CategoryData {
tests/mocks/Unity/fake_previewmodel.cpp+2−15
@@ -27,22 +27,14 @@
2727// Qt
2828#include <QDebug>
2929
30−PreviewModel::PreviewModel(QObject* parent) : QAbstractListModel(parent)
30+PreviewModel::PreviewModel(QObject* parent)
31+ : unity::shell::scopes::PreviewModelInterface(parent)
3132{
3233 // we have one column by default
3334 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
3435 m_previewWidgetModels.append(columnModel);
3536}
3637
37−QHash<int, QByteArray> PreviewModel::roleNames() const
38−{
39− QHash<int, QByteArray> roles;
40−
41− roles[Roles::RoleColumnModel] = "columnModel";
42−
43− return roles;
44−}
45−
4638void PreviewModel::setWidgetColumnCount(int count)
4739{
4840 if (count != 1) {
@@ -65,11 +57,6 @@ bool PreviewModel::processingAction() const
6557 return false;
6658}
6759
68−void PreviewModel::setProcessingAction(bool /*processing*/)
69−{
70− qFatal("PreviewModel::setProcessingAction not implemented");
71−}
72−
7360int PreviewModel::rowCount(const QModelIndex&) const
7461{
7562 return m_previewWidgetModels.size();
tests/mocks/Unity/fake_previewmodel.h+7−25
@@ -18,47 +18,29 @@
1818#ifndef FAKE_PREVIEWMODEL_H
1919#define FAKE_PREVIEWMODEL_H
2020
21−#include <QAbstractListModel>
21+#include <unity/shell/scopes/PreviewModelInterface.h>
22+
2223#include <QSharedPointer>
2324#include <QVariantMap>
2425
2526class PreviewWidgetModel;
2627
27−class PreviewModel : public QAbstractListModel
28+class PreviewModel : public unity::shell::scopes::PreviewModelInterface
2829{
2930 Q_OBJECT
3031
31− Q_ENUMS(Roles)
32−
33− Q_PROPERTY(int widgetColumnCount READ widgetColumnCount WRITE setWidgetColumnCount NOTIFY widgetColumnCountChanged)
34− Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
35− Q_PROPERTY(bool processingAction READ processingAction NOTIFY processingActionChanged)
36−
3732public:
3833 explicit PreviewModel(QObject* parent = 0);
3934
40− enum Roles {
41− RoleColumnModel
42− };
43−
4435 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
45− QHash<int, QByteArray> roleNames() const override;
4636 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4737
48− void setWidgetColumnCount(int count);
49− int widgetColumnCount() const;
50− bool loaded() const;
51− bool processingAction() const;
52− void setProcessingAction(bool processing);
53−
54−Q_SIGNALS:
55− void widgetColumnCountChanged();
56− void loadedChanged();
57− void processingActionChanged();
58− void triggered(QString const&, QString const&, QVariantMap const&);
38+ void setWidgetColumnCount(int count) override;
39+ int widgetColumnCount() const override;
40+ bool loaded() const override;
41+ bool processingAction() const override;
5942
6043private:
61− QHash<int, QByteArray> m_roles;
6244 QList<PreviewWidgetModel*> m_previewWidgetModels;
6345};
6446
tests/mocks/Unity/fake_previewstack.cpp+3−11
@@ -21,7 +21,8 @@
2121#include "fake_previewmodel.h"
2222#include "fake_scope.h"
2323
24−PreviewStack::PreviewStack(QObject* parent) : QAbstractListModel(parent)
24+PreviewStack::PreviewStack(QObject* parent)
25+ : unity::shell::scopes::PreviewStackInterface(parent)
2526{
2627 m_previews << new PreviewModel(this);
2728}
@@ -30,15 +31,6 @@ PreviewStack::~PreviewStack()
3031{
3132}
3233
33−QHash<int, QByteArray> PreviewStack::roleNames() const
34−{
35− QHash<int, QByteArray> roles;
36−
37− roles[Roles::RolePreviewModel] = "previewModel";
38−
39− return roles;
40−}
41−
4234void PreviewStack::setWidgetColumnCount(int columnCount)
4335{
4436 if (columnCount != 1) {
@@ -56,7 +48,7 @@ int PreviewStack::rowCount(const QModelIndex&) const
5648 return m_previews.size();
5749}
5850
59−PreviewModel* PreviewStack::get(int index) const
51+unity::shell::scopes::PreviewModelInterface* PreviewStack::getPreviewModel(int index) const
6052{
6153 if (index >= m_previews.size()) {
6254 return nullptr;
tests/mocks/Unity/fake_previewstack.h+6−17
@@ -18,39 +18,28 @@
1818#ifndef FAKE_PREVIEWSTACK_H
1919#define FAKE_PREVIEWSTACK_H
2020
21−#include <QAbstractListModel>
21+#include <unity/shell/scopes/PreviewStackInterface.h>
22+
2223#include <QSharedPointer>
2324#include <QVariantMap>
2425
2526class PreviewModel;
2627
27−class PreviewStack : public QAbstractListModel
28+class PreviewStack : public unity::shell::scopes::PreviewStackInterface
2829{
2930 Q_OBJECT
3031
31− Q_ENUMS(Roles)
32−
33− Q_PROPERTY(int widgetColumnCount READ widgetColumnCount WRITE setWidgetColumnCount NOTIFY widgetColumnCountChanged)
34−
3532public:
3633 explicit PreviewStack(QObject* parent = 0);
3734 virtual ~PreviewStack();
3835
39− enum Roles {
40− RolePreviewModel
41− };
42−
4336 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
44− QHash<int, QByteArray> roleNames() const override;
4537 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4638
47− Q_INVOKABLE PreviewModel* get(int index) const;
48−
49− void setWidgetColumnCount(int columnCount);
50− int widgetColumnCount() const;
39+ Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* getPreviewModel(int index) const override;
5140
52−Q_SIGNALS:
53− void widgetColumnCountChanged();
41+ void setWidgetColumnCount(int columnCount) override;
42+ int widgetColumnCount() const override;
5443
5544private:
5645 QList<PreviewModel*> m_previews;
tests/mocks/Unity/fake_previewwidgetmodel.cpp+2−10
@@ -35,12 +35,9 @@ struct PreviewData
3535 }
3636};
3737
38−PreviewWidgetModel::PreviewWidgetModel(QObject* parent) : QAbstractListModel(parent)
38+PreviewWidgetModel::PreviewWidgetModel(QObject* parent)
39+ : unity::shell::scopes::PreviewWidgetModelInterface(parent)
3940{
40− m_roles[Roles::RoleWidgetId] = "widgetId";
41− m_roles[Roles::RoleType] = "type";
42− m_roles[Roles::RoleProperties] = "properties";
43−
4441 populateWidgets();
4542}
4643
@@ -60,11 +57,6 @@ void PreviewWidgetModel::populateWidgets()
6057
6158}
6259
63−QHash<int, QByteArray> PreviewWidgetModel::roleNames() const
64−{
65− return m_roles;
66−}
67−
6860int PreviewWidgetModel::rowCount(const QModelIndex&) const
6961{
7062 return m_previewWidgets.size();
tests/mocks/Unity/fake_previewwidgetmodel.h+3−12
@@ -18,33 +18,24 @@
1818#ifndef FAKE_PREVIEWWIDGETMODEL_H
1919#define FAKE_PREVIEWWIDGETMODEL_H
2020
21−#include <QAbstractListModel>
21+#include <unity/shell/scopes/PreviewWidgetModelInterface.h>
22+
2223#include <QSharedPointer>
2324#include <QVariantMap>
2425
2526class PreviewData;
2627
27−class PreviewWidgetModel : public QAbstractListModel
28+class PreviewWidgetModel : public unity::shell::scopes::PreviewWidgetModelInterface
2829{
2930 Q_OBJECT
3031
31− Q_ENUMS(Roles)
32−
3332public:
3433 explicit PreviewWidgetModel(QObject* parent = 0);
3534
36− enum Roles {
37− RoleWidgetId,
38− RoleType,
39− RoleProperties
40− };
41−
4235 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
43− QHash<int, QByteArray> roleNames() const override;
4436 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4537
4638private:
47− QHash<int, QByteArray> m_roles;
4839 QList<QSharedPointer<PreviewData>> m_previewWidgets;
4940
5041 void populateWidgets();
tests/mocks/Unity/fake_resultsmodel.cpp+1−44
@@ -23,25 +23,10 @@
2323#include <paths.h>
2424
2525ResultsModel::ResultsModel(int result_count, int categoryId, QObject* parent)
26− : QAbstractListModel(parent)
26+ : unity::shell::scopes::ResultsModelInterface(parent)
2727 , m_result_count(result_count)
2828 , m_categoryId(categoryId)
2929{
30− m_roles[ResultsModel::RoleUri] = "uri";
31− m_roles[ResultsModel::RoleCategoryId] = "categoryId";
32− m_roles[ResultsModel::RoleDndUri] = "dndUri";
33− m_roles[ResultsModel::RoleResult] = "result";
34− m_roles[ResultsModel::RoleTitle] = "title";
35− m_roles[ResultsModel::RoleArt] = "art";
36− m_roles[ResultsModel::RoleSubtitle] = "subtitle";
37− m_roles[ResultsModel::RoleMascot] = "mascot";
38− m_roles[ResultsModel::RoleEmblem] = "emblem";
39− m_roles[ResultsModel::RoleOldPrice] = "oldPrice";
40− m_roles[ResultsModel::RolePrice] = "price";
41− m_roles[ResultsModel::RoleAltPrice] = "altPrice";
42− m_roles[ResultsModel::RoleRating] = "rating";
43− m_roles[ResultsModel::RoleAltRating] = "altRating";
44− m_roles[ResultsModel::RoleSummary] = "summary";
4530}
4631
4732QString ResultsModel::categoryId() const
@@ -54,12 +39,6 @@ void ResultsModel::setCategoryId(QString const& /*id*/)
5439 qFatal("Calling un-implemented ResultsModel::setCategoryId");
5540}
5641
57−QHash<int, QByteArray>
58−ResultsModel::roleNames() const
59−{
60− return m_roles;
61−}
62−
6342int ResultsModel::rowCount(const QModelIndex& parent) const
6443{
6544 Q_UNUSED(parent);
@@ -72,23 +51,6 @@ int ResultsModel::count() const
7251 return rowCount();
7352}
7453
75−QVariant ResultsModel::get(int row) const
76−{
77− if (row >= m_result_count || row < 0) return QVariantMap();
78−
79− QVariantMap result;
80− QModelIndex modelIndex(index(row));
81− QHashIterator<int, QByteArray> it(roleNames());
82− while (it.hasNext()) {
83− it.next();
84− QVariant val(data(modelIndex, it.key()));
85− if (val.isNull()) continue;
86− result[it.value()] = val;
87− }
88−
89− return result;
90−}
91−
9254QVariant
9355ResultsModel::data(const QModelIndex& index, int role) const
9456{
@@ -106,11 +68,6 @@ ResultsModel::data(const QModelIndex& index, int role) const
10668 return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
10769 case RoleMascot:
10870 case RoleEmblem:
109− case RoleOldPrice:
110− case RolePrice:
111− case RoleAltPrice:
112− case RoleRating:
113− case RoleAltRating:
11471 case RoleSummary:
11572 default:
11673 return QVariant();
tests/mocks/Unity/fake_resultsmodel.h+5−37
@@ -21,58 +21,26 @@
2121#ifndef FAKE_RESULTS_MODEL_H
2222#define FAKE_RESULTS_MODEL_H
2323
24−#include <QAbstractListModel>
24+#include <unity/shell/scopes/ResultsModelInterface.h>
2525
26−class ResultsModel : public QAbstractListModel
26+class ResultsModel : public unity::shell::scopes::ResultsModelInterface
2727{
2828 Q_OBJECT
2929
30− Q_ENUMS(Roles)
31−
32− Q_PROPERTY(QString categoryId READ categoryId WRITE setCategoryId NOTIFY categoryIdChanged)
33− Q_PROPERTY(int count READ count NOTIFY countChanged)
34−
3530public:
3631 explicit ResultsModel(int result_count, int categoryId, QObject* parent = 0);
3732
38− enum Roles {
39− RoleUri,
40− RoleCategoryId,
41− RoleDndUri,
42− RoleResult,
43− // card components
44− RoleTitle,
45− RoleArt,
46− RoleSubtitle,
47− RoleMascot,
48− RoleEmblem,
49− RoleOldPrice,
50− RolePrice,
51− RoleAltPrice,
52− RoleRating,
53− RoleAltRating,
54− RoleSummary
55− };
56−
5733 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
58− QHash<int, QByteArray> roleNames() const override;
5934 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
6035
61− Q_INVOKABLE QVariant get(int row) const;
62−
6336 /* getters */
64− QString categoryId() const;
65− int count() const;
37+ QString categoryId() const override;
38+ int count() const override;
6639
6740 /* setters */
68− void setCategoryId(QString const& id);
69−
70−Q_SIGNALS:
71− void categoryIdChanged();
72− void countChanged();
41+ void setCategoryId(QString const& id) override;
7342
7443private:
75− QHash<int, QByteArray> m_roles;
7644 int m_result_count;
7745 int m_categoryId;
7846};
tests/mocks/Unity/fake_scope.cpp+3−14
@@ -22,7 +22,7 @@ Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
2222}
2323
2424Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent)
25− : QObject(parent)
25+ : unity::shell::scopes::ScopeInterface(parent)
2626 , m_id(id)
2727 , m_name(name)
2828 , m_visible(visible)
@@ -61,15 +61,11 @@ QString Scope::shortcut() const {
6161 return QString("");
6262}
6363
64−bool Scope::connected() const {
65− return true;
66−}
67−
6864bool Scope::searchInProgress() const {
6965 return m_searching;
7066}
7167
72−Categories* Scope::categories() const {
68+unity::shell::scopes::CategoriesInterface* Scope::categories() const {
7369 return m_categories;
7470}
7571
@@ -89,13 +85,6 @@ bool Scope::isActive() const {
8985 return m_isActive;
9086}
9187
92−void Scope::setName(const QString &str) {
93− if (str != m_name) {
94− m_name = str;
95− Q_EMIT nameChanged(m_name);
96− }
97−}
98−
9988void Scope::setSearchQuery(const QString &str) {
10089 if (str != m_searchQuery) {
10190 m_searchQuery = str;
@@ -149,7 +138,7 @@ void Scope::cancelActivation()
149138{
150139}
151140
152−void Scope::closeScope(Scope* /*scope*/)
141+void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
153142{
154143 qFatal("Scope::closeScope is not implemented");
155144}
tests/mocks/Unity/fake_scope.h+26−72
@@ -17,93 +17,47 @@
1717#ifndef FAKE_SCOPE_H
1818#define FAKE_SCOPE_H
1919
20+#include <unity/shell/scopes/ScopeInterface.h>
21+
2022#include "fake_categories.h"
2123#include "fake_previewstack.h"
2224
23−#include <QObject>
2425#include <QTimer>
2526
26−class Preview;
27−
28−class Scope : public QObject
27+class Scope : public unity::shell::scopes::ScopeInterface
2928{
3029 Q_OBJECT
3130
32− Q_PROPERTY(QString id READ id NOTIFY idChanged)
33− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
34− Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
35− Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
36− Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
37− Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
38− Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
39− Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
40− Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
41− //Q_PROPERTY(Filters* filters READ filters NOTIFY filtersChanged)
42−
43− Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
44− Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
45− Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
46− Q_PROPERTY(bool isActive READ isActive WRITE setActive NOTIFY isActiveChanged)
47−
4831public:
4932 Scope(QObject* parent = 0);
5033 Scope(QString const& id, QString const& name, bool visible, QObject* parent = 0);
5134
5235 /* getters */
53− QString id() const;
54− QString name() const;
55− QString iconHint() const;
56− QString description() const;
57− QString searchHint() const;
58− bool visible() const;
59− QString shortcut() const;
60− bool connected() const;
61− bool searchInProgress() const;
62− Categories* categories() const;
63− QString searchQuery() const;
64− QString noResultsHint() const;
65− QString formFactor() const;
66− bool isActive() const;
36+ QString id() const override;
37+ QString name() const override;
38+ QString iconHint() const override;
39+ QString description() const override;
40+ QString searchHint() const override;
41+ bool visible() const override;
42+ QString shortcut() const override;
43+ bool searchInProgress() const override;
44+ unity::shell::scopes::CategoriesInterface* categories() const override;
45+ QString searchQuery() const override;
46+ QString noResultsHint() const override;
47+ QString formFactor() const override;
48+ bool isActive() const override;
6749
6850 /* setters */
69− void setName(const QString& name);
70− void setSearchQuery(const QString& search_query);
71− void setNoResultsHint(const QString& hint);
72− void setFormFactor(const QString& form_factor);
73− void setActive(const bool);
74− void setSearchInProgress(const bool inProg);
75−
76− Q_INVOKABLE void activate(QVariant const& result);
77− Q_INVOKABLE PreviewStack* preview(QVariant const& result);
78− Q_INVOKABLE void cancelActivation();
79− Q_INVOKABLE void closeScope(Scope* scope);
80−
81−Q_SIGNALS:
82− void idChanged();
83− void nameChanged(const QString&);
84− void iconHintChanged(const QString&);
85− void descriptionChanged(const QString&);
86− void searchHintChanged(const QString&);
87− void searchInProgressChanged();
88− void visibleChanged(bool);
89− void shortcutChanged(const QString&);
90− void categoriesChanged();
91− //void filtersChanged();
92− void searchQueryChanged();
93− void noResultsHintChanged();
94− void formFactorChanged();
95− void isActiveChanged(bool);
96−
97− // signals triggered by activate(..) or preview(..) requests.
98− void showDash();
99− void hideDash();
100− void gotoUri(const QString &uri);
101− void activated();
102− void previewRequested(QVariant const& result);
103− void gotoScope(QString const& scopeId);
104− void openScope(Scope* scope);
105−
106− void activateApplication(const QString &desktop);
51+ void setSearchQuery(const QString& search_query) override;
52+ void setNoResultsHint(const QString& hint) override;
53+ void setFormFactor(const QString& form_factor) override;
54+ void setActive(const bool) override;
55+ Q_INVOKABLE void setSearchInProgress(const bool inProg); // This is not invokable in the Interface, here for testing benefits
56+
57+ Q_INVOKABLE void activate(QVariant const& result) override;
58+ Q_INVOKABLE PreviewStack* preview(QVariant const& result) override;
59+ Q_INVOKABLE void cancelActivation() override;
60+ Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
10761
10862protected:
10963
tests/mocks/Unity/fake_scopes.cpp+11−22
@@ -25,15 +25,10 @@
2525#include <QTimer>
2626
2727Scopes::Scopes(QObject *parent)
28−: QAbstractListModel(parent)
29−, m_loaded(false)
30−, timer(this)
28+ : unity::shell::scopes::ScopesInterface(parent)
29+ , m_loaded(false)
30+ , timer(this)
3131{
32− m_roles[Scopes::RoleScope] = "scope";
33− m_roles[Scopes::RoleId] = "id";
34− m_roles[Scopes::RoleVisible] = "visible";
35− m_roles[Scopes::RoleTitle] = "title";
36−
3732 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
3833 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
3934 QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
@@ -83,11 +78,6 @@ void Scopes::load()
8378 timer.start();
8479}
8580
86−QHash<int, QByteArray> Scopes::roleNames() const
87−{
88− return m_roles;
89−}
90−
9181int Scopes::rowCount(const QModelIndex&) const
9282{
9383 return m_scopes.count();
@@ -114,14 +104,18 @@ QVariant Scopes::data(const QModelIndex& index, int role) const
114104 }
115105}
116106
117−QVariant Scopes::get(int row) const
107+unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
118108{
119− return data(QAbstractListModel::index(row), 0);
109+ if (row < 0 || row >= m_scopes.size()) {
110+ return nullptr;
111+ }
112+
113+ return m_scopes[row];
120114}
121115
122−QVariant Scopes::get(QString const&) const
116+unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const&) const
123117{
124− return QVariant();
118+ return nullptr;
125119}
126120
127121QModelIndex Scopes::parent(const QModelIndex&) const
@@ -134,11 +128,6 @@ bool Scopes::loaded() const
134128 return m_loaded;
135129}
136130
137−int Scopes::count() const
138−{
139− return rowCount();
140−}
141−
142131void Scopes::addScope(Scope* scope)
143132{
144133 int index = rowCount();
tests/mocks/Unity/fake_scopes.h+7−24
@@ -19,36 +19,27 @@
1919#ifndef FAKE_SCOPES_H
2020#define FAKE_SCOPES_H
2121
22+#include <unity/shell/scopes/ScopesInterface.h>
23+
2224// Local
2325#include "fake_scope.h"
2426
2527// Qt
26−#include <QAbstractListModel>
2728#include <QList>
2829#include <QTimer>
2930
30−class Scopes : public QAbstractListModel
31+class Scopes : public unity::shell::scopes::ScopesInterface
3132{
3233 Q_OBJECT
33− Q_ENUMS(Roles)
34− Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
35− Q_PROPERTY(int count READ count NOTIFY countChanged)
3634
3735public:
3836 explicit Scopes(QObject *parent = 0);
3937 ~Scopes();
4038
41− enum Roles {
42− RoleScope,
43− RoleId,
44− RoleVisible,
45− RoleTitle
46− };
47−
48− Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const;
39+ Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4940
50− Q_INVOKABLE QVariant get(int row) const;
51− Q_INVOKABLE QVariant get(const QString& scope_id) const;
41+ Q_INVOKABLE unity::shell::scopes::ScopeInterface* getScope(int row) const override;
42+ Q_INVOKABLE unity::shell::scopes::ScopeInterface* getScope(const QString& scope_id) const override;
5243
5344 Q_INVOKABLE void addScope(Scope* scope);
5445
@@ -56,23 +47,15 @@ public:
5647 Q_INVOKABLE void load();
5748
5849 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
59− QHash<int, QByteArray> roleNames() const;
6050 QModelIndex parent ( const QModelIndex & index ) const;
6151
62− bool loaded() const;
63− int count() const;
64−
65−Q_SIGNALS:
66− void activateScopeRequested(const QString& scope_id);
67− void loadedChanged(bool);
68− void countChanged();
52+ bool loaded() const override;
6953
7054private Q_SLOTS:
7155 void updateScopes();
7256
7357private:
7458 QList<Scope*> m_scopes;
75− QHash<int, QByteArray> m_roles;
7659 bool m_loaded;
7760 QTimer timer;
7861};
tests/mocks/Unity/fake_unity_plugin.cpp+3−2
@@ -40,8 +40,9 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4040 Q_ASSERT(uri == QLatin1String("Unity"));
4141
4242 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
43− qmlRegisterType<Scope>(uri, 0, 2, "Scope");
44− qmlRegisterUncreatableType<Categories>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
43+ qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
44+ qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
45+ qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4546 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
4647 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
4748 qmlRegisterUncreatableType<PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", "Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.");
tests/qmltests/Components/tst_PageHeaderLabel.qml+4−4
@@ -26,7 +26,7 @@ Item {
2626 width: units.gu(110)
2727 height: units.gu(30)
2828
29− Scope {
29+ MockScope {
3030 id: scopeMock
3131 }
3232
@@ -148,17 +148,17 @@ Item {
148148
149149 pageHeader.triggerSearch()
150150
151− scopeMock.searchInProgress = false
151+ scopeMock.setSearchInProgress(false);
152152 compare(searchIndicator.running, false, "Search indicator is running.")
153153 tryCompare(primaryImage, "visible", true)
154154
155− scopeMock.searchInProgress = true
155+ scopeMock.setSearchInProgress(true);
156156 compare(searchIndicator.running, true, "Search indicator isn't running.")
157157 tryCompare(primaryImage, "visible", false)
158158 }
159159
160160 function cleanup() {
161− scopeMock.searchInProgress = false;
161+ scopeMock.setSearchInProgress(false);
162162 pageHeader.resetSearch();
163163 }
164164
tests/qmltests/Dash/tst_DashContent.qml+5−5
@@ -166,7 +166,7 @@ Item {
166166
167167 // test greater than scope count.
168168 var currentScopeIndex = dashContent.currentIndex;
169− dashContent.setCurrentScopeAtIndex(scopesModel.count, true, false);
169+ dashContent.setCurrentScopeAtIndex(8, true, false);
170170 compare(dashContent.currentIndex, currentScopeIndex, "Scope should not change if changing to greater index than count");
171171 }
172172
@@ -195,7 +195,7 @@ Item {
195195 dashContent.setCurrentScopeAtIndex(data.index, true, false);
196196 tryCompareFunction(get_current_item_object_name, data.objectName)
197197 var pageHeader = findChild(dashContent, "pageHeader");
198− compare(pageHeader.scope, scopesModel.get(data.index));
198+ compare(pageHeader.scope, scopesModel.getScope(data.index));
199199 }
200200
201201 function test_is_active_data() {
@@ -212,9 +212,9 @@ Item {
212212 dashContent.setCurrentScopeAtIndex(data.select, true, false);
213213 dashContent.visible = data.visible;
214214
215− tryCompare(scopesModel.get(0), "isActive", data.active0);
216− tryCompare(scopesModel.get(1), "isActive", data.active1);
217− tryCompare(scopesModel.get(2), "isActive", data.active2);
215+ tryCompare(scopesModel.getScope(0), "isActive", data.active0);
216+ tryCompare(scopesModel.getScope(1), "isActive", data.active1);
217+ tryCompare(scopesModel.getScope(2), "isActive", data.active2);
218218 }
219219
220220 function doFindMusicButton(parent) {
tests/qmltests/Dash/tst_GenericScopeView.qml+10−10
@@ -39,7 +39,7 @@ Item {
3939 id: scopes
4040
4141 onLoadedChanged: {
42− genericScopeView.scope = scopes.get(2)
42+ genericScopeView.scope = scopes.getScope(2)
4343 }
4444 }
4545
@@ -67,7 +67,7 @@ Item {
6767 when: scopes.loaded && windowShown
6868
6969 function init() {
70− genericScopeView.scope = scopes.get(2)
70+ genericScopeView.scope = scopes.getScope(2)
7171 shell.width = units.gu(120)
7272 genericScopeView.categoryView.positionAtBeginning();
7373 tryCompare(genericScopeView.categoryView, "contentY", 0)
@@ -96,31 +96,31 @@ Item {
9696
9797 function test_showDash() {
9898 previewListView.open = true;
99− scopes.get(2).showDash();
99+ scopes.getScope(2).showDash();
100100 tryCompare(previewListView, "open", false);
101101 }
102102
103103 function test_hideDash() {
104104 previewListView.open = true;
105− scopes.get(2).hideDash();
105+ scopes.getScope(2).hideDash();
106106 tryCompare(previewListView, "open", false);
107107 }
108108
109109 function test_searchQuery() {
110− genericScopeView.scope = scopes.get(0);
110+ genericScopeView.scope = scopes.getScope(0);
111111 genericScopeView.scope.searchQuery = "test";
112− genericScopeView.scope = scopes.get(1);
112+ genericScopeView.scope = scopes.getScope(1);
113113 genericScopeView.scope.searchQuery = "test2";
114− genericScopeView.scope = scopes.get(0);
114+ genericScopeView.scope = scopes.getScope(0);
115115 tryCompare(genericScopeView.scope, "searchQuery", "test");
116− genericScopeView.scope = scopes.get(1);
116+ genericScopeView.scope = scopes.getScope(1);
117117 tryCompare(genericScopeView.scope, "searchQuery", "test2");
118118 }
119119
120120 function test_changeScope() {
121121 genericScopeView.scope.searchQuery = "test"
122− genericScopeView.scope = scopes.get(1)
123− genericScopeView.scope = scopes.get(2)
122+ genericScopeView.scope = scopes.getScope(1)
123+ genericScopeView.scope = scopes.getScope(2)
124124 tryCompare(genericScopeView.scope, "searchQuery", "test")
125125 }
126126