mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Avoid triple conversion for Date/Time field
In QgsDateTimeFieldFormatter::representValue(), QDate and QDateTime fields don't need a triple conversion (QVariant->toString->fromString->toString) where a double conversion (QVariant->QDateTime->toString) is enough.
This commit is contained in:
parent
f86f476f2b
commit
add71e84aa
@ -51,13 +51,20 @@ QString QgsDateTimeFieldFormatter::representValue( QgsVectorLayer *layer, int fi
|
||||
const QString displayFormat = config.value( QStringLiteral( "display_format" ), defaultFormat( field.type() ) ).toString();
|
||||
|
||||
QDateTime date;
|
||||
if ( fieldIsoFormat )
|
||||
if ( static_cast<QMetaType::Type>( value.type() ) == QMetaType::QDate || static_cast<QMetaType::Type>( value.type() ) == QMetaType::QDateTime )
|
||||
{
|
||||
date = QDateTime::fromString( value.toString(), Qt::ISODate );
|
||||
date = value.toDateTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
date = QDateTime::fromString( value.toString(), fieldFormat );
|
||||
if ( fieldIsoFormat )
|
||||
{
|
||||
date = QDateTime::fromString( value.toString(), Qt::ISODate );
|
||||
}
|
||||
else
|
||||
{
|
||||
date = QDateTime::fromString( value.toString(), fieldFormat );
|
||||
}
|
||||
}
|
||||
|
||||
if ( date.isValid() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user