Fix for #980 - remove dialogs after loading and saving styles

git-svn-id: http://svn.osgeo.org/qgis/trunk@8741 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2008-07-08 21:50:48 +00:00
parent 014c185288
commit 51a26c26c5
3 changed files with 91 additions and 47 deletions

View File

@ -2866,13 +2866,18 @@ void QgsRasterLayerProperties::on_pbnLoadDefaultStyle_clicked()
//reset if the default style was loaded ok only //reset if the default style was loaded ok only
if ( defaultLoadedFlag ) if ( defaultLoadedFlag )
{ {
//it worked so do it quietly
sync(); sync();
} }
else
{
//otherwise let the user know what went wrong
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Default Style"),
myMessage myMessage
); );
} }
}
void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked() void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked()
{ {
@ -2881,11 +2886,15 @@ void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked()
// after calling this the above flag will be set true for success // after calling this the above flag will be set true for success
// or false if the save operation failed // or false if the save operation failed
QString myMessage = mRasterLayer->saveDefaultStyle( defaultSavedFlag ); QString myMessage = mRasterLayer->saveDefaultStyle( defaultSavedFlag );
if ( !defaultSavedFlag )
{
//let the user know what went wrong
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Default Style"),
myMessage myMessage
); );
} }
}
void QgsRasterLayerProperties::on_pbnLoadStyle_clicked() void QgsRasterLayerProperties::on_pbnLoadStyle_clicked()
@ -2933,11 +2942,15 @@ void QgsRasterLayerProperties::on_pbnLoadStyle_clicked()
{ {
sync(); sync();
} }
else
{
//let the user know something went wrong...
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Saved Style"),
myMessage myMessage
); );
} }
}
else else
{ {
QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) + QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) +
@ -2993,13 +3006,18 @@ void QgsRasterLayerProperties::on_pbnSaveStyleAs_clicked()
//reset if the default style was loaded ok only //reset if the default style was loaded ok only
if ( defaultLoadedFlag ) if ( defaultLoadedFlag )
{ {
//dont show the message if all went well...
sync(); sync();
} }
else
{
//if something went wrong let the user know why
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Saved Style"),
myMessage myMessage
); );
} }
}
else else
{ {
QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) + QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) +

View File

@ -629,13 +629,18 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
//reset if the default style was loaded ok only //reset if the default style was loaded ok only
if ( defaultLoadedFlag ) if ( defaultLoadedFlag )
{ {
// all worked ok so no need to inform user
reset (); reset ();
} }
else
{
//something went wrong - let them know why
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Default Style"),
myMessage myMessage
); );
} }
}
void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked() void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
{ {
@ -646,11 +651,15 @@ void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
// after calling this the above flag will be set true for success // after calling this the above flag will be set true for success
// or false if the save operation failed // or false if the save operation failed
QString myMessage = layer->saveDefaultStyle( defaultSavedFlag ); QString myMessage = layer->saveDefaultStyle( defaultSavedFlag );
if ( !defaultSavedFlag )
{
//only raise the message if something went wrong
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Default Style"),
myMessage myMessage
); );
} }
}
void QgsVectorLayerProperties::on_pbnLoadStyle_clicked() void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
@ -698,11 +707,15 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
{ {
reset (); reset ();
} }
else
{
//let the user know what went wrong
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Saved Style"),
myMessage myMessage
); );
} }
}
else else
{ {
QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) + QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) +
@ -762,11 +775,15 @@ void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked()
{ {
reset (); reset ();
} }
else
{
//let the user know what went wrong
QMessageBox::information( this, QMessageBox::information( this,
tr("Default Style"), tr("Saved Style"),
myMessage myMessage
); );
} }
}
else else
{ {
QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) + QMessageBox::warning ( this, tr ( "QGIS" ), tr ( "Unknown style format: " ) +

View File

@ -465,9 +465,11 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
QString qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) ); QString qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) );
theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column ); theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column );
if(!theResultFlag) if(!theResultFlag)
{
myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column); myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
} }
} }
}
else else
{ {
theResultFlag = false; theResultFlag = false;
@ -479,14 +481,16 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
} }
if(!theResultFlag) if(!theResultFlag)
{
return myErrorMessage; return myErrorMessage;
}
// now get the layer node out and pass it over to the layer // now get the layer node out and pass it over to the layer
// to deserialise... // to deserialise...
QDomElement myRoot = myDocument.firstChildElement("qgis"); QDomElement myRoot = myDocument.firstChildElement("qgis");
if (myRoot.isNull()) if (myRoot.isNull())
{ {
myErrorMessage = "Error: qgis element could not be found in " + theURI; myErrorMessage = "Error: qgis element could not be found in " + theURI;
theResultFlag = false;
return myErrorMessage; return myErrorMessage;
} }
@ -494,6 +498,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
if (myLayer.isNull()) if (myLayer.isNull())
{ {
myErrorMessage = "Error: maplayer element could not be found in " + theURI; myErrorMessage = "Error: maplayer element could not be found in " + theURI;
theResultFlag = false;
return myErrorMessage; return myErrorMessage;
} }
@ -505,6 +510,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
if (myDataSource.isNull()) if (myDataSource.isNull())
{ {
myErrorMessage = "Error: datasource element could not be found in " + theURI; myErrorMessage = "Error: datasource element could not be found in " + theURI;
theResultFlag = false;
return myErrorMessage; return myErrorMessage;
} }
QDomElement myNewDataSource = myDocument.createElement( "datasource" ); QDomElement myNewDataSource = myDocument.createElement( "datasource" );
@ -562,10 +568,12 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
// save as utf-8 with 2 spaces for indents // save as utf-8 with 2 spaces for indents
myDocument.save( myFileStream, 2 ); myDocument.save( myFileStream, 2 );
myFile.close(); myFile.close();
theResultFlag = true;
return QObject::tr( "Created default style file as " ) + myFileName; return QObject::tr( "Created default style file as " ) + myFileName;
} }
else else
{ {
theResultFlag = false;
return QObject::tr( "ERROR: Failed to created default style file as %1 Check file permissions and retry." ).arg(myFileName); return QObject::tr( "ERROR: Failed to created default style file as %1 Check file permissions and retry." ).arg(myFileName);
} }
} }
@ -596,6 +604,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
{ {
sqlite3_finalize(myPreparedStatement); sqlite3_finalize(myPreparedStatement);
sqlite3_close(myDatabase); sqlite3_close(myDatabase);
theResultFlag = false;
return tr("The style table could not be created."); return tr("The style table could not be created.");
} }
} }
@ -632,7 +641,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
} }
else else
{ {
theResultFlag = true; theResultFlag = false;
myErrorMessage = tr("The style %1 could not be updated in the database.").arg(theURI); myErrorMessage = tr("The style %1 could not be updated in the database.").arg(theURI);
} }
} }