Show a message box if there was an error during the merge operation (instead of crashing). Fixes ticket

git-svn-id: http://svn.osgeo.org/qgis/trunk@12673 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2010-01-05 16:06:18 +00:00
parent a9ae72243e
commit a8ce63c20b
2 changed files with 23 additions and 5 deletions

@ -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;
@ -3660,6 +3661,7 @@ QgsGeometry* QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
{
delete unionGeom;
QApplication::restoreOverrideCursor();
canceled = true;
return 0;
}
progress.setValue( i );
@ -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;
@ -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;
}
@ -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;
}

@ -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();