Skip to content

Commit

Permalink
[composer] Remove use of runtime_error for providing feedback from atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2014
1 parent 88b8369 commit c38d3e1
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 88 deletions.
31 changes: 26 additions & 5 deletions python/core/composer/qgsatlascomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,27 @@ public:
* atlas page.
* @returns filename pattern
* @see setFilenamePattern
* @see filenamePatternErrorString
* @note This property has no effect when exporting to PDF if singleFile() is true
*/
QString filenamePattern() const;

/**Sets the filename expression used for generating output filenames for each
* atlas page.
* @returns true if filename expression could be successful set, false if expression is invalid
* @param pattern expression to use for output filenames
* @see filenamePattern
* @see filenamePatternErrorString
* @note This method has no effect when exporting to PDF if singleFile() is true
*/
void setFilenamePattern( const QString& pattern );
bool setFilenamePattern( const QString& pattern );

/**Returns an error string from parsing the filename expression.
* @returns filename pattern parser error
* @see setFilenamePattern
* @see filenamePattern
*/
QString filenamePatternErrorString() const;

/**Returns the coverage layer used for the atlas features
* @returns atlas coverage layer
Expand Down Expand Up @@ -125,6 +135,13 @@ public:

QString featureFilter() const;
void setFeatureFilter( const QString& expression );

/**Returns an error string from parsing the feature filter expression.
* @returns filename pattern parser error
* @see setFilenamePattern
* @see filenamePattern
*/
QString featureFilterErrorString() const;

QString sortKeyAttributeName() const;
void setSortKeyAttributeName( QString fieldName );
Expand Down Expand Up @@ -157,11 +174,15 @@ public:
/** Returns the number of features in the coverage layer */
int numFeatures() const;

/** Prepare the atlas map for the given feature. Sets the extent and context variables */
void prepareForFeature( int i );
/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( int i );

/** Prepare the atlas map for the given feature. Sets the extent and context variables */
void prepareForFeature( QgsFeature * feat );
/**Prepare the atlas map for the given feature. Sets the extent and context variables
* @returns true if feature was successfully prepared
*/
bool prepareForFeature( QgsFeature * feat );

/** Returns the current filename. Must be called after prepareForFeature( i ) */
const QString& currentFilename() const;
Expand Down
13 changes: 11 additions & 2 deletions src/app/composer/qgsatlascompositionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,24 @@ void QgsAtlasCompositionWidget::changeCoverageLayer( QgsMapLayer *layer )
}
}

void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_editingFinished()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}

atlasMap->setFilenamePattern( text );
if ( ! atlasMap->setFilenamePattern( mAtlasFilenamePatternEdit->text() ) )
{
//expression could not be set
QMessageBox::warning( this
, tr( "Could not evaluate filename pattern" )
, tr( "Could not set filename pattern as '%1'.\nParser error:\n%2" )
.arg( mAtlasFilenamePatternEdit->text() )
.arg( atlasMap->filenamePatternErrorString() )
);
}
}

void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgsatlascompositionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class QgsAtlasCompositionWidget:
public slots:
void on_mUseAtlasCheckBox_stateChanged( int state );
void changeCoverageLayer( QgsMapLayer* layer );
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
void on_mAtlasFilenamePatternEdit_editingFinished();
void on_mAtlasFilenameExpressionButton_clicked();
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
void on_mAtlasSingleFileCheckBox_stateChanged( int state );
Expand Down
74 changes: 21 additions & 53 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,15 +1336,11 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )

QPainter painter;

try
{
loadAtlasPredefinedScalesFromProject();
atlasMap->beginRender();
}
catch ( std::exception& e )
loadAtlasPredefinedScalesFromProject();
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand All @@ -1371,14 +1367,10 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
atlasMap->endRender();
break;
}
try
{
atlasMap->prepareForFeature( featureI );
}
catch ( std::runtime_error& e )
if ( !atlasMap->prepareForFeature( featureI ) )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Atlas processing error" ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand Down Expand Up @@ -1491,15 +1483,12 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )

mComposition->beginPrint( mPrinter );
QPainter painter( &mPrinter );
try
{
loadAtlasPredefinedScalesFromProject();
atlasMap->beginRender();
}
catch ( std::exception& e )

loadAtlasPredefinedScalesFromProject();
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand All @@ -1518,21 +1507,16 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
atlasMap->endRender();
break;
}
try
{
atlasMap->prepareForFeature( i );
}
catch ( std::runtime_error& e )
if ( !atlasMap->prepareForFeature( i ) )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Atlas processing error" ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
return;
}


if ( i > 0 )
{
mPrinter.newPage();
Expand Down Expand Up @@ -1753,15 +1737,11 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
mView->setPaintingEnabled( false );
QApplication::setOverrideCursor( Qt::BusyCursor );

try
{
loadAtlasPredefinedScalesFromProject();
atlasMap->beginRender();
}
catch ( std::exception& e )
loadAtlasPredefinedScalesFromProject();
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand All @@ -1781,14 +1761,10 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
atlasMap->endRender();
break;
}
try
{
atlasMap->prepareForFeature( feature );
}
catch ( std::runtime_error& e )
if ( ! atlasMap->prepareForFeature( feature ) )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Atlas processing error" ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand Down Expand Up @@ -2021,15 +1997,11 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
int featureI = 0;
if ( mode == QgsComposer::Atlas )
{
try
{
loadAtlasPredefinedScalesFromProject();
atlasMap->beginRender();
}
catch ( std::exception& e )
loadAtlasPredefinedScalesFromProject();
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Feature filter parser error: %1" ).arg( atlasMap->featureFilterErrorString() ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand All @@ -2053,14 +2025,10 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
atlasMap->endRender();
break;
}
try
{
atlasMap->prepareForFeature( featureI );
}
catch ( std::runtime_error& e )
if ( !atlasMap->prepareForFeature( featureI ) )
{
QMessageBox::warning( this, tr( "Atlas processing error" ),
e.what(),
tr( "Atlas processing error" ),
QMessageBox::Ok,
QMessageBox::Ok );
mView->setPaintingEnabled( true );
Expand Down

0 comments on commit c38d3e1

Please sign in to comment.