Skip to content
Permalink
Browse files
Add time field filter option for QgsFieldComboWidget (also add docs)
  • Loading branch information
nyalldawson committed May 11, 2016
1 parent b4029dc commit 5177d93b5a2a15c02232bba115146f4fbf362ade
@@ -10,15 +10,18 @@ class QgsFieldProxyModel : QSortFilterProxyModel
%End

public:

//! Field type filters
enum Filter
{
String,
Int,
LongLong,
Double,
Numeric,
Date,
All
String, /*!< String fields */
Int, /*!< Integer fields */
LongLong, /*!< Longlong fields */
Double, /*!< Double fields */
Numeric, /*!< All numeric fields */
Date, /*!< Date or datetime fields */
Time, /*!< Time fields */
All, /*!< All fields */
};
typedef QFlags<QgsFieldProxyModel::Filter> Filters;

@@ -28,15 +31,19 @@ class QgsFieldProxyModel : QSortFilterProxyModel
*/
explicit QgsFieldProxyModel( QObject *parent /TransferThis/ = 0 );

//! sourceFieldModel returns the QgsFieldModel used in this QSortFilterProxyModel
//! Returns the QgsFieldModel used in this QSortFilterProxyModel
QgsFieldModel* sourceFieldModel();

/**
* @brief setFilters set flags that affect how fields are filtered
* Set flags that affect how fields are filtered in the model.
* @param filters are Filter flags
* @note added in 2.3
* @see filters()
*/
QgsFieldProxyModel* setFilters( const Filters& filters );

/** Returns the filters controlling displayed fields.
* @see setFilters()
*/
const Filters& filters() const;

// QSortFilterProxyModel interface
@@ -54,7 +54,8 @@ bool QgsFieldProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
( mFilters.testFlag( Int ) && type == QVariant::Int ) ||
( mFilters.testFlag( Double ) && type == QVariant::Double ) ||
( mFilters.testFlag( Date ) && type == QVariant::Date ) ||
( mFilters.testFlag( Date ) && type == QVariant::DateTime ) )
( mFilters.testFlag( Date ) && type == QVariant::DateTime ) ||
( mFilters.testFlag( Time ) && type == QVariant::Time ) )
return true;

return false;
@@ -30,15 +30,18 @@ class GUI_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
Q_FLAGS( Filters )

public:

//! Field type filters
enum Filter
{
String = 1,
Int = 2,
LongLong = 4,
Double = 8,
Numeric = Int | LongLong | Double,
Date = 16,
All = Numeric | Date | String
String = 1, /*!< String fields */
Int = 2, /*!< Integer fields */
LongLong = 4, /*!< Longlong fields */
Double = 8, /*!< Double fields */
Numeric = Int | LongLong | Double, /*!< All numeric fields */
Date = 16, /*!< Date or datetime fields */
Time = 32, /*!< Time fields */
All = Numeric | Date | String | Time, /*!< All fields */
};
Q_DECLARE_FLAGS( Filters, Filter )

@@ -48,15 +51,19 @@ class GUI_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel
*/
explicit QgsFieldProxyModel( QObject *parent = nullptr );

//! sourceFieldModel returns the QgsFieldModel used in this QSortFilterProxyModel
//! Returns the QgsFieldModel used in this QSortFilterProxyModel
QgsFieldModel* sourceFieldModel() { return mModel; }

/**
* @brief setFilters set flags that affect how fields are filtered
* Set flags that affect how fields are filtered in the model.
* @param filters are Filter flags
* @note added in 2.3
* @see filters()
*/
QgsFieldProxyModel* setFilters( const QgsFieldProxyModel::Filters& filters );

/** Returns the filters controlling displayed fields.
* @see setFilters()
*/
const Filters& filters() const { return mFilters; }

private:
@@ -266,6 +266,10 @@ void TestQgsFieldExpressionWidget::testFilters()
QCOMPARE( widget->mCombo->itemText( 0 ), QString( "datefld" ) );
QCOMPARE( widget->mCombo->itemText( 1 ), QString( "datetimefld" ) );

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

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

0 comments on commit 5177d93

Please sign in to comment.