on xenial help sign in
Use the new unity-api
90b9f85Albert Astals
tests/mocks/Unity/CMakeLists.txt+1
@@ -30,6 +30,7 @@ set(UnityQML_SOURCES
30 fake_previewwidgetmodel.cpp
30 fake_previewwidgetmodel.cpp
31 fake_unity_plugin.cpp
31 fake_unity_plugin.cpp
32 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
32 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
33+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/DepartmentInterface.h
33 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
34 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
34 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
35 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
35 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
36 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
tests/mocks/Unity/fake_department.cpp+3−4
@@ -21,8 +21,7 @@
21#include <QTimer>
21#include <QTimer>
22
22
23Department::Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope)
23Department::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)
26 , m_label(label)
25 , m_label(label)
27 , m_allLabel(allLabel)
26 , m_allLabel(allLabel)
28 , m_parentId(parentId)
27 , m_parentId(parentId)
@@ -31,7 +30,7 @@ Department::Department(const QString& departmentId, const QString& label, const
31 , m_scope(scope)
30 , m_scope(scope)
32{
31{
33 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
32 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
34− connect(scope, SIGNAL(currentDepartmentChanged(QString)), this, SLOT(slotCurrentDepartmentChanged()));
33+ connect(scope, SIGNAL(currentDepartmentChanged()), this, SLOT(slotCurrentDepartmentChanged()));
35}
34}
36
35
37QString Department::departmentId() const
36QString Department::departmentId() const
@@ -62,7 +61,7 @@ QString Department::parentLabel() const
62void Department::slotLoaded()
61void Department::slotLoaded()
63{
62{
64 m_loaded = true;
63 m_loaded = true;
65− Q_EMIT loadedChanged(m_loaded);
64+ Q_EMIT loadedChanged();
66}
65}
67
66
68bool Department::loaded() const
67bool Department::loaded() const
tests/mocks/Unity/fake_department.h+2−29
@@ -17,34 +17,17 @@
17#ifndef FAKE_DEPARTMENT_H
17#ifndef FAKE_DEPARTMENT_H
18#define FAKE_DEPARTMENT_H
18#define FAKE_DEPARTMENT_H
19
19
20−#include <QAbstractListModel>
20+#include <unity/shell/scopes/DepartmentInterface.h>
21
21
22class Scope;
22class Scope;
23
23
24−class Department : public QAbstractListModel
24+class Department : public unity::shell::scopes::DepartmentInterface
25{
25{
26 Q_OBJECT
26 Q_OBJECT
27
27
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−
38public:
28public:
39 Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope);
29 Department(const QString& departmentId, const QString& label, const QString& allLabel, const QString& parentId, const QString& parentLabel, Scope* scope);
40
30
41− enum Roles {
42− RoleDepartmentId,
43− RoleLabel,
44− RoleHasChildren,
45− RoleIsActive
46− };
47−
48 QString departmentId() const;
31 QString departmentId() const;
49 QString label() const;
32 QString label() const;
50 QString allLabel() const;
33 QString allLabel() const;
@@ -61,16 +44,6 @@ public:
61public Q_SLOTS:
44public Q_SLOTS:
62 void slotCurrentDepartmentChanged();
45 void slotCurrentDepartmentChanged();
63
46
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−
74private Q_SLOTS:
47private Q_SLOTS:
75 void slotLoaded();
48 void slotLoaded();
76
49
tests/mocks/Unity/fake_scope.cpp+3−3
@@ -104,7 +104,7 @@ void Scope::setFormFactor(const QString &str) {
104void Scope::setActive(const bool active) {
104void Scope::setActive(const bool active) {
105 if (active != m_isActive) {
105 if (active != m_isActive) {
106 m_isActive = active;
106 m_isActive = active;
107− Q_EMIT isActiveChanged(active);
107+ Q_EMIT isActiveChanged();
108 }
108 }
109}
109}
110
110
@@ -155,7 +155,7 @@ bool Scope::hasDepartments() const
155 return true;
155 return true;
156}
156}
157
157
158−Department *Scope::getDepartment(const QString& id)
158+unity::shell::scopes::DepartmentInterface* Scope::getDepartment(const QString& id)
159{
159{
160 if (id.isEmpty())
160 if (id.isEmpty())
161 return nullptr;
161 return nullptr;
@@ -175,5 +175,5 @@ Department *Scope::getDepartment(const QString& id)
175void Scope::loadDepartment(const QString& id)
175void Scope::loadDepartment(const QString& id)
176{
176{
177 m_currentDeparment = id;
177 m_currentDeparment = id;
178− currentDepartmentChanged(m_currentDeparment);
178+ Q_EMIT currentDepartmentChanged();
179}
179}
tests/mocks/Unity/fake_scope.h+4−19
@@ -29,13 +29,6 @@ class Preview;
29
29
30class Scope : public unity::shell::scopes::ScopeInterface
30class Scope : public unity::shell::scopes::ScopeInterface
31{
31{
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−
39public:
32public:
40 Scope(QObject* parent = 0);
33 Scope(QObject* parent = 0);
41 Scope(QString const& id, QString const& name, bool visible, QObject* parent = 0);
34 Scope(QString const& id, QString const& name, bool visible, QObject* parent = 0);
@@ -67,18 +60,10 @@ public:
67 Q_INVOKABLE void cancelActivation() override;
60 Q_INVOKABLE void cancelActivation() override;
68 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
61 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
69
62
70− // TODO this will go to unity-api eventually
71− QString currentDepartment() const;
63+ QString currentDepartment() const override;
72− bool hasDepartments() const;
64+ bool hasDepartments() const override;
73− Q_INVOKABLE Department *getDepartment(const QString& id); // returns a Department with lazy-loaded children
65+ Q_INVOKABLE unity::shell::scopes::DepartmentInterface* getDepartment(const QString& id) override;
74− Q_INVOKABLE void loadDepartment(const QString& id); // loads results for the department
66+ Q_INVOKABLE void loadDepartment(const QString& id) override;
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
82
67
83protected:
68protected:
84
69
tests/mocks/Unity/fake_scopes.cpp+2−2
@@ -53,7 +53,7 @@ void Scopes::updateScopes()
53
53
54 if (!m_loaded) {
54 if (!m_loaded) {
55 m_loaded = true;
55 m_loaded = true;
56− Q_EMIT loadedChanged(m_loaded);
56+ Q_EMIT loadedChanged();
57 }
57 }
58}
58}
59
59
@@ -69,7 +69,7 @@ void Scopes::clear()
69
69
70 if (m_loaded) {
70 if (m_loaded) {
71 m_loaded = false;
71 m_loaded = false;
72− Q_EMIT loadedChanged(m_loaded);
72+ Q_EMIT loadedChanged();
73 }
73 }
74}
74}
75
75
tests/mocks/Unity/fake_unity_plugin.cpp+1−1
@@ -43,7 +43,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
43 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
43 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
44 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
44 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
45 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
45 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.");
47 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
47 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
48 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
48 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
49 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
49 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");