Skip to content

Commit 973e43b

Browse files
author
telwertowski
committed
Convert all uses of QMessageBox to Qt 4.2 StandardButton API.
Also add tr() where missing. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6441 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ee11108 commit 973e43b

32 files changed

+169
-227
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ void QgsComposer::on_mActionPrint_activated(void)
555555
if ( mComposition->paperWidth() != mPrinter->widthMM() ||
556556
mComposition->paperHeight() != mPrinter->heightMM() )
557557
{
558-
int answer = QMessageBox::warning ( 0, tr("Paper does not match"),
558+
int answer = QMessageBox::warning ( this, tr("Paper does not match"),
559559
tr("The selected paper size does not match the composition size"),
560-
QMessageBox::Ok, QMessageBox::Abort );
560+
QMessageBox::Ok | QMessageBox::Abort );
561561

562562
if ( answer == QMessageBox::Abort )
563563
print = false;
@@ -613,12 +613,12 @@ void QgsComposer::on_mActionExportAsImage_activated(void)
613613
#endif
614614

615615
if ( memuse > 200 ) { // cca 4500 x 4500
616-
int answer = QMessageBox::warning ( 0, tr("Big image"),
616+
int answer = QMessageBox::warning ( this, tr("Big image"),
617617
tr("To create image ") + QString::number(width) + " x "
618618
+ QString::number(height)
619619
+ tr(" requires circa ")
620620
+ QString::number(memuse) + tr(" MB of memory"),
621-
QMessageBox::Ok, QMessageBox::Abort );
621+
QMessageBox::Ok | QMessageBox::Abort );
622622

623623
raise ();
624624
if ( answer == QMessageBox::Abort ) return;

src/app/composer/qgscomposerpicture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void QgsComposerPicture::pictureChanged ( )
416416
loadPicture();
417417

418418
if ( !mPictureValid ) {
419-
QMessageBox::warning( 0, tr("Warning"),
419+
QMessageBox::warning( this, tr("Warning"),
420420
tr("Cannot load picture.") );
421421
}
422422
else

src/app/composer/qgscomposition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void QgsComposition::paperSizeChanged ( void )
595595
// A better solution here would be to set the canvas back to the
596596
// original size and carry on, but for the moment this will
597597
// prevent a crash due to an uncaught exception.
598-
QMessageBox::critical( 0, tr("Out of memory"),
598+
QMessageBox::critical( this, tr("Out of memory"),
599599
tr("Qgis is unable to resize the paper size due to "
600600
"insufficient memory.\n It is best that you avoid "
601601
"using the map composer until you restart qgis.\n") );
@@ -790,7 +790,7 @@ void QgsComposition::setTool ( Tool tool )
790790
}
791791
else
792792
{
793-
QMessageBox::warning( 0, tr("Warning"),
793+
QMessageBox::warning( this, tr("Warning"),
794794
tr("Cannot load picture.") );
795795

796796
delete pi;

src/app/legend/qgslegendlayerfile.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,21 @@ void QgsLegendLayerFile::saveAsShapefile()
321321

322322
if (error == "DRIVER_NOT_FOUND")
323323
{
324-
QMessageBox::warning(0, "Driver not found", "ESRI Shapefile driver is not available");
324+
QMessageBox::warning(0, tr("Driver not found"), tr("ESRI Shapefile driver is not available"));
325325
}
326326
else if (error == "ERROR_CREATE_SOURCE")
327327
{
328-
QMessageBox::warning(0, "Error creating shapefile",
329-
"The shapefile could not be created (" +
328+
QMessageBox::warning(0, tr("Error creating shapefile"),
329+
tr("The shapefile could not be created (") +
330330
shapefileName + ")");
331331
}
332332
else if (error == "ERROR_CREATE_LAYER")
333333
{
334-
QMessageBox::warning(0, "Error", "Layer creation failed");
334+
QMessageBox::warning(0, tr("Error"), tr("Layer creation failed"));
335335
}
336336
else
337337
{
338-
QMessageBox::information( 0, "Saving done", "Export to Shapefile has been completed");
338+
QMessageBox::information(0, tr("Saving done"), tr("Export to Shapefile has been completed"));
339339
}
340340
}
341341

@@ -351,34 +351,33 @@ void QgsLegendLayerFile::toggleEditing()
351351
if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures))
352352
{
353353
QMessageBox::information(0,tr("Start editing failed"),
354-
tr("Provider cannot be opened for editing"),
355-
QMessageBox::Ok);
354+
tr("Provider cannot be opened for editing"));
356355
}
357356
}
358357
else
359358
{
360359
// commit or roll back?
361-
int commit = QMessageBox::information(0,tr("Stop editing"),
360+
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
362361
tr("Do you want to save the changes?"),
363-
tr("&Yes"),tr("&No"),QString::null,0,1);
362+
QMessageBox::Save | QMessageBox::Discard);
364363

365-
if(commit==0)
364+
if(commit==QMessageBox::Save)
366365
{
367366
if(!vlayer->commitChanges())
368367
{
369-
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"),QMessageBox::Ok);
368+
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));
370369

371370
// Leave the in-memory editing state alone,
372371
// to give the user a chance to enter different values
373372
// and try the commit again later
374373
}
375374
}
376-
else if(commit==1)
375+
else if(commit==QMessageBox::Discard)
377376
{
378377
if(!vlayer->rollBack())
379378
{
380379
QMessageBox::information(0,tr("Error"),
381-
tr("Problems during roll back"),QMessageBox::Ok);
380+
tr("Problems during roll back"));
382381
}
383382
}
384383
vlayer->triggerRepaint();

