Skip to content

Commit 1aae468

Browse files
author
mhugent
committedJan 5, 2010
Show a message box if there was an error during the merge operation (instead of crashing). Fixes ticket #2342
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12673 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,8 +3635,9 @@ void QgisApp::deletePart()
36353635
mMapCanvas->setMapTool( mMapTools.mDeletePart );
36363636
}
36373637

3638-
QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList )
3638+
QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled )
36393639
{
3640+
canceled = false;
36403641
if ( !vl || featureList.size() < 2 )
36413642
{
36423643
return 0;
@@ -3660,6 +3661,7 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
36603661
{
36613662
delete unionGeom;
36623663
QApplication::restoreOverrideCursor();
3664+
canceled = true;
36633665
return 0;
36643666
}
36653667
progress.setValue( i );
@@ -3668,6 +3670,12 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
36683670
{
36693671
backupPtr = unionGeom;
36703672
unionGeom = unionGeom->combine( currentGeom );
3673+
if ( !unionGeom )
3674+
{
3675+
delete backupPtr;
3676+
QApplication::restoreOverrideCursor();
3677+
return 0;
3678+
}
36713679
if ( i > 1 ) //delete previous intermediate results
36723680
{
36733681
delete backupPtr;
@@ -3798,9 +3806,14 @@ void QgisApp::mergeSelectedFeatures()
37983806

37993807
//get initial selection (may be altered by attribute merge dialog later)
38003808
QgsFeatureList featureList = vl->selectedFeatures(); //get QList<QgsFeature>
3801-
QgsGeometry* unionGeom = unionGeometries( vl, featureList );
3809+
bool canceled;
3810+
QgsGeometry* unionGeom = unionGeometries( vl, featureList, canceled );
38023811
if ( !unionGeom )
38033812
{
3813+
if ( !canceled )
3814+
{
3815+
QMessageBox::critical( 0, tr( "Merge failed" ), tr( "An error occured during the merge operation" ) );
3816+
}
38043817
return;
38053818
}
38063819

@@ -3835,9 +3848,14 @@ void QgisApp::mergeSelectedFeatures()
38353848
if ( featureList.size() != featureListAfter.size() )
38363849
{
38373850
delete unionGeom;
3838-
unionGeom = unionGeometries( vl, featureListAfter );
3851+
bool canceled;
3852+
unionGeom = unionGeometries( vl, featureListAfter, canceled );
38393853
if ( !unionGeom )
38403854
{
3855+
if ( !canceled )
3856+
{
3857+
QMessageBox::critical( 0, tr( "Merge failed" ), tr( "An error occured during the merge operation" ) );
3858+
}
38413859
return;
38423860
}
38433861

‎src/app/qgisapp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ class QgisApp : public QMainWindow
710710
//! check to see if file is dirty and if so, prompt the user th save it
711711
bool saveDirty();
712712
/** Helper function to union several geometries together (used in function mergeSelectedFeatures)
713-
@return 0 in case of error*/
714-
QgsGeometry* unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList );
713+
@return 0 in case of error or if canceled*/
714+
QgsGeometry* unionGeometries( const QgsVectorLayer* vl, QgsFeatureList& featureList, bool& canceled );
715715

716716
/**Deletes all the composer objects and clears mPrintComposers*/
717717
void deletePrintComposers();

0 commit comments

Comments
 (0)
Please sign in to comment.