on xenial help sign in
Use the new unity-api
commit90b9f85b2f9860269e19073e810ea66c1c194b37 authorAlbert Astals <albert.astals@canonical.com> dateWed 28 May 2014, 16:59 (12 years ago) parentba99bef
7 files changed+16−58
tests/mocks/Unity/CMakeLists.txt+1 tests/mocks/Unity/fake_department.cpp+3−4 tests/mocks/Unity/fake_department.h+2−29 tests/mocks/Unity/fake_scope.cpp+3−3 tests/mocks/Unity/fake_scope.h+4−19 tests/mocks/Unity/fake_scopes.cpp+2−2 tests/mocks/Unity/fake_unity_plugin.cpp+1−1
tests/mocks/Unity/CMakeLists.txt+1
@@ -30,6 +30,7 @@ set(UnityQML_SOURCES
3030 fake_previewwidgetmodel.cpp
3131 fake_unity_plugin.cpp
3232 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
33+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/DepartmentInterface.h
3334 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
3435 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
3536 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
tests/mocks/Unity/fake_department.cpp+3−4
@@ -21,8 +21,7 @@
2121#include <QTimer>
2222
2323Department::Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope)
24− : QAbstractListModel()
25− , m_departmentId(departmentId)
24+ : m_departmentId(departmentId)
2625 , m_label(label)
2726 , m_allLabel(allLabel)
2827 , m_parentId(parentId)
@@ -31,7 +30,7 @@ Department::Department(const QString& departmentId, const QString& label, const
3130 , m_scope(scope)
3231{
3332 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
34− connect(scope, SIGNAL(currentDepartmentChanged(QString)), this, SLOT(slotCurrentDepartmentChanged()));
33+ connect(scope, SIGNAL(currentDepartmentChanged()), this, SLOT(slotCurrentDepartmentChanged()));
3534}
3635
3736QString Department::departmentId() const
@@ -62,7 +61,7 @@ QString Department::parentLabel() const
6261void Department::slotLoaded()
6362{
6463 m_loaded = true;
65− Q_EMIT loadedChanged(m_loaded);
64+ Q_EMIT loadedChanged();
6665}
6766
6867bool Department::loaded() const
tests/mocks/Unity/fake_department.h+2−29
@@ -17,34 +17,17 @@
1717#ifndef FAKE_DEPARTMENT_H
1818#define FAKE_DEPARTMENT_H
1919
20−#include <QAbstractListModel>
20+#include <unity/shell/scopes/DepartmentInterface.h>
2121
2222class Scope;
2323
24−class Department : public QAbstractListModel
24+class Department : public unity::shell::scopes::DepartmentInterface
2525{
2626 Q_OBJECT
2727
28− Q_PROPERTY(QString departmentId READ departmentId NOTIFY departmentIdChanged)
29− Q_PROPERTY(QString label READ label NOTIFY labelChanged)
30− Q_PROPERTY(QString allLabel READ allLabel NOTIFY allLabelChanged)
31− Q_PROPERTY(QString parentId READ parentId NOTIFY parentIdChanged)
32− Q_PROPERTY(QString parentLabel READ parentLabel NOTIFY parentLabelChanged)
33− Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
34− Q_PROPERTY(int count READ count NOTIFY countChanged)
35− Q_PROPERTY(bool isRoot READ isRoot NOTIFY isRootChanged)
36− // roles: string departmentId, string label, bool hasChildren, bool isActive
37−
3828public:
3929 Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope);
4030
41− enum Roles {
42− RoleDepartmentId,
43− RoleLabel,
44− RoleHasChildren,
45− RoleIsActive
46− };
47−
4831 QString departmentId() const;
4932 QString label() const;
5033 QString allLabel() const;
@@ -61,16 +44,6 @@ public:
6144public Q_SLOTS:
6245 void slotCurrentDepartmentChanged();
6346
64−Q_SIGNALS:
65− void departmentIdChanged(const QString&);
66− void labelChanged(const QString&);
67− void allLabelChanged(const QString&);
68− void parentIdChanged(const QString&);
69− void parentLabelChanged(const QString&);
70− void loadedChanged(bool);
71− void countChanged(int);
72− void isRootChanged(bool);
73−
7447private Q_SLOTS:
7548 void slotLoaded();
7649
tests/mocks/Unity/fake_scope.cpp+3−3
@@ -104,7 +104,7 @@ void Scope::setFormFactor(const QString &str) {
104104void Scope::setActive(const bool active) {
105105 if (active != m_isActive) {
106106 m_isActive = active;
107− Q_EMIT isActiveChanged(active);
107+ Q_EMIT isActiveChanged();
108108 }
109109}
110110
@@ -155,7 +155,7 @@ bool Scope::hasDepartments() const
155155 return true;
156156}
157157
158−Department *Scope::getDepartment(const QString& id)
158+unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
159159{
160160 if (id.isEmpty())
161161 return nullptr;
@@ -175,5 +175,5 @@ Department *Scope::getDepartment(const QString& id)
175175void Scope::loadDepartment(const QString& id)
176176{
177177 m_currentDeparment = id;
178− currentDepartmentChanged(m_currentDeparment);
178+ Q_EMIT currentDepartmentChanged();
179179}
tests/mocks/Unity/fake_scope.h+4−19
@@ -29,13 +29,6 @@ class Preview;
2929
3030class Scope : public unity::shell::scopes::ScopeInterface
3131{
32−// TODO
33− Q_OBJECT
34−
35− Q_PROPERTY(QString currentDepartment READ currentDepartment NOTIFY currentDepartmentChanged)
36− Q_PROPERTY(bool hasDepartments READ hasDepartments NOTIFY hasDepartmentsChanged)
37−// END TODO
38−
3932public:
4033 Scope(QObject* parent = 0);
4134 Scope(QString const& id, QString const& name, bool visible, QObject* parent = 0);
@@ -67,18 +60,10 @@ public:
6760 Q_INVOKABLE void cancelActivation() override;
6861 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
6962
70− // TODO this will go to unity-api eventually
71− QString currentDepartment() const;
72− bool hasDepartments() const;
73− Q_INVOKABLE Department *getDepartment(const QString& id); // returns a Department with lazy-loaded children
74− Q_INVOKABLE void loadDepartment(const QString& id); // loads results for the department
75− // END TODO
76−
77−Q_SIGNALS:
78− // TODO this will go to unity-api eventually
79− void currentDepartmentChanged(const QString&);
80− void hasDepartmentsChanged(bool);
81− // END TODO
63+ QString currentDepartment() 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;
8267
8368protected:
8469
tests/mocks/Unity/fake_scopes.cpp+2−2
@@ -53,7 +53,7 @@ void Scopes::updateScopes()
5353
5454 if (!m_loaded) {
5555 m_loaded = true;
56− Q_EMIT loadedChanged(m_loaded);
56+ Q_EMIT loadedChanged();
5757 }
5858}
5959
@@ -69,7 +69,7 @@ void Scopes::clear()
6969
7070 if (m_loaded) {
7171 m_loaded = false;
72− Q_EMIT loadedChanged(m_loaded);
72+ Q_EMIT loadedChanged();
7373 }
7474}
7575
tests/mocks/Unity/fake_unity_plugin.cpp+1−1
@@ -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<Department>(uri, 0, 2, "Department", "Can't create Department object in QML.");
46+ qmlRegisterUncreatableType<unity::shell::scopes::DepartmentInterface>(uri, 0, 2, "Department", "Can't create Department object in QML.");
4747 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4848 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
4949 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");