mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[composer] Fix editing of map item variables
On behalf of Faunalia, sponsored by ENEL
This commit is contained in:
parent
b2f4582f00
commit
5384e203fb
@ -296,6 +296,13 @@ class QgsExpressionContext
|
||||
*/
|
||||
int indexOfScope( QgsExpressionContextScope* scope ) const;
|
||||
|
||||
/** Returns the index of the first scope with a matching name within the context.
|
||||
* @param scopeName name of scope to find
|
||||
* @returns index of scope, or -1 if scope was not found within the context.
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
int indexOfScope( const QString& scopeName ) const;
|
||||
|
||||
/** Returns a list of variables names set by all scopes in the context.
|
||||
* @returns list of unique variable names
|
||||
* @see filteredVariableNames
|
||||
|
@ -114,7 +114,9 @@ void QgsComposerItemWidget::updateVariables()
|
||||
{
|
||||
QgsExpressionContext* context = mItem->createExpressionContext();
|
||||
mVariableEditor->setContext( context );
|
||||
mVariableEditor->setEditableScopeIndex( context->scopeCount() - 1 );
|
||||
int editableIndex = context->indexOfScope( tr( "Composer Item" ) );
|
||||
if ( editableIndex >= 0 )
|
||||
mVariableEditor->setEditableScopeIndex( editableIndex );
|
||||
delete context;
|
||||
}
|
||||
|
||||
|
@ -312,6 +312,19 @@ int QgsExpressionContext::indexOfScope( QgsExpressionContextScope* scope ) const
|
||||
return mStack.indexOf( scope );
|
||||
}
|
||||
|
||||
int QgsExpressionContext::indexOfScope( const QString& scopeName ) const
|
||||
{
|
||||
int index = 0;
|
||||
Q_FOREACH ( const QgsExpressionContextScope* scope, mStack )
|
||||
{
|
||||
if ( scope->name() == scopeName )
|
||||
return index;
|
||||
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QStringList QgsExpressionContext::variableNames() const
|
||||
{
|
||||
QStringList names;
|
||||
|
@ -334,6 +334,13 @@ class CORE_EXPORT QgsExpressionContext
|
||||
*/
|
||||
int indexOfScope( QgsExpressionContextScope* scope ) const;
|
||||
|
||||
/** Returns the index of the first scope with a matching name within the context.
|
||||
* @param scopeName name of scope to find
|
||||
* @returns index of scope, or -1 if scope was not found within the context.
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
int indexOfScope( const QString& scopeName ) const;
|
||||
|
||||
/** Returns a list of variables names set by all scopes in the context.
|
||||
* @returns list of unique variable names
|
||||
* @see filteredVariableNames
|
||||
|
@ -37,6 +37,7 @@ class TestQgsExpressionContext : public QObject
|
||||
void contextScopeCopy();
|
||||
void contextScopeFunctions();
|
||||
void contextStack();
|
||||
void scopeByName();
|
||||
void contextCopy();
|
||||
void contextStackFunctions();
|
||||
void evaluate();
|
||||
@ -302,6 +303,17 @@ void TestQgsExpressionContext::contextStack()
|
||||
QCOMPARE( scopes.at( 0 ), scope1 );
|
||||
}
|
||||
|
||||
void TestQgsExpressionContext::scopeByName()
|
||||
{
|
||||
QgsExpressionContext context;
|
||||
QCOMPARE( context.indexOfScope( "test1" ), -1 );
|
||||
context << new QgsExpressionContextScope( "test1" );
|
||||
context << new QgsExpressionContextScope( "test2" );
|
||||
QCOMPARE( context.indexOfScope( "test1" ), 0 );
|
||||
QCOMPARE( context.indexOfScope( "test2" ), 1 );
|
||||
QCOMPARE( context.indexOfScope( "not in context" ), -1 );
|
||||
}
|
||||
|
||||
void TestQgsExpressionContext::contextCopy()
|
||||
{
|
||||
QgsExpressionContext context;
|
||||
|
Loading…
x
Reference in New Issue
Block a user