Skip to content

Commit

Permalink
Convert all uses of QMessageBox to Qt 4.2 StandardButton API.
Browse files Browse the repository at this point in the history
Also add tr() where missing.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6441 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Jan 18, 2007
1 parent ee11108 commit 973e43b
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 227 deletions.
8 changes: 4 additions & 4 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -555,9 +555,9 @@ void QgsComposer::on_mActionPrint_activated(void)
if ( mComposition->paperWidth() != mPrinter->widthMM() ||
mComposition->paperHeight() != mPrinter->heightMM() )
{
int answer = QMessageBox::warning ( 0, tr("Paper does not match"),
int answer = QMessageBox::warning ( this, tr("Paper does not match"),
tr("The selected paper size does not match the composition size"),
QMessageBox::Ok, QMessageBox::Abort );
QMessageBox::Ok | QMessageBox::Abort );

if ( answer == QMessageBox::Abort )
print = false;
Expand Down Expand Up @@ -613,12 +613,12 @@ void QgsComposer::on_mActionExportAsImage_activated(void)
#endif

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

raise ();
if ( answer == QMessageBox::Abort ) return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerpicture.cpp
Expand Up @@ -416,7 +416,7 @@ void QgsComposerPicture::pictureChanged ( )
loadPicture();

if ( !mPictureValid ) {
QMessageBox::warning( 0, tr("Warning"),
QMessageBox::warning( this, tr("Warning"),
tr("Cannot load picture.") );
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposition.cpp
Expand Up @@ -595,7 +595,7 @@ void QgsComposition::paperSizeChanged ( void )
// A better solution here would be to set the canvas back to the
// original size and carry on, but for the moment this will
// prevent a crash due to an uncaught exception.
QMessageBox::critical( 0, tr("Out of memory"),
QMessageBox::critical( this, tr("Out of memory"),
tr("Qgis is unable to resize the paper size due to "
"insufficient memory.\n It is best that you avoid "
"using the map composer until you restart qgis.\n") );
Expand Down Expand Up @@ -790,7 +790,7 @@ void QgsComposition::setTool ( Tool tool )
}
else
{
QMessageBox::warning( 0, tr("Warning"),
QMessageBox::warning( this, tr("Warning"),
tr("Cannot load picture.") );

delete pi;
Expand Down
25 changes: 12 additions & 13 deletions src/app/legend/qgslegendlayerfile.cpp
Expand Up @@ -321,21 +321,21 @@ void QgsLegendLayerFile::saveAsShapefile()

if (error == "DRIVER_NOT_FOUND")
{
QMessageBox::warning(0, "Driver not found", "ESRI Shapefile driver is not available");
QMessageBox::warning(0, tr("Driver not found"), tr("ESRI Shapefile driver is not available"));
}
else if (error == "ERROR_CREATE_SOURCE")
{
QMessageBox::warning(0, "Error creating shapefile",
"The shapefile could not be created (" +
QMessageBox::warning(0, tr("Error creating shapefile"),
tr("The shapefile could not be created (") +
shapefileName + ")");
}
else if (error == "ERROR_CREATE_LAYER")
{
QMessageBox::warning(0, "Error", "Layer creation failed");
QMessageBox::warning(0, tr("Error"), tr("Layer creation failed"));
}
else
{
QMessageBox::information( 0, "Saving done", "Export to Shapefile has been completed");
QMessageBox::information(0, tr("Saving done"), tr("Export to Shapefile has been completed"));
}
}

Expand All @@ -351,34 +351,33 @@ void QgsLegendLayerFile::toggleEditing()
if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures))
{
QMessageBox::information(0,tr("Start editing failed"),
tr("Provider cannot be opened for editing"),
QMessageBox::Ok);
tr("Provider cannot be opened for editing"));
}
}
else
{
// commit or roll back?
int commit = QMessageBox::information(0,tr("Stop editing"),
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
tr("Do you want to save the changes?"),
tr("&Yes"),tr("&No"),QString::null,0,1);
QMessageBox::Save | QMessageBox::Discard);

if(commit==0)
if(commit==QMessageBox::Save)
{
if(!vlayer->commitChanges())
{
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"),QMessageBox::Ok);
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));

// Leave the in-memory editing state alone,
// to give the user a chance to enter different values
// and try the commit again later
}
}
else if(commit==1)
else if(commit==QMessageBox::Discard)
{
if(!vlayer->rollBack())
{
QMessageBox::information(0,tr("Error"),
tr("Problems during roll back"),QMessageBox::Ok);
tr("Problems during roll back"));
}
}
vlayer->triggerRepaint();
Expand Down
5 changes: 1 addition & 4 deletions src/app/main.cpp
Expand Up @@ -200,10 +200,7 @@ void myMessageOutput( QtMsgType type, const char *msg )
if ( 0 == strncmp(msg, "libpng error:", 13) )
{
// Let the user know
QMessageBox::warning( 0, "libpng Error",
msg,
QMessageBox::Ok,
Qt::NoButton);
QMessageBox::warning( 0, "libpng Error", msg );
}

