From ead7ac8686841ef43e2524d04a664e375cae3300 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 6 Nov 2016 18:03:32 +0300 Subject: [PATCH 1/4] Historty: DoubleValidator applied to "amount filter" fields --- pages/History.qml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pages/History.qml b/pages/History.qml index a6c216bf..8821bb12 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -229,10 +229,12 @@ Rectangle { model.paymentIdFilter = paymentIdLine.text model.dateFromFilter = fromDatePicker.currentDate model.dateToFilter = toDatePicker.currentDate + if (advancedFilteringCheckBox.checked) { if (amountFromLine.text.length) { model.amountFromFilter = parseFloat(amountFromLine.text) } + if (amountToLine.text.length) { model.amountToFilter = parseFloat(amountToLine.text) } @@ -243,7 +245,6 @@ Rectangle { } selectedAmount.text = getSelectedAmount() - } } @@ -315,6 +316,15 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 width: 156 + validator: DoubleValidator { + locale: "C" + notation: DoubleValidator.StandardNotation + bottom: 0.0 + top: { + console.log("top"); + parseFloat(amountToLine.text) + } + } } Label { @@ -336,6 +346,15 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 width: 156 + validator: DoubleValidator { + locale: "C" + notation: DoubleValidator.StandardNotation + bottom: { + console.log("Botton") + parseFloat(amountFromLine.text) + } + } + } Item { From 69b4d461c8f562faefc14a90164fc1a57b06f343 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 6 Nov 2016 19:10:25 +0300 Subject: [PATCH 2/4] DatePicker: 'error' property for indicating invalid input --- components/DatePicker.qml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/DatePicker.qml b/components/DatePicker.qml index 9d0cbf20..ac67f8ed 100644 --- a/components/DatePicker.qml +++ b/components/DatePicker.qml @@ -35,6 +35,10 @@ Item { property bool expanded: false property date currentDate property bool showCurrentDate: true + property color backgroundColor : "#FFFFFF" + property color errorColor : "#FFDDDD" + property bool error: false + height: 37 width: 156 @@ -56,7 +60,6 @@ Item { Item { id: head anchors.fill: parent - Rectangle { anchors.left: parent.left anchors.right: parent.right @@ -64,6 +67,7 @@ Item { //radius: 4 y: 0 color: "#DBDBDB" + } Rectangle { @@ -74,7 +78,7 @@ Item { anchors.rightMargin: datePicker.expanded ? 1 : 0 //radius: 4 y: 1 - color: "#FFFFFF" + color: datePicker.error ? datePicker.errorColor : datePicker.backgroundColor } Item { From 328b7b05d88ad8e7070a2bfd0014c1a0fe5433ec Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 10 Nov 2016 23:51:03 +0300 Subject: [PATCH 3/4] History: amount filter: empty line disables filter --- pages/History.qml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pages/History.qml b/pages/History.qml index 8821bb12..b4764e1c 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -233,10 +233,16 @@ Rectangle { if (advancedFilteringCheckBox.checked) { if (amountFromLine.text.length) { model.amountFromFilter = parseFloat(amountFromLine.text) + } else { + // negative value disables filter here; + model.amountFromFilter = -1; } if (amountToLine.text.length) { model.amountToFilter = parseFloat(amountToLine.text) + } else { + // negative value disables filter here; + model.amountToFilter = -1; } var directionFilter = transactionsModel.get(transactionTypeDropdown.currentIndex).value @@ -319,11 +325,6 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation - bottom: 0.0 - top: { - console.log("top"); - parseFloat(amountToLine.text) - } } } @@ -349,10 +350,6 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation - bottom: { - console.log("Botton") - parseFloat(amountFromLine.text) - } } } From 02503e44ee1cdac01f48cbc180abb9b8cfcf0bcd Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 6 Nov 2016 19:11:19 +0300 Subject: [PATCH 4/4] History: amount and date filters validation --- pages/History.qml | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/pages/History.qml b/pages/History.qml index b4764e1c..f9fa9df7 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -66,6 +66,20 @@ Rectangle { } } + function onFilterChanged() { + var datesValid = fromDatePicker.currentDate <= toDatePicker.currentDate + var amountsValid = amountFromLine.text === "" ? true : + amountToLine.text === "" ? true: + parseFloat(amountFromLine.text) <= parseFloat(amountToLine.text) + + // reset error state if amount filter valid + if (amountsValid) { + amountFromLine.error = amountToLine.error = false + } + + filterButton.enabled = datesValid && amountsValid + } + Text { id: filterHeaderText @@ -141,6 +155,9 @@ Rectangle { anchors.rightMargin: 17 anchors.topMargin: 5 placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString + validator: RegExpValidator { + regExp: /[0-9a-fA-F]+/ + } } @@ -190,6 +207,10 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate > toDatePicker.currentDate + onFilterChanged() + } } // DateTo picker @@ -211,8 +232,14 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate < fromDatePicker.currentDate + onFilterChanged() + } } + + StandardButton { id: filterButton anchors.bottom: toDatePicker.bottom @@ -226,9 +253,15 @@ Rectangle { pressedColor: "#4D0051" onClicked: { // Apply filter here; + model.paymentIdFilter = paymentIdLine.text - model.dateFromFilter = fromDatePicker.currentDate - model.dateToFilter = toDatePicker.currentDate + + if (fromDatePicker.currentDate > toDatePicker.currentDate) { + console.error("Invalid date filter set: ", fromDatePicker.currentDate, toDatePicker.currentDate) + } else { + model.dateFromFilter = fromDatePicker.currentDate + model.dateToFilter = toDatePicker.currentDate + } if (advancedFilteringCheckBox.checked) { if (amountFromLine.text.length) { @@ -325,7 +358,14 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation + bottom: 0 } + onTextChanged: { + // indicating error + amountFromLine.error = amountFromLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text) + onFilterChanged() + } + } Label { @@ -350,6 +390,13 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation + bottom: 0.0 + } + + onTextChanged: { + // indicating error + amountToLine.error = amountToLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text) + onFilterChanged() } }