Skip to content

Commit b0a5f21

Browse files
author
jef
committed
fix #3616
git-svn-id: http://svn.osgeo.org/qgis/trunk@15479 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ed77994 commit b0a5f21

5 files changed

+198
-35
lines changed

src/app/qgsmanageconnectionsdialog.cpp

+157-34
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ void QgsManageConnectionsDialog::doExportImport()
9898
mFileName = fileName;
9999

100100
QDomDocument doc;
101-
if ( mConnectionType == WMS )
101+
switch ( mConnectionType )
102102
{
103-
doc = saveWMSConnections( items );
104-
}
105-
else
106-
{
107-
doc = savePgConnections( items );
103+
case WMS:
104+
doc = saveWMSConnections( items );
105+
break;
106+
case WFS:
107+
doc = saveWFSConnections( items );
108+
break;
109+
case PostGIS:
110+
doc = savePgConnections( items );
111+
break;
108112
}
109113

110114
QFile file( mFileName );
@@ -147,13 +151,17 @@ void QgsManageConnectionsDialog::doExportImport()
147151
return;
148152
}
149153

150-
if ( mConnectionType == WMS )
154+
switch ( mConnectionType )
151155
{
152-
loadWMSConnections( doc, items );
153-
}
154-
else
155-
{
156-
loadPgConnections( doc, items );
156+
case WMS:
157+
loadWMSConnections( doc, items );
158+
break;
159+
case WFS:
160+
loadWFSConnections( doc, items );
161+
break;
162+
case PostGIS:
163+
loadPgConnections( doc, items );
164+
break;
157165
}
158166
// clear connections list and close window
159167
listConnections->clear();
@@ -169,13 +177,17 @@ bool QgsManageConnectionsDialog::populateConnections()
169177
if ( mDialogMode == Export )
170178
{
171179
QSettings settings;
172-
if ( mConnectionType == WMS )
173-
{
174-
settings.beginGroup( "/Qgis/connections-wms" );
175-
}
176-
else
180+
switch ( mConnectionType )
177181
{
178-
settings.beginGroup( "/PostgreSQL/connections" );
182+
case WMS:
183+
settings.beginGroup( "/Qgis/connections-wms" );
184+
break;
185+
case WFS:
186+
settings.beginGroup( "/Qgis/connections-wfs" );
187+
break;
188+
case PostGIS:
189+
settings.beginGroup( "/PostgreSQL/connections" );
190+
break;
179191
}
180192
QStringList keys = settings.childGroups();
181193
QStringList::Iterator it = keys.begin();
@@ -217,23 +229,34 @@ bool QgsManageConnectionsDialog::populateConnections()
217229
}
218230

219231
QDomElement root = doc.documentElement();
220-
if ( mConnectionType == WMS )
232+
switch ( mConnectionType )
221233
{
222-
if ( root.tagName() != "qgsWMSConnections" )
223-
{
224-
QMessageBox::information( this, tr( "Loading connections" ),
225-
tr( "The file is not an WMS connections exchange file." ) );
226-
return false;
227-
}
228-
}
229-
else
230-
{
231-
if ( root.tagName() != "qgsPgConnections" )
232-
{
233-
QMessageBox::information( this, tr( "Loading connections" ),
234-
tr( "The file is not an PostGIS connections exchange file." ) );
235-
return false;
236-
}
234+
case WMS:
235+
if ( root.tagName() != "qgsWMSConnections" )
236+
{
237+
QMessageBox::information( this, tr( "Loading connections" ),
238+
tr( "The file is not an WMS connections exchange file." ) );
239+
return false;
240+
}
241+
break;
242+
243+
case WFS:
244+
if ( root.tagName() != "qgsWFSConnections" )
245+
{
246+
QMessageBox::information( this, tr( "Loading connections" ),
247+
tr( "The file is not an WFS connections exchange file." ) );
248+
return false;
249+
}
250+
break;
251+
252+
case PostGIS:
253+
if ( root.tagName() != "qgsPgConnections" )
254+
{
255+
QMessageBox::information( this, tr( "Loading connections" ),
256+
tr( "The file is not an PostGIS connections exchange file." ) );
257+
return false;
258+
}
259+
break;
237260
}
238261

