on xenial help sign in
Patching in single-preview
commit19ea80edb0d184352717238c2962c33fc80b4abd authorAndrea Cimitan <andrea.cimitan@gmail.com> dateFri 19 Feb 2016, 11:42 (11 years ago) parent8122d43
17 files changed+104−319
debian/control+2−2 qml/Dash/GenericScopeView.qml+13−41 qml/Dash/PreviewListView.qml+24−67 qml/Dash/Previews/Preview.qml−4 qml/Dash/Previews/PreviewExpandable.qml−1 qml/Dash/Previews/PreviewRatingEdit.qml−1 qml/Dash/Previews/PreviewWidget.qml−3 qml/Dash/Previews/PreviewWidgetFactory.qml−4 tests/mocks/Unity/CMakeLists.txt+1−3 tests/mocks/Unity/Unity.qmltypes+33−50 tests/mocks/Unity/fake_previewstack.cpp−68 tests/mocks/Unity/fake_previewstack.h−52 tests/mocks/Unity/fake_scope.cpp+2−2 tests/mocks/Unity/fake_scope.h+2−2 tests/mocks/Unity/fake_unity_plugin.cpp+1−2 tests/qmltests/CMakeLists.txt+1−1 tests/qmltests/Dash/tst_PreviewListView.qml+25−16
debian/control+2−2
@@ -29,7 +29,7 @@ Build-Depends: cmake,
2929 libqt5xmlpatterns5-dev,
3030 libsystemsettings-dev,
3131 libudev-dev,
32− libunity-api-dev (>= 7.106),
32+ libunity-api-dev (>= 7.107),
3333 libusermetricsoutput1-dev,
3434# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
3535 libx11-dev[!armhf],
@@ -135,7 +135,7 @@ Depends: qml-module-qtquick-layouts,
135135 unity-application-impl-12,
136136 unity-notifications-impl-3,
137137 unity-plugin-scopes | unity-scopes-impl,
138− unity-scopes-impl-10,
138+ unity-scopes-impl-11,
139139 unity8-fake-env | unity-application-impl,
140140 ${misc:Depends},
141141Breaks: unity8 (<< 7.86),
qml/Dash/GenericScopeView.qml+13−41
@@ -73,49 +73,30 @@ FocusScope {
7373 }
7474
7575 property var maybePreviewResult;
76− property int maybePreviewIndex;
77− property var maybePreviewResultsModel;
78− property int maybePreviewLimitedCategoryItemCount;
7976 property string maybePreviewCategoryId;
8077
8178 function clearMaybePreviewData() {
8279 scopeView.maybePreviewResult = undefined;
83− scopeView.maybePreviewIndex = -1;
84− scopeView.maybePreviewResultsModel = undefined;
85− scopeView.maybePreviewLimitedCategoryItemCount = -1;
8680 scopeView.maybePreviewCategoryId = "";
8781 }
8882
89− function itemClicked(index, result, itemModel, resultsModel, limitedCategoryItemCount, categoryId) {
83+ function itemClicked(result, categoryId) {
9084 scopeView.maybePreviewResult = result;
91− scopeView.maybePreviewIndex = index;
92− scopeView.maybePreviewResultsModel = resultsModel;
93− scopeView.maybePreviewLimitedCategoryItemCount = limitedCategoryItemCount;
9485 scopeView.maybePreviewCategoryId = categoryId;
9586
9687 scope.activate(result, categoryId);
9788 }
9889
99− function itemPressedAndHeld(index, result, resultsModel, limitedCategoryItemCount, categoryId) {
90+ function itemPressedAndHeld(result, categoryId) {
10091 clearMaybePreviewData();
10192
102− openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId);
93+ openPreview(result, categoryId);
10394 }
10495
105− function openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId) {
106− var previewStack = scope.preview(result, categoryId);
107− if (previewStack) {
108− if (limitedCategoryItemCount > 0) {
109− previewLimitModel.model = resultsModel;
110− previewLimitModel.limit = limitedCategoryItemCount;
111− subPageLoader.model = previewLimitModel;
112− } else {
113− subPageLoader.model = resultsModel;
114− }
115− subPageLoader.initialIndex = -1;
116− subPageLoader.initialIndex = index;
117− subPageLoader.categoryId = categoryId;
118− subPageLoader.previewStack = previewStack;
96+ function openPreview(result, categoryId) {
97+ var previewModel = scope.preview(result, categoryId);
98+ if (previewModel) {
99+ subPageLoader.previewModel = previewModel;
119100 subPageLoader.openSubPage("preview");
120101 }
121102 }
@@ -166,9 +147,6 @@ FocusScope {
166147 onPreviewRequested: { // (QVariant const& result)
167148 if (result === scopeView.maybePreviewResult) {
168149 openPreview(result,
169− scopeView.maybePreviewIndex,
170− scopeView.maybePreviewResultsModel,
171− scopeView.maybePreviewLimitedCategoryItemCount,
172150 scopeView.maybePreviewCategoryId);
173151
174152 clearMaybePreviewData();
@@ -390,11 +368,11 @@ FocusScope {
390368 Connections {
391369 target: rendererLoader.item
392370 onClicked: { // (int index, var result, var item, var itemModel)
393− scopeView.itemClicked(index, result, itemModel, target.model, categoryItemCount(), baseItem.category);
371+ scopeView.itemClicked(result, baseItem.category);
394372 }
395373
396374 onPressAndHold: { // (int index, var result, var itemModel)
397− scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
375+ scopeView.itemPressedAndHeld(result, baseItem.category);
398376 }
399377
400378 function categoryItemCount() {
@@ -768,13 +746,10 @@ FocusScope {
768746 property var scope: scopeView.scope
769747 property var scopeStyle: scopeView.scopeStyle
770748 property int initialIndex: -1
771− property var previewStack;
772− property string categoryId
773− property var model: null
749+ property var previewModel;
774750
775751 readonly property bool processing: item && item.processing || false
776752 readonly property int count: item && item.count || 0
777− readonly property int currentIndex: item && item.currentIndex || 0
778753 readonly property var currentItem: item && item.currentItem || null
779754
780755 property string subPage: ""
@@ -789,7 +764,7 @@ FocusScope {
789764 }
790765
791766 source: switch(subPage) {
792− case "preview": return "PreviewListView.qml";
767+ case "preview": return "PreviewView.qml";
793768 case "settings": return "ScopeSettingsPage.qml";
794769 default: return "";
795770 }
@@ -799,11 +774,8 @@ FocusScope {
799774 item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle; } )
800775 if (subPage == "preview") {
801776 item.open = Qt.binding(function() { return subPageLoader.open; } )
802− item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
803− item.model = Qt.binding(function() { return subPageLoader.model; } )
804− item.categoryId = Qt.binding(function() { return subPageLoader.categoryId; } )
805− item.initialIndexPreviewStack = subPageLoader.previewStack;
806− subPageLoader.previewStack = null;
777+ item.previewModel = subPageLoader.previewModel;
778+ subPageLoader.previewModel = null;
807779 }
808780 open = true;
809781 }
qml/Dash/PreviewListView.qml+24−67
@@ -23,20 +23,14 @@ import "Previews" as Previews
2323Item {
2424 id: root
2525
26− property int initialIndex: -1
27− property var initialIndexPreviewStack: null
26+ property bool open: false
2827 property var scope: null
2928 property var scopeStyle: null
30− property string categoryId
31− property bool usedInitialIndex: false
3229
3330 property alias showSignatureLine: header.showSignatureLine
3431
35− property alias open: previewListView.open
36− property alias model: previewListView.model
37− property alias currentIndex: previewListView.currentIndex
38− property alias currentItem: previewListView.currentItem
39− property alias count: previewListView.count
32+ property alias currentItem: previewLoader.item
33+ property var previewModel
4034
4135 readonly property bool processing: currentItem && (!currentItem.previewModel.loaded
4236 || currentItem.previewModel.processingAction)
@@ -55,73 +49,36 @@ Item {
5549 onBackClicked: root.backClicked()
5650 }
5751
58− ListView {
59− id: previewListView
60− objectName: "listView"
52+ onOpenChanged: {
53+ if (!open) {
54+ // Cancel any pending preview requests or actions
55+ if (currentItem && currentItem.previewData !== undefined) {
56+ currentItem.previewData.cancelAction();
57+ }
58+ root.scope.cancelActivation();
59+ }
60+ }
61+
62+ Loader {
63+ id: previewLoader
64+ objectName: "loader"
6165 anchors {
6266 top: header.bottom
6367 bottom: parent.bottom
6468 left: parent.left
6569 right: parent.right
6670 }
67− orientation: ListView.Horizontal
68− highlightRangeMode: ListView.StrictlyEnforceRange
69− snapMode: ListView.SnapOneItem
70− boundsBehavior: Flickable.DragAndOvershootBounds
71− highlightMoveDuration: 250
72− flickDeceleration: units.gu(625)
73− maximumFlickVelocity: width * 5
74− cacheBuffer: 0
75−
76− property bool open: false
7771
78− onOpenChanged: {
79− if (!open) {
80− // Cancel any pending preview requests or actions
81− if (previewListView.currentItem && previewListView.currentItem.previewData !== undefined) {
82− previewListView.currentItem.previewData.cancelAction();
83− }
84− root.scope.cancelActivation();
85− model = undefined;
86− }
87− }
88−
89− onModelChanged: {
90− if (count > 0 && initialIndex >= 0 && !usedInitialIndex) {
91− usedInitialIndex = true;
92− previewListView.positionViewAtIndex(initialIndex, ListView.SnapPosition);
93− }
94− }
95−
96− delegate: Previews.Preview {
72+ sourceComponent: Previews.Preview {
9773 id: preview
98− objectName: "preview" + index
99− height: previewListView.height
100− width: previewListView.width
101−
102− isCurrent: ListView.isCurrentItem
103−
104− readonly property var previewStack: {
105− if (root.open) {
106− if (index === root.initialIndex) {
107− return root.initialIndexPreviewStack;
108− } else {
109− return root.scope.preview(result, root.categoryId);
110− }
111− } else {
112− return null;
113− }
114− }
115−
116− previewModel: {
117− if (previewStack) {
118− return previewStack.getPreviewModel(0);
119− } else {
120− return null;
121− }
122− }
74+ objectName: "preview"
75+ height: previewLoader.height
76+ width: previewLoader.width
77+ }
12378
124− scopeStyle: root.scopeStyle
79+ onLoaded: {
80+ item.scopeStyle = Qt.binding(function() { return root.scopeStyle; });
81+ item.previewModel = Qt.binding(function() { return root.previewModel; });
12582 }
12683 }
12784
qml/Dash/Previews/Preview.qml−4
@@ -34,9 +34,6 @@ Item {
3434 */
3535 property var previewModel
3636
37− //! \brief Should be set to true if this preview is currently displayed.
38− property bool isCurrent: false
39−
4037 //! \brief The ScopeStyle component.
4138 property var scopeStyle: null
4239
@@ -88,7 +85,6 @@ Item {
8885 widgetId: model.widgetId
8986 widgetType: model.type
9087 widgetData: model.properties
91− isCurrentPreview: root.isCurrent
9288 scopeStyle: root.scopeStyle
9389 parentFlickable: column
9490
qml/Dash/Previews/PreviewExpandable.qml−1
@@ -84,7 +84,6 @@ PreviewWidget {
8484 widgetId: model.widgetId
8585 widgetType: model.type
8686 widgetData: model.properties
87− isCurrentPreview: root.isCurrentPreview
8887 scopeStyle: root.scopeStyle
8988 anchors {
9089 left: parent.left
qml/Dash/Previews/PreviewRatingEdit.qml−1
@@ -68,7 +68,6 @@ PreviewWidget {
6868
6969 widgetId: root.widgetId
7070 widgetData: root.widgetData
71− isCurrentPreview: root.isCurrentPreview
7271 scopeStyle: root.scopeStyle
7372
7473 ratingValue: widgetData["rating"]
qml/Dash/Previews/PreviewWidget.qml−3
@@ -19,9 +19,6 @@ import QtQuick 2.4
1919/*! Interface for preview widgets. */
2020
2121Item {
22− //! Specifies the preview widget being currently used or not
23− property bool isCurrentPreview: true
24−
2522 //! The widget identifier
2623 property string widgetId
2724
qml/Dash/Previews/PreviewWidgetFactory.qml−4
@@ -37,9 +37,6 @@ Loader {
3737 //! Should the widget show in expanded mode (For those that support it)
3838 property bool expanded: widgetType !== "expandable" || widgetData["expanded"] === true
3939
40− //! Set to true if the parent preview is displayed.
41− property bool isCurrentPreview: false
42−
4340 //! Set margins width.
4441 property real widgetMargins: status === Loader.Ready ? item.widgetMargins : units.gu(1)
4542
@@ -82,7 +79,6 @@ Loader {
8279 onLoaded: {
8380 item.widgetId = Qt.binding(function() { return root.widgetId } )
8481 item.widgetData = Qt.binding(function() { return root.widgetData } )
85− item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
8682 item.expanded = Qt.binding(function() { return root.expanded } )
8783 item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
8884 item.parentFlickable = Qt.binding(function() { return root.parentFlickable } )
tests/mocks/Unity/CMakeLists.txt+1−3
@@ -7,7 +7,7 @@ add_subdirectory(Notifications)
77add_subdirectory(DashCommunicator)
88
99pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
10−pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=10)
10+pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=11)
1111
1212include_directories(
1313 ${CMAKE_CURRENT_BINARY_DIR}
@@ -27,13 +27,11 @@ set(UnityQML_SOURCES
2727 fake_navigation.cpp
2828 fake_resultsmodel.cpp
2929 fake_previewmodel.cpp
30− fake_previewstack.cpp
3130 fake_previewwidgetmodel.cpp
3231 fake_unity_plugin.cpp
3332 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
3433 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/NavigationInterface.h
3534 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
36− ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
3735 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
3836 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h
3937 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
tests/mocks/Unity/Unity.qmltypes+33−50
@@ -1,4 +1,4 @@
1−import QtQuick.tooling 1.1
1+import QtQuick.tooling 1.2
22
33// This file describes the plugin-supplied types contained in the library.
44// It is used for QML tooling purposes only.
@@ -7,17 +7,10 @@ import QtQuick.tooling 1.1
77// 'qmlplugindump -notrelocatable Unity 0.2 tests/mocks'
88
99Module {
10+ dependencies: ["QtQuick 2.4", "Unity.Indicators 0.1"]
1011 Component {
1112 name: "Categories"
1213 prototype: "unity::shell::scopes::CategoriesInterface"
13− Method {
14− name: "addSpecialCategory"
15− Parameter { name: "categoryId"; type: "string" }
16− Parameter { name: "name"; type: "string" }
17− Parameter { name: "icon"; type: "string" }
18− Parameter { name: "rawTemplate"; type: "string" }
19− Parameter { name: "countObject"; type: "QObject"; isPointer: true }
20− }
2114 Method {
2215 name: "overrideCategoryJson"
2316 type: "bool"
@@ -60,18 +53,6 @@ Module {
6053 Parameter { type: "bool" }
6154 }
6255 }
63− Component {
64− name: "PreviewStack"
65− prototype: "unity::shell::scopes::PreviewStackInterface"
66− exports: ["Unity/PreviewStack 0.2"]
67− isCreatable: false
68− exportMetaObjectRevisions: [0]
69− Method {
70− name: "getPreviewModel"
71− type: "unity::shell::scopes::PreviewModelInterface*"
72− Parameter { name: "index"; type: "int" }
73− }
74− }
7556 Component {
7657 name: "PreviewWidgetModel"
7758 prototype: "unity::shell::scopes::PreviewWidgetModelInterface"
@@ -95,11 +76,11 @@ Module {
9576 prototype: "unity::shell::scopes::ScopeInterface"
9677 exports: ["Unity/MockScope 0.2"]
9778 exportMetaObjectRevisions: [0]
79+ Signal { name: "refreshed" }
9880 Signal {
99− name: "performQuery"
81+ name: "queryPerformed"
10082 Parameter { name: "query"; type: "string" }
10183 }
102− Signal { name: "refreshed" }
10384 Method {
10485 name: "setId"
10586 Parameter { name: "id"; type: "string" }
@@ -115,11 +96,13 @@ Module {
11596 Method {
11697 name: "activate"
11798 Parameter { name: "result"; type: "QVariant" }
99+ Parameter { name: "categoryId"; type: "string" }
118100 }
119101 Method {
120102 name: "preview"
121− type: "PreviewStack*"
103+ type: "PreviewModel*"
122104 Parameter { name: "result"; type: "QVariant" }
105+ Parameter { name: "categoryId"; type: "string" }
123106 }
124107 Method { name: "cancelActivation" }
125108 Method {
@@ -142,6 +125,12 @@ Module {
142125 Parameter { name: "isAltNavigation"; type: "bool" }
143126 }
144127 Method { name: "refresh" }
128+ Method {
129+ name: "activateAction"
130+ Parameter { name: "result"; type: "QVariant" }
131+ Parameter { name: "categoryId"; type: "string" }
132+ Parameter { name: "actionId"; type: "string" }
133+ }
145134 }
146135 Component {
147136 name: "Scopes"
@@ -181,6 +170,10 @@ Module {
181170 Parameter { name: "scopeId"; type: "string" }
182171 Parameter { name: "index"; type: "int" }
183172 }
173+ Method {
174+ name: "closeScope"
175+ Parameter { name: "scope"; type: "unity::shell::scopes::ScopeInterface"; isPointer: true }
176+ }
184177 Method {
185178 name: "getScopeFromAll"
186179 type: "Scope*"
@@ -214,14 +207,6 @@ Module {
214207 Parameter { name: "categoryId"; type: "string" }
215208 Parameter { name: "json"; type: "string" }
216209 }
217− Method {
218− name: "addSpecialCategory"
219− Parameter { name: "categoryId"; type: "string" }
220− Parameter { name: "name"; type: "string" }
221− Parameter { name: "icon"; type: "string" }
222− Parameter { name: "rawTemplate"; type: "string" }
223− Parameter { name: "countObject"; type: "QObject"; isPointer: true }
224− }
225210 }
226211 Component {
227212 name: "unity::shell::scopes::NavigationInterface"
@@ -270,22 +255,6 @@ Module {
270255 Parameter { type: "QVariantMap" }
271256 }
272257 }
273− Component {
274− name: "unity::shell::scopes::PreviewStackInterface"
275− prototype: "QAbstractListModel"
276− Enum {
277− name: "Roles"
278− values: {
279− "RolePreviewModel": 0
280− }
281− }
282− Property { name: "widgetColumnCount"; type: "int" }
283− Method {
284− name: "getPreviewModel"
285− type: "unity::shell::scopes::PreviewModelInterface*"
286− Parameter { name: "index"; type: "int" }
287− }
288− }
289258 Component {
290259 name: "unity::shell::scopes::PreviewWidgetModelInterface"
291260 prototype: "QAbstractListModel"
@@ -316,7 +285,8 @@ Module {
316285 "RoleSummary": 9,
317286 "RoleAttributes": 10,
318287 "RoleBackground": 11,
319− "RoleOverlayColor": 12
288+ "RoleOverlayColor": 12,
289+ "RoleQuickPreviewData": 13
320290 }
321291 }
322292 Property { name: "categoryId"; type: "string" }
@@ -343,6 +313,7 @@ Module {
343313 Property { name: "description"; type: "string"; isReadonly: true }
344314 Property { name: "searchHint"; type: "string"; isReadonly: true }
345315 Property { name: "searchInProgress"; type: "bool"; isReadonly: true }
316+ Property { name: "activationInProgress"; type: "bool"; isReadonly: true }
346317 Property { name: "favorite"; type: "bool" }
347318 Property { name: "shortcut"; type: "string"; isReadonly: true }
348319 Property {
@@ -393,11 +364,13 @@ Module {
393364 Method {
394365 name: "activate"
395366 Parameter { name: "result"; type: "QVariant" }
367+ Parameter { name: "categoryId"; type: "string" }
396368 }
397369 Method {
398370 name: "preview"
399− type: "unity::shell::scopes::PreviewStackInterface*"
371+ type: "unity::shell::scopes::PreviewModelInterface*"
400372 Parameter { name: "result"; type: "QVariant" }
373+ Parameter { name: "categoryId"; type: "string" }
401374 }
402375 Method { name: "cancelActivation" }
403376 Method {
@@ -424,6 +397,12 @@ Module {
424397 Parameter { name: "cannedQuery"; type: "string" }
425398 }
426399 Method { name: "refresh" }
400+ Method {
401+ name: "activateAction"
402+ Parameter { name: "result"; type: "QVariant" }
403+ Parameter { name: "categoryId"; type: "string" }
404+ Parameter { name: "actionId"; type: "string" }
405+ }
427406 }
428407 Component {
429408 name: "unity::shell::scopes::ScopesInterface"
@@ -464,6 +443,10 @@ Module {
464443 Parameter { name: "scopeId"; type: "string" }
465444 Parameter { name: "index"; type: "int" }
466445 }
446+ Method {
447+ name: "closeScope"
448+ Parameter { name: "scope"; type: "unity::shell::scopes::ScopeInterface"; isPointer: true }
449+ }
467450 }
468451 Component {
469452 name: "unity::shell::scopes::SettingsModelInterface"
tests/mocks/Unity/fake_previewstack.cppdeleted−68
@@ -1,68 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−// self
18−#include "fake_previewstack.h"
19−
20−// local
21−#include "fake_previewmodel.h"
22−#include "fake_scope.h"
23−
24−PreviewStack::PreviewStack(Scope *scope)
25− : unity::shell::scopes::PreviewStackInterface(nullptr)
26−{
27− m_previews << new PreviewModel(this, scope);
28−}
29−
30−PreviewStack::~PreviewStack()
31−{
32−}
33−
34−void PreviewStack::setWidgetColumnCount(int columnCount)
35−{
36− if (columnCount != 1) {
37− qFatal("PreviewStack::setWidgetColumnCount != 1 not implemented");
38− }
39−}
40−
41−int PreviewStack::widgetColumnCount() const
42−{
43− return 1;
44−}
45−
46−int PreviewStack::rowCount(const QModelIndex&) const
47−{
48− return m_previews.size();
49−}
50−
51−unity::shell::scopes::PreviewModelInterface* PreviewStack::getPreviewModel(int index) const
52−{
53− if (index >= m_previews.size()) {
54− return nullptr;
55− }
56−
57− return m_previews.at(index);
58−}
59−
60−QVariant PreviewStack::data(const QModelIndex& index, int role) const
61−{
62− switch (role) {
63− case RolePreviewModel:
64− return QVariant::fromValue(m_previews.at(index.row()));
65− default:
66− return QVariant();
67− }
68−}
tests/mocks/Unity/fake_previewstack.hdeleted−52
@@ -1,52 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−
18−#ifndef FAKE_PREVIEWSTACK_H
19−#define FAKE_PREVIEWSTACK_H
20−
21−#include <unity/shell/scopes/PreviewStackInterface.h>
22−
23−#include <QSharedPointer>
24−#include <QVariantMap>
25−
26−class PreviewModel;
27−
28−class Scope;
29−
30−class PreviewStack : public unity::shell::scopes::PreviewStackInterface
31−{
32− Q_OBJECT
33−
34−public:
35− explicit PreviewStack(Scope* scope = 0);
36− virtual ~PreviewStack();
37−
38− QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
39− int rowCount(const QModelIndex& parent = QModelIndex()) const override;
40−
41− Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* getPreviewModel(int index) const override;
42−
43− void setWidgetColumnCount(int columnCount) override;
44− int widgetColumnCount() const override;
45−
46−private:
47− QList<PreviewModel*> m_previews;
48−};
49−
50−Q_DECLARE_METATYPE(PreviewStack*)
51−
52−#endif // FAKE_PREVIEWSTACK_H
tests/mocks/Unity/fake_scope.cpp+2−2
@@ -199,14 +199,14 @@ void Scope::activate(QVariant const& result, QString const& categoryId)
199199 }
200200}
201201
202−PreviewStack* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
202+PreviewModel* Scope::preview(QVariant const& result, QString const& /*categoryId*/)
203203{
204204 Q_UNUSED(result);
205205
206206 if (m_returnNullPreview) {
207207 return nullptr;
208208 } else {
209− return new PreviewStack(this);
209+ return new PreviewModel(this);
210210 }
211211}
212212
tests/mocks/Unity/fake_scope.h+2−2
@@ -20,7 +20,7 @@
2020#include <unity/shell/scopes/ScopeInterface.h>
2121
2222#include "fake_categories.h"
23−#include "fake_previewstack.h"
23+#include "fake_previewmodel.h"
2424
2525#include <QTimer>
2626
@@ -62,7 +62,7 @@ public:
6262 Q_INVOKABLE void setSearchInProgress(const bool inProg); // This is not invokable in the Interface, here for testing benefits
6363
6464 Q_INVOKABLE void activate(QVariant const& result, QString const& categoryId) override;
65− Q_INVOKABLE PreviewStack* preview(QVariant const& result, QString const& categoryId) override;
65+ Q_INVOKABLE PreviewModel* preview(QVariant const& result, QString const& categoryId) override;
6666 Q_INVOKABLE void cancelActivation() override;
6767 Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override;
6868
tests/mocks/Unity/fake_unity_plugin.cpp+1−2
@@ -47,10 +47,9 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4747 qmlRegisterUncreatableType<unity::shell::scopes::SettingsModelInterface>(uri, 0, 2, "SettingsModel", "Can't create SettingsModel object in QML.");
4848 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
4949 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
50− qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
50+ qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from Scope instance.");
5151 qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
5252 qmlRegisterType<ResultsModel>(uri, 0, 2, "FakeResultsModel");
5353 qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
5454 qmlRegisterUncreatableType<PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", "Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.");
55− qmlRegisterUncreatableType<PreviewStack>(uri, 0, 2, "PreviewStack", "Can't create new PreviewStack in QML. Get them from Scope instance.");
5655}
tests/qmltests/CMakeLists.txt+1−1
@@ -28,7 +28,7 @@ add_unity8_qmlbenchmark(Dash CardBenchmark 1000)
2828add_unity8_qmltest(Dash CardTool)
2929add_unity8_qmltest(Dash GenericScopeView)
3030add_unity8_qmltest(Dash DashPageHeader)
31−add_unity8_qmltest(Dash PreviewListView)
31+add_unity8_qmltest(Dash PreviewView)
3232add_unity8_qmltest(Dash/Previews Preview)
3333add_unity8_qmltest(Dash/Previews PreviewActions)
3434add_unity8_qmltest(Dash/Previews PreviewAudioPlayback)
tests/qmltests/Dash/tst_PreviewListView.qml+25−16
@@ -36,8 +36,8 @@ Rectangle {
3636 id: mockResultsModel
3737 }
3838
39− PreviewListView {
40− id: listView
39+ PreviewView {
40+ id: view
4141 anchors.fill: parent
4242 scope: mockScope
4343 scopeStyle: ScopeStyle {
@@ -45,12 +45,23 @@ Rectangle {
4545 }
4646 }
4747
48+ Item {
49+ Repeater {
50+ id: repeater
51+ model: mockResultsModel
52+ Item {
53+ property var previewModel: mockScope.preview(model.result, model.categoryId);
54+ }
55+ }
56+ }
57+
58+
4859 UT.UnityTestCase {
4960 id: testCase
50− name: "PreviewListView"
61+ name: "PreviewView"
5162 when: windowShown
5263
53− property MouseArea mouseArea: findChild(listView, "processingMouseArea")
64+ property MouseArea mouseArea: findChild(view, "processingMouseArea")
5465
5566 SignalSpy {
5667 id: clickedSpy
@@ -59,43 +70,41 @@ Rectangle {
5970 }
6071
6172 function init() {
62− listView.model = mockResultsModel;
63− listView.currentIndex = 1;
64− listView.open = true;
73+ view.open = true;
74+ view.previewModel = repeater.itemAt(0).previewModel
6575 verify(testCase.mouseArea, "Can't find the processingMouseArea object.");
6676 }
6777
6878 function cleanup() {
69− listView.open = false;
70− listView.model = null;
79+ view.open = false;
7180 clickedSpy.clear();
7281 }
7382
7483 function test_notProcessing() {
7584 expectFail("", "processingMouseArea should not receive the click.");
76− mouseClick(listView);
85+ mouseClick(view);
7786 clickedSpy.wait();
7887 }
7988
8089 function test_processing() {
81− verify(listView.currentItem, "currentItem is not ready yet");
82− listView.currentItem.previewModel.setLoaded(false);
90+ verify(view.currentItem, "currentItem is not ready yet");
91+ view.currentItem.previewModel.setLoaded(false);
8392
84− tryCompare(listView, "processing", true);
93+ tryCompare(view, "processing", true);
8594
86− mouseClick(listView);
95+ mouseClick(view);
8796 clickedSpy.wait();
8897 }
8998
9099 function test_title() {
91− var header = findChild(listView, "innerPageHeader");
100+ var header = findChild(view, "innerPageHeader");
92101 verify(header, "Could not find the preview header");
93102
94103 compare(header.config.title, "Mock Scope");
95104 }
96105
97106 function test_header_style() {
98− var header = findChild(listView, "pageHeader");
107+ var header = findChild(view, "pageHeader");
99108 verify(header, "Could not find the header");
100109
101110 var innerHeader = findChild(header, "innerPageHeader");