[QGIS Commit] r15264 - in trunk/qgis/src: app app/postgres ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Feb 25 12:29:39 EST 2011


Author: alexbruy
Date: 2011-02-25 09:29:39 -0800 (Fri, 25 Feb 2011)
New Revision: 15264

Modified:
   trunk/qgis/src/app/postgres/qgspgsourceselect.cpp
   trunk/qgis/src/app/postgres/qgspgsourceselect.h
   trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp
   trunk/qgis/src/app/qgsmanageconnectionsdialog.h
   trunk/qgis/src/app/qgswmssourceselect.cpp
   trunk/qgis/src/app/qgswmssourceselect.h
   trunk/qgis/src/ui/qgsmanageconnectionsdialogbase.ui
Log:
manage connections dialog cleanup and usability improvement. Also add support for service parameter in PostgreSQL connection introduced in r15258


Modified: trunk/qgis/src/app/postgres/qgspgsourceselect.cpp
===================================================================
--- trunk/qgis/src/app/postgres/qgspgsourceselect.cpp	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/postgres/qgspgsourceselect.cpp	2011-02-25 17:29:39 UTC (rev 15264)
@@ -30,6 +30,7 @@
 #include "qgsvectorlayer.h"
 #include "qgscredentials.h"
 
+#include <QFileDialog>
 #include <QInputDialog>
 #include <QMessageBox>
 #include <QSettings>
@@ -157,13 +158,20 @@
 
 void QgsPgSourceSelect::saveClicked()
 {
-  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Save, QgsManageConnectionsDialog::PostGIS );
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::PostGIS );
   dlg.exec();
 }
 
 void QgsPgSourceSelect::loadClicked()
 {
-  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Load, QgsManageConnectionsDialog::PostGIS );
+  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections )" ), ".",
+                                                   tr( "XML files (*.xml *XML)" ) );
+  if ( fileName.isEmpty() )
+  {
+    return;
+  }
+
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::PostGIS, fileName );
   dlg.exec();
   populateConnectionList();
 }

Modified: trunk/qgis/src/app/postgres/qgspgsourceselect.h
===================================================================
--- trunk/qgis/src/app/postgres/qgspgsourceselect.h	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/postgres/qgspgsourceselect.h	2011-02-25 17:29:39 UTC (rev 15264)
@@ -131,9 +131,9 @@
     void on_btnBuildQuery_clicked();
     //! Deletes the selected connection
     void on_btnDelete_clicked();
-    //! Saves the selected connections to the file
+    //! Saves the selected connections to file
     void saveClicked();
-    //! Loads the selected connections from the file
+    //! Loads the selected connections from file
     void loadClicked();
     void on_mSearchTableEdit_textChanged( const QString & text );
     void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );

Modified: trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp	2011-02-25 17:29:39 UTC (rev 15264)
@@ -16,84 +16,87 @@
 
 /* $Id$ */
 
+#include <QCloseEvent>
 #include <QFileDialog>
 #include <QMessageBox>
+#include <QPushButton>
 #include <QSettings>
 #include <QTextStream>
 
 #include "qgsmanageconnectionsdialog.h"
 
-QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type ) : QDialog( parent ), mDialogMode( mode ), mConnectionType( type )
+QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type, QString fileName )
+    : QDialog( parent )
+    , mFileName( fileName )
+    , mDialogMode( mode )
+    , mConnectionType( type )
 {
   setupUi( this );
 
-  if ( mDialogMode == Load )
-  {
-    label->setText( tr( "Load from file" ) );
-    buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Load" ) );
-  }
-  else
-  {
-    buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Save" ) );
-    populateConnections();
-  }
+  // additional buttons
+  QPushButton *pb;
+  pb = new QPushButton( tr( "Select all" ) );
+  buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
+  connect( pb, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
 
-  connect( btnBrowse, SIGNAL( clicked() ), this, SLOT( selectFile() ) );
-  // use Ok button for starting import and export operations
-  disconnect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
-  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( doSaveLoad() ) );
-  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
-}
+  pb = new QPushButton( tr( "Clear selection" ) );
+  buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
+  connect( pb, SIGNAL( clicked() ), this, SLOT( clearSelection() ) );
 
