Skip to content

Commit 7aa18da

Browse files
vsklencarwonder-sk
authored andcommittedSep 11, 2020
[QgsQuick] Support for custom formats and strings
1 parent 3fc61a4 commit 7aa18da

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
 

‎src/quickgui/plugin/editor/qgsquickdatetime.qml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Item {
116116
onClicked: {
117117
var usedDate = new Date();
118118
if (value !== undefined && value !== '') {
119-
usedDate = value;
119+
usedDate = main.isDateOrTime ? value : Date.fromLocaleString(Qt.locale(), value, config['field_format'])
120120
}
121121

122122
calendar.selectedDate = usedDate
@@ -147,7 +147,8 @@ Item {
147147
anchors.fill: parent
148148
onClicked: {
149149
var newDate = new Date()
150-
valueChanged(newDate, false)
150+
var newValue = field.isDateOrTime ? newDate : Qt.formatDateTime(newDate, config['field_format'])
151+
valueChanged(newValue, false)
151152
}
152153
}
153154
}
@@ -197,7 +198,10 @@ Item {
197198

198199
Controls1.Calendar {
199200
id: calendar
200-
selectedDate: main.currentValue || new Date()
201+
selectedDate: {
202+
var date = field.isDateOrTime ? main.currentValue : Date.fromLocaleString(Qt.locale(), value, config['field_format'])
203+
date || new Date()
204+
}
201205
weekNumbersVisible: true
202206
focus: false
203207
implicitWidth: calendarOverlay.width
@@ -302,8 +306,8 @@ Item {
302306
newDate.setSeconds(secondsSpinBox.value);
303307
}
304308

305-
label.text = timeToString(newDate)
306-
valueChanged(newDate, newDate === undefined)
309+
var newValue = field.isDateOrTime ? newDate : Qt.formatDateTime(newDate, config['field_format'])
310+
valueChanged(newValue, newValue === undefined)
307311
popup.close()
308312
}
309313
}
@@ -313,7 +317,7 @@ Item {
313317
}
314318

315319
onCurrentValueChanged: {
316-
label.text = timeToString(main.currentValue)
320+
label.text = field.isDateOrTime ? timeToString(main.currentValue) : main.currentValue
317321
}
318322
}
319323

‎src/quickgui/qgsquickutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ QString QgsQuickUtils::dateTimeFieldFormat( const QString &fieldFormat )
405405
}
406406
else
407407
{
408-
return QString();
408+
return QString( "Date Time" );
409409
}
410410
}
411411

0 commit comments

Comments
 (0)
Please sign in to comment.