on xenial help sign in
Make the mock compile

Altnavigation is still untested/unimplemented in the qml side

commit3f644ceb9bae14f4dc727d634166271e1247e1b6 authorAlbert Astals <albert.astals@canonical.com> dateFri 1 Aug 2014, 17:28 (12 years ago) parentb9916d3
12 files changed+164−101
qml/Dash/Dash.qml+9−11 qml/Dash/DashContent.qml+1−3 qml/Dash/DashDepartments.qml+1−1 qml/Dash/DashDepartmentsList.qml+1−1 tests/mocks/Unity/CMakeLists.txt+2−2 tests/mocks/Unity/fake_department.cpp → tests/mocks/Unity/fake_navigation.cpp+44−40 tests/mocks/Unity/fake_department.h → tests/mocks/Unity/fake_navigation.h+15−13 tests/mocks/Unity/fake_scope.cpp+64−17 tests/mocks/Unity/fake_scope.h+14−9 tests/mocks/Unity/fake_scopes.cpp+10−2 tests/mocks/Unity/fake_scopes.h+1 tests/mocks/Unity/fake_unity_plugin.cpp+2−2
qml/Dash/Dash.qml+9−11
@@ -30,7 +30,13 @@ Showable {
3030 property real contentScale: 1.0
3131
3232 function setCurrentScope(scopeId, animate, reset) {
33− var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId)
33+ var scopeIndex = -1;
34+ for (var i = 0; i < scopes.count; ++i) {
35+ if (scopes.getScope(i).id == scopeId) {
36+ scopeIndex = i;
37+ break;
38+ }
39+ }
3440
3541 if (scopeIndex == -1) {
3642 console.warn("No match for scope with id: %1".arg(scopeId))
@@ -55,15 +61,8 @@ Showable {
5561 }
5662 }
5763
58− SortFilterProxyModel {
59− id: filteredScopes
60− model: Scopes {
61− id: scopes
62− }
63− dynamicSortFilter: true
64−
65− filterRole: Scopes.RoleVisible
66− filterRegExp: RegExp("^true$")
64+ Scopes {
65+ id: scopes
6766 }
6867
6968 DashContent {
@@ -71,7 +70,6 @@ Showable {
7170 objectName: "dashContent"
7271 width: parent.width
7372 height: parent.height
74− model: filteredScopes
7573 scopes: scopes
7674 visible: x != -width
7775 onGotoScope: {
qml/Dash/DashContent.qml+1−3
@@ -23,8 +23,7 @@ import "../Components"
2323Item {
2424 id: dashContent
2525
26− property var model: null
27− property var scopes: null
26+ property alias scopes: dashContentList.model
2827 readonly property alias currentIndex: dashContentList.currentIndex
2928
3029 signal scopeLoaded(string scopeId)
@@ -92,7 +91,6 @@ Item {
9291 interactive: dashContent.scopes.loaded && currentItem && !currentItem.moving
9392
9493 anchors.fill: parent
95− model: dashContent.model
9694 orientation: ListView.Horizontal
9795 boundsBehavior: Flickable.DragAndOvershootBounds
9896 flickDeceleration: units.gu(625)
qml/Dash/DashDepartments.qml+1−1
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.2
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
1919
2020AbstractButton {
2121 id: root
qml/Dash/DashDepartmentsList.qml+1−1
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.2
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
1919
2020Item {
2121 id: root
tests/mocks/Unity/CMakeLists.txt+2−2
@@ -22,14 +22,14 @@ set(UnityQML_SOURCES
2222 fake_scope.cpp
2323 fake_scopes.cpp
2424 fake_categories.cpp
25− fake_department.cpp
25+ fake_navigation.cpp
2626 fake_resultsmodel.cpp
2727 fake_previewmodel.cpp
2828 fake_previewstack.cpp
2929 fake_previewwidgetmodel.cpp
3030 fake_unity_plugin.cpp
3131 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
32− ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/DepartmentInterface.h
32+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/NavigationInterface.h
3333 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
3434 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
3535 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
tests/mocks/Unity/fake_department.cpp → tests/mocks/Unity/fake_navigation.cpprenamed+44−40
@@ -14,14 +14,15 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include "fake_department.h"
17+#include "fake_navigation.h"
1818
1919#include "fake_scope.h"
2020
21+#include <QDebug>
2122#include <QTimer>
2223
23−Department::Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope)
24− : m_departmentId(departmentId)
24+Navigation::Navigation(const QString& navigationId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope)
25+ : m_navigationId(navigationId)
2526 , m_label(label)
2627 , m_allLabel(allLabel)
2728 , m_parentId(parentId)
@@ -30,96 +31,99 @@ Department::Department(const QString& departmentId, const QString& label, const
3031 , m_scope(scope)
3132{
3233 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
33− connect(scope, SIGNAL(currentDepartmentIdChanged()), this, SLOT(slotCurrentDepartmentChanged()));
34+ connect(scope, SIGNAL(currentNavigationIdChanged()), this, SLOT(slotCurrentNavigationChanged()));
3435}
3536
36−QString Department::departmentId() const
37+QString Navigation::navigationId() const
3738{
38− return m_departmentId;
39+ return m_navigationId;
3940}
4041
41−QString Department::label() const
42+QString Navigation::query() const
43+{
44+ return "navigation:/" + m_navigationId;
45+}
46+
47+QString Navigation::label() const
4248{
4349 return m_label;
4450}
4551
46−QString Department::allLabel() const
52+QString Navigation::allLabel() const
4753{
4854 return m_allLabel;
4955}
5056
51−QString Department::parentDepartmentId() const
57+QString Navigation::parentNavigationId() const
5258{
5359 return m_parentId;
5460}
5561
56−QString Department::parentLabel() const
62+QString Navigation::parentQuery() const
63+{
64+ return "navigation:/" + m_parentId;
65+}
66+
67+QString Navigation::parentLabel() const
5768{
5869 return m_parentLabel;
5970}
6071
61−void Department::slotLoaded()
72+void Navigation::slotLoaded()
6273{
6374 m_loaded = true;
6475 Q_EMIT loadedChanged();
6576}
6677
67−bool Department::loaded() const
78+bool Navigation::loaded() const
6879{
6980 return m_loaded;
7081}
7182
72−int Department::count() const
83+int Navigation::count() const
7384{
7485 return rowCount();
7586}
7687
77−bool Department::isRoot() const
88+bool Navigation::isRoot() const
7889{
79− return m_departmentId == "root";
90+ return m_navigationId == "root" || m_navigationId == "altroot";
8091}
8192
82−int Department::rowCount(const QModelIndex & /*parent*/) const
93+bool Navigation::hidden() const
8394{
84− if (!m_loaded || m_departmentId.startsWith("child") || m_departmentId == "middle3")
85− return 0;
86− else
87− return 8;
95+ return m_navigationId == "altroot";
8896}
8997
90−QHash<int, QByteArray> Department::roleNames() const
98+int Navigation::rowCount(const QModelIndex & /*parent*/) const
9199{
92− QHash<int, QByteArray> res;
93− res[RoleDepartmentId] = "departmentId";
94− res[RoleLabel] = "label";
95− res[RoleHasChildren] = "hasChildren";
96− res[RoleIsActive] = "isActive";
97− return res;
100+ if (!m_loaded || m_navigationId.startsWith("child") || m_navigationId == "middle3")
101+ return 0;
102+ else
103+ return 8;
98104}
99105
100−QVariant Department::data(const QModelIndex &index, int role) const
106+QVariant Navigation::data(const QModelIndex &index, int role) const
101107{
102108 switch (role) {
103− case RoleDepartmentId:
104− if (m_departmentId == "root")
109+ case RoleQuery:
110+ return QString("navigation:/%1").arg(data(index, RoleNavigationId).toString());
111+ case RoleNavigationId:
112+ if (m_navigationId == "root")
105113 return QString("middle%1").arg(index.row());
106− else if (m_departmentId.startsWith("middle"))
107− return QString("child%1%2").arg(m_departmentId).arg(index.row());
108− break;
114+ else if (m_navigationId.startsWith("middle"))
115+ return QString("child%1%2").arg(m_navigationId).arg(index.row());
109116 case RoleLabel:
110− return QString("%1Child%2").arg(m_departmentId).arg(index.row());
111− break;
117+ return QString("%1Child%2").arg(m_navigationId).arg(index.row());
112118 case RoleHasChildren:
113− return m_departmentId == "root" && index.row() != 3;
114− break;
119+ return m_navigationId == "root" && index.row() != 3;
115120 case RoleIsActive:
116− return m_scope->currentDepartmentId() == data(index, RoleDepartmentId);
117− break;
121+ return m_scope->currentNavigationId() == data(index, RoleNavigationId);
118122 }
119123 return QVariant();
120124}
121125
122−void Department::slotCurrentDepartmentChanged()
126+void Navigation::slotCurrentNavigationChanged()
123127{
124128 // This is wasteful, should only emit it if really something changed in this
125129 // deparment, but this is a mock, so no need to optimize
tests/mocks/Unity/fake_department.h → tests/mocks/Unity/fake_navigation.hrenamed+15−13
@@ -14,48 +14,50 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef FAKE_DEPARTMENT_H
18−#define FAKE_DEPARTMENT_H
17+#ifndef FAKE_NAVIGATION_H
18+#define FAKE_NAVIGATION_H
1919
20−#include <unity/shell/scopes/DepartmentInterface.h>
20+#include <unity/shell/scopes/NavigationInterface.h>
2121
2222class Scope;
2323
24−class Department : public unity::shell::scopes::DepartmentInterface
24+class Navigation : public unity::shell::scopes::NavigationInterface
2525{
2626 Q_OBJECT
2727
2828public:
29− Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope);
29+ Navigation(const QString& navigationId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope);
3030
31− QString departmentId() const override;
31+ QString navigationId() const override;
32+ QString query() const override;
3233 QString label() const override;
3334 QString allLabel() const override;
34− QString parentDepartmentId() const override;
35+ QString parentNavigationId() const override;
36+ QString parentQuery() const override;
3537 QString parentLabel() const override;
3638 bool loaded() const override;
37− int count() const override;
3839 bool isRoot() const override;
40+ bool hidden() const override;
41+ int count() const override;
3942
4043 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
41− QHash<int, QByteArray> roleNames() const;
4244 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
4345
4446public Q_SLOTS:
45− void slotCurrentDepartmentChanged();
47+ void slotCurrentNavigationChanged();
4648
4749private Q_SLOTS:
4850 void slotLoaded();
4951
5052private:
51− QString m_departmentId;
53+ QString m_navigationId;
5254 QString m_label;
5355 QString m_allLabel;
5456 QString m_parentId;
5557 QString m_parentLabel;
5658 bool m_loaded;
57− QString m_currentDepartment;
59+ QString m_currentNavigation;
5860 Scope *m_scope;
5961};
6062
61−#endif // FAKE_DEPARTMENT_H
63+#endif // FAKE_NAVIGATION_H
tests/mocks/Unity/fake_scope.cpp+64−17
@@ -14,24 +14,26 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17+#include <QDebug>
1718#include <QUrl>
1819
1920#include "fake_scope.h"
20−#include "fake_department.h"
21+#include "fake_navigation.h"
2122#include "fake_resultsmodel.h"
2223
2324Scope::Scope(QObject* parent) : Scope(QString(), QString(), false, parent)
2425{
2526}
2627
27−Scope::Scope(QString const& id, QString const& name, bool visible, QObject* parent, int categories)
28+Scope::Scope(QString const& id, QString const& name, bool favorite, QObject* parent, int categories)
2829 : unity::shell::scopes::ScopeInterface(parent)
2930 , m_id(id)
3031 , m_name(name)
31− , m_visible(visible)
3232 , m_searching(false)
33+ , m_favorite(favorite)
3334 , m_isActive(false)
34− , m_currentDeparment("root")
35+ , m_currentNavigationId("root")
36+ , m_currentAltNavigationId("altroot")
3537 , m_previewRendererName("preview-generic")
3638 , m_categories(new Categories(categories, this))
3739{
@@ -77,6 +79,11 @@ bool Scope::searchInProgress() const
7779 return m_searching;
7880}
7981
82+bool Scope::favorite() const
83+{
84+ return m_favorite;
85+}
86+
8087unity::shell::scopes::CategoriesInterface* Scope::categories() const
8188{
8289 return m_categories;
@@ -97,11 +104,6 @@ QString Scope::formFactor() const
97104 return m_formFactor;
98105}
99106
100−bool Scope::visible() const
101−{
102− return m_visible;
103−}
104−
105107bool Scope::isActive() const
106108{
107109 return m_isActive;
@@ -131,6 +133,13 @@ void Scope::setActive(const bool active)
131133 }
132134}
133135
136+void Scope::setFavorite(const bool favorite)
137+{
138+ if (favorite != m_favorite) {
139+ m_favorite = favorite;
140+ Q_EMIT favoriteChanged();
141+ }
142+}
134143void Scope::setSearchInProgress(const bool inProg)
135144{
136145 if (inProg != m_searching) {
@@ -170,16 +179,31 @@ void Scope::closeScope(unity::shell::scopes::ScopeInterface* /*scope*/)
170179 qFatal("Scope::closeScope is not implemented");
171180}
172181
173−QString Scope::currentDepartmentId() const
182+QString Scope::currentNavigationId() const
174183{
175− return m_currentDeparment;
184+ return m_currentNavigationId;
176185}
177186
178−bool Scope::hasDepartments() const
187+bool Scope::hasNavigation() const
179188{
180189 return true;
181190}
182191
192+QString Scope::currentAltNavigationId() const
193+{
194+ return m_currentAltNavigationId;
195+}
196+
197+bool Scope::hasAltNavigation() const
198+{
199+ return true;
200+}
201+
202+Scope::Status Scope::status() const
203+{
204+ return Status::Okay;
205+}
206+
183207QVariantMap Scope::customizations() const
184208{
185209 QVariantMap m, h;
@@ -196,7 +220,7 @@ QVariantMap Scope::customizations() const
196220 return m;
197221}
198222
199−unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
223+unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
200224{
201225 if (id.isEmpty())
202226 return nullptr;
@@ -210,11 +234,34 @@ unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& i
210234 parentId = id.mid(5, 7);
211235 parentLabel = parentId;
212236 }
213− return new Department(id, id, "all"+id, parentId, parentLabel, this);
237+ return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
238+}
239+
240+unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const& id)
241+{
242+ if (id.isEmpty())
243+ return nullptr;
244+
245+ QString parentId;
246+ QString parentLabel;
247+ if (id.startsWith("altmiddle")) {
248+ parentId = "altroot";
249+ parentLabel = "altroot";
250+ }
251+ return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
214252}
215253
216−void Scope::loadDepartment(const QString& id)
254+void Scope::performQuery(const QString& query)
217255{
218− m_currentDeparment = id;
219− Q_EMIT currentDepartmentIdChanged();
256+ if (query.startsWith("navigation:/")) {
257+ QString navigationId = query;
258+ navigationId.remove(0, QString("navigation:/").length());
259+ if (navigationId.startsWith("alt")) {
260+ m_currentAltNavigationId = navigationId;
261+ Q_EMIT currentAltNavigationIdChanged();
262+ } else {
263+ m_currentNavigationId = navigationId;
264+ Q_EMIT currentNavigationIdChanged();
265+ }
266+ }
220267}
tests/mocks/Unity/fake_scope.h+14−9
@@ -30,7 +30,7 @@ class Scope : public unity::shell::scopes::ScopeInterface
3030
3131public:
3232 Scope(QObject* parent = 0);
33− Scope(QString const& id, QString const& name, bool visible, QObject* parent = 0, int categories = 20);
33+ Scope(QString const& id, QString const& name, bool favorite, QObject* parent = 0, int categories = 20);
3434
3535 /* getters */
3636 QString id() const override;
@@ -38,9 +38,9 @@ public:
3838 QString iconHint() const override;
3939 QString description() const override;
4040 QString searchHint() const override;
41− bool visible() const override;
4241 QString shortcut() const override;
4342 bool searchInProgress() const override;
43+ bool favorite() const override;
4444 unity::shell::scopes::CategoriesInterface* categories() const override;
4545 QString searchQuery() const override;
4646 QString noResultsHint() const override;
@@ -53,6 +53,7 @@ public:
5353 void setNoResultsHint(const QString& hint) override;
5454 void setFormFactor(const QString& form_factor) override;
5555 void setActive(const bool) override;
56+ void setFavorite(const bool) override;
5657 Q_INVOKABLE void setSearchInProgress(const bool inProg); // This is not invokable in the Interface, here for testing benefits
5758
5859 Q_INVOKABLE void activate(QVariant const& result) override;
@@ -60,12 +61,15 @@ public:
6061 Q_INVOKABLE void cancelActivation() override;
6162 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
6263
63− QString currentDepartmentId() const override;
64− bool hasDepartments() const override;
65− Q_INVOKABLE unity::shell::scopes::DepartmentInterface* getDepartment(const QString& id) override;
66− Q_INVOKABLE void loadDepartment(const QString& id) override;
67− Q_SIGNAL void performQuery(const QString& query) override;
64+ QString currentNavigationId() const override;
65+ bool hasNavigation() const override;
66+ QString currentAltNavigationId() const override;
67+ bool hasAltNavigation() const override;
68+ Q_INVOKABLE unity::shell::scopes::NavigationInterface* getNavigation(QString const& navigationId) override;
69+ Q_INVOKABLE unity::shell::scopes::NavigationInterface* getAltNavigation(QString const& altNavigationId) override;
70+ Q_INVOKABLE void performQuery(const QString& query) override;
6871
72+ Status status() const override;
6973 QVariantMap customizations() const override;
7074
7175protected:
@@ -77,10 +81,11 @@ protected:
7781 QString m_searchQuery;
7882 QString m_noResultsHint;
7983 QString m_formFactor;
80− bool m_visible;
8184 bool m_searching;
85+ bool m_favorite;
8286 bool m_isActive;
83− QString m_currentDeparment;
87+ QString m_currentNavigationId;
88+ QString m_currentAltNavigationId;
8489
8590 QString m_previewRendererName;
8691
tests/mocks/Unity/fake_scopes.cpp+10−2
@@ -32,6 +32,11 @@ Scopes::Scopes(QObject *parent)
3232 timer.setSingleShot(true);
3333 timer.setInterval(100);
3434 QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateScopes()));
35+
36+ QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
37+ QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
38+ QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
39+
3540 load();
3641}
3742
@@ -92,8 +97,6 @@ QVariant Scopes::data(const QModelIndex& index, int role) const
9297 return QVariant::fromValue(scope);
9398 } else if (role == Scopes::RoleId) {
9499 return QVariant::fromValue(scope->id());
95− } else if (role == Scopes::RoleVisible) {
96− return QVariant::fromValue(scope->visible());
97100 } else if (role == Scopes::RoleTitle) {
98101 return QVariant::fromValue(scope->name());
99102 } else {
@@ -125,6 +128,11 @@ bool Scopes::loaded() const
125128 return m_loaded;
126129}
127130
131+int Scopes::count() const
132+{
133+ return rowCount();
134+}
135+
128136unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
129137{
130138 return nullptr;
tests/mocks/Unity/fake_scopes.h+1
@@ -50,6 +50,7 @@ public:
5050 QModelIndex parent ( const QModelIndex & index ) const;
5151
5252 bool loaded() const override;
53+ int count() const override;
5354 unity::shell::scopes::ScopeInterface* overviewScope() const override;
5455
5556private Q_SLOTS:
tests/mocks/Unity/fake_unity_plugin.cpp+2−2
@@ -22,7 +22,7 @@
2222// local
2323#include "fake_scopes.h"
2424#include "fake_categories.h"
25−#include "fake_department.h"
25+#include "fake_navigation.h"
2626#include "fake_previewmodel.h"
2727#include "fake_previewwidgetmodel.h"
2828#include "fake_resultsmodel.h"
@@ -43,7 +43,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4343 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
4444 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
4545 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
46− qmlRegisterUncreatableType<unity::shell::scopes::DepartmentInterface>(uri, 0, 2, "Department", "Can't create Department object in QML.");
46+ qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
4747 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4848 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
4949 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");