Navigation Menu

Skip to content

Commit

Permalink
Fix datetime fields not shown in QgsFieldComboWidget when set to date…
Browse files Browse the repository at this point in the history
… filter
  • Loading branch information
nyalldawson committed May 11, 2016
1 parent a389d23 commit b4029dc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gui/qgsfieldproxymodel.cpp
Expand Up @@ -53,7 +53,8 @@ bool QgsFieldProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
( mFilters.testFlag( LongLong ) && type == QVariant::LongLong ) ||
( mFilters.testFlag( Int ) && type == QVariant::Int ) ||
( mFilters.testFlag( Double ) && type == QVariant::Double ) ||
( mFilters.testFlag( Date ) && type == QVariant::Date ) )
( mFilters.testFlag( Date ) && type == QVariant::Date ) ||
( mFilters.testFlag( Date ) && type == QVariant::DateTime ) )
return true;

return false;
Expand Down
50 changes: 50 additions & 0 deletions tests/src/gui/testqgsfieldexpressionwidget.cpp
Expand Up @@ -50,6 +50,7 @@ class TestQgsFieldExpressionWidget : public QObject
void testRemoveJoin();
void asExpression();
void testIsValid();
void testFilters();

private:
QgsFieldExpressionWidget* mWidget;
Expand Down Expand Up @@ -219,6 +220,55 @@ void TestQgsFieldExpressionWidget::testIsValid()
QgsMapLayerRegistry::instance()->removeMapLayer( layer );
}

void TestQgsFieldExpressionWidget::testFilters()
{
QgsVectorLayer* layer = new QgsVectorLayer( "point?field=intfld:int&field=stringfld:string&field=string2fld:string&field=longfld:long&field=doublefld:double&field=datefld:date&field=timefld:time&field=datetimefld:datetime", "x", "memory" );
QgsMapLayerRegistry::instance()->addMapLayer( layer );

QScopedPointer< QgsFieldExpressionWidget > widget( new QgsFieldExpressionWidget() );
widget->setLayer( layer );

QCOMPARE( widget->mCombo->count(), 8 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "intfld" ) );
QCOMPARE( widget->mCombo->itemText( 1 ), QString( "stringfld" ) );
QCOMPARE( widget->mCombo->itemText( 2 ), QString( "string2fld" ) );
QCOMPARE( widget->mCombo->itemText( 3 ), QString( "longfld" ) );
QCOMPARE( widget->mCombo->itemText( 4 ), QString( "doublefld" ) );
QCOMPARE( widget->mCombo->itemText( 5 ), QString( "datefld" ) );
QCOMPARE( widget->mCombo->itemText( 6 ), QString( "timefld" ) );
QCOMPARE( widget->mCombo->itemText( 7 ), QString( "datetimefld" ) );

widget->setFilters( QgsFieldProxyModel::String );
QCOMPARE( widget->mCombo->count(), 2 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "stringfld" ) );
QCOMPARE( widget->mCombo->itemText( 1 ), QString( "string2fld" ) );

widget->setFilters( QgsFieldProxyModel::Int );
QCOMPARE( widget->mCombo->count(), 1 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "intfld" ) );

widget->setFilters( QgsFieldProxyModel::LongLong );
QCOMPARE( widget->mCombo->count(), 1 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "longfld" ) );

widget->setFilters( QgsFieldProxyModel::Double );
QCOMPARE( widget->mCombo->count(), 1 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "doublefld" ) );

widget->setFilters( QgsFieldProxyModel::Numeric );
QCOMPARE( widget->mCombo->count(), 3 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "intfld" ) );
QCOMPARE( widget->mCombo->itemText( 1 ), QString( "longfld" ) );
QCOMPARE( widget->mCombo->itemText( 2 ), QString( "doublefld" ) );

widget->setFilters( QgsFieldProxyModel::Date );
QCOMPARE( widget->mCombo->count(), 2 );
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "datefld" ) );
QCOMPARE( widget->mCombo->itemText( 1 ), QString( "datetimefld" ) );

QgsMapLayerRegistry::instance()->removeMapLayer( layer );
}

QTEST_MAIN( TestQgsFieldExpressionWidget )
#include "testqgsfieldexpressionwidget.moc"

Expand Down

0 comments on commit b4029dc

Please sign in to comment.