@@ -1540,7 +1540,7 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
15401540
15411541 if (pluginName == " __error__" || description == " __error__" || version == " __error__" )
15421542 {
1543- QMessageBox::warning (0 , tr (" Python error" ), tr (" Error when reading metadata of plugin " ) + packageName);
1543+ QMessageBox::warning (this , tr (" Python error" ), tr (" Error when reading metadata of plugin " ) + packageName);
15441544 continue ;
15451545 }
15461546
@@ -1608,7 +1608,7 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)
16081608
16091609 if (!driverRegistrar)
16101610 {
1611- QMessageBox::warning (0 ,tr (" OGR Driver Manager" ),tr (" unable to get OGRDriverManager" ));
1611+ QMessageBox::warning (this ,tr (" OGR Driver Manager" ),tr (" unable to get OGRDriverManager" ));
16121612 return ; // XXX good place to throw exception if we
16131613 } // XXX decide to do exceptions
16141614
@@ -2425,13 +2425,9 @@ findLayers_( QString const & fileFilters, list<QDomNode> const & layerNodes )
24252425
24262426
24272427
2428-
2429-
2430-
2431-
24322428void QgisApp::fileExit ()
24332429{
2434- if (saveDirty () != QMessageBox::Cancel )
2430+ if (saveDirty ())
24352431 {
24362432 removeAllLayers ();
24372433 qApp->exit (0 );
@@ -2451,9 +2447,7 @@ void QgisApp::fileNew(bool thePromptToSaveFlag)
24512447{
24522448 if (thePromptToSaveFlag)
24532449 {
2454- int answer = saveDirty ();
2455-
2456- if (answer == QMessageBox::Cancel)
2450+ if (!saveDirty ())
24572451 {
24582452 return ;
24592453 }
@@ -2649,9 +2643,7 @@ void QgisApp::newVectorLayer()
26492643void QgisApp::fileOpen ()
26502644{
26512645 // possibly save any pending work before opening a new project
2652- int answer = saveDirty ();
2653-
2654- if (answer != QMessageBox::Cancel)
2646+ if (saveDirty ())
26552647 {
26562648 // Retrieve last used project dir from persistent settings
26572649 QSettings settings;
@@ -2768,12 +2760,11 @@ bool QgisApp::addProject(QString projectFile)
27682760 {
27692761 qDebug ( " %s:%d %d bad layers found" , __FILE__, __LINE__, e.layers ().size () );
27702762
2771- if ( QMessageBox::Yes == QMessageBox::critical ( this ,
2763+ if ( QMessageBox::Ok == QMessageBox::critical ( this ,
27722764 tr (" QGIS Project Read Error" ),
27732765 tr (" " ) + " \n " + e.what () + " \n " +
27742766 tr (" Try to find missing layers?" ),
2775- QMessageBox::Yes | QMessageBox::Default,
2776- QMessageBox::No | QMessageBox::Escape ) )
2767+ QMessageBox::Ok | QMessageBox::Cancel ) )
27772768 {
27782769 qDebug ( " %s:%d want to find missing layers is true" , __FILE__, __LINE__ );
27792770
@@ -2787,9 +2778,8 @@ bool QgisApp::addProject(QString projectFile)
27872778 {
27882779 qDebug ( " %s:%d BAD LAYERS FOUND" , __FILE__, __LINE__ );
27892780
2790- QMessageBox::critical ( 0x0 ,
2791- tr (" Unable to open project" ), QString::fromLocal8Bit (e.what ()), QMessageBox::Ok,
2792- Qt::NoButton );
2781+ QMessageBox::critical ( this ,
2782+ tr (" Unable to open project" ), QString::fromLocal8Bit (e.what ()) );
27932783
27942784 mMapCanvas ->freeze (false );
27952785 mMapCanvas ->refresh ();
@@ -2881,12 +2871,9 @@ bool QgisApp::fileSave()
28812871 }
28822872 catch ( std::exception & e )
28832873 {
2884- QMessageBox::critical ( 0x0 ,
2874+ QMessageBox::critical ( this ,
28852875 tr (" Unable to save project " ) + QgsProject::instance ()->filename (),
2886- e.what (),
2887- QMessageBox::Ok,
2888- Qt::NoButton );
2889-
2876+ e.what () );
28902877 }
28912878 return true ;
28922879} // QgisApp::fileSave
@@ -2974,8 +2961,7 @@ void QgisApp::openProject(QAction *action)
29742961
29752962 debugme = action->text ();
29762963
2977- int answer = saveDirty ();
2978- if (answer != QMessageBox::Cancel)
2964+ if (saveDirty ())
29792965 {
29802966 addProject (debugme);
29812967
@@ -2994,9 +2980,7 @@ void QgisApp::openProject(QAction *action)
29942980void QgisApp::openProject (const QString & fileName)
29952981{
29962982 // possibly save any pending work before opening a different project
2997- int answer = saveDirty ();
2998-
2999- if (answer != QMessageBox::Cancel)
2983+ if (saveDirty ())
30002984 {
30012985 try
30022986 {
@@ -3012,7 +2996,7 @@ void QgisApp::openProject(const QString & fileName)
30122996 }
30132997 catch ( QgsIOException & io_exception )
30142998 {
3015- QMessageBox::critical ( 0x0 ,
2999+ QMessageBox::critical ( this ,
30163000 tr (" QGIS: Unable to load project" ),
30173001 tr (" Unable to load project " ) + fileName );
30183002 }
@@ -3408,14 +3392,14 @@ void QgisApp::deleteSelected()
34083392
34093393 if (!(vlayer->getDataProvider ()->capabilities () & QgsVectorDataProvider::DeleteFeatures))
34103394 {
3411- QMessageBox::information (0 , tr (" Provider does not support deletion" ),
3395+ QMessageBox::information (this , tr (" Provider does not support deletion" ),
34123396 tr (" Data provider does not support deleting features" ));
34133397 return ;
34143398 }
34153399
34163400 if (!vlayer->isEditable ())
34173401 {
3418- QMessageBox::information (0 , tr (" Layer not editable" ),
3402+ QMessageBox::information (this , tr (" Layer not editable" ),
34193403 tr (" The current layer is not editable. Choose 'Start editing' in the digitizing toolbar." ));
34203404 return ;
34213405 }
@@ -4151,8 +4135,8 @@ void QgisApp::socketConnectionClosed()
41514135 {
41524136 versionInfo += parts[1 ] + " \n\n " + tr (" Would you like more information?" );
41534137 ;
4154- int result = QMessageBox::information (this , tr (" QGIS Version Information" ), versionInfo, tr ( " Yes " ), tr ( " No " ) );
4155- if (result == 0 )
4138+ QMessageBox::StandardButton result = QMessageBox::information (this , tr (" QGIS Version Information" ), versionInfo, QMessageBox::Ok | QMessageBox::Cancel );
4139+ if (result == QMessageBox::Ok )
41564140 {
41574141 // show more info
41584142 QgsMessageViewer *mv = new QgsMessageViewer (this );
@@ -4412,12 +4396,13 @@ void QgisApp::setExtent(QgsRect theRect)
44124396 mMapCanvas ->setExtent (theRect);
44134397}
44144398
4415-
4416-
4417-
4418- int QgisApp::saveDirty ()
4399+ /* *
4400+ Prompt and save if project has been modified.
4401+ @return true if saved or discarded, false if cancelled
4402+ */
4403+ bool QgisApp::saveDirty ()
44194404{
4420- int answer (QMessageBox::No );
4405+ QMessageBox::StandardButton answer (QMessageBox::Discard );
44214406 mMapCanvas ->freeze (true );
44224407
44234408#ifdef QGISDEBUG
@@ -4456,20 +4441,18 @@ int QgisApp::saveDirty()
44564441
44574442 // prompt user to save
44584443 answer = QMessageBox::information (this , tr (" Save?" ),
4459- tr (" <p>Do you want to save the current project?</p>" ),
4460- QMessageBox::Yes | QMessageBox::Default,
4461- QMessageBox::No,
4462- QMessageBox::Cancel | QMessageBox::Escape);
4463- if (QMessageBox::Yes == answer )
4444+ tr (" Do you want to save the current project?" ),
4445+ QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard);
4446+ if (QMessageBox::Save == answer)
44644447 {
44654448 if (!fileSave ())
4466- answer = QMessageBox::Cancel;
4449+ answer = QMessageBox::Cancel;
44674450 }
44684451 }
44694452
44704453 mMapCanvas ->freeze (false );
44714454
4472- return answer;
4455+ return ( answer != QMessageBox::Cancel) ;
44734456
44744457} // QgisApp::saveDirty()
44754458
0 commit comments