[QGIS Commit] r8741 - in trunk/qgis/src: app core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 8 17:50:49 EDT 2008


Author: timlinux
Date: 2008-07-08 17:50:48 -0400 (Tue, 08 Jul 2008)
New Revision: 8741

Modified:
   trunk/qgis/src/app/qgsrasterlayerproperties.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
   trunk/qgis/src/core/qgsmaplayer.cpp
Log:
Fix for #980 - remove dialogs after loading and saving styles

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-07-08 20:46:17 UTC (rev 8740)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-07-08 21:50:48 UTC (rev 8741)
@@ -2866,12 +2866,17 @@
   //reset if the default style was loaded ok only
   if ( defaultLoadedFlag )
   {
+    //it worked so do it quietly
     sync();
   }
-  QMessageBox::information( this, 
-      tr("Default Style"), 
-      myMessage
-      ); 
+  else
+  {
+    //otherwise let the user know what went wrong
+    QMessageBox::information( this, 
+        tr("Default Style"), 
+        myMessage
+        ); 
+  }
 }
 
 void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked()
@@ -2881,10 +2886,14 @@
   // after calling this the above flag will be set true for success
   // or false if the save operation failed
   QString myMessage = mRasterLayer->saveDefaultStyle( defaultSavedFlag );
-  QMessageBox::information( this, 
-      tr("Default Style"), 
-      myMessage
-      ); 
+  if ( !defaultSavedFlag )
+  {
+    //let the user know what went wrong
+    QMessageBox::information( this, 
+        tr("Default Style"), 
+        myMessage
+        ); 
+  }
 }
 
 
@@ -2933,10 +2942,14 @@
       {
         sync();
       }
-      QMessageBox::information( this, 
-          tr("Default Style"), 
-          myMessage
-          ); 
+      else
+      {
+        //let the user know something went wrong...
+        QMessageBox::information( this, 
+            tr("Saved Style"), 
+            myMessage
+            ); 
+      }
     }
     else
     {
@@ -2993,12 +3006,17 @@
       //reset if the default style was loaded ok only
       if ( defaultLoadedFlag )
       {
+        //dont show the message if all went well...
         sync();
       }
-      QMessageBox::information( this, 
-          tr("Default Style"), 
-          myMessage
-          ); 
+      else
+      {
+        //if something went wrong let the user know why
+        QMessageBox::information( this, 
+            tr("Saved Style"), 
+            myMessage
+            ); 
+      }
     }
     else
     {

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2008-07-08 20:46:17 UTC (rev 8740)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2008-07-08 21:50:48 UTC (rev 8741)
@@ -629,12 +629,17 @@
   //reset if the default style was loaded ok only
   if ( defaultLoadedFlag )
   {
+    // all worked ok so no need to inform user
     reset ();
   }
-  QMessageBox::information( this, 
-      tr("Default Style"), 
-      myMessage
-      ); 
+  else
+  {
+    //something went wrong - let them know why
+    QMessageBox::information( this, 
+        tr("Default Style"), 
+        myMessage
+        ); 
+  }
 }
 
 void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
@@ -646,10 +651,14 @@
   // after calling this the above flag will be set true for success
   // or false if the save operation failed
   QString myMessage = layer->saveDefaultStyle( defaultSavedFlag );
-  QMessageBox::information( this, 
-      tr("Default Style"), 
-      myMessage
-      ); 
+  if ( !defaultSavedFlag )
+  {
+    //only raise the message if something went wrong
+    QMessageBox::information( this, 
+        tr("Default Style"), 
+        myMessage
+        ); 
+  }
 }
 
 
@@ -698,10 +707,14 @@
       {
         reset ();
       }
