Add DateTime filter support to QgsFieldProxyModel

This commit is contained in:
Nyall Dawson 2019-06-24 19:09:41 +10:00
parent 49731f21ec
commit 42562c6226
3 changed files with 6 additions and 0 deletions

View File

@ -85,6 +85,7 @@ bool QgsFieldProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
( mFilters.testFlag( Double ) && type == QVariant::Double ) ||
( mFilters.testFlag( Date ) && type == QVariant::Date ) ||
( mFilters.testFlag( Date ) && type == QVariant::DateTime ) ||
( mFilters.testFlag( DateTime ) && type == QVariant::DateTime ) ||
( mFilters.testFlag( Time ) && type == QVariant::Time ) )
return true;

View File

@ -46,6 +46,7 @@ class CORE_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
Date = 16, //!< Date or datetime fields
Time = 32, //!< Time fields
HideReadOnly = 64, //!< Hide read-only fields
DateTime = 128, //!< Datetime fieldss
AllTypes = Numeric | Date | String | Time, //!< All field types
};
Q_DECLARE_FLAGS( Filters, Filter )

View File

@ -306,6 +306,10 @@ void TestQgsFieldExpressionWidget::testFilters()
QCOMPARE( widget->mCombo->count(), 1 );
QCOMPARE( widget->mCombo->itemText( 0 ), QStringLiteral( "timefld" ) );
widget->setFilters( QgsFieldProxyModel::DateTime );
QCOMPARE( widget->mCombo->count(), 1 );
QCOMPARE( widget->mCombo->itemText( 0 ), QStringLiteral( "datetimefld" ) );
QgsProject::instance()->removeMapLayer( layer );
}