Merge lp:~fboucault/unity-2d/activate_first_result into lp:unity-2d/3.0

Proposed by Florian Boucault
Status: Merged
Approved by: Ugo Riboni
Approved revision: 479
Merged at revision: 482
Proposed branch: lp:~fboucault/unity-2d/activate_first_result
Merge into: lp:unity-2d/3.0
Diff against target: 134 lines (+81/-2)
5 files modified
libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp (+24/-0)
libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h (+3/-0)
places/Home.qml (+18/-0)
places/PlaceEntryView.qml (+34/-0)
places/SearchEntry.qml (+2/-2)
To merge this branch: bzr merge lp:~fboucault/unity-2d/activate_first_result
Reviewer Review Type Date Requested Status
Ugo Riboni Pending
Review via email: mp+54529@code.launchpad.net

Description of the change

[dash] Pressing enter/return key activates the first result available.

New APIs to manually access the result sets were added:
- QVariantMap QSortFilterProxyModelQML::get(int row)
- int QSortFilterProxyModelQML::count()

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

Note that the latest version of libqtdee is needed for this MR to work. It should be available in the PPA now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp'
2--- libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp 2011-03-10 01:13:42 +0000
3+++ libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp 2011-03-23 14:06:54 +0000
4@@ -56,3 +56,27 @@
5 connect(itemModel, SIGNAL(modelAboutToBeReset()), SLOT(updateRoleNames()));
6 connect(itemModel, SIGNAL(modelReset()), SLOT(updateRoleNames()));
7 }
8+
9+QVariantMap
10+QSortFilterProxyModelQML::get(int row)
11+{
12+ if (sourceModel() == NULL) {
13+ return QVariantMap();
14+ }
15+
16+ QVariantMap result;
17+ QHashIterator<int, QByteArray> i(roleNames());
18+ while (i.hasNext()) {
19+ i.next();
20+ QModelIndex modelIndex = index(row, 0);
21+ QVariant data = modelIndex.data(i.key());
22+ result[i.value()] = data;
23+ }
24+ return result;
25+}
26+
27+int
28+QSortFilterProxyModelQML::count()
29+{
30+ return rowCount();
31+}
32
33=== modified file 'libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h'
34--- libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h 2011-02-08 11:48:16 +0000
35+++ libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h 2011-03-23 14:06:54 +0000
36@@ -28,6 +28,9 @@
37 public:
38 explicit QSortFilterProxyModelQML(QObject *parent = 0);
39
40+ Q_INVOKABLE QVariantMap get(int row);
41+ Q_INVOKABLE int count();
42+
43 /* getters */
44 QObject* sourceModelQObject() const;
45
46
47=== modified file 'places/Home.qml'
48--- places/Home.qml 2011-03-22 06:15:19 +0000
49+++ places/Home.qml 2011-03-23 14:06:54 +0000
50@@ -32,6 +32,24 @@
51 }
52 }
53
54+ function activateFirstResult() {
55+ /* Going through the list of place entries and selecting the first one
56+ that has results for the global search, that is items in its
57+ globalResultsModel */
58+ var placeEntry, i
59+ for (i=0; i<dash.places.rowCount(); i=i+1) {
60+ placeEntry = dash.places.get(i)
61+ if (placeEntry.globalResultsModel != null && placeEntry.globalResultsModel.count() != 0) {
62+ var firstResult = placeEntry.globalResultsModel.get(0)
63+ /* Places give back the uri of the item in 'column_0' per specification */
64+ var uri = firstResult.column_0
65+ dashView.active = false
66+ placeEntry.place.activate(decodeURIComponent(uri))
67+ return;
68+ }
69+ }
70+ }
71+
72 /* Set to true if shortcut buttons are visible */
73 property bool shortcutsActive: false
74
75
76=== modified file 'places/PlaceEntryView.qml'
77--- places/PlaceEntryView.qml 2011-03-22 06:15:19 +0000
78+++ places/PlaceEntryView.qml 2011-03-23 14:06:54 +0000
79@@ -25,6 +25,40 @@
80 /* An instance of PlaceEntryModel */
81 property variant model
82
83+ function activateFirstResult() {
84+ /* Going through the list of groups and selecting the first one
85+ that has results for the search. A QSortFilterProxyModelQML
86+ ('firstGroupModel') is used to filter the search results per group.
87+ */
88+ var placeEntry, i
89+ for (i=0; i<placeEntryView.model.entryGroupsModel.count(); i=i+1) {
90+ firstGroupModel.groupId = i
91+ if (firstGroupModel.count() != 0) {
92+ var firstResult = firstGroupModel.get(0)
93+ /* Places give back the uri of the item in 'column_0' per specification */
94+ var uri = firstResult.column_0
95+ dashView.active = false
96+ model.place.activate(decodeURIComponent(uri))
97+ return;
98+ }
99+ }
100+ }
101+
102+ QSortFilterProxyModelQML {
103+ id: firstGroupModel
104+
105+ property int groupId
106+ model: placeEntryView.model.entryResultsModel
107+
108+ /* placeEntryView.model.entryResultsModel contains data for all
109+ the groups of a given Place.
110+ Each row has a column (the second one) containing the id of
111+ the group it belongs to (groupId).
112+ */
113+ filterRole: 2 /* second column (see above comment) */
114+ filterRegExp: RegExp("^%1$".arg(groupId)) /* exact match */
115+ }
116+
117 ListViewWithScrollbar {
118 id: results
119
120
121=== modified file 'places/SearchEntry.qml'
122--- places/SearchEntry.qml 2011-03-22 15:31:25 +0000
123+++ places/SearchEntry.qml 2011-03-23 14:06:54 +0000
124@@ -109,8 +109,8 @@
125 }
126
127 Keys.onPressed: {
128- if (event.key == Qt.Key_Return) {
129- searchQuery = text
130+ if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter) {
131+ dash.currentPage.activateFirstResult()
132 event.accepted = true;
133 }
134 }

Subscribers

People subscribed via source and target branches