break;
Expand Down
75 changes: 29 additions & 46 deletions src/app/qgisapp.cpp
Expand Up @@ -1540,7 +1540,7 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)

if (pluginName == "__error__" || description == "__error__" || version == "__error__")
{
QMessageBox::warning(0, tr("Python error"), tr("Error when reading metadata of plugin ") + packageName);
QMessageBox::warning(this, tr("Python error"), tr("Error when reading metadata of plugin ") + packageName);
continue;
}

Expand Down Expand Up @@ -1608,7 +1608,7 @@ static void buildSupportedVectorFileFilter_(QString & fileFilters)

if (!driverRegistrar)
{
QMessageBox::warning(0,tr("OGR Driver Manager"),tr("unable to get OGRDriverManager"));
QMessageBox::warning(this,tr("OGR Driver Manager"),tr("unable to get OGRDriverManager"));
return; // XXX good place to throw exception if we
} // XXX decide to do exceptions

Expand Down Expand Up @@ -2425,13 +2425,9 @@ findLayers_( QString const & fileFilters, list<QDomNode> const & layerNodes )







void QgisApp::fileExit()
{
if (saveDirty() != QMessageBox::Cancel)
if (saveDirty())
{
removeAllLayers();
qApp->exit(0);
Expand All @@ -2451,9 +2447,7 @@ void QgisApp::fileNew(bool thePromptToSaveFlag)
{
if (thePromptToSaveFlag)
{
int answer = saveDirty();

if (answer == QMessageBox::Cancel)
if (!saveDirty())
{
return;
}
Expand Down Expand Up @@ -2649,9 +2643,7 @@ void QgisApp::newVectorLayer()
void QgisApp::fileOpen()
{
// possibly save any pending work before opening a new project
int answer = saveDirty();

if (answer != QMessageBox::Cancel)
if (saveDirty())
{
// Retrieve last used project dir from persistent settings
QSettings settings;
Expand Down Expand Up @@ -2768,12 +2760,11 @@ bool QgisApp::addProject(QString projectFile)
{
qDebug( "%s:%d %d bad layers found", __FILE__, __LINE__, e.layers().size() );

if ( QMessageBox::Yes == QMessageBox::critical( this,
if ( QMessageBox::Ok == QMessageBox::critical( this,
tr("QGIS Project Read Error"),
tr("") + "\n" + e.what() + "\n" +
tr("Try to find missing layers?"),
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape ) )
QMessageBox::Ok | QMessageBox::Cancel ) )
{
qDebug( "%s:%d want to find missing layers is true", __FILE__, __LINE__ );

Expand All @@ -2787,9 +2778,8 @@ bool QgisApp::addProject(QString projectFile)
{
qDebug( "%s:%d BAD LAYERS FOUND", __FILE__, __LINE__ );

QMessageBox::critical( 0x0,
tr("Unable to open project"), QString::fromLocal8Bit(e.what()), QMessageBox::Ok,
Qt::NoButton );
QMessageBox::critical( this,
tr("Unable to open project"), QString::fromLocal8Bit(e.what()) );

mMapCanvas->freeze(false);
mMapCanvas->refresh();
Expand Down Expand Up @@ -2881,12 +2871,9 @@ bool QgisApp::fileSave()
}
catch ( std::exception & e )
{
QMessageBox::critical( 0x0,
QMessageBox::critical( this,
tr("Unable to save project ") + QgsProject::instance()->filename(),
e.what(),
QMessageBox::Ok,
Qt::NoButton );

e.what() );
}
return true;
} // QgisApp::fileSave
Expand Down Expand Up @@ -2974,8 +2961,7 @@ void QgisApp::openProject(QAction *action)

debugme = action->text();

int answer = saveDirty();
if (answer != QMessageBox::Cancel)
if (saveDirty())
{
addProject(debugme);

Expand All @@ -2994,9 +2980,7 @@ void QgisApp::openProject(QAction *action)
void QgisApp::openProject(const QString & fileName)
{
// possibly save any pending work before opening a different project
int answer = saveDirty();

if (answer != QMessageBox::Cancel)
if (saveDirty())
{
try
{
Expand All @@ -3012,7 +2996,7 @@ void QgisApp::openProject(const QString & fileName)
}
catch ( QgsIOException & io_exception )
{
QMessageBox::critical( 0x0,
QMessageBox::critical( this,
tr("QGIS: Unable to load project"),
tr("Unable to load project ") + fileName );
}
Expand Down Expand Up @@ -3408,14 +3392,14 @@ void QgisApp::deleteSelected()

if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures))
{
QMessageBox::information(0, tr("Provider does not support deletion"),
QMessageBox::information(this, tr("Provider does not support deletion"),
tr("Data provider does not support deleting features"));
return;
}

if(!vlayer->isEditable())
{
QMessageBox::information(0, tr("Layer not editable"),
QMessageBox::information(this, tr("Layer not editable"),
tr("The current layer is not editable. Choose 'Start editing' in the digitizing toolbar."));
return;
}
Expand Down Expand Up @@ -4151,8 +4135,8 @@ void QgisApp::socketConnectionClosed()
{
versionInfo += parts[1] + "\n\n" + tr("Would you like more information?");
;
int result = QMessageBox::information(this, tr("QGIS Version Information"), versionInfo, tr("Yes"), tr("No"));
if (result == 0)
QMessageBox::StandardButton result = QMessageBox::information(this, tr("QGIS Version Information"), versionInfo, QMessageBox::Ok | QMessageBox::Cancel);
if (result == QMessageBox::Ok)
{
// show more info
QgsMessageViewer *mv = new QgsMessageViewer(this);
Expand Down Expand Up @@ -4412,12 +4396,13 @@ void QgisApp::setExtent(QgsRect theRect)
mMapCanvas->setExtent(theRect);
}




int QgisApp::saveDirty()
/**
Prompt and save if project has been modified.
@return true if saved or discarded, false if cancelled
*/
bool QgisApp::saveDirty()
{
int answer(QMessageBox::No);
QMessageBox::StandardButton answer(QMessageBox::Discard);
mMapCanvas->freeze(true);

#ifdef QGISDEBUG
Expand Down Expand Up @@ -4456,20 +4441,18 @@ int QgisApp::saveDirty()

// prompt user to save
answer = QMessageBox::information(this, tr("Save?"),
tr("<p>Do you want to save the current project?</p>"),
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No,
QMessageBox::Cancel | QMessageBox::Escape);
if (QMessageBox::Yes == answer )
tr("Do you want to save the current project?"),
QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard);
if (QMessageBox::Save == answer)
{
if (!fileSave())
answer = QMessageBox::Cancel;
answer = QMessageBox::Cancel;
}
}

mMapCanvas->freeze(false);

return answer;
return (answer != QMessageBox::Cancel);

} // QgisApp::saveDirty()

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -416,7 +416,7 @@ public slots:
//! shows the paste-transformations dialog
void pasteTransformations();
//! check to see if file is dirty and if so, prompt the user th save it
int saveDirty();
bool saveDirty();
//! Have some control over closing of the application
virtual void closeEvent(QCloseEvent* event);

Expand Down
10 changes: 6 additions & 4 deletions src/app/qgsattributetabledisplay.cpp
Expand Up @@ -133,7 +133,7 @@ void QgsAttributeTableDisplay::addAttribute()
{
if(!table()->addAttribute(dialog.name(),dialog.type()))
{
QMessageBox::information(0,"Name conflict","The attribute could not be inserted. The name already exists in the table",QMessageBox::Ok);
QMessageBox::information(this,tr("Name conflict"),tr("The attribute could not be inserted. The name already exists in the table"));
}
}
}
Expand Down Expand Up @@ -182,12 +182,14 @@ void QgsAttributeTableDisplay::stopEditing()
if(table()->edited())
{
//commit or roll back?
int commit=QMessageBox::information(0,"Stop editing","Do you want to save the changes?",QMessageBox::Yes,QMessageBox::No);
if(commit==QMessageBox::Yes)
QMessageBox::StandardButton commit=QMessageBox::information(this,tr("Stop editing"),
tr("Do you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard);
if(commit==QMessageBox::Save)
{
if(!table()->commitChanges(mLayer))
{
QMessageBox::information(0,"Error","Could not commit changes",QMessageBox::Ok);
QMessageBox::information(this,tr("Error"),tr("Could not commit changes"));
}
}
else
Expand Down
9 changes: 4 additions & 5 deletions src/app/qgsbookmarks.cpp
Expand Up @@ -124,9 +124,9 @@ void QgsBookmarks::on_btnDelete_clicked()
if(lvi)
{
// make sure the user really wants to delete this bookmark
if(0 == QMessageBox::information(this,tr("Really Delete?"),
tr("Are you sure you want to delete the ") + lvi->text(0) +
tr(" bookmark?"), tr("&Yes"), tr("&No"), QString::null, 0, 1))
if(QMessageBox::Ok == QMessageBox::information(this,tr("Really Delete?"),
tr("Are you sure you want to delete the ") + lvi->text(0) + tr(" bookmark?"),
QMessageBox::Ok | QMessageBox::Cancel))
{
// remove it from the listview
lstBookmarks->takeItem(lvi);
Expand All @@ -145,8 +145,7 @@ void QgsBookmarks::on_btnDelete_clicked()
tr("Failed to delete the ") +
lvi->text(0) +
tr(" bookmark from the database. The "
"database said:\n") + QString(errmsg),
QMessageBox::Ok, QMessageBox::NoButton);
"database said:\n") + QString(errmsg));
sqlite3_free(errmsg);
}
// close the database
Expand Down

0 comments on commit 973e43b

Please sign in to comment.