Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atlas featurenumber padded #59978

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmlayoutatlastoimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void QgsLayoutAtlasToImageAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterExpression( QStringLiteral( "SORTBY_EXPRESSION" ), QObject::tr( "Sort expression" ), QString(), QStringLiteral( "COVERAGE_LAYER" ), true ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "SORTBY_REVERSE" ), QObject::tr( "Reverse sort order (used when a sort expression is provided)" ), false ) );

addParameter( new QgsProcessingParameterExpression( QStringLiteral( "FILENAME_EXPRESSION" ), QObject::tr( "Output filename expression" ), QStringLiteral( "'output_'||@atlas_featurenumber" ), QStringLiteral( "COVERAGE_LAYER" ) ) );
addParameter( new QgsProcessingParameterExpression( QStringLiteral( "FILENAME_EXPRESSION" ), QObject::tr( "Output filename expression" ), QStringLiteral( "'output_'||@atlas_featurenumber_padded" ), QStringLiteral( "COVERAGE_LAYER" ) ) );
addParameter( new QgsProcessingParameterFile( QStringLiteral( "FOLDER" ), QObject::tr( "Output folder" ), Qgis::ProcessingFileParameterBehavior::Folder ) );


Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmlayoutatlastopdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ QVariantMap QgsLayoutAtlasToMultiplePdfAlgorithm::exportAtlas( QgsLayoutAtlas *a
QgsLayoutExporter::ExportResult result;
if ( atlas->filenameExpression().isEmpty() && filename.isEmpty() )
{
atlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber" ), error );
atlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber_padded" ), error );
}
else if ( !filename.isEmpty() )
{
Expand Down
6 changes: 3 additions & 3 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,7 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()
return;
}
QString error;
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber" ), error );
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber_padded" ), error );
}
else
{
Expand Down Expand Up @@ -3008,7 +3008,7 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
return;
}
QString error;
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber" ), error );
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber_padded" ), error );
}

QString lastUsedDir = defaultExportPath();
Expand Down Expand Up @@ -3200,7 +3200,7 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
return;
}
QString error;
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber" ), error );
printAtlas->setFilenameExpression( QStringLiteral( "'output_'||@atlas_featurenumber_padded" ), error );
}


Expand Down
1 change: 1 addition & 0 deletions src/core/expression/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts()->insert( QStringLiteral( "atlas_layername" ), QCoreApplication::translate( "variable_help", "Current atlas coverage layer name." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_totalfeatures" ), QCoreApplication::translate( "variable_help", "Total number of features in atlas." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_featurenumber" ), QCoreApplication::translate( "variable_help", "Current atlas feature number." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_featurenumber_padded" ), QCoreApplication::translate( "variable_help", "Current atlas feature number (zero-padded)." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_filename" ), QCoreApplication::translate( "variable_help", "Current atlas file name." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_pagename" ), QCoreApplication::translate( "variable_help", "Current atlas page name." ) );
sVariableHelpTexts()->insert( QStringLiteral( "atlas_feature" ), QCoreApplication::translate( "variable_help", "Current atlas feature (as feature object)." ) );
Expand Down
2 changes: 2 additions & 0 deletions src/core/expression/qgsexpressioncontextutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ QgsExpressionContextScope *QgsExpressionContextUtils::atlasScope( const QgsLayou
//add known atlas variables
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_totalfeatures" ), atlas->count(), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featurenumber" ), atlas->currentFeatureNumber() + 1, true, true ) );
const QString padded = QString::number( atlas->currentFeatureNumber() + 1 ).rightJustified( QString::number( atlas->count() ).size(), '0' );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featurenumber_padded" ), padded, true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_filename" ), atlas->currentFilename(), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_pagename" ), atlas->nameForPage( atlas->currentFeatureNumber() ), true, true ) );

Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
QgsLayoutAtlas::QgsLayoutAtlas( QgsLayout *layout )
: QObject( layout )
, mLayout( layout )
, mFilenameExpressionString( QStringLiteral( "'output_'||@atlas_featurenumber" ) )
, mFilenameExpressionString( QStringLiteral( "'output_'||@atlas_featurenumber_padded" ) )
{

//listen out for layer removal
Expand Down
38 changes: 12 additions & 26 deletions src/gui/layout/qgslayoutatlaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,15 @@ void QgsLayoutAtlasWidget::setMessageBar( QgsMessageBar *bar )

void QgsLayoutAtlasWidget::mUseAtlasCheckBox_stateChanged( int state )
{
if ( state == Qt::Checked )
{
mAtlas->setEnabled( true );
mConfigurationGroup->setEnabled( true );
mOutputGroup->setEnabled( true );
}
else
{
mAtlas->setEnabled( false );
mConfigurationGroup->setEnabled( false );
mOutputGroup->setEnabled( false );
}
const bool enabled = state == Qt::Checked;
mAtlas->setEnabled( enabled );
mAtlasCoverageLayerComboBox->setEnabled( enabled );
mAtlasCoverageLayerLabel->setEnabled( enabled );

const bool validLayer = mAtlas->coverageLayer() != nullptr;

mConfigurationGroup->setEnabled( enabled && validLayer );
mOutputGroup->setEnabled( enabled && validLayer );
}

void QgsLayoutAtlasWidget::changeCoverageLayer( QgsMapLayer *layer )
Expand All @@ -112,6 +109,9 @@ void QgsLayoutAtlasWidget::changeCoverageLayer( QgsMapLayer *layer )
updateAtlasFeatures();
}

