Skip to content

Commit c38d3e1

Browse files
committed
[composer] Remove use of runtime_error for providing feedback from atlas
1 parent 88b8369 commit c38d3e1

File tree

6 files changed

+130
-88
lines changed

6 files changed

+130
-88
lines changed

python/core/composer/qgsatlascomposition.sip

+26-5
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,27 @@ public:
7474
* atlas page.
7575
* @returns filename pattern
7676
* @see setFilenamePattern
77+
* @see filenamePatternErrorString
7778
* @note This property has no effect when exporting to PDF if singleFile() is true
7879
*/
7980
QString filenamePattern() const;
8081

8182
/**Sets the filename expression used for generating output filenames for each
8283
* atlas page.
84+
* @returns true if filename expression could be successful set, false if expression is invalid
8385
* @param pattern expression to use for output filenames
8486
* @see filenamePattern
87+
* @see filenamePatternErrorString
8588
* @note This method has no effect when exporting to PDF if singleFile() is true
8689
*/
87-
void setFilenamePattern( const QString& pattern );
90+
bool setFilenamePattern( const QString& pattern );
91+
92+
/**Returns an error string from parsing the filename expression.
93+
* @returns filename pattern parser error
94+
* @see setFilenamePattern
95+
* @see filenamePattern
96+
*/
97+
QString filenamePatternErrorString() const;
8898

8999
/**Returns the coverage layer used for the atlas features
90100
* @returns atlas coverage layer
@@ -125,6 +135,13 @@ public:
125135

126136
QString featureFilter() const;
127137
void setFeatureFilter( const QString& expression );
138+
139+
/**Returns an error string from parsing the feature filter expression.
140+
* @returns filename pattern parser error
141+
* @see setFilenamePattern
142+
* @see filenamePattern
143+
*/
144+
QString featureFilterErrorString() const;
128145

129146
QString sortKeyAttributeName() const;
130147
void setSortKeyAttributeName( QString fieldName );
@@ -157,11 +174,15 @@ public:
157174
/** Returns the number of features in the coverage layer */
158175
int numFeatures() const;
159176

160-
/** Prepare the atlas map for the given feature. Sets the extent and context variables */
161-
void prepareForFeature( int i );
177+
/**Prepare the atlas map for the given feature. Sets the extent and context variables
178+
* @returns true if feature was successfully prepared
179+
*/
180+
bool prepareForFeature( int i );
162181

163-
/** Prepare the atlas map for the given feature. Sets the extent and context variables */
164-
void prepareForFeature( QgsFeature * feat );
182+
/**Prepare the atlas map for the given feature. Sets the extent and context variables
183+
* @returns true if feature was successfully prepared
184+
*/
185+
bool prepareForFeature( QgsFeature * feat );
165186

166187
/** Returns the current filename. Must be called after prepareForFeature( i ) */
167188
const QString& currentFilename() const;

src/app/composer/qgsatlascompositionwidget.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,24 @@ void QgsAtlasCompositionWidget::changeCoverageLayer( QgsMapLayer *layer )
8888
}
8989
}
9090

91-
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
91+
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_editingFinished()
9292
{
9393
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
9494
if ( !atlasMap )
9595
{
9696
return;
9797
}
9898

99-
atlasMap->setFilenamePattern( text );
99+
if ( ! atlasMap->setFilenamePattern( mAtlasFilenamePatternEdit->text() ) )
100+
{
101+
//expression could not be set
102+
QMessageBox::warning( this
103+
, tr( "Could not evaluate filename pattern" )
104+
, tr( "Could not set filename pattern as '%1'.\nParser error:\n%2" )
105+
.arg( mAtlasFilenamePatternEdit->text() )
106+
.arg( atlasMap->filenamePatternErrorString() )
107+
);
108+
}
100109
}
101110

102111
void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()

src/app/composer/qgsatlascompositionwidget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsAtlasCompositionWidget:
3737
public slots:
3838
void on_mUseAtlasCheckBox_stateChanged( int state );
3939
void changeCoverageLayer( QgsMapLayer* layer );
40-
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
40+
void on_mAtlasFilenamePatternEdit_editingFinished();
4141
void on_mAtlasFilenameExpressionButton_clicked();
4242
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
4343
void on_mAtlasSingleFileCheckBox_stateChanged( int state );

src/app/composer/qgscomposer.cpp

+21-53
Original file line numberDiff line numberDiff line change
@@ -1336,15 +1336,11 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
13361336

13371337
QPainter painter;
13381338

