Skip to content
Permalink
Browse files

use appropriate field type in date time edit widget wrapper

  • Loading branch information
3nids committed Jan 4, 2018
1 parent 5d245a9 commit 1d730685fe82187d10393e1ba75911047a925278
Showing with 73 additions and 54 deletions.
  1. +73 −54 src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp
@@ -113,15 +113,29 @@ void QgsDateTimeEditWrapper::showIndeterminateState()

void QgsDateTimeEditWrapper::dateTimeChanged( const QDateTime& dateTime )
{
const bool fieldIsoFormat = config( "field_iso_format" , false ).toBool();
const QString fieldFormat = config( "field_format" , QGSDATETIMEEDIT_DATEFORMAT ).toString();
if ( fieldIsoFormat )
{
emit valueChanged( dateTime.toString( Qt::ISODate ) );
}
else
{
emit valueChanged( dateTime.toString( fieldFormat ) );
switch ( field().type() )
{
case QVariant::DateTime:
emit valueChanged( dateTime );
break;
case QVariant::Date:
emit valueChanged( dateTime.date() );
break;
case QVariant::Time:
emit valueChanged( dateTime.time() );
break;
default:
const bool fieldIsoFormat = config( "field_iso_format" , false ).toBool();
const QString fieldFormat = config( "field_format" , QGSDATETIMEEDIT_DATEFORMAT ).toString();
if ( fieldIsoFormat )
{
emit valueChanged( dateTime.toString( Qt::ISODate ) );
}
else
{
emit valueChanged( dateTime.toString( fieldFormat ) );
}
break;
}
}

@@ -130,37 +144,39 @@ QVariant QgsDateTimeEditWrapper::value() const
if ( !mQDateTimeEdit )
return QVariant( field().type() );

if ( field().type() == QVariant::DateTime )
{
if ( mQgsDateTimeEdit )
{
return mQgsDateTimeEdit->dateTime();
}
else
{
return mQDateTimeEdit->dateTime();
}
}

const bool fieldIsoFormat = config( "field_iso_format", false ).toBool();
const QString fieldFormat = config( "field_format", QGSDATETIMEEDIT_DATEFORMAT ).toString();

QDateTime date;
QDateTime dateTime;
if ( mQgsDateTimeEdit )
{
date = mQgsDateTimeEdit->dateTime();
dateTime = mQgsDateTimeEdit->dateTime();
}
else
{
date = mQDateTimeEdit->dateTime();
}
if ( fieldIsoFormat )
{
return date.toString( Qt::ISODate );
}
else
{
return date.toString( fieldFormat );
dateTime = mQDateTimeEdit->dateTime();
}

switch ( field().type() )
{
case QVariant::DateTime:
return dateTime;
break;
case QVariant::Date:
return dateTime.date();
break;
case QVariant::Time:
return dateTime.time();
break;
default:
const bool fieldIsoFormat = config( "field_iso_format", false ).toBool();
const QString fieldFormat = config( "field_format", QGSDATETIMEEDIT_DATEFORMAT ).toString();
if ( fieldIsoFormat )
{
return dateTime.toString( Qt::ISODate );
}
else
{
return dateTime.toString( fieldFormat );
}
break;
}
}

@@ -169,33 +185,36 @@ void QgsDateTimeEditWrapper::setValue( const QVariant &value )
if ( !mQDateTimeEdit )
return;

const bool fieldIsoFormat = config( "field_iso_format", false ).toBool();
const QString fieldFormat = config( "field_format", QGSDATETIMEEDIT_DATEFORMAT ).toString();

QDateTime date;
if ( field().type() == QVariant::DateTime )
{
date = value.toDateTime();
}
else
{
if ( fieldIsoFormat )
{
date = QDateTime::fromString( value.toString(), Qt::ISODate );
}
else
{
date = QDateTime::fromString( value.toString(), fieldFormat );
}
QDateTime dateTime;
switch ( field().type() )
{
case QVariant::DateTime:
case QVariant::Date:
case QVariant::Time:
dateTime = value.toDateTime();
break;
default:
const bool fieldIsoFormat = config( "field_iso_format", false ).toBool();
const QString fieldFormat = config( "field_format", QGSDATETIMEEDIT_DATEFORMAT ).toString();
if ( fieldIsoFormat )
{
dateTime = QDateTime::fromString( value.toString(), Qt::ISODate );
}
else
{
dateTime = QDateTime::fromString( value.toString(), fieldFormat );
}
break;
}

if ( mQgsDateTimeEdit )
{
mQgsDateTimeEdit->setDateTime( date );
mQgsDateTimeEdit->setDateTime( dateTime );
}
else
{
mQDateTimeEdit->setDateTime( date );
mQDateTimeEdit->setDateTime( dateTime );
}
}

0 comments on commit 1d73068

Please sign in to comment.
You can’t perform that action at this time.