Skip to content
Permalink
Browse files

Fix datetime fields not shown in QgsFieldComboWidget when set to date…

… filter
  • Loading branch information
nyalldawson committed May 11, 2016
1 parent a389d23 commit b4029dc7f0169b60117c4ece7c15a31a8766cb4f
Showing with 52 additions and 1 deletion.
  1. +2 −1 src/gui/qgsfieldproxymodel.cpp
  2. +50 −0 tests/src/gui/testqgsfieldexpressionwidget.cpp
@@ -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;
@@ -50,6 +50,7 @@ class TestQgsFieldExpressionWidget : public QObject
void testRemoveJoin();
void asExpression();
void testIsValid();
void testFilters();

private:
QgsFieldExpressionWidget* mWidget;
@@ -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"

0 comments on commit b4029dc

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