1339-
try
1340-
{
1341-
loadAtlasPredefinedScalesFromProject();
1342-
atlasMap->beginRender();
1343-
}
1344-
catch ( std::exception& e )
1339+
loadAtlasPredefinedScalesFromProject();
1340+
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
13451341
{
13461342
QMessageBox::warning( this, tr( "Atlas processing error" ),
1347-
e.what(),
1343+
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
13481344
QMessageBox::Ok,
13491345
QMessageBox::Ok );
13501346
mView->setPaintingEnabled( true );
@@ -1371,14 +1367,10 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
13711367
atlasMap->endRender();
13721368
break;
13731369
}
1374-
try
1375-
{
1376-
atlasMap->prepareForFeature( featureI );
1377-
}
1378-
catch ( std::runtime_error& e )
1370+
if ( !atlasMap->prepareForFeature( featureI ) )
13791371
{
13801372
QMessageBox::warning( this, tr( "Atlas processing error" ),
1381-
e.what(),
1373+
tr( "Atlas processing error" ),
13821374
QMessageBox::Ok,
13831375
QMessageBox::Ok );
13841376
mView->setPaintingEnabled( true );
@@ -1491,15 +1483,12 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
14911483

14921484
mComposition->beginPrint( mPrinter );
14931485
QPainter painter( &mPrinter );
1494-
try
1495-
{
1496-
loadAtlasPredefinedScalesFromProject();
1497-
atlasMap->beginRender();
1498-
}
1499-
catch ( std::exception& e )
1486+
1487+
loadAtlasPredefinedScalesFromProject();
1488+
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
15001489
{
15011490
QMessageBox::warning( this, tr( "Atlas processing error" ),
1502-
e.what(),
1491+
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
15031492
QMessageBox::Ok,
15041493
QMessageBox::Ok );
15051494
mView->setPaintingEnabled( true );
@@ -1518,21 +1507,16 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
15181507
atlasMap->endRender();
15191508
break;
15201509
}
1521-
try
1522-
{
1523-
atlasMap->prepareForFeature( i );
1524-
}
1525-
catch ( std::runtime_error& e )
1510+
if ( !atlasMap->prepareForFeature( i ) )
15261511
{
15271512
QMessageBox::warning( this, tr( "Atlas processing error" ),
1528-
e.what(),
1513+
tr( "Atlas processing error" ),
15291514
QMessageBox::Ok,
15301515
QMessageBox::Ok );
15311516
mView->setPaintingEnabled( true );
15321517
return;
15331518
}
15341519

1535-
15361520
if ( i > 0 )
15371521
{
15381522
mPrinter.newPage();
@@ -1753,15 +1737,11 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
17531737
mView->setPaintingEnabled( false );
17541738
QApplication::setOverrideCursor( Qt::BusyCursor );
17551739

1756-
try
1757-
{
1758-
loadAtlasPredefinedScalesFromProject();
1759-
atlasMap->beginRender();
1760-
}
1761-
catch ( std::exception& e )
1740+
loadAtlasPredefinedScalesFromProject();
1741+
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
17621742
{
17631743
QMessageBox::warning( this, tr( "Atlas processing error" ),
1764-
e.what(),
1744+
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
17651745
QMessageBox::Ok,
17661746
QMessageBox::Ok );
17671747
mView->setPaintingEnabled( true );
@@ -1781,14 +1761,10 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
17811761
atlasMap->endRender();
17821762
break;
17831763
}
1784-
try
1785-
{
1786-
atlasMap->prepareForFeature( feature );
1787-
}
1788-
catch ( std::runtime_error& e )
1764+
if ( ! atlasMap->prepareForFeature( feature ) )
17891765
{
17901766
QMessageBox::warning( this, tr( "Atlas processing error" ),
1791-
e.what(),
1767+
tr( "Atlas processing error" ),
17921768
QMessageBox::Ok,
17931769
QMessageBox::Ok );
17941770
mView->setPaintingEnabled( true );
@@ -2021,15 +1997,11 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
20211997
int featureI = 0;
20221998
if ( mode == QgsComposer::Atlas )
20231999
{
2024-
try
2025-
{
2026-
loadAtlasPredefinedScalesFromProject();
2027-
atlasMap->beginRender();
2028-
}
2029-
catch ( std::exception& e )
2000+
loadAtlasPredefinedScalesFromProject();
2001+
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
20302002
{
20312003
QMessageBox::warning( this, tr( "Atlas processing error" ),
2032-
e.what(),
2004+
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
20332005
QMessageBox::Ok,
20342006
QMessageBox::Ok );
20352007
mView->setPaintingEnabled( true );
@@ -2053,14 +2025,10 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
20532025
atlasMap->endRender();
20542026
break;
20552027
}
2056-
try
2057-
{
2058-
atlasMap->prepareForFeature( featureI );
2059-
}
2060-
catch ( std::runtime_error& e )
2028+
if ( !atlasMap->prepareForFeature( featureI ) )
20612029
{
20622030
QMessageBox::warning( this, tr( "Atlas processing error" ),
2063-
e.what(),
2031+
tr( "Atlas processing error" ),
20642032
QMessageBox::Ok,
20652033
QMessageBox::Ok );
20662034
mView->setPaintingEnabled( true );

0 commit comments

Comments
 (0)