on xenial help sign in
Adapt to new api
commite671b827f6dee6507e509e2dd8c34c0f1d43b9cf authorAlbert Astals <albert.astals@canonical.com> dateMon 19 May 2014, 13:10 (12 years ago) parent8952dae
17 files changed+41−58
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/fake_previewstack.cpp+1−1 tests/mocks/Unity/fake_previewstack.h+1−1 tests/mocks/Unity/fake_resultsmodel.cpp−17 tests/mocks/Unity/fake_resultsmodel.h−2 tests/mocks/Unity/fake_scopes.cpp+8−4 tests/mocks/Unity/fake_scopes.h+2−2 tests/mocks/Unity/fake_unity_plugin.cpp+1−1 tests/qmltests/Dash/tst_DashContent.qml+4−4 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
@@ -43,8 +43,8 @@ DashRenderer {
4343 cacheBuffer: 1404 // 18px * 13gu * 6
4444 model: cardCarousel.model
4545
46− onClicked: cardCarousel.clicked(index, itemY)
47− onPressAndHold: cardCarousel.pressAndHold(index, itemY)
46+ onClicked: cardCarousel.clicked(index, null)
47+ onPressAndHold: cardCarousel.pressAndHold(index)
4848
4949 property real fontScale: 1 / selectedItemScaleFactor
5050 property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
qml/Dash/CardFilterGrid.qml+2−2
@@ -62,8 +62,8 @@ DashRenderer {
6262
6363 headerAlignment: cardTool.headerAlignment
6464
65− onClicked: genericFilterGrid.clicked(index, card.y)
66− onPressAndHold: genericFilterGrid.pressAndHold(index, card.y)
65+ onClicked: genericFilterGrid.clicked(index, result)
66+ onPressAndHold: genericFilterGrid.pressAndHold(index)
6767 }
6868 }
6969 }
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/fake_previewstack.cpp+1−1
@@ -48,7 +48,7 @@ int PreviewStack::rowCount(const QModelIndex&) const
4848 return m_previews.size();
4949}
5050
51−unity::shell::scopes::PreviewModelInterface* PreviewStack::get(int index) const
51+unity::shell::scopes::PreviewModelInterface* PreviewStack::getPreviewModel(int index) const
5252{
5353 if (index >= m_previews.size()) {
5454 return nullptr;
tests/mocks/Unity/fake_previewstack.h+1−1
@@ -36,7 +36,7 @@ public:
3636 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
3737 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
3838
39− Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* get(int index) const override;
39+ Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* getPreviewModel(int index) const override;
4040
4141 void setWidgetColumnCount(int columnCount) override;
4242 int widgetColumnCount() const override;
tests/mocks/Unity/fake_resultsmodel.cpp−17
@@ -51,23 +51,6 @@ int ResultsModel::count() const
5151 return rowCount();
5252}
5353
54−QVariant ResultsModel::get(int row) const
55−{
56− if (row >= m_result_count || row < 0) return QVariantMap();
57−
58− QVariantMap result;
59− QModelIndex modelIndex(index(row));
60− QHashIterator<int, QByteArray> it(roleNames());
61− while (it.hasNext()) {
62− it.next();
63− QVariant val(data(modelIndex, it.key()));
64− if (val.isNull()) continue;
65− result[it.value()] = val;
66− }
67−
68− return result;
69−}
70−
7154QVariant
7255ResultsModel::data(const QModelIndex& index, int role) const
7356{
tests/mocks/Unity/fake_resultsmodel.h−2
@@ -33,8 +33,6 @@ public:
3333 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
3434 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
3535
36− Q_INVOKABLE QVariant get(int row) const override;
37−
3836 /* getters */
3937 QString categoryId() const override;
4038 int count() const override;
tests/mocks/Unity/fake_scopes.cpp+8−4
@@ -104,14 +104,18 @@ QVariant Scopes::data(const QModelIndex& index, int role) const
104104 }
105105}
106106
107−QVariant Scopes::get(int row) const
107+unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
108108{
109− return data(QAbstractListModel::index(row), 0);
109+ if (row < 0 || row >= m_scopes.size()) {
110+ return nullptr;
111+ }
112+
113+ return m_scopes[row];
110114}
111115
112−QVariant Scopes::get(QString const&) const
116+unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const&) const
113117{
114− return QVariant();
118+ return nullptr;
115119}
116120
117121QModelIndex Scopes::parent(const QModelIndex&) const
tests/mocks/Unity/fake_scopes.h+2−2
@@ -38,8 +38,8 @@ public:
3838
3939 Q_INVOKABLE int rowCount(const QModelIndex& parent = QModelIndex()) const override;
4040
41− Q_INVOKABLE QVariant get(int row) const override;
42− Q_INVOKABLE QVariant get(const QString& scope_id) const override;
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;
4343
4444 Q_INVOKABLE void addScope(Scope* scope);
4545
tests/mocks/Unity/fake_unity_plugin.cpp+1−1
@@ -40,7 +40,7 @@ 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");
43+ qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
4444 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
4545 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
4646 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
tests/qmltests/Dash/tst_DashContent.qml+4−4
@@ -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