[QGIS Commit] r15479 - in trunk/qgis/src: app plugins/wfs

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Mar 14 16:03:51 EDT 2011


Author: jef
Date: 2011-03-14 13:03:51 -0700 (Mon, 14 Mar 2011)
New Revision: 15479

Modified:
   trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp
   trunk/qgis/src/app/qgsmanageconnectionsdialog.h
   trunk/qgis/src/plugins/wfs/CMakeLists.txt
   trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp
   trunk/qgis/src/plugins/wfs/qgswfssourceselect.h
Log:
fix #3616

Modified: trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp	2011-03-14 19:49:53 UTC (rev 15478)
+++ trunk/qgis/src/app/qgsmanageconnectionsdialog.cpp	2011-03-14 20:03:51 UTC (rev 15479)
@@ -98,14 +98,18 @@
     mFileName = fileName;
 
     QDomDocument doc;
-    if ( mConnectionType == WMS )
+    switch ( mConnectionType )
     {
-      doc = saveWMSConnections( items );
+      case WMS:
+        doc = saveWMSConnections( items );
+        break;
+      case WFS:
+        doc = saveWFSConnections( items );
+        break;
+      case PostGIS:
+        doc = savePgConnections( items );
+        break;
     }
-    else
-    {
-      doc = savePgConnections( items );
-    }
 
     QFile file( mFileName );
     if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
@@ -147,14 +151,18 @@
       return;
     }
 
-    if ( mConnectionType == WMS )
+    switch ( mConnectionType )
     {
-      loadWMSConnections( doc, items );
+      case WMS:
+        loadWMSConnections( doc, items );
+        break;
+      case WFS:
+        loadWFSConnections( doc, items );
+        break;
+      case PostGIS:
+        loadPgConnections( doc, items );
+        break;
     }
-    else
-    {
-      loadPgConnections( doc, items );
-    }
     // clear connections list and close window
     listConnections->clear();
     accept();
@@ -169,14 +177,18 @@
   if ( mDialogMode == Export )
   {
     QSettings settings;
-    if ( mConnectionType == WMS )
+    switch ( mConnectionType )
     {
-      settings.beginGroup( "/Qgis/connections-wms" );
+      case WMS:
+        settings.beginGroup( "/Qgis/connections-wms" );
+        break;
+      case WFS:
+        settings.beginGroup( "/Qgis/connections-wfs" );
+        break;
+      case PostGIS:
+        settings.beginGroup( "/PostgreSQL/connections" );
+        break;
     }
-    else
-    {
-      settings.beginGroup( "/PostgreSQL/connections" );
-    }
     QStringList keys = settings.childGroups();
     QStringList::Iterator it = keys.begin();
     while ( it != keys.end() )
@@ -217,24 +229,35 @@
     }
 
     QDomElement root = doc.documentElement();
-    if ( mConnectionType == WMS )
+    switch ( mConnectionType )
     {
-      if ( root.tagName() != "qgsWMSConnections" )
-      {
-        QMessageBox::information( this, tr( "Loading connections" ),
-                                  tr( "The file is not an WMS connections exchange file." ) );
-        return false;
-      }
+      case WMS:
+        if ( root.tagName() != "qgsWMSConnections" )
+        {
+          QMessageBox::information( this, tr( "Loading connections" ),
+                                    tr( "The file is not an WMS connections exchange file." ) );
+          return false;
+        }
+        break;
+
+      case WFS:
+        if ( root.tagName() != "qgsWFSConnections" )
+        {
+          QMessageBox::information( this, tr( "Loading connections" ),
+                                    tr( "The file is not an WFS connections exchange file." ) );
+          return false;
+        }
+        break;
+
+      case PostGIS:
+        if ( root.tagName() != "qgsPgConnections" )
+        {
+          QMessageBox::information( this, tr( "Loading connections" ),
+                                    tr( "The file is not an PostGIS connections exchange file." ) );
+          return false;
+        }
+        break;
     }
