Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[QgsQuick] Support for custom formats and strings
  • Loading branch information
vsklencar authored and wonder-sk committed Sep 11, 2020
1 parent 3fc61a4 commit 7aa18da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/quickgui/plugin/editor/qgsquickdatetime.qml
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -313,7 +317,7 @@ Item {
}

onCurrentValueChanged: {
label.text = timeToString(main.currentValue)
label.text = field.isDateOrTime ? timeToString(main.currentValue) : main.currentValue
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/quickgui/qgsquickutils.cpp
Expand Up @@ -405,7 +405,7 @@ QString QgsQuickUtils::dateTimeFieldFormat( const QString &fieldFormat )
}
else
{
return QString();
return QString( "Date Time" );
}
}

Expand Down

0 comments on commit 7aa18da

Please sign in to comment.