on xenial help sign in
Enable SearchHistoryModel to dynamicaly set search history size
deb0503Josh Arenson
qml/Components/SearchHistoryModel/SearchHistoryModel.qml+5−2
@@ -20,6 +20,9 @@ import QtQuick 2.4
20// TODO sanitize input, move to persistent storage
20// TODO sanitize input, move to persistent storage
21
21
22ListModel {
22ListModel {
23+
24+ property int searchesToRemember: 3
25+
23 function addQuery(newQuery) {
26 function addQuery(newQuery) {
24 // strip whitespaces
27 // strip whitespaces
25 newQuery = newQuery.replace(/^\s+|\s+$/g, '');
28 newQuery = newQuery.replace(/^\s+|\s+$/g, '');
@@ -34,9 +37,9 @@ ListModel {
34 }
37 }
35 // add a new entry
38 // add a new entry
36 insert(0, { "query": newQuery })
39 insert(0, { "query": newQuery })
37− if (count > 3) {
40+ if (count > searchesToRemember) {
38 // remove entries if there's more than three
41 // remove entries if there's more than three
39− remove(3)
42+ remove(searchesToRemember)
40 }
43 }
41 }
44 }
42}
45}
tests/qmltests/Dash/tst_DashPageHeader.qml+32
@@ -320,6 +320,38 @@ Item {
320 }
320 }
321 }
321 }
322
322
323+ Row {
324+ spacing: units.gu(1)
325+ anchors {
326+ left: parent.left
327+ right: parent.right
328+ }
329+
330+ Label {
331+ text: "Searches to remember: " + pageHeader.searchHistory.searchesToRemember
332+ anchors.verticalCenter: parent.verticalCenter
333+ }
334+ }
335+
336+ Row {
337+ id: sliderRow
338+ spacing: units.gu(1)
339+ anchors {
340+ left: parent.left
341+ right: parent.right
342+ margins: units.gu(1)
343+ }
344+
345+ Slider {
346+ id: slider
347+ maximumValue: 20
348+ minimumValue: 1
349+ width: units.gu(40)
350+ value: pageHeader.searchHistory.searchesToRemember
351+ onValueChanged: pageHeader.searchHistory.searchesToRemember = Math.round(value)
352+ }
353+ }
354+
323 Row {
355 Row {
324 spacing: units.gu(1)
356 spacing: units.gu(1)
325 anchors {
357 anchors {