Skip to content

Commit

Permalink
Show a message box if there was an error during the merge operation (…
Browse files Browse the repository at this point in the history
…instead of crashing). Fixes ticket #2342

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12673 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 5, 2010
1 parent ec0cf0c commit 1aae468
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3635,8 +3635,9 @@ void QgisApp::deletePart()
mMapCanvas->setMapTool( mMapTools.mDeletePart );
}

QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList )
QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled )
{
canceled = false;
if ( !vl || featureList.size() < 2 )
{
return 0;
Expand All @@ -3660,6 +3661,7 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
{
delete unionGeom;
QApplication::restoreOverrideCursor();
canceled = true;
return 0;
}
progress.setValue( i );
Expand All @@ -3668,6 +3670,12 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
{
backupPtr = unionGeom;
unionGeom = unionGeom->combine( currentGeom );
if ( !unionGeom )
{
delete backupPtr;
QApplication::restoreOverrideCursor();
return 0;
}
if ( i > 1 ) //delete previous intermediate results
{
delete backupPtr;
Expand Down Expand Up @@ -3798,9 +3806,14 @@ void QgisApp::mergeSelectedFeatures()

//get initial selection (may be altered by attribute merge dialog later)
QgsFeatureList featureList = vl->selectedFeatures(); //get QList<QgsFeature>
QgsGeometry* unionGeom = unionGeometries( vl, featureList );
bool canceled;
QgsGeometry* unionGeom = unionGeometries( vl, featureList, canceled );
if ( !unionGeom )
{
if ( !canceled )
{
QMessageBox::critical( 0, tr( "Merge failed" ), tr( "An error occured during the merge operation" ) );
}
return;
}

Expand Down Expand Up @@ -3835,9 +3848,14 @@ void QgisApp::mergeSelectedFeatures()
if ( featureList.size() != featureListAfter.size() )
{
delete unionGeom;
unionGeom = unionGeometries( vl, featureListAfter );
bool canceled;
unionGeom = unionGeometries( vl, featureListAfter, canceled );
if ( !unionGeom )
{
if ( !canceled )
{
QMessageBox::critical( 0, tr( "Merge failed" ), tr( "An error occured during the merge operation" ) );
}
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ class QgisApp : public QMainWindow
//! check to see if file is dirty and if so, prompt the user th save it
bool saveDirty();
/** Helper function to union several geometries together (used in function mergeSelectedFeatures)
@return 0 in case of error*/
QgsGeometry* unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList );
@return 0 in case of error or if canceled*/
QgsGeometry* unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled );

/**Deletes all the composer objects and clears mPrintComposers*/
void deletePrintComposers();
Expand Down

0 comments on commit 1aae468

Please sign in to comment.