-void QgsManageConnectionsDialog::selectFile()
-{
-  QString fileName;
-  if ( mDialogMode == Save )
+  if ( mDialogMode == Import )
   {
-    fileName = QFileDialog::getSaveFileName( this, tr( "Save connections" ), ".", tr( "XML files (*.xml *.XML)" ) );
+    label->setText( tr( "Select connections to import" ) );
+    buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) );
   }
   else
   {
-    fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), ".", tr( "XML files (*.xml *XML)" ) );
+    //label->setText( tr( "Select connections to export" ) );
+    buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Export" ) );
   }
 
-  if ( fileName.isEmpty() )
+  if ( !populateConnections() )
   {
-    return;
+    QApplication::postEvent( this, new QCloseEvent() );
   }
 
-  // ensure the user never ommited the extension from the file name
-  if ( !fileName.toLower().endsWith( ".xml" ) )
-  {
-    fileName += ".xml";
-  }
-
-  mFileName = fileName;
-  leFileName->setText( mFileName );
-
-  if ( mDialogMode == Load )
-  {
-    populateConnections();
-  }
-
-  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
+  // use Ok button for starting import and export operations
+  disconnect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
+  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( doExportImport() ) );
 }
 
-void QgsManageConnectionsDialog::doSaveLoad()
+void QgsManageConnectionsDialog::doExportImport()
 {
   QList<QListWidgetItem *> selection = listConnections->selectedItems();
   if ( selection.isEmpty() )
   {
+    QMessageBox::warning( this, tr( "Export/import error" ),
+                          tr( "You should select at least one connection from list." ) );
     return;
   }
+
   QStringList items;
   for ( int i = 0; i < selection.size(); ++i )
   {
     items.append( selection.at( i )->text() );
   }
 
-  if ( mDialogMode == Save )
+  if ( mDialogMode == Export )
   {
+    QString fileName = QFileDialog::getSaveFileName( this, tr( "Save connections" ), ".",
+                                                     tr( "XML files (*.xml *.XML)" ) );
+    if ( fileName.isEmpty() )
+    {
+      return;
+    }
+
+    // ensure the user never ommited the extension from the file name
+    if ( !fileName.toLower().endsWith( ".xml" ) )
+    {
+      fileName += ".xml";
+    }
+
+    mFileName = fileName;
+
     QDomDocument doc;
     if ( mConnectionType == WMS )
     {
@@ -117,7 +120,7 @@
     QTextStream out( &file );
     doc.save( out, 4 );
   }
-  else // load connections
+  else // import connections
   {
     QFile file( mFileName );
     if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
@@ -152,22 +155,21 @@
     {
       loadPgConnections( doc, items );
     }
-    // clear connections list
+    // clear connections list and close window
     listConnections->clear();
+    accept();
   }
 
   mFileName = "";
-  leFileName->clear();
-  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
 }
 
-void QgsManageConnectionsDialog::populateConnections()
+bool QgsManageConnectionsDialog::populateConnections()
 {
-  // Save mode. Populate connections list from settings
-  if ( mDialogMode == 0 )
+  // Export mode. Populate connections list from settings
+  if ( mDialogMode == Export )
   {
     QSettings settings;
-    if ( mConnectionType == 0 )
+    if ( mConnectionType == WMS )
     {
       settings.beginGroup( "/Qgis/connections-wms" );
     }
@@ -186,7 +188,7 @@
     }
     settings.endGroup();
   }
-  // Load mode. Populate connections list from file
+  // Import mode. Populate connections list from file
   else
   {
     QFile file( mFileName );
@@ -196,7 +198,7 @@
                             tr( "Cannot read file %1:\n%2." )
                             .arg( mFileName )
                             .arg( file.errorString() ) );
-      return;
+      return false;
     }
 
     QDomDocument doc;
@@ -211,20 +213,17 @@
                             .arg( errorLine )
                             .arg( errorColumn )
                             .arg( errorStr ) );
-      return;
+      return false;
     }
 
     QDomElement root = doc.documentElement();
-    if ( mConnectionType == 0 )
+    if ( mConnectionType == WMS )
     {
       if ( root.tagName() != "qgsWMSConnections" )
       {
         QMessageBox::information( this, tr( "Loading connections" ),
                                   tr( "The file is not an WMS connections exchange file." ) );
-        mFileName = "";
-        leFileName->clear();
-        listConnections->clear();
-        return;
+        return false;
       }
     }
     else
@@ -233,10 +232,7 @@
       {
         QMessageBox::information( this, tr( "Loading connections" ),
                                   tr( "The file is not an PostGIS connections exchange file." ) );
-        mFileName = "";
-        leFileName->clear();
-        listConnections->clear();
-        return;
+        return false;
       }
     }
 
