From 7aa18dab5ef4c78be9636a03ecb2996e66387926 Mon Sep 17 00:00:00 2001 From: vsklencar Date: Thu, 10 Sep 2020 12:28:39 +0200 Subject: [PATCH] [QgsQuick] Support for custom formats and strings --- src/quickgui/plugin/editor/qgsquickdatetime.qml | 16 ++++++++++------ src/quickgui/qgsquickutils.cpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/quickgui/plugin/editor/qgsquickdatetime.qml b/src/quickgui/plugin/editor/qgsquickdatetime.qml index e2348f010ad..1d49983a1c9 100644 --- a/src/quickgui/plugin/editor/qgsquickdatetime.qml +++ b/src/quickgui/plugin/editor/qgsquickdatetime.qml @@ -116,7 +116,7 @@ Item { onClicked: { var usedDate = new Date(); if (value !== undefined && value !== '') { - usedDate = value; + usedDate = main.isDateOrTime ? value : Date.fromLocaleString(Qt.locale(), value, config['field_format']) } calendar.selectedDate = usedDate @@ -147,7 +147,8 @@ Item { anchors.fill: parent onClicked: { var newDate = new Date() - valueChanged(newDate, false) + var newValue = field.isDateOrTime ? newDate : Qt.formatDateTime(newDate, config['field_format']) + valueChanged(newValue, false) } } } @@ -197,7 +198,10 @@ Item { Controls1.Calendar { id: calendar - selectedDate: main.currentValue || new Date() + selectedDate: { + var date = field.isDateOrTime ? main.currentValue : Date.fromLocaleString(Qt.locale(), value, config['field_format']) + date || new Date() + } weekNumbersVisible: true focus: false implicitWidth: calendarOverlay.width @@ -302,8 +306,8 @@ Item { newDate.setSeconds(secondsSpinBox.value); } - label.text = timeToString(newDate) - valueChanged(newDate, newDate === undefined) + var newValue = field.isDateOrTime ? newDate : Qt.formatDateTime(newDate, config['field_format']) + valueChanged(newValue, newValue === undefined) popup.close() } } @@ -313,7 +317,7 @@ Item { } onCurrentValueChanged: { - label.text = timeToString(main.currentValue) + label.text = field.isDateOrTime ? timeToString(main.currentValue) : main.currentValue } } diff --git a/src/quickgui/qgsquickutils.cpp b/src/quickgui/qgsquickutils.cpp index a5abd1b70fb..dc86f3cb09a 100644 --- a/src/quickgui/qgsquickutils.cpp +++ b/src/quickgui/qgsquickutils.cpp @@ -405,7 +405,7 @@ QString QgsQuickUtils::dateTimeFieldFormat( const QString &fieldFormat ) } else { - return QString(); + return QString( "Date Time" ); } }