Skip to content

Commit

Permalink
fix #3616
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15479 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 14, 2011
1 parent b599a8a commit 0f48d37
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 35 deletions.
191 changes: 157 additions & 34 deletions src/app/qgsmanageconnectionsdialog.cpp
Expand Up @@ -98,13 +98,17 @@ void QgsManageConnectionsDialog::doExportImport()
mFileName = fileName;

QDomDocument doc;
if ( mConnectionType == WMS )
switch ( mConnectionType )
{
doc = saveWMSConnections( items );
}
else
{
doc = savePgConnections( items );
case WMS:
doc = saveWMSConnections( items );
break;
case WFS:
doc = saveWFSConnections( items );
break;
case PostGIS:
doc = savePgConnections( items );
break;
}

QFile file( mFileName );
Expand Down Expand Up @@ -147,13 +151,17 @@ void QgsManageConnectionsDialog::doExportImport()
return;
}

if ( mConnectionType == WMS )
switch ( mConnectionType )
{
loadWMSConnections( doc, items );
}
else
{
loadPgConnections( doc, items );
case WMS:
loadWMSConnections( doc, items );
break;
case WFS:
loadWFSConnections( doc, items );
break;
case PostGIS:
loadPgConnections( doc, items );
break;
}
// clear connections list and close window
listConnections->clear();
Expand All @@ -169,13 +177,17 @@ bool QgsManageConnectionsDialog::populateConnections()
if ( mDialogMode == Export )
{
QSettings settings;
if ( mConnectionType == WMS )
{
settings.beginGroup( "/Qgis/connections-wms" );
}
else
switch ( mConnectionType )
{
settings.beginGroup( "/PostgreSQL/connections" );
case WMS:
settings.beginGroup( "/Qgis/connections-wms" );
break;
case WFS:
settings.beginGroup( "/Qgis/connections-wfs" );
break;
case PostGIS:
settings.beginGroup( "/PostgreSQL/connections" );
break;
}
QStringList keys = settings.childGroups();
QStringList::Iterator it = keys.begin();
Expand Down Expand Up @@ -217,23 +229,34 @@ bool QgsManageConnectionsDialog::populateConnections()
}

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;
}
}
else
{
if ( root.tagName() != "qgsPgConnections" )
{
QMessageBox::information( this, tr( "Loading connections" ),
tr( "The file is not an PostGIS 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;
}

QDomElement child = root.firstChildElement();
Expand Down Expand Up @@ -273,6 +296,31 @@ QDomDocument QgsManageConnectionsDialog::saveWMSConnections( const QStringList &
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" );
Expand Down Expand Up @@ -388,6 +436,81 @@ void QgsManageConnectionsDialog::loadWMSConnections( const QDomDocument &doc, co
}
}

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();
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsmanageconnectionsdialog.h
Expand Up @@ -37,7 +37,8 @@ class QgsManageConnectionsDialog : public QDialog, private Ui::QgsManageConnecti
enum Type
{
WMS,
PostGIS
PostGIS,
WFS,
};

// constructor
Expand All @@ -53,8 +54,10 @@ class QgsManageConnectionsDialog : public QDialog, private Ui::QgsManageConnecti
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;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/wfs/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ SET (WFS_SRCS
qgswfsplugin.cpp
qgswfssourceselect.cpp
../../app/qgsnewhttpconnection.cpp
../../app/qgsmanageconnectionsdialog.cpp
)

SET (WFS_UIS qgswfssourceselectbase.ui)
Expand All @@ -14,6 +15,7 @@ SET (WFS_MOC_HDRS
qgswfsplugin.h
qgswfssourceselect.h
../../app/qgsnewhttpconnection.h
../../app/qgsmanageconnectionsdialog.h
)

SET (WFS_RCCS wfsplugin.qrc)
Expand Down
32 changes: 32 additions & 0 deletions src/plugins/wfs/qgswfssourceselect.cpp
Expand Up @@ -25,13 +25,15 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h" //for current view extent
#include "qgsnetworkaccessmanager.h"
#include "qgsmanageconnectionsdialog.h"

#include <QDomDocument>
#include <QListWidgetItem>
#include <QMessageBox>
#include <QSettings>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFileDialog>

static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";

Expand All @@ -44,6 +46,16 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, QgisInterface* iface )
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() ) );
Expand Down Expand Up @@ -456,3 +468,23 @@ void QgsWFSSourceSelect::on_cmbConnections_activated( int index )
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();
}
3 changes: 3 additions & 0 deletions src/plugins/wfs/qgswfssourceselect.h
Expand Up @@ -67,6 +67,9 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
void capabilitiesReplyFinished();
void capabilitiesReplyProgress( qint64, qint64 );

void saveClicked();
void loadClicked();

void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
};

Expand Down

0 comments on commit 0f48d37

Please sign in to comment.