-      QMessageBox::information( this, 
-          tr("Default Style"), 
-          myMessage
-          ); 
+      else
+      {
+        //let the user know what went wrong
+        QMessageBox::information( this, 
+            tr("Saved Style"), 
+            myMessage
+            ); 
+      }
     }
     else
     {
@@ -762,10 +775,14 @@
       {
         reset ();
       }
-      QMessageBox::information( this, 
-          tr("Default Style"), 
-          myMessage
-          ); 
+      else
+      {
+        //let the user know what went wrong
+        QMessageBox::information( this, 
+            tr("Saved Style"), 
+            myMessage
+            ); 
+      }
     }
     else
     {

Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp	2008-07-08 20:46:17 UTC (rev 8740)
+++ trunk/qgis/src/core/qgsmaplayer.cpp	2008-07-08 21:50:48 UTC (rev 8741)
@@ -446,7 +446,7 @@
     sqlite3_stmt *myPreparedStatement;
     const char *myTail;
     int myResult;
-    
+
     myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase);
     if (myResult)
     {
@@ -464,8 +464,10 @@
       {
         QString qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) );
         theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column );
-	if(!theResultFlag)
-	  myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
+        if(!theResultFlag)
+        {
+          myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
+        }
       }
     }
     else
@@ -479,14 +481,16 @@
   }
 
   if(!theResultFlag)
+  {
     return myErrorMessage;
-
+  }
   // now get the layer node out and pass it over to the layer
   // to deserialise...
   QDomElement myRoot = myDocument.firstChildElement("qgis");
   if (myRoot.isNull())
   {
     myErrorMessage = "Error: qgis element could not be found in " + theURI;
+    theResultFlag = false;
     return myErrorMessage;
   }
 
@@ -494,6 +498,7 @@
   if (myLayer.isNull())
   {
     myErrorMessage = "Error: maplayer element could not be found in " + theURI;
+    theResultFlag = false;
     return myErrorMessage;
   }
 
@@ -505,6 +510,7 @@
   if (myDataSource.isNull())
   {
     myErrorMessage = "Error: datasource element could not be found in " + theURI;
+    theResultFlag = false;
     return myErrorMessage;
   }
   QDomElement myNewDataSource = myDocument.createElement( "datasource" );
@@ -562,23 +568,25 @@
       // save as utf-8 with 2 spaces for indents
       myDocument.save( myFileStream, 2 );  
       myFile.close();
+      theResultFlag = true;
       return QObject::tr( "Created default style file as " ) + myFileName;
     }
     else
     {
+      theResultFlag = false;
       return QObject::tr( "ERROR: Failed to created default style file as %1 Check file permissions and retry." ).arg(myFileName); 
     }
   }
   else
   {
     QString qml = myDocument.toString();
-    
+
     // read from database
     sqlite3 *myDatabase; 
     sqlite3_stmt *myPreparedStatement;
     const char *myTail;
     int myResult;
-    
+
     myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase);
     if (myResult)
     {
@@ -595,7 +603,8 @@
       if( sqlite3_step(myPreparedStatement)!=SQLITE_DONE ) 
       {
         sqlite3_finalize(myPreparedStatement);
-	sqlite3_close(myDatabase);
+        sqlite3_close(myDatabase);
+        theResultFlag = false;
         return tr("The style table could not be created.");
       }
     }
@@ -611,7 +620,7 @@
           sqlite3_step(myPreparedStatement)==SQLITE_DONE ) 
       {
         theResultFlag = true;
-	myErrorMessage = tr("The style %1 was saved to database").arg(theURI);
+        myErrorMessage = tr("The style %1 was saved to database").arg(theURI);
       }
     }
 
@@ -628,13 +637,13 @@
             sqlite3_step(myPreparedStatement)==SQLITE_DONE ) 
         {
           theResultFlag = true;
-	  myErrorMessage = tr("The style %1 was updated in the database.").arg(theURI);
+          myErrorMessage = tr("The style %1 was updated in the database.").arg(theURI);
         }
-	else
-	{
-          theResultFlag = true;
-	  myErrorMessage = tr("The style %1 could not be updated in the database.").arg(theURI);
-	}
+        else
+        {
+          theResultFlag = false;
+          myErrorMessage = tr("The style %1 could not be updated in the database.").arg(theURI);
+        }
       }
       else
       {
@@ -645,7 +654,7 @@
 
       sqlite3_finalize(myPreparedStatement);
     }
-    
+
     sqlite3_close(myDatabase);
   }
 



More information about the QGIS-commit mailing list