mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[composer] Remove use of runtime_error for providing feedback from atlas
This commit is contained in:
parent
88b8369acf
commit
c38d3e12af
@ -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
|
||||
@ -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 );
|
||||
@ -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;
|
||||
|
@ -88,7 +88,7 @@ void QgsAtlasCompositionWidget::changeCoverageLayer( QgsMapLayer *layer )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
|
||||
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_editingFinished()
|
||||
{
|
||||
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
|
||||
if ( !atlasMap )
|
||||
@ -96,7 +96,16 @@ void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const
|
||||
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()
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
@ -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 );
|
||||
@ -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 );
|
||||
@ -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();
|
||||
@ -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 );
|
||||
@ -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 );
|
||||
@ -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 );
|
||||
@ -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 );
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qgsgeometry.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include "qgsproject.h"
|
||||
#include "qgsmessagelog.h"
|
||||
|
||||
QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
|
||||
mComposition( composition ),
|
||||
@ -33,7 +34,9 @@ QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
|
||||
mHideCoverage( false ), mFilenamePattern( "'output_'||$feature" ),
|
||||
mCoverageLayer( 0 ), mSingleFile( false ),
|
||||
mSortFeatures( false ), mSortAscending( true ), mCurrentFeatureNo( 0 ),
|
||||
mFilterFeatures( false ), mFeatureFilter( "" )
|
||||
mFilterFeatures( false ), mFeatureFilter( "" ),
|
||||
mFilenameParserError( QString() ),
|
||||
mFilterParserError( QString() )
|
||||
{
|
||||
|
||||
// declare special columns with a default value
|
||||
@ -181,9 +184,11 @@ int QgsAtlasComposition::updateFeatures()
|
||||
filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
|
||||
if ( filterExpression->hasParserError() )
|
||||
{
|
||||
throw std::runtime_error( tr( "Feature filter parser error: %1" ).arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
|
||||
mFilterParserError = filterExpression->parserErrorString();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
mFilterParserError = QString();
|
||||
|
||||
// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
|
||||
// We thus store the feature ids for future extraction
|
||||
@ -198,7 +203,7 @@ int QgsAtlasComposition::updateFeatures()
|
||||
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
|
||||
if ( filterExpression->hasEvalError() )
|
||||
{
|
||||
throw std::runtime_error( tr( "Feature filter eval error: %1" ).arg( filterExpression->evalErrorString() ).toLocal8Bit().data() );
|
||||
QgsMessageLog::logMessage( tr( "Atlas filter eval error: %1" ).arg( filterExpression->evalErrorString() ), tr( "Composer" ) );
|
||||
}
|
||||
|
||||
// skip this feature if the filter evaluation if false
|
||||
@ -326,23 +331,23 @@ void QgsAtlasComposition::lastFeature()
|
||||
prepareForFeature( mFeatureIds.size() - 1 );
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
|
||||
bool QgsAtlasComposition::prepareForFeature( QgsFeature * feat )
|
||||
{
|
||||
int featureI = mFeatureIds.indexOf( feat->id() );
|
||||
prepareForFeature( featureI );
|
||||
return prepareForFeature( featureI );
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::prepareForFeature( int featureI )
|
||||
bool QgsAtlasComposition::prepareForFeature( int featureI )
|
||||
{
|
||||
if ( !mCoverageLayer )
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( mFeatureIds.size() == 0 )
|
||||
{
|
||||
emit statusMsgChanged( tr( "No matching atlas features" ) );
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
mCurrentFeatureNo = featureI;
|
||||
@ -355,7 +360,11 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
|
||||
QgsExpression::setSpecialColumn( "$feature", QVariant(( int )featureI + 1 ) );
|
||||
|
||||
// generate filename for current feature
|
||||
evalFeatureFilename();
|
||||
if ( !evalFeatureFilename() )
|
||||
{
|
||||
//error evaluating filename
|
||||
return false;
|
||||
}
|
||||
|
||||
emit featureChanged( &mCurrentFeature );
|
||||
emit statusMsgChanged( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );
|
||||
@ -382,7 +391,7 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
|
||||
if ( atlasMaps.isEmpty() )
|
||||
{
|
||||
//no atlas enabled maps
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compute extent of current feature in the map CRS. This should be set on a per-atlas map basis,
|
||||
@ -395,6 +404,8 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
|
||||
{
|
||||
prepareMap( *mit );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::computeExtent( QgsComposerMap* map )
|
||||
@ -670,16 +681,18 @@ void QgsAtlasComposition::setHideCoverage( bool hide )
|
||||
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::setFilenamePattern( const QString& pattern )
|
||||
bool QgsAtlasComposition::setFilenamePattern( const QString& pattern )
|
||||
{
|
||||
mFilenamePattern = pattern;
|
||||
updateFilenameExpression();
|
||||
return updateFilenameExpression();
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::updateFilenameExpression()
|
||||
bool QgsAtlasComposition::updateFilenameExpression()
|
||||
{
|
||||
if ( !mCoverageLayer )
|
||||
return;
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const QgsFields& fields = mCoverageLayer->pendingFields();
|
||||
|
||||
@ -690,7 +703,8 @@ void QgsAtlasComposition::updateFilenameExpression()
|
||||
// test for evaluation errors
|
||||
if ( mFilenameExpr->hasParserError() )
|
||||
{
|
||||
throw std::runtime_error( tr( "Filename parsing error: %1" ).arg( mFilenameExpr->parserErrorString() ).toLocal8Bit().data() );
|
||||
mFilenameParserError = mFilenameExpr->parserErrorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare the filename expression
|
||||
@ -702,10 +716,10 @@ void QgsAtlasComposition::updateFilenameExpression()
|
||||
{
|
||||
evalFeatureFilename();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::evalFeatureFilename()
|
||||
bool QgsAtlasComposition::evalFeatureFilename()
|
||||
{
|
||||
//generate filename for current atlas feature
|
||||
if ( mFilenamePattern.size() > 0 )
|
||||
@ -713,11 +727,13 @@ void QgsAtlasComposition::evalFeatureFilename()
|
||||
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
|
||||
if ( mFilenameExpr->hasEvalError() )
|
||||
{
|
||||
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
|
||||
QgsMessageLog::logMessage( tr( "Atlas filename evaluation error: %1" ).arg( mFilenameExpr->evalErrorString() ), tr( "Composer" ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
mCurrentFilename = filenameRes.toString();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::setPredefinedScales( const QVector<double>& scales )
|
||||
|
@ -102,17 +102,27 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
* 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 { return mFilenamePattern; }
|
||||
|
||||
/**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 { return mFilenameParserError; }
|
||||
|
||||
/**Returns the coverage layer used for the atlas features
|
||||
* @returns atlas coverage layer
|
||||
@ -154,6 +164,13 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
QString featureFilter() const { return mFeatureFilter; }
|
||||
void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
|
||||
|
||||
/**Returns an error string from parsing the feature filter expression.
|
||||
* @returns filename pattern parser error
|
||||
* @see setFilenamePattern
|
||||
* @see filenamePattern
|
||||
*/
|
||||
QString featureFilterErrorString() const { return mFilterParserError; }
|
||||
|
||||
QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
|
||||
void setSortKeyAttributeName( QString fieldName ) { mSortKeyAttributeName = fieldName; }
|
||||
|
||||
@ -185,11 +202,15 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
/** 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;
|
||||
@ -237,11 +258,15 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
void featureChanged( QgsFeature* feature );
|
||||
|
||||
private:
|
||||
/**Updates the filename expression*/
|
||||
void updateFilenameExpression();
|
||||
/**Updates the filename expression.
|
||||
* @returns true if expression was successfully parsed, false if expression is invalid
|
||||
*/
|
||||
bool updateFilenameExpression();
|
||||
|
||||
/**Evaluates filename for current feature*/
|
||||
void evalFeatureFilename();
|
||||
/**Evaluates filename for current feature
|
||||
* @returns true if feature filename was successfully evaluated
|
||||
*/
|
||||
bool evalFeatureFilename();
|
||||
|
||||
QgsComposition* mComposition;
|
||||
|
||||
@ -261,6 +286,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
// current atlas feature number
|
||||
int mCurrentFeatureNo;
|
||||
|
||||
QString mFilenameParserError;
|
||||
QString mFilterParserError;
|
||||
|
||||
public:
|
||||
typedef QMap< QgsFeatureId, QVariant > SorterKeys;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user