Skip to content

Commit

Permalink
Use @row_number, @column_number to unify variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 1878f2e commit 8e3151a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -793,6 +793,7 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts()->insert( QStringLiteral( "row_number" ), QCoreApplication::translate( "variable_help", "Stores the number of the current row." ) );
sVariableHelpTexts()->insert( QStringLiteral( "grid_number" ), QCoreApplication::translate( "variable_help", "Current grid annotation value." ) );
sVariableHelpTexts()->insert( QStringLiteral( "grid_axis" ), QCoreApplication::translate( "variable_help", "Current grid annotation axis (e.g., 'x' for longitude, 'y' for latitude)." ) );
sVariableHelpTexts()->insert( QStringLiteral( "column_number" ), QCoreApplication::translate( "variable_help", "Stores the number of the current column." ) );

// map canvas item variables
sVariableHelpTexts()->insert( QStringLiteral( "canvas_cursor_point" ), QCoreApplication::translate( "variable_help", "Last cursor position on the canvas in the project's geographical coordinates." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayouttable.cpp
Expand Up @@ -992,8 +992,8 @@ QMap<int, QString> QgsLayoutTable::headerLabels() const
QgsExpressionContextScope *QgsLayoutTable::scopeForCell( int row, int column ) const
{
std::unique_ptr< QgsExpressionContextScope > cellScope = qgis::make_unique< QgsExpressionContextScope >();
cellScope->setVariable( QStringLiteral( "table_row" ), row + 1, true );
cellScope->setVariable( QStringLiteral( "table_column" ), column + 1, true );
cellScope->setVariable( QStringLiteral( "row_number" ), row + 1, true );
cellScope->setVariable( QStringLiteral( "column_number" ), column + 1, true );
return cellScope.release();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgslayoutmanualtable.cpp
Expand Up @@ -284,8 +284,8 @@ void TestQgsLayoutManualTable::scopeForCell()
std::unique_ptr< QgsExpressionContextScope > scope( table->scopeForCell( 1, 2 ) );

// variable values for row/col should start at 1, not 0!
QCOMPARE( scope->variable( QStringLiteral( "table_row" ) ).toInt(), 2 );
QCOMPARE( scope->variable( QStringLiteral( "table_column" ) ).toInt(), 3 );
QCOMPARE( scope->variable( QStringLiteral( "row_number" ) ).toInt(), 2 );
QCOMPARE( scope->variable( QStringLiteral( "column_number" ) ).toInt(), 3 );
}

void TestQgsLayoutManualTable::expressionContents()
Expand All @@ -307,7 +307,7 @@ void TestQgsLayoutManualTable::expressionContents()
expectedRows.append( row );

table->setTableContents(
QgsTableContents() << ( QgsTableRow() << QgsTableCell( QStringLiteral( "Jet" ) ) << QgsTableCell( QgsProperty::fromExpression( QStringLiteral( "@table_row || ',' || @table_column" ) ) ) << QgsTableCell( QgsProperty::fromExpression( QStringLiteral( "@table_row || ',' || @table_column" ) ) ) )
QgsTableContents() << ( QgsTableRow() << QgsTableCell( QStringLiteral( "Jet" ) ) << QgsTableCell( QgsProperty::fromExpression( QStringLiteral( "@row_number || ',' || @column_number" ) ) ) << QgsTableCell( QgsProperty::fromExpression( QStringLiteral( "@row_number || ',' || @column_number" ) ) ) )
<< ( QgsTableRow() << QgsTableCell( QgsProperty::fromExpression( QStringLiteral( "@layout_name" ) ) ) << QgsTableCell( QStringLiteral( "Helicopter" ) ) << QgsTableCell( QStringLiteral( "Plane" ) ) ) );
compareTable( table, expectedRows );

Expand Down
12 changes: 6 additions & 6 deletions tests/src/core/testqgslayouttable.cpp
Expand Up @@ -1651,16 +1651,16 @@ void TestQgsLayoutTable::testScopeForCell()
std::unique_ptr< QgsExpressionContextScope > scope( table->scopeForCell( 0, 0 ) );

// variable values for row/col should start at 1, not 0!
QCOMPARE( scope->variable( QStringLiteral( "table_row" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "table_column" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "row_number" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "column_number" ) ).toInt(), 1 );
QCOMPARE( scope->feature().attribute( 0 ).toString(), QStringLiteral( "Jet" ) );
scope.reset( table->scopeForCell( 0, 1 ) );
QCOMPARE( scope->variable( QStringLiteral( "table_row" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "table_column" ) ).toInt(), 2 );
QCOMPARE( scope->variable( QStringLiteral( "row_number" ) ).toInt(), 1 );
QCOMPARE( scope->variable( QStringLiteral( "column_number" ) ).toInt(), 2 );
QCOMPARE( scope->feature().attribute( 0 ).toString(), QStringLiteral( "Jet" ) );
scope.reset( table->scopeForCell( 1, 2 ) );
QCOMPARE( scope->variable( QStringLiteral( "table_row" ) ).toInt(), 2 );
QCOMPARE( scope->variable( QStringLiteral( "table_column" ) ).toInt(), 3 );
QCOMPARE( scope->variable( QStringLiteral( "row_number" ) ).toInt(), 2 );
QCOMPARE( scope->variable( QStringLiteral( "column_number" ) ).toInt(), 3 );
QCOMPARE( scope->feature().attribute( 0 ).toString(), QStringLiteral( "Biplane" ) );

// make sure fields are set
Expand Down

0 comments on commit 8e3151a

Please sign in to comment.