mConfigurationGroup->setEnabled( mAtlas->enabled() && !vl );
mOutputGroup->setEnabled( mAtlas->enabled() && !vl );

// if page name expression is still valid, retain it. Otherwise switch to a nice default.
QgsExpression exp( prevPageNameExpression );
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vl ) );
Expand Down Expand Up @@ -192,18 +192,6 @@ void QgsLayoutAtlasWidget::mAtlasSingleFileCheckBox_stateChanged( int state )
{
if ( !mLayout )
return;

if ( state == Qt::Checked )
{
mAtlasFilenamePatternEdit->setEnabled( false );
mAtlasFilenameExpressionButton->setEnabled( false );
}
else
{
mAtlasFilenamePatternEdit->setEnabled( true );
mAtlasFilenameExpressionButton->setEnabled( true );
}

mLayout->setCustomProperty( QStringLiteral( "singleFile" ), state == Qt::Checked );
}

Expand Down Expand Up @@ -400,8 +388,6 @@ void QgsLayoutAtlasWidget::updateGuiElements()

const bool singleFile = mLayout->customProperty( QStringLiteral( "singleFile" ) ).toBool();
mAtlasSingleFileCheckBox->setCheckState( singleFile ? Qt::Checked : Qt::Unchecked );
mAtlasFilenamePatternEdit->setEnabled( !singleFile );
mAtlasFilenameExpressionButton->setEnabled( !singleFile );

mAtlasSortFeatureCheckBox->setCheckState( mAtlas->sortFeatures() ? Qt::Checked : Qt::Unchecked );
mAtlasSortFeatureDirectionButton->setEnabled( mAtlas->sortFeatures() );
Expand Down
75 changes: 39 additions & 36 deletions src/ui/layout/qgslayoutatlaswidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>359</height>
<width>430</width>
<height>452</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -66,19 +66,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
Expand All @@ -95,7 +82,7 @@
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<item row="2" column="0" colspan="4">
<widget class="QgsScrollArea" name="scrollArea">
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
Expand All @@ -111,14 +98,35 @@
<rect>
<x>0</x>
<y>0</y>
<width>417</width>
<height>354</height>
<width>426</width>
<height>420</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mAtlasCoverageLayerLabel">
<property name="text">
<string>Coverage layer</string>
</property>
</widget>
</item>
<item>
<widget class="QgsMapLayerComboBox" name="mAtlasCoverageLayerComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mConfigurationGroup">
<property name="enabled">
Expand Down Expand Up @@ -181,13 +189,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mHorizontalAlignementLabel">
<property name="text">
<string>Coverage layer</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
Expand All @@ -198,16 +199,6 @@
<item row="3" column="1">
<widget class="QLineEdit" name="mAtlasFeatureFilterEdit"/>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsMapLayerComboBox" name="mAtlasCoverageLayerComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsFieldExpressionWidget" name="mPageNameWidget" native="true">
<property name="sizePolicy">
Expand Down Expand Up @@ -319,6 +310,19 @@
</widget>
</widget>
</item>
<item row="0" column="2" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -353,7 +357,6 @@
<tabstop>mUseAtlasCheckBox</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>mConfigurationGroup</tabstop>
<tabstop>mAtlasCoverageLayerComboBox</tabstop>
<tabstop>mAtlasHideCoverageCheckBox</tabstop>
<tabstop>mAtlasFeatureFilterCheckBox</tabstop>
<tabstop>mAtlasFeatureFilterEdit</tabstop>
Expand Down
6 changes: 3 additions & 3 deletions tests/src/analysis/testqgsprocessingalgspt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ void TestQgsProcessingAlgsPt2::exportAtlasLayoutPdfMultiple()
results = alg->run( parameters, *context, &feedback, &ok );
QVERIFY( ok );

QVERIFY( QFile::exists( outputPdfDir + "/output_1.pdf" ) );
QVERIFY( QFile::exists( outputPdfDir + "/output_2.pdf" ) );
QVERIFY( QFile::exists( outputPdfDir + "/output_3.pdf" ) );
QVERIFY( QFile::exists( outputPdfDir + "/output_01.pdf" ) );
QVERIFY( QFile::exists( outputPdfDir + "/output_02.pdf" ) );
QVERIFY( QFile::exists( outputPdfDir + "/output_03.pdf" ) );
}

void TestQgsProcessingAlgsPt2::exportAtlasLayoutPng()
Expand Down
Loading