Skip to content

Commit

Permalink
Avoid triple conversion for Date/Time field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agiudiceandrea authored and nyalldawson committed May 28, 2020
1 parent f86f476 commit add71e8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/fieldformatter/qgsdatetimefieldformatter.cpp
Expand Up @@ -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() )
Expand Down

0 comments on commit add71e8

Please sign in to comment.