Skip to content

Commit

Permalink
use appropriate field type in date time edit widget wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 4, 2018
1 parent 5d245a9 commit 1d73068
Showing 1 changed file with 73 additions and 54 deletions.
127 changes: 73 additions & 54 deletions src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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 );
}
}

Expand Down

0 comments on commit 1d73068

Please sign in to comment.