@@ -249,6 +245,7 @@
       child = child.nextSiblingElement();
     }
   }
+  return true;
 }
 
 QDomDocument QgsManageConnectionsDialog::saveWMSConnections( const QStringList &connections )
@@ -293,6 +290,7 @@
     el.setAttribute( "host", settings.value( path + "/host", "" ).toString() );
     el.setAttribute( "port", settings.value( path + "/port", "" ).toString() );
     el.setAttribute( "database", settings.value( path + "/database", "" ).toString() );
+    el.setAttribute( "service", settings.value( path + "/service", "" ).toString() );
     el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() );
     el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() );
 
@@ -332,6 +330,9 @@
   QStringList keys = settings.childGroups();
   settings.endGroup();
   QDomElement child = root.firstChildElement();
+  bool prompt = true;
+  bool overwrite = true;
+
   while ( !child.isNull() )
   {
     connectionName = child.attribute( "name" );
@@ -342,19 +343,35 @@
     }
 
     // check for duplicates
-    if ( keys.contains( connectionName ) )
+    if ( keys.contains( connectionName ) && prompt )
     {
       int res = QMessageBox::warning( this, tr( "Loading connections" ),
-                                      tr( "Connection with name %1 already exists. Overwrite?" )
+                                      tr( "Connection with name '%1' already exists. Overwrite?" )
                                       .arg( connectionName ),
-                                      QMessageBox::Yes | QMessageBox::No );
-      if ( res != QMessageBox::Yes )
+                                      QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
+
+      switch ( res )
       {
-        child = child.nextSiblingElement();
-        continue;
+        case QMessageBox::Cancel:   return;
+        case QMessageBox::No:       child = child.nextSiblingElement();
+                                    continue;
+        case QMessageBox::Yes:      overwrite = true;
+                                    break;
+        case QMessageBox::YesToAll: prompt = false;
+                                    overwrite = true;
+                                    break;
+        case QMessageBox::NoToAll:  prompt = false;
+                                    overwrite = false;
+                                    break;
       }
     }
 
+    if ( keys.contains( connectionName ) && !overwrite )
+    {
+      child = child.nextSiblingElement();
+      continue;
+    }
+
     // no dups detected or overwrite is allowed
     settings.beginGroup( "/Qgis/connections-wms" );
     settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
@@ -388,6 +405,9 @@
   QStringList keys = settings.childGroups();
   settings.endGroup();
   QDomElement child = root.firstChildElement();
+  bool prompt = true;
+  bool overwrite = true;
+
   while ( !child.isNull() )
   {
     connectionName = child.attribute( "name" );
@@ -398,26 +418,49 @@
     }
 
     // check for duplicates
-    if ( keys.contains( connectionName ) )
+    if ( keys.contains( connectionName ) && prompt )
     {
       int res = QMessageBox::warning( this,
                                       tr( "Loading connections" ),
-                                      tr( "Connection with name %1 already exists. Overwrite?" )
+                                      tr( "Connection with name '%1' already exists. Overwrite?" )
                                       .arg( connectionName ),
-                                      QMessageBox::Yes | QMessageBox::No );
-      if ( res != QMessageBox::Yes )
+                                      QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
+      switch ( res )
       {
-        child = child.nextSiblingElement();
-        continue;
+        case QMessageBox::Cancel:   return;
+        case QMessageBox::No:       child = child.nextSiblingElement();
+                                    continue;
+        case QMessageBox::Yes:      overwrite = true;
+                                    break;
+        case QMessageBox::YesToAll: prompt = false;
+                                    overwrite = true;
+                                    break;
+        case QMessageBox::NoToAll:  prompt = false;
+                                    overwrite = false;
+                                    break;
       }
     }
 
+    if ( keys.contains( connectionName ) && !overwrite )
+    {
+      child = child.nextSiblingElement();
+      continue;
+    }
+
     //no dups detected or overwrite is allowed
     settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
 
     settings.setValue( "/host", child.attribute( "host" ) );
     settings.setValue( "/port", child.attribute( "port" ) );
     settings.setValue( "/database", child.attribute( "database" ) );
+    if ( child.hasAttribute( "service" ) )
+    {
+      settings.setValue( "/service", child.attribute( "service" ) );
+    }
+    else
+    {
+      settings.setValue( "/service", "" );
+    }
     settings.setValue( "/sslmode", child.attribute( "sslmode" ) );
     settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) );
     settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
