mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
proper use of category tags - use of all tag as default in filtering
This commit is contained in:
parent
272d022dbc
commit
e89ebf1b69
@ -20,7 +20,9 @@ struct QgsStoredExpression
|
||||
|
||||
enum Category
|
||||
{
|
||||
FilterExpression
|
||||
FilterExpression,
|
||||
DefaultValueExpression,
|
||||
All
|
||||
};
|
||||
|
||||
|
||||
@ -51,7 +53,7 @@ Adds an expression to the list
|
||||
|
||||
:param name: optional name of the expression
|
||||
:param expression: expression text
|
||||
:param tag: category of the expression
|
||||
:param tag: category of the expression - default FilterExpression
|
||||
|
||||
:return: generated id as QString
|
||||
%End
|
||||
@ -63,7 +65,7 @@ Removes an expression to the list
|
||||
:param id: id of the expression as identification
|
||||
%End
|
||||
|
||||
void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
|
||||
void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag );
|
||||
%Docstring
|
||||
Updates an expression by id
|
||||
|
||||
@ -80,11 +82,11 @@ Appends a list of expressions to the existing list
|
||||
:param storedExpressions: list of expressions and the optional name
|
||||
%End
|
||||
|
||||
QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
|
||||
QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All );
|
||||
%Docstring
|
||||
Returns the list of named expressions
|
||||
|
||||
:param tag: where the expression is used
|
||||
:param tag: where the expression is used - default all
|
||||
%End
|
||||
|
||||
|
||||
@ -95,12 +97,12 @@ Returns an expression according to the id
|
||||
:param id: id of the expression as identification
|
||||
%End
|
||||
|
||||
QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression ) const;
|
||||
QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All ) const;
|
||||
%Docstring
|
||||
Returns an expression according to the expression text
|
||||
|
||||
:param expression: id of the expression as identification
|
||||
:param tag: category of the expression
|
||||
:param tag: category of the expression - default all
|
||||
%End
|
||||
|
||||
void clearStoredExpressions();
|
||||
|
@ -1168,7 +1168,7 @@ void QgsAttributeTableDialog::editStoredFilterExpression()
|
||||
if ( dlg->exec() == QDialog::Accepted )
|
||||
{
|
||||
//update stored expression
|
||||
mLayer->storedExpressionManager()->updateStoredExpression( mActionHandleStoreFilterExpression->data().toString(), nameEdit->text(), expressionEdit->expression() );
|
||||
mLayer->storedExpressionManager()->updateStoredExpression( mActionHandleStoreFilterExpression->data().toString(), nameEdit->text(), expressionEdit->expression(), QgsStoredExpression::Category::FilterExpression );
|
||||
|
||||
//update text
|
||||
mFilterQuery->setValue( expressionEdit->expression() );
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
QString QgsStoredExpressionManager::addStoredExpression( const QString &name, const QString &expression, const QgsStoredExpression::Category &tag )
|
||||
{
|
||||
Q_UNUSED( tag );
|
||||
|
||||
QgsStoredExpression storedExpression( name, expression, tag );
|
||||
|
||||
mStoredExpressions.append( storedExpression );
|
||||
@ -49,8 +47,6 @@ void QgsStoredExpressionManager::removeStoredExpression( const QString &id )
|
||||
|
||||
void QgsStoredExpressionManager::updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag )
|
||||
{
|
||||
Q_UNUSED( tag );
|
||||
|
||||
int i = 0;
|
||||
for ( const QgsStoredExpression &storedExpression : qgis::as_const( mStoredExpressions ) )
|
||||
{
|
||||
@ -75,9 +71,16 @@ void QgsStoredExpressionManager::addStoredExpressions( QList< QgsStoredExpressio
|
||||
|
||||
QList< QgsStoredExpression > QgsStoredExpressionManager::storedExpressions( const QgsStoredExpression::Category &tag )
|
||||
{
|
||||
Q_UNUSED( tag );
|
||||
QList< QgsStoredExpression > storedExpressions;
|
||||
|
||||
return mStoredExpressions;
|
||||
for ( const QgsStoredExpression &storedExpression : qgis::as_const( mStoredExpressions ) )
|
||||
{
|
||||
if ( storedExpression.tag & tag )
|
||||
{
|
||||
storedExpressions.append( storedExpression );
|
||||
}
|
||||
}
|
||||
return storedExpressions;
|
||||
}
|
||||
|
||||
QgsStoredExpression QgsStoredExpressionManager::storedExpression( const QString &id ) const
|
||||
@ -94,8 +97,6 @@ QgsStoredExpression QgsStoredExpressionManager::storedExpression( const QString
|
||||
|
||||
QgsStoredExpression QgsStoredExpressionManager::findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag ) const
|
||||
{
|
||||
Q_UNUSED( tag );
|
||||
|
||||
for ( const QgsStoredExpression &storedExpression : qgis::as_const( mStoredExpressions ) )
|
||||
{
|
||||
if ( storedExpression.expression == expression && storedExpression.tag & tag )
|
||||
|
@ -44,10 +44,13 @@ struct CORE_EXPORT QgsStoredExpression
|
||||
/**
|
||||
* Categories of use cases
|
||||
* FilterExpression for stored expressions to filter attribute table
|
||||
* DefaultValueExpression for stored expressions to use for default values (not yet used)
|
||||
*/
|
||||
enum Category
|
||||
{
|
||||
FilterExpression = 1 << 0 //!< Expressions to filter features
|
||||
FilterExpression = 1 << 0, //!< Expressions to filter features
|
||||
DefaultValueExpression = 1 << 1, //!< Expressions to determine default values (not yet used)
|
||||
All = FilterExpression | DefaultValueExpression
|
||||
};
|
||||
|
||||
#ifndef SIP_RUN
|
||||
@ -86,7 +89,7 @@ class CORE_EXPORT QgsStoredExpressionManager : public QObject
|
||||
*
|
||||
* \param name optional name of the expression
|
||||
* \param expression expression text
|
||||
* \param tag category of the expression
|
||||
* \param tag category of the expression - default FilterExpression
|
||||
* \returns generated id as QString
|
||||
*/
|
||||
QString addStoredExpression( const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
|
||||
@ -106,7 +109,7 @@ class CORE_EXPORT QgsStoredExpressionManager : public QObject
|
||||
* \param expression new expression text
|
||||
* \param tag new category of the expression
|
||||
*/
|
||||
void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
|
||||
void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag );
|
||||
|
||||
/**
|
||||
* Appends a list of expressions to the existing list
|
||||
@ -118,9 +121,9 @@ class CORE_EXPORT QgsStoredExpressionManager : public QObject
|
||||
/**
|
||||
* Returns the list of named expressions
|
||||
*
|
||||
* \param tag where the expression is used
|
||||
* \param tag where the expression is used - default all
|
||||
*/
|
||||
QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
|
||||
QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All );
|
||||
|
||||
|
||||
/**
|
||||
@ -134,9 +137,9 @@ class CORE_EXPORT QgsStoredExpressionManager : public QObject
|
||||
* Returns an expression according to the expression text
|
||||
*
|
||||
* \param expression id of the expression as identification
|
||||
* \param tag category of the expression
|
||||
* \param tag category of the expression - default all
|
||||
*/
|
||||
QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression ) const;
|
||||
QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All ) const;
|
||||
|
||||
//! clears list of stored expressions
|
||||
void clearStoredExpressions();
|
||||
|
@ -39,10 +39,16 @@ void TestQgsStoredExpressionManager::init()
|
||||
|
||||
QList <QgsStoredExpression> newStoredExpressions;
|
||||
|
||||
//fill up
|
||||
//fill up some for the FilterExpression
|
||||
for ( int i = 0; i < 10; i++ )
|
||||
{
|
||||
QgsStoredExpression storedExpression( QStringLiteral( "test%1" ).arg( i ), QStringLiteral( "\"age\"=%1" ).arg( i ) );
|
||||
QgsStoredExpression storedExpression( QStringLiteral( "filter%1" ).arg( i ), QStringLiteral( "\"age\"=%1" ).arg( i ), QgsStoredExpression::Category::FilterExpression );
|
||||
newStoredExpressions.append( storedExpression );
|
||||
}
|
||||
//fill up some for the DefaultValues
|
||||
for ( int i = 10; i < 20; i++ )
|
||||
{
|
||||
QgsStoredExpression storedExpression( QStringLiteral( "default%1" ).arg( i ), QStringLiteral( "'ID_'+%1" ).arg( i ), QgsStoredExpression::Category::DefaultValueExpression );
|
||||
newStoredExpressions.append( storedExpression );
|
||||
}
|
||||
mManager->addStoredExpressions( newStoredExpressions );
|
||||
@ -55,8 +61,9 @@ void TestQgsStoredExpressionManager::cleanup()
|
||||
|
||||
void TestQgsStoredExpressionManager::storeSingleExpression()
|
||||
{
|
||||
QString name = QStringLiteral( "test0" );
|
||||
QString expression = QStringLiteral( "\"age\"=0" );
|
||||
//add single stored filter expression
|
||||
QString name = QStringLiteral( "test20" );
|
||||
QString expression = QStringLiteral( "\"age\"=20" );
|
||||
QString id = mManager->addStoredExpression( name, expression );
|
||||
|
||||
//get stored expression by id
|
||||
@ -64,13 +71,20 @@ void TestQgsStoredExpressionManager::storeSingleExpression()
|
||||
QCOMPARE( storedExpression.id, id );
|
||||
QCOMPARE( storedExpression.name, name );
|
||||
QCOMPARE( storedExpression.expression, expression );
|
||||
QCOMPARE( storedExpression.tag, QgsStoredExpression::Category::FilterExpression );
|
||||
|
||||
//get all expressions
|
||||
QList <QgsStoredExpression> allStoredExpressions = mManager->storedExpressions();
|
||||
QCOMPARE( allStoredExpressions.count(), 11 );
|
||||
QCOMPARE( allStoredExpressions.at( 10 ).id, id );
|
||||
QCOMPARE( allStoredExpressions.at( 10 ).name, name );
|
||||
QCOMPARE( allStoredExpressions.at( 10 ).expression, expression );
|
||||
QCOMPARE( allStoredExpressions.count(), 21 );
|
||||
|
||||
//get all expressions for Category::FilterExpression
|
||||
QList <QgsStoredExpression> allStoredFilterExpressions = mManager->storedExpressions( QgsStoredExpression::Category::FilterExpression );
|
||||
QCOMPARE( allStoredFilterExpressions.count(), 11 );
|
||||
|
||||
QCOMPARE( allStoredFilterExpressions.at( 10 ).id, id );
|
||||
QCOMPARE( allStoredFilterExpressions.at( 10 ).name, name );
|
||||
QCOMPARE( allStoredFilterExpressions.at( 10 ).expression, expression );
|
||||
QCOMPARE( allStoredFilterExpressions.at( 10 ).tag, QgsStoredExpression::Category::FilterExpression );
|
||||
}
|
||||
|
||||
void TestQgsStoredExpressionManager::storeListOfExpressions()
|
||||
@ -78,7 +92,7 @@ void TestQgsStoredExpressionManager::storeListOfExpressions()
|
||||
QList <QgsStoredExpression> newStoredExpressions;
|
||||
|
||||
//fill up
|
||||
for ( int i = 10; i < 20; i++ )
|
||||
for ( int i = 20; i < 30; i++ )
|
||||
{
|
||||
QgsStoredExpression storedExpression( QStringLiteral( "test%1" ).arg( i ), QStringLiteral( "\"age\"=%1" ).arg( i ) );
|
||||
newStoredExpressions.append( storedExpression );
|
||||
@ -87,35 +101,38 @@ void TestQgsStoredExpressionManager::storeListOfExpressions()
|
||||
|
||||
//get all expressions
|
||||
QList <QgsStoredExpression> allStoredExpressions = mManager->storedExpressions();
|
||||
QCOMPARE( allStoredExpressions.count(), 20 );
|
||||
QCOMPARE( allStoredExpressions.at( 0 ).name, QStringLiteral( "test0" ) );
|
||||
QCOMPARE( allStoredExpressions.count(), 30 );
|
||||
QCOMPARE( allStoredExpressions.at( 0 ).name, QStringLiteral( "filter0" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 0 ).expression, QStringLiteral( "\"age\"=0" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 14 ).name, QStringLiteral( "test14" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 14 ).expression, QStringLiteral( "\"age\"=14" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 19 ).name, QStringLiteral( "test19" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 19 ).expression, QStringLiteral( "\"age\"=19" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 14 ).name, QStringLiteral( "default14" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 14 ).expression, QStringLiteral( "'ID_'+14" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 25 ).name, QStringLiteral( "test25" ) );
|
||||
QCOMPARE( allStoredExpressions.at( 25 ).expression, QStringLiteral( "\"age\"=25" ) );
|
||||
}
|
||||
|
||||
void TestQgsStoredExpressionManager::editExpressionsByExpression()
|
||||
{
|
||||
QgsStoredExpression storedExpression = mManager->findStoredExpressionByExpression( QStringLiteral( "\"age\"=4" ) );
|
||||
QCOMPARE( storedExpression.name, QStringLiteral( "test4" ) );
|
||||
QCOMPARE( storedExpression.name, QStringLiteral( "filter4" ) );
|
||||
|
||||
mManager->updateStoredExpression( storedExpression.id, QStringLiteral( "Much older" ), QStringLiteral( "\"age\">99" ) );
|
||||
mManager->updateStoredExpression( storedExpression.id, QStringLiteral( "Much older" ), QStringLiteral( "\"age\">99" ), QgsStoredExpression::Category::FilterExpression );
|
||||
|
||||
QCOMPARE( mManager->storedExpression( storedExpression.id ).name, QStringLiteral( "Much older" ) );
|
||||
QCOMPARE( mManager->storedExpression( storedExpression.id ).expression, QStringLiteral( "\"age\">99" ) );
|
||||
QCOMPARE( mManager->storedExpression( storedExpression.id ).tag, QgsStoredExpression::Category::FilterExpression );
|
||||
|
||||
QgsStoredExpression newStoredExpression = mManager->findStoredExpressionByExpression( QStringLiteral( "\"age\">99" ) );
|
||||
QCOMPARE( newStoredExpression.name, QStringLiteral( "Much older" ) );
|
||||
}
|
||||
|
||||
void TestQgsStoredExpressionManager::deleteExpressionByExpression()
|
||||
{
|
||||
QgsStoredExpression storedExpression = mManager->findStoredExpressionByExpression( QStringLiteral( "\"age\"=4" ) );
|
||||
QCOMPARE( storedExpression.name, QStringLiteral( "test4" ) );
|
||||
QCOMPARE( storedExpression.name, QStringLiteral( "filter4" ) );
|
||||
|
||||
mManager->removeStoredExpression( storedExpression.id );
|
||||
|
||||
storedExpression = mManager->findStoredExpressionByExpression( QStringLiteral( "\"age\"=4" ) );
|
||||
|
||||
QVERIFY( storedExpression.id.isNull() );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user