src/app/main.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ void myMessageOutput( QtMsgType type, const char *msg )
200200
if ( 0 == strncmp(msg, "libpng error:", 13) )
201201
{
202202
// Let the user know
203-
QMessageBox::warning( 0, "libpng Error",
204-
msg,
205-
QMessageBox::Ok,
206-
Qt::NoButton);
203+
QMessageBox::warning( 0, "libpng Error", msg );
207204
}
208205

209206
break;

src/app/qgisapp.cpp

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
24322428
void 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()
26492643
void 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)
29942980
void 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

src/app/qgisapp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public slots:
416416
//! shows the paste-transformations dialog
417417
void pasteTransformations();
418418
//! check to see if file is dirty and if so, prompt the user th save it
419-
int saveDirty();
419+
bool saveDirty();
420420
//! Have some control over closing of the application
421421
virtual void closeEvent(QCloseEvent* event);
422422

src/app/qgsattributetabledisplay.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void QgsAttributeTableDisplay::addAttribute()
133133
{
134134
if(!table()->addAttribute(dialog.name(),dialog.type()))
135135
{
136-
QMessageBox::information(0,"Name conflict","The attribute could not be inserted. The name already exists in the table",QMessageBox::Ok);
136+
QMessageBox::information(this,tr("Name conflict"),tr("The attribute could not be inserted. The name already exists in the table"));
137137
}
138138
}
139139
}
@@ -182,12 +182,14 @@ void QgsAttributeTableDisplay::stopEditing()
182182
if(table()->edited())
183183
{
184184
//commit or roll back?
185-
int commit=QMessageBox::information(0,"Stop editing","Do you want to save the changes?",QMessageBox::Yes,QMessageBox::No);
186-
if(commit==QMessageBox::Yes)
185+
QMessageBox::StandardButton commit=QMessageBox::information(this,tr("Stop editing"),
186+
tr("Do you want to save the changes?"),
187+
QMessageBox::Save | QMessageBox::Discard);
188+
if(commit==QMessageBox::Save)
187189
{
188190
if(!table()->commitChanges(mLayer))
189191
{
190-
QMessageBox::information(0,"Error","Could not commit changes",QMessageBox::Ok);
192+
QMessageBox::information(this,tr("Error"),tr("Could not commit changes"));
191193
}
192194
}
193195
else

src/app/qgsbookmarks.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ void QgsBookmarks::on_btnDelete_clicked()
124124
if(lvi)
125125
{
126126
// make sure the user really wants to delete this bookmark
127-
if(0 == QMessageBox::information(this,tr("Really Delete?"),
128-
tr("Are you sure you want to delete the ") + lvi->text(0) +
129-
tr(" bookmark?"), tr("&Yes"), tr("&No"), QString::null, 0, 1))
127+
if(QMessageBox::Ok == QMessageBox::information(this,tr("Really Delete?"),
128+
tr("Are you sure you want to delete the ") + lvi->text(0) + tr(" bookmark?"),
129+
QMessageBox::Ok | QMessageBox::Cancel))
130130
{
131131
// remove it from the listview
132132
lstBookmarks->takeItem(lvi);
@@ -145,8 +145,7 @@ void QgsBookmarks::on_btnDelete_clicked()
145145
tr("Failed to delete the ") +
146146
lvi->text(0) +
147147
tr(" bookmark from the database. The "
148-
"database said:\n") + QString(errmsg),
149-
QMessageBox::Ok, QMessageBox::NoButton);
148+
"database said:\n") + QString(errmsg));
150149
sqlite3_free(errmsg);
151150
}
152151
// close the database

0 commit comments

Comments
 (0)