@@ -429,3 +472,13 @@
     child = child.nextSiblingElement();
   }
 }
+
+void QgsManageConnectionsDialog::selectAll()
+{
+  listConnections->selectAll();
+}
+
+void QgsManageConnectionsDialog::clearSelection()
+{
+  listConnections->clearSelection();
+}

Modified: trunk/qgis/src/app/qgsmanageconnectionsdialog.h
===================================================================
--- trunk/qgis/src/app/qgsmanageconnectionsdialog.h	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/qgsmanageconnectionsdialog.h	2011-02-25 17:29:39 UTC (rev 15264)
@@ -30,8 +30,8 @@
   public:
     enum Mode
     {
-      Save,
-      Load
+      Export,
+      Import
     };
 
     enum Type
@@ -41,17 +41,17 @@
     };
 
     // constructor
-    // mode argument must be 0 for saving and 1 for loading
+    // mode argument must be 0 for export and 1 for import
     // type argument must be 0 for WMS and 1 for PostGIS
-    QgsManageConnectionsDialog( QWidget *parent = NULL, Mode mode = Save, Type type = WMS );
+    QgsManageConnectionsDialog( QWidget *parent = NULL, Mode mode = Export, Type type = WMS, QString fileName = "" );
 
   public slots:
-    void selectFile();
-    void doSaveLoad();
+    void doExportImport();
+    void selectAll();
+    void clearSelection();
 
-    void populateConnections();
-
   private:
+    bool populateConnections();
     QDomDocument saveWMSConnections( const QStringList &connections );
     QDomDocument savePgConnections( const QStringList & connections );
     void loadWMSConnections( const QDomDocument &doc, const QStringList &items );

Modified: trunk/qgis/src/app/qgswmssourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.cpp	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/qgswmssourceselect.cpp	2011-02-25 17:29:39 UTC (rev 15264)
@@ -20,7 +20,7 @@
 /* $Id$ */
 
 #include "../providers/wms/qgswmsprovider.h"
-#include "qgis.h" // GEO_EPSG_CRS_ID 
+#include "qgis.h" // GEO_EPSG_CRS_ID
 #include "qgisapp.h" //for getThemeIcon
 #include "qgscontexthelp.h"
 #include "qgscoordinatereferencesystem.h"
@@ -36,6 +36,7 @@
 #include "qgsnetworkaccessmanager.h"
 
 #include <QButtonGroup>
+#include <QFileDialog>
 #include <QRadioButton>
 #include <QDomDocument>
 #include <QHeaderView>
@@ -245,13 +246,20 @@
 
 void QgsWMSSourceSelect::saveClicked()
 {
-  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Save, QgsManageConnectionsDialog::WMS );
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::WMS );
   dlg.exec();
 }
 
 void QgsWMSSourceSelect::loadClicked()
 {
-  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Load, QgsManageConnectionsDialog::WMS );
+  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), ".",
+                                                   tr( "XML files (*.xml *XML)" ) );
+  if ( fileName.isEmpty() )
+  {
+    return;
+  }
+
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WMS, fileName );
   dlg.exec();
   populateConnectionList();
 }

Modified: trunk/qgis/src/app/qgswmssourceselect.h
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.h	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/app/qgswmssourceselect.h	2011-02-25 17:29:39 UTC (rev 15264)
@@ -59,7 +59,7 @@
     void on_btnEdit_clicked();
     //! Deletes the selected connection
     void on_btnDelete_clicked();
-    //! Saves conncetions to the file
+    //! Saves connections to the file
     void saveClicked();
     //! Loads connections from the file
     void loadClicked();

Modified: trunk/qgis/src/ui/qgsmanageconnectionsdialogbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsmanageconnectionsdialogbase.ui	2011-02-25 13:30:24 UTC (rev 15263)
+++ trunk/qgis/src/ui/qgsmanageconnectionsdialogbase.ui	2011-02-25 17:29:39 UTC (rev 15264)
@@ -15,25 +15,11 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Save to file</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="leFileName"/>
-     </item>
-     <item>
-      <widget class="QPushButton" name="btnBrowse">
-       <property name="text">
-        <string>Browse</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Select connections to export</string>
+     </property>
+    </widget>
    </item>
    <item>
     <widget class="QListWidget" name="listConnections">



More information about the QGIS-commit mailing list