[QGIS Commit] r11524 - in trunk/qgis/src: app gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Aug 29 15:14:28 EDT 2009


Author: homann
Date: 2009-08-29 15:14:28 -0400 (Sat, 29 Aug 2009)
New Revision: 11524

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/gui/qgsencodingfiledialog.cpp
   trunk/qgis/src/gui/qgsencodingfiledialog.h
Log:
Add a "cancel all" button when searching for missing files after opening a project. Fixes #1317

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-08-28 20:32:23 UTC (rev 11523)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-08-29 19:14:28 UTC (rev 11524)
@@ -2338,10 +2338,13 @@
 
 */
 
-static void openFilesRememberingFilter_( QString const &filterName,
-    QString const &filters, QStringList & selectedFiles, QString& enc, QString &title )
+static bool openFilesRememberingFilter_( QString const &filterName,
+    QString const &filters, QStringList & selectedFiles, QString& enc, QString &title,
+    bool cancelAll = false )
 {
 
+  bool retVal = false;
+
   bool haveLastUsedFilter = false; // by default, there is no last
   // used filter
 
@@ -2367,6 +2370,12 @@
     openFileDialog->selectFilter( lastUsedFilter );
   }
 
+  // Check if we should add a cancel all button
+  if ( cancelAll )
+  {
+    openFileDialog->addCancelAll();
+  }
+
   if ( openFileDialog->exec() == QDialog::Accepted )
   {
     selectedFiles = openFileDialog->selectedFiles();
@@ -2383,8 +2392,14 @@
     settings.setValue( "/UI/" + filterName, openFileDialog->selectedFilter() );
     settings.setValue( "/UI/" + filterName + "Dir", myPath );
   }
+  else
+  {
+    // Cancel or cancel all
+    retVal = openFileDialog->cancelAll();
+  }
 
   delete openFileDialog;
+  return retVal;
 }   // openFilesRememberingFilter_
 
 
@@ -2938,7 +2953,7 @@
 
 */
 static
-void
+bool
 findMissingFile_( QString const & fileFilters, QDomNode & layerNode )
 {
   // Prepend that file name to the valid file format filter list since it
@@ -2966,7 +2981,7 @@
     }
     default:
       QgsDebugMsg( "unable to determine data type" );
-      return;
+      return false;
   }
 
   // Prepend the original data source base name to make it easier to pick it
@@ -2982,15 +2997,16 @@
                   .arg( originalDataSource.fileName() )
                   .arg( originalDataSource.absoluteFilePath() );
 
-  openFilesRememberingFilter_( memoryQualifier,
-                               myFileFilters,
-                               selectedFiles,
-                               enc,
-                               title );
+  bool retVal = openFilesRememberingFilter_( memoryQualifier,
+                myFileFilters,
+                selectedFiles,
+                enc,
+                title,
+                true );
 
   if ( selectedFiles.isEmpty() )
   {
-    return;
+    return retVal;
   }
   else
   {
@@ -3000,7 +3016,7 @@
       QgsDebugMsg( "unable to re-read layer" );
     }
   }
-
+  return retVal;
 } // findMissingFile_
 
 
@@ -3019,17 +3035,19 @@
 
 */
 static
-void
+bool
 findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
 {
   // XXX actually we could possibly get away with a copy of the node
   QDomNode & layerNode = const_cast<QDomNode&>( constLayerNode );
 
+  bool retVal = false;
+
   switch ( providerType_( layerNode ) )
   {
     case IS_FILE:
       QgsDebugMsg( "layer is file based" );
-      findMissingFile_( fileFilters, layerNode );
+      retVal = findMissingFile_( fileFilters, layerNode );
       break;
 
     case IS_DATABASE:
@@ -3044,7 +3062,7 @@
       QgsDebugMsg( "layer has an unkown type" );
       break;
   }
-
+  return retVal;
 } // findLayer_
 
 
@@ -3064,7 +3082,11 @@
         i != layerNodes.end();
         ++i )
   {
-    findLayer_( fileFilters, *i );
+    if ( findLayer_( fileFilters, *i ) )
+    {
+      // If findLayer returns true, the user hit Cancel All button
+      break;
+    }
   }
 
 } // findLayers_

Modified: trunk/qgis/src/gui/qgsencodingfiledialog.cpp
===================================================================
--- trunk/qgis/src/gui/qgsencodingfiledialog.cpp	2009-08-28 20:32:23 UTC (rev 11523)
+++ trunk/qgis/src/gui/qgsencodingfiledialog.cpp	2009-08-29 19:14:28 UTC (rev 11524)
@@ -18,6 +18,7 @@
 #include "qgslogger.h"
 #include <QSettings>
 #include <QComboBox>
+#include <QPushButton>
 #include <QLabel>
 #include <QLayout>
 #include <QTextCodec>
@@ -28,6 +29,8 @@
     const QString & filter, const QString & encoding )
     : QFileDialog( parent, caption, directory, filter )
 {
+  mCancelAll       = false;
+  mCancelAllButton = 0;
   mEncodingComboBox = new QComboBox( this );
   QLabel* l = new QLabel( tr( "Encoding:" ), this );
   layout()->addWidget( l );
@@ -121,3 +124,25 @@
   settings.setValue( "/UI/encoding", encoding() );
   QgsDebugMsg( QString( "Set encoding " + encoding() + " as default." ) );
 }
+
+void QgsEncodingFileDialog::addCancelAll()
+{
+  if ( ! mCancelAllButton )
+  {
+    mCancelAllButton = new QPushButton( "Cancel &All", NULL );
+    layout()->addWidget( mCancelAllButton ); // Ownership transfered, no need to delete later on
+    connect( mCancelAllButton, SIGNAL( clicked() ), this, SLOT( pbnCancelAll_clicked() ) );
+  }
+}
+
+bool QgsEncodingFileDialog::cancelAll()
+{
+  return mCancelAll;
+}
+
+void QgsEncodingFileDialog::pbnCancelAll_clicked()
+{
+  mCancelAll = true;
+  // Now, continue as the user clicked the cancel button
+  reject();
+}

Modified: trunk/qgis/src/gui/qgsencodingfiledialog.h
===================================================================
--- trunk/qgis/src/gui/qgsencodingfiledialog.h	2009-08-28 20:32:23 UTC (rev 11523)
+++ trunk/qgis/src/gui/qgsencodingfiledialog.h	2009-08-29 19:14:28 UTC (rev 11524)
@@ -18,6 +18,7 @@
 
 #include <QFileDialog>
 class QComboBox;
+class QPushButton;
 
 /** \ingroup gui
  * A file dialog which lets the user select the prefered encoding type for a data provider.
@@ -32,12 +33,25 @@
     ~QgsEncodingFileDialog();
     /**Returns a string describing the choosen encoding*/
     QString encoding() const;
+    /* Adds a 'Cancel All' button for the user to click */
+    void addCancelAll();
+    /* Returns true if the user clicked 'Cancel All' */
+    bool cancelAll();
+
   public slots:
     void saveUsedEncoding();
 
+    void pbnCancelAll_clicked();
+
   private:
     /**Box to choose the encoding type*/
     QComboBox* mEncodingComboBox;
+
+    /* The button to click */
+    QPushButton *mCancelAllButton;
+
+    /* Set if user clicked 'Cancel All' */
+    bool mCancelAll;
 };
 
 #endif



More information about the QGIS-commit mailing list