-    else
-    {
-      if ( root.tagName() != "qgsPgConnections" )
-      {
-        QMessageBox::information( this, tr( "Loading connections" ),
-                                  tr( "The file is not an PostGIS connections exchange file." ) );
-        return false;
-      }
-    }
 
     QDomElement child = root.firstChildElement();
     while ( !child.isNull() )
@@ -273,6 +296,31 @@
   return doc;
 }
 
+QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &connections )
+{
+  QDomDocument doc( "connections" );
+  QDomElement root = doc.createElement( "qgsWFSConnections" );
+  root.setAttribute( "version", "1.0" );
+  doc.appendChild( root );
+
+  QSettings settings;
+  QString path;
+  for ( int i = 0; i < connections.count(); ++i )
+  {
+    path = "/Qgis/connections-wfs/";
+    QDomElement el = doc.createElement( "wfs" );
+    el.setAttribute( "name", connections[ i ] );
+    el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() );
+
+    path = "/Qgis/WFS/";
+    el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
+    el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
+    root.appendChild( el );
+  }
+
+  return doc;
+}
+
 QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
 {
   QDomDocument doc( "connections" );
@@ -388,6 +436,81 @@
   }
 }
 
+void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, const QStringList &items )
+{
+  QDomElement root = doc.documentElement();
+  if ( root.tagName() != "qgsWFSConnections" )
+  {
+    QMessageBox::information( this, tr( "Loading connections" ),
+                              tr( "The file is not an WFS connections exchange file." ) );
+    return;
+  }
+
+  QString connectionName;
+  QSettings settings;
+  settings.beginGroup( "/Qgis/connections-wfs" );
+  QStringList keys = settings.childGroups();
+  settings.endGroup();
+  QDomElement child = root.firstChildElement();
+  bool prompt = true;
+  bool overwrite = true;
+
+  while ( !child.isNull() )
+  {
+    connectionName = child.attribute( "name" );
+    if ( !items.contains( connectionName ) )
+    {
+      child = child.nextSiblingElement();
+      continue;
+    }
+
+    // check for duplicates
+    if ( keys.contains( connectionName ) && prompt )
+    {
+      int res = QMessageBox::warning( this, tr( "Loading connections" ),
+                                      tr( "Connection with name '%1' already exists. Overwrite?" )
+                                      .arg( connectionName ),
+                                      QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
+
+      switch ( res )
+      {
+        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-wfs" );
+    settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
+    settings.endGroup();
+
+    if ( !child.attribute( "username" ).isEmpty() )
+    {
+      settings.beginGroup( "/Qgis/WFS/" + connectionName );
+      settings.setValue( "/username", child.attribute( "username" ) );
+      settings.setValue( "/password", child.attribute( "password" ) );
+      settings.endGroup();
+    }
+    child = child.nextSiblingElement();
+  }
+}
+
+
 void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
 {
   QDomElement root = doc.documentElement();

Modified: trunk/qgis/src/app/qgsmanageconnectionsdialog.h
===================================================================
--- trunk/qgis/src/app/qgsmanageconnectionsdialog.h	2011-03-14 19:49:53 UTC (rev 15478)
+++ trunk/qgis/src/app/qgsmanageconnectionsdialog.h	2011-03-14 20:03:51 UTC (rev 15479)
@@ -37,7 +37,8 @@
     enum Type
     {
       WMS,
-      PostGIS
+      PostGIS,
+      WFS,
     };
 
     // constructor
@@ -53,8 +54,10 @@
   private:
     bool populateConnections();
     QDomDocument saveWMSConnections( const QStringList &connections );
+    QDomDocument saveWFSConnections( const QStringList &connections );
     QDomDocument savePgConnections( const QStringList & connections );
     void loadWMSConnections( const QDomDocument &doc, const QStringList &items );
+    void loadWFSConnections( const QDomDocument &doc, const QStringList &items );
     void loadPgConnections( const QDomDocument &doc, const QStringList &items );
 
     QString mFileName;

Modified: trunk/qgis/src/plugins/wfs/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/wfs/CMakeLists.txt	2011-03-14 19:49:53 UTC (rev 15478)
+++ trunk/qgis/src/plugins/wfs/CMakeLists.txt	2011-03-14 20:03:51 UTC (rev 15479)
@@ -6,6 +6,7 @@
      qgswfsplugin.cpp
      qgswfssourceselect.cpp
      ../../app/qgsnewhttpconnection.cpp
+     ../../app/qgsmanageconnectionsdialog.cpp
 )
 
 SET (WFS_UIS qgswfssourceselectbase.ui)
@@ -14,6 +15,7 @@
      qgswfsplugin.h
      qgswfssourceselect.h
      ../../app/qgsnewhttpconnection.h
+     ../../app/qgsmanageconnectionsdialog.h
 )
 
 SET (WFS_RCCS  wfsplugin.qrc)

Modified: trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp
===================================================================
--- trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp	2011-03-14 19:49:53 UTC (rev 15478)
+++ trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp	2011-03-14 20:03:51 UTC (rev 15479)
@@ -25,6 +25,7 @@
 #include "qgslogger.h"
 #include "qgsmapcanvas.h" //for current view extent
 #include "qgsnetworkaccessmanager.h"
+#include "qgsmanageconnectionsdialog.h"
 
 #include <QDomDocument>
 #include <QListWidgetItem>
@@ -32,6 +33,7 @@
 #include <QSettings>
 #include <QNetworkRequest>
 #include <QNetworkReply>
+#include <QFileDialog>
 
 static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";
 
@@ -44,6 +46,16 @@
   btnAdd = buttonBox->button( QDialogButtonBox::Ok );
   btnAdd->setEnabled( false );
 
+  QPushButton *pb = new QPushButton( tr( "&Save" ) );
+  pb->setToolTip( tr( "Save WFS server connections to file" ) );
+  buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
+  connect( pb, SIGNAL( clicked() ), this, SLOT( saveClicked() ) );
+
+  pb = new QPushButton( tr( "&Load" ) );
+  pb->setToolTip( tr( "Load WFS server connections from file" ) );
+  buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
+  connect( pb, SIGNAL( clicked() ), this, SLOT( loadClicked() ) );
+
   connect( buttonBox, SIGNAL( accepted() ), this, SLOT( addLayer() ) );
   connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
   connect( btnNew, SIGNAL( clicked() ), this, SLOT( addEntryToServerList() ) );
@@ -456,3 +468,23 @@
   QSettings s;
   s.setValue( "/Qgis/connections-wfs/selected", cmbConnections->currentText() );
 }
+
+void QgsWFSSourceSelect::saveClicked()
+{
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::WFS );
+  dlg.exec();
+}
+
+void QgsWFSSourceSelect::loadClicked()
+{
+  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), ".",
+                     tr( "XML files (*.xml *XML)" ) );
+  if ( fileName.isEmpty() )
+  {
+    return;
+  }
+
+  QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WFS, fileName );
+  dlg.exec();
+  populateConnectionList();
+}

Modified: trunk/qgis/src/plugins/wfs/qgswfssourceselect.h
===================================================================
--- trunk/qgis/src/plugins/wfs/qgswfssourceselect.h	2011-03-14 19:49:53 UTC (rev 15478)
+++ trunk/qgis/src/plugins/wfs/qgswfssourceselect.h	2011-03-14 20:03:51 UTC (rev 15479)
@@ -67,6 +67,9 @@
     void capabilitiesReplyFinished();
     void capabilitiesReplyProgress( qint64, qint64 );
 
+    void saveClicked();
+    void loadClicked();
+
     void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
 };
 



More information about the QGIS-commit mailing list