239262
QDomElement child = root.firstChildElement();
@@ -273,6 +296,31 @@ QDomDocument QgsManageConnectionsDialog::saveWMSConnections( const QStringList &
273296
return doc;
274297
}
275298

299+
QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &connections )
300+
{
301+
QDomDocument doc( "connections" );
302+
QDomElement root = doc.createElement( "qgsWFSConnections" );
303+
root.setAttribute( "version", "1.0" );
304+
doc.appendChild( root );
305+
306+
QSettings settings;
307+
QString path;
308+
for ( int i = 0; i < connections.count(); ++i )
309+
{
310+
path = "/Qgis/connections-wfs/";
311+
QDomElement el = doc.createElement( "wfs" );
312+
el.setAttribute( "name", connections[ i ] );
313+
el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() );
314+
315+
path = "/Qgis/WFS/";
316+
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
317+
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
318+
root.appendChild( el );
319+
}
320+
321+
return doc;
322+
}
323+
276324
QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
277325
{
278326
QDomDocument doc( "connections" );
@@ -388,6 +436,81 @@ void QgsManageConnectionsDialog::loadWMSConnections( const QDomDocument &doc, co
388436
}
389437
}
390438

439+
void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, const QStringList &items )
440+
{
441+
QDomElement root = doc.documentElement();
442+
if ( root.tagName() != "qgsWFSConnections" )
443+
{
444+
QMessageBox::information( this, tr( "Loading connections" ),
445+
tr( "The file is not an WFS connections exchange file." ) );
446+
return;
447+
}
448+
449+
QString connectionName;
450+
QSettings settings;
451+
settings.beginGroup( "/Qgis/connections-wfs" );
452+
QStringList keys = settings.childGroups();
453+
settings.endGroup();
454+
QDomElement child = root.firstChildElement();
455+
bool prompt = true;
456+
bool overwrite = true;
457+
458+
while ( !child.isNull() )
459+
{
460+
connectionName = child.attribute( "name" );
461+
if ( !items.contains( connectionName ) )
462+
{
463+
child = child.nextSiblingElement();
464+
continue;
465+
}
466+
467+
// check for duplicates
468+
if ( keys.contains( connectionName ) && prompt )
469+
{
470+
int res = QMessageBox::warning( this, tr( "Loading connections" ),
471+
tr( "Connection with name '%1' already exists. Overwrite?" )
472+
.arg( connectionName ),
473+
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
474+
475+
switch ( res )
476+
{
477+
case QMessageBox::Cancel: return;
478+
case QMessageBox::No: child = child.nextSiblingElement();
479+
continue;
480+
case QMessageBox::Yes: overwrite = true;
481+
break;
482+
case QMessageBox::YesToAll: prompt = false;
483+
overwrite = true;
484+
break;
485+
case QMessageBox::NoToAll: prompt = false;
486+
overwrite = false;
487+
break;
488+
}
489+
}
490+
491+
if ( keys.contains( connectionName ) && !overwrite )
492+
{
493+
child = child.nextSiblingElement();
494+
continue;
495+
}
496+
497+
// no dups detected or overwrite is allowed
498+
settings.beginGroup( "/Qgis/connections-wfs" );
499+
settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
500+
settings.endGroup();
501+
502+
if ( !child.attribute( "username" ).isEmpty() )
503+
{
504+
settings.beginGroup( "/Qgis/WFS/" + connectionName );
505+
settings.setValue( "/username", child.attribute( "username" ) );
506+
settings.setValue( "/password", child.attribute( "password" ) );
507+
settings.endGroup();
508+
}
509+
child = child.nextSiblingElement();
510+
}
511+
}
512+
513+
391514
void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
392515
{
393516
QDomElement root = doc.documentElement();

src/app/qgsmanageconnectionsdialog.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class QgsManageConnectionsDialog : public QDialog, private Ui::QgsManageConnecti
3737
enum Type
3838
{
3939
WMS,
40-
PostGIS
40+
PostGIS,
41+
WFS,
4142
};
4243

4344
// constructor
@@ -53,8 +54,10 @@ class QgsManageConnectionsDialog : public QDialog, private Ui::QgsManageConnecti
5354
private:
5455
bool populateConnections();
5556
QDomDocument saveWMSConnections( const QStringList &connections );
57+
QDomDocument saveWFSConnections( const QStringList &connections );
5658
QDomDocument savePgConnections( const QStringList & connections );
5759
void loadWMSConnections( const QDomDocument &doc, const QStringList &items );
60+
void loadWFSConnections( const QDomDocument &doc, const QStringList &items );
5861
void loadPgConnections( const QDomDocument &doc, const QStringList &items );
5962

6063
QString mFileName;

src/plugins/wfs/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SET (WFS_SRCS
66
qgswfsplugin.cpp
77
qgswfssourceselect.cpp
88
../../app/qgsnewhttpconnection.cpp
9+
../../app/qgsmanageconnectionsdialog.cpp
910
)
1011

1112
SET (WFS_UIS qgswfssourceselectbase.ui)
@@ -14,6 +15,7 @@ SET (WFS_MOC_HDRS
1415
qgswfsplugin.h
1516
qgswfssourceselect.h
1617
../../app/qgsnewhttpconnection.h
18+
../../app/qgsmanageconnectionsdialog.h
1719
)
1820

1921
SET (WFS_RCCS wfsplugin.qrc)

src/plugins/wfs/qgswfssourceselect.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
#include "qgslogger.h"
2626
#include "qgsmapcanvas.h" //for current view extent
2727
#include "qgsnetworkaccessmanager.h"
28+
#include "qgsmanageconnectionsdialog.h"
2829

2930
#include <QDomDocument>
3031
#include <QListWidgetItem>
3132
#include <QMessageBox>
3233
#include <QSettings>
3334
#include <QNetworkRequest>
3435
#include <QNetworkReply>
36+
#include <QFileDialog>
3537

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

@@ -44,6 +46,16 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, QgisInterface* iface )
4446
btnAdd = buttonBox->button( QDialogButtonBox::Ok );
4547
btnAdd->setEnabled( false );
4648

49+
QPushButton *pb = new QPushButton( tr( "&Save" ) );
50+
pb->setToolTip( tr( "Save WFS server connections to file" ) );
51+
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
52+
connect( pb, SIGNAL( clicked() ), this, SLOT( saveClicked() ) );
53+
54+
pb = new QPushButton( tr( "&Load" ) );
55+
pb->setToolTip( tr( "Load WFS server connections from file" ) );
56+
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
57+
connect( pb, SIGNAL( clicked() ), this, SLOT( loadClicked() ) );
58+
4759
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( addLayer() ) );
4860
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
4961
connect( btnNew, SIGNAL( clicked() ), this, SLOT( addEntryToServerList() ) );
@@ -456,3 +468,23 @@ void QgsWFSSourceSelect::on_cmbConnections_activated( int index )
456468
QSettings s;
457469
s.setValue( "/Qgis/connections-wfs/selected", cmbConnections->currentText() );
458470
}
471+
472+
void QgsWFSSourceSelect::saveClicked()
473+
{
474+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::WFS );
475+
dlg.exec();
476+
}
477+
478+
void QgsWFSSourceSelect::loadClicked()
479+
{
480+
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), ".",
481+
tr( "XML files (*.xml *XML)" ) );
482+
if ( fileName.isEmpty() )
483+
{
484+
return;
485+
}
486+
487+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WFS, fileName );
488+
dlg.exec();
489+
populateConnectionList();
490+
}

src/plugins/wfs/qgswfssourceselect.h

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
6767
void capabilitiesReplyFinished();
6868
void capabilitiesReplyProgress( qint64, qint64 );
6969

70+
void saveClicked();
71+
void loadClicked();
72+
7073
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
7174
};
7275

0 commit comments

Comments
 (0)