18 #include <QImageWriter>
30 , mAtlas( layout->atlas() )
33 connect( mUseAtlasCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutAtlasWidget::mUseAtlasCheckBox_stateChanged );
34 connect( mAtlasFilenamePatternEdit, &QLineEdit::editingFinished,
this, &QgsLayoutAtlasWidget::mAtlasFilenamePatternEdit_editingFinished );
35 connect( mAtlasFilenameExpressionButton, &QToolButton::clicked,
this, &QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked );
36 connect( mAtlasHideCoverageCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutAtlasWidget::mAtlasHideCoverageCheckBox_stateChanged );
37 connect( mAtlasSingleFileCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutAtlasWidget::mAtlasSingleFileCheckBox_stateChanged );
38 connect( mAtlasSortFeatureCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutAtlasWidget::mAtlasSortFeatureCheckBox_stateChanged );
39 connect( mAtlasSortFeatureDirectionButton, &QToolButton::clicked,
this, &QgsLayoutAtlasWidget::mAtlasSortFeatureDirectionButton_clicked );
40 connect( mAtlasFeatureFilterEdit, &QLineEdit::editingFinished,
this, &QgsLayoutAtlasWidget::mAtlasFeatureFilterEdit_editingFinished );
41 connect( mAtlasFeatureFilterButton, &QToolButton::clicked,
this, &QgsLayoutAtlasWidget::mAtlasFeatureFilterButton_clicked );
42 connect( mAtlasFeatureFilterCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutAtlasWidget::mAtlasFeatureFilterCheckBox_stateChanged );
53 mAtlasSortFeatureDirectionButton->setEnabled(
false );
54 mAtlasSortExpressionWidget->setEnabled(
false );
59 mPageNameWidget->registerExpressionContextGenerator( mLayout );
61 QList<QByteArray> formats = QImageWriter::supportedImageFormats();
62 for (
int i = 0; i < formats.size(); ++i )
64 mAtlasFileFormat->addItem( QString( formats.at( i ) ) );
66 connect( mAtlasFileFormat, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, [ = ](
int ) { changeFileFormat(); } );
76 void QgsLayoutAtlasWidget::mUseAtlasCheckBox_stateChanged(
int state )
78 if ( state == Qt::Checked )
81 mConfigurationGroup->setEnabled(
true );
82 mOutputGroup->setEnabled(
true );
87 mConfigurationGroup->setEnabled(
false );
88 mOutputGroup->setEnabled(
false );
92 void QgsLayoutAtlasWidget::changeCoverageLayer(
QgsMapLayer *layer )
99 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Layer" ) );
100 mLayout->reportContext().setLayer( vl );
108 updateAtlasFeatures();
110 mLayout->undoStack()->endCommand();
113 void QgsLayoutAtlasWidget::mAtlasFilenamePatternEdit_editingFinished()
119 mBlockUpdates =
true;
120 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Filename" ) );
125 tr(
"Could not set filename expression to '%1'.\nParser error:\n%2" )
126 .arg( mAtlasFilenamePatternEdit->text(),
129 mLayout->undoStack()->endCommand();
130 mBlockUpdates =
false;
133 void QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked()
142 exprDlg.setWindowTitle( tr(
"Expression Based Filename" ) );
144 if ( exprDlg.exec() == QDialog::Accepted )
146 QString expression = exprDlg.expressionText();
147 if ( !expression.isEmpty() )
150 mAtlasFilenamePatternEdit->setText( expression );
152 mBlockUpdates =
true;
153 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Filename" ) );
157 mMessageBar->
pushWarning( tr(
"Atlas" ), tr(
"Could not set filename expression to '%1'.\nParser error:\n%2" )
161 mBlockUpdates =
false;
162 mLayout->undoStack()->endCommand();
167 void QgsLayoutAtlasWidget::mAtlasHideCoverageCheckBox_stateChanged(
int state )
172 mBlockUpdates =
true;
173 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Toggle Atlas Layer" ) );
175 mLayout->undoStack()->endCommand();
176 mBlockUpdates =
false;
179 void QgsLayoutAtlasWidget::mAtlasSingleFileCheckBox_stateChanged(
int state )
184 if ( state == Qt::Checked )
186 mAtlasFilenamePatternEdit->setEnabled(
false );
187 mAtlasFilenameExpressionButton->setEnabled(
false );
191 mAtlasFilenamePatternEdit->setEnabled(
true );
192 mAtlasFilenameExpressionButton->setEnabled(
true );
195 mLayout->setCustomProperty( QStringLiteral(
"singleFile" ), state == Qt::Checked );
198 void QgsLayoutAtlasWidget::mAtlasSortFeatureCheckBox_stateChanged(
int state )
203 if ( state == Qt::Checked )
205 mAtlasSortFeatureDirectionButton->setEnabled(
true );
206 mAtlasSortExpressionWidget->setEnabled(
true );
210 mAtlasSortFeatureDirectionButton->setEnabled(
false );
211 mAtlasSortExpressionWidget->setEnabled(
false );
213 mBlockUpdates =
true;
214 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Toggle Atlas Sorting" ) );
216 mLayout->undoStack()->endCommand();
217 mBlockUpdates =
false;
218 updateAtlasFeatures();
221 void QgsLayoutAtlasWidget::changesSortFeatureExpression(
const QString &expression,
bool )
226 mBlockUpdates =
true;
227 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Sort" ) );
229 mLayout->undoStack()->endCommand();
230 mBlockUpdates =
false;
231 updateAtlasFeatures();
234 void QgsLayoutAtlasWidget::updateAtlasFeatures()
239 mMessageBar->
pushInfo( tr(
"Atlas" ),
240 tr(
"No matching atlas features found!" ) );
247 void QgsLayoutAtlasWidget::mAtlasFeatureFilterCheckBox_stateChanged(
int state )
252 if ( state == Qt::Checked )
254 mAtlasFeatureFilterEdit->setEnabled(
true );
255 mAtlasFeatureFilterButton->setEnabled(
true );
259 mAtlasFeatureFilterEdit->setEnabled(
false );
260 mAtlasFeatureFilterButton->setEnabled(
false );
262 mBlockUpdates =
true;
263 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Filter" ) );
265 mLayout->undoStack()->endCommand();
266 mBlockUpdates =
false;
267 updateAtlasFeatures();
270 void QgsLayoutAtlasWidget::pageNameExpressionChanged(
const QString &,
bool valid )
275 QString expression = mPageNameWidget->asExpression();
276 if ( !valid && !expression.isEmpty() )
281 mBlockUpdates =
true;
282 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Name" ) );
284 mLayout->undoStack()->endCommand();
285 mBlockUpdates =
false;
288 void QgsLayoutAtlasWidget::mAtlasFeatureFilterEdit_editingFinished()
294 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Filter" ) );
296 mBlockUpdates =
true;
300 mMessageBar->
pushWarning( tr(
"Atlas" ), tr(
"Could not set filter expression to '%1'.\nParser error:\n%2" )
301 .arg( mAtlasFeatureFilterEdit->text(),
304 mBlockUpdates =
false;
305 mLayout->undoStack()->endCommand();
306 updateAtlasFeatures();
309 void QgsLayoutAtlasWidget::mAtlasFeatureFilterButton_clicked()
314 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mAtlasCoverageLayerComboBox->currentLayer() );
323 exprDlg.setWindowTitle( tr(
"Expression Based Filter" ) );
325 if ( exprDlg.exec() == QDialog::Accepted )
327 QString expression = exprDlg.expressionText();
328 if ( !expression.isEmpty() )
330 mAtlasFeatureFilterEdit->setText( expression );
332 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Filter" ) );
333 mBlockUpdates =
true;
338 tr(
"Could not set filter expression to '%1'.\nParser error:\n%2" )
339 .arg( mAtlasFeatureFilterEdit->text(),
343 mBlockUpdates =
false;
344 mLayout->undoStack()->endCommand();
345 updateAtlasFeatures();
350 void QgsLayoutAtlasWidget::mAtlasSortFeatureDirectionButton_clicked()
355 Qt::ArrowType at = mAtlasSortFeatureDirectionButton->arrowType();
356 at = ( at == Qt::UpArrow ) ? Qt::DownArrow : Qt::UpArrow;
357 mAtlasSortFeatureDirectionButton->setArrowType( at );
359 mBlockUpdates =
true;
360 mLayout->undoStack()->beginCommand( mAtlas, tr(
"Change Atlas Sort" ) );
362 mLayout->undoStack()->endCommand();
363 mBlockUpdates =
false;
364 updateAtlasFeatures();
367 void QgsLayoutAtlasWidget::changeFileFormat()
372 mLayout->setCustomProperty( QStringLiteral(
"atlasRasterFormat" ), mAtlasFileFormat->currentText() );
375 void QgsLayoutAtlasWidget::updateGuiElements()
380 blockAllSignals(
true );
381 mUseAtlasCheckBox->setCheckState( mAtlas->
enabled() ? Qt::Checked : Qt::Unchecked );
382 mConfigurationGroup->setEnabled( mAtlas->
enabled() );
383 mOutputGroup->setEnabled( mAtlas->
enabled() );
385 mAtlasCoverageLayerComboBox->setLayer( mAtlas->
coverageLayer() );
389 mAtlasSortExpressionWidget->setLayer( mAtlas->
coverageLayer() );
393 mAtlasHideCoverageCheckBox->setCheckState( mAtlas->
hideCoverage() ? Qt::Checked : Qt::Unchecked );
395 bool singleFile = mLayout->customProperty( QStringLiteral(
"singleFile" ),
true ).toBool();
396 mAtlasSingleFileCheckBox->setCheckState( singleFile ? Qt::Checked : Qt::Unchecked );
397 mAtlasFilenamePatternEdit->setEnabled( !singleFile );
398 mAtlasFilenameExpressionButton->setEnabled( !singleFile );
400 mAtlasSortFeatureCheckBox->setCheckState( mAtlas->
sortFeatures() ? Qt::Checked : Qt::Unchecked );
401 mAtlasSortFeatureDirectionButton->setEnabled( mAtlas->
sortFeatures() );
402 mAtlasSortExpressionWidget->setEnabled( mAtlas->
sortFeatures() );
404 mAtlasSortFeatureDirectionButton->setArrowType( mAtlas->
sortAscending() ? Qt::UpArrow : Qt::DownArrow );
407 mAtlasFeatureFilterCheckBox->setCheckState( mAtlas->
filterFeatures() ? Qt::Checked : Qt::Unchecked );
409 mAtlasFeatureFilterButton->setEnabled( mAtlas->
filterFeatures() );
411 mAtlasFileFormat->setCurrentIndex( mAtlasFileFormat->findText( mLayout->customProperty( QStringLiteral(
"atlasRasterFormat" ), QStringLiteral(
"png" ) ).toString() ) );
413 blockAllSignals(
false );
416 void QgsLayoutAtlasWidget::blockAllSignals(
bool b )
418 mUseAtlasCheckBox->blockSignals( b );
419 mConfigurationGroup->blockSignals( b );
420 mOutputGroup->blockSignals( b );
421 mAtlasCoverageLayerComboBox->blockSignals( b );
422 mPageNameWidget->blockSignals( b );
423 mAtlasSortExpressionWidget->blockSignals( b );
424 mAtlasFilenamePatternEdit->blockSignals( b );
425 mAtlasHideCoverageCheckBox->blockSignals( b );
426 mAtlasSingleFileCheckBox->blockSignals( b );
427 mAtlasSortFeatureCheckBox->blockSignals( b );
428 mAtlasSortFeatureDirectionButton->blockSignals( b );
429 mAtlasFeatureFilterEdit->blockSignals( b );
430 mAtlasFeatureFilterCheckBox->blockSignals( b );
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString sortExpression() const
Returns the expression (or field name) to use for sorting features.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
QString filenameExpression() const
Returns the filename expression used for generating output filenames for each atlas page.
bool sortAscending() const
Returns true if features should be sorted in an ascending order.
void setCoverageLayer(QgsVectorLayer *layer)
Sets the coverage layer to use for the atlas features.
bool setFilterExpression(const QString &expression, QString &errorString)
Sets the expression used for filtering features in the coverage layer.
void setSortAscending(bool ascending)
Sets whether features should be sorted in an ascending order.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
void setEnabled(bool enabled)
Sets whether the atlas is enabled.
void setPageNameExpression(const QString &expression)
Sets the expression (or field name) used for calculating the page name.
QString filterExpression() const
Returns the expression used for filtering features in the coverage layer.
bool enabled() const
Returns whether the atlas generation is enabled.
bool setFilenameExpression(const QString &expression, QString &errorString)
Sets the filename expression used for generating output filenames for each atlas page.
void setSortFeatures(bool enabled)
Sets whether features should be sorted in the atlas.
QString pageNameExpression() const
Returns the expression (or field name) used for calculating the page name.
void setSortExpression(const QString &expression)
Sets the expression (or field name) to use for sorting features.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
void changed()
Emitted when one of the atlas parameters changes.
int updateFeatures()
Requeries the current atlas coverage layer and applies filtering and sorting.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
void setHideCoverage(bool hide)
Sets whether the coverage layer should be hidden in map items in the layouts.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
Base class for all map layer types.
A bar for displaying non-blocking messages to the user.
void pushInfo(const QString &title, const QString &message)
Pushes a information message with default timeout to the message bar.
void pushWarning(const QString &title, const QString &message)
Pushes a warning message with default timeout to the message bar.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Represents a vector layer which manages a vector based data sets.