Skip to content

Commit ab9c0e9

Browse files
author
mhugent
committedFeb 1, 2010
Applied patch #2341 (loading and saving of WMS and PostGIS connections) from alexbruy
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12855 c8812cc2-4d05-0410-92ff-de0c093fc19c

10 files changed

+696
-38
lines changed
 

‎src/app/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ SET(QGIS_APP_SRCS
7272
qgsvectorlayerproperties.cpp
7373
qgsquerybuilder.cpp
7474

75+
qgsmanageconnectionsdialog.cpp
76+
7577
composer/qgsattributeselectiondialog.cpp
7678
composer/qgscomposer.cpp
7779
composer/qgscomposerarrowwidget.cpp
@@ -138,6 +140,8 @@ SET (QGIS_APP_MOC_HDRS
138140
qgsidentifyresults.h
139141
qgslabeldialog.h
140142

143+
qgsmanageconnectionsdialog.h
144+
141145
qgsmaptoolidentify.h
142146
qgsmaptoolsplitfeatures.h
143147
qgsmaptoolvertexedit.h

‎src/app/postgres/qgspgsourceselect.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ email : sherman at mrcc.com
2424
#include "qgsapplication.h"
2525
#include "qgscontexthelp.h"
2626
#include "qgspgnewconnection.h"
27+
#include "qgsmanageconnectionsdialog.h"
2728
#include "qgsquerybuilder.h"
2829
#include "qgsdatasourceuri.h"
2930
#include "qgsvectorlayer.h"
@@ -126,6 +127,19 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
126127
populateConnectionList();
127128
}
128129

130+
void QgsPgSourceSelect::on_btnSave_clicked()
131+
{
132+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Save, QgsManageConnectionsDialog::PostGIS );
133+
dlg.exec();
134+
}
135+
136+
void QgsPgSourceSelect::on_btnLoad_clicked()
137+
{
138+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Load, QgsManageConnectionsDialog::PostGIS );
139+
dlg.exec();
140+
populateConnectionList();
141+
}
142+
129143
// Slot for editing a connection
130144
void QgsPgSourceSelect::on_btnEdit_clicked()
131145
{

‎src/app/postgres/qgspgsourceselect.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
131131
void on_btnBuildQuery_clicked();
132132
//! Deletes the selected connection
133133
void on_btnDelete_clicked();
134+
//! Saves the selected connections to the file
135+
void on_btnSave_clicked();
136+
//! Loads the selected connections from the file
137+
void on_btnLoad_clicked();
134138
void on_mSearchOptionsButton_clicked();
135139
void on_mSearchTableEdit_textChanged( const QString & text );
136140
void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );

‎src/app/qgsmanageconnectionsdialog.cpp‎

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/***************************************************************************
2+
qgsmanageconnectionsdialog.h
3+
---------------------
4+
begin : Dec 2009
5+
copyright : (C) 2009 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
/* $Id$ */
18+
19+
#ifndef QGSMANAGECONNECTIONSDIALOG_H
20+
#define QGSMANAGECONNECTIONSDIALOG_H
21+
22+
#include <QDialog>
23+
#include <QDomDocument>
24+
#include "ui_qgsmanageconnectionsdialogbase.h"
25+
26+
class QgsManageConnectionsDialog : public QDialog, private Ui::QgsManageConnectionsDialogBase
27+
{
28+
Q_OBJECT
29+
30+
public:
31+
enum Mode
32+
{
33+
Save,
34+
Load
35+
};
36+
37+
enum Type
38+
{
39+
WMS,
40+
PostGIS
41+
};
42+
43+
// constructor
44+
// mode argument must be 0 for saving and 1 for loading
45+
// type argument must be 0 for WMS and 1 for PostGIS
46+
QgsManageConnectionsDialog( QWidget *parent = NULL, Mode mode = Save, Type type = WMS );
47+
48+
public slots:
49+
void on_btnBrowse_clicked();
50+
void on_buttonBox_accepted();
51+
52+
void populateConnections();
53+
54+
private:
55+
QDomDocument saveWMSConnections( const QStringList &connections );
56+
QDomDocument savePgConnections( const QStringList & connections );
57+
void loadWMSConnections( const QDomDocument &doc, const QStringList &items );
58+
void loadPgConnections( const QDomDocument &doc, const QStringList &items );
59+
60+
QString mFileName;
61+
Mode mDialogMode;
62+
Type mConnectionType;
63+
};
64+
65+
#endif // QGSMANAGECONNECTIONSDIALOG_H
66+

‎src/app/qgswmssourceselect.cpp‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgsgenericprojectionselector.h"
2828
#include "qgshttptransaction.h"
2929
#include "qgslogger.h"
30+
#include "qgsmanageconnectionsdialog.h"
3031
#include "qgsmessageviewer.h"
3132
#include "qgsnewhttpconnection.h"
3233
#include "qgsnumericsortlistviewitem.h"
@@ -35,7 +36,6 @@
3536
#include "qgswmssourceselect.h"
3637
#include <qgisinterface.h>
3738

38-
3939
#include <QButtonGroup>
4040
#include <QDomDocument>
4141
#include <QHeaderView>
@@ -203,11 +203,25 @@ void QgsWMSSourceSelect::on_btnDelete_clicked()
203203
if ( result == QMessageBox::Ok )
204204
{
205205
settings.remove( key );
206+
settings.remove( "/Qgis/WMS/" + cmbConnections->currentText() );
206207
cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
207208
setConnectionListPosition();
208209
}
209210
}
210211

212+
void QgsWMSSourceSelect::on_btnSave_clicked()
213+
{
214+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Save, QgsManageConnectionsDialog::WMS );
215+
dlg.exec();
216+
}
217+
218+
void QgsWMSSourceSelect::on_btnLoad_clicked()
219+
{
220+
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Load, QgsManageConnectionsDialog::WMS );
221+
dlg.exec();
222+
populateConnectionList();
223+
}
224+
211225
QgsNumericSortTreeWidgetItem *QgsWMSSourceSelect::createItem(
212226
int id, const QStringList &names, QMap<int, QgsNumericSortTreeWidgetItem *> &items, int &layerAndStyleCount,
213227
const QMap<int, int> &layerParents, const QMap<int, QStringList> &layerParentNames )
@@ -821,7 +835,7 @@ bool QgsWMSSourceSelect::retrieveSearchResults( const QString& searchTerm, QByte
821835
}
822836
// Get username/password from settings for protected WMS
823837

824-
QString mySearchUrl = settings.value("/qgis/WMSSearchUrl", "http://geopole.org/wms/search?search=%1&type=rss").toString();
838+
QString mySearchUrl = settings.value( "/qgis/WMSSearchUrl", "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
825839
QUrl url( mySearchUrl.arg( searchTerm ) );
826840
QgsDebugMsg( url.toString() );
827841
QgsHttpTransaction http( url.toEncoded(),

‎src/app/qgswmssourceselect.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
9898
void on_btnEdit_clicked();
9999
//! Deletes the selected connection
100100
void on_btnDelete_clicked();
101+
//! Saves conncetions to the file
102+
void on_btnSave_clicked();
103+
//! Loads connections from the file
104+
void on_btnLoad_clicked();
101105

102106
/*! Connects to the database using the stored connection parameters.
103107
* Once connected, available layers are displayed.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsManageConnectionsDialogBase</class>
4+
<widget class="QDialog" name="QgsManageConnectionsDialogBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Manage connections</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<layout class="QHBoxLayout" name="horizontalLayout">
19+
<item>
20+
<widget class="QLabel" name="label">
21+
<property name="text">
22+
<string>Save to file</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<widget class="QLineEdit" name="leFileName"/>
28+
</item>
29+
<item>
30+
<widget class="QPushButton" name="btnBrowse">
31+
<property name="text">
32+
<string>Browse</string>
33+
</property>
34+
</widget>
35+
</item>
36+
</layout>
37+
</item>
38+
<item>
39+
<widget class="QListWidget" name="listConnections">
40+
<property name="editTriggers">
41+
<set>QAbstractItemView::NoEditTriggers</set>
42+
</property>
43+
<property name="alternatingRowColors">
44+
<bool>true</bool>
45+
</property>
46+
<property name="selectionMode">
47+
<enum>QAbstractItemView::ExtendedSelection</enum>
48+
</property>
49+
</widget>
50+
</item>
51+
<item>
52+
<widget class="QDialogButtonBox" name="buttonBox">
53+
<property name="orientation">
54+
<enum>Qt::Horizontal</enum>
55+
</property>
56+
<property name="standardButtons">
57+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
58+
</property>
59+
</widget>
60+
</item>
61+
</layout>
62+
</widget>
63+
<resources/>
64+
<connections>
65+
<connection>
66+
<sender>buttonBox</sender>
67+
<signal>accepted()</signal>
68+
<receiver>QgsManageConnectionsDialogBase</receiver>
69+
<slot>accept()</slot>
70+
<hints>
71+
<hint type="sourcelabel">
72+
<x>248</x>
73+
<y>254</y>
74+
</hint>
75+
<hint type="destinationlabel">
76+
<x>157</x>
77+
<y>274</y>
78+
</hint>
79+
</hints>
80+
</connection>
81+
<connection>
82+
<sender>buttonBox</sender>
83+
<signal>rejected()</signal>
84+
<receiver>QgsManageConnectionsDialogBase</receiver>
85+
<slot>reject()</slot>
86+
<hints>
87+
<hint type="sourcelabel">
88+
<x>316</x>
89+
<y>260</y>
90+
</hint>
91+
<hint type="destinationlabel">
92+
<x>286</x>
93+
<y>274</y>
94+
</hint>
95+
</hints>
96+
</connection>
97+
</connections>
98+
</ui>

‎src/ui/qgspgsourceselectbase.ui‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>406</width>
10-
<height>470</height>
10+
<height>500</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -37,28 +37,28 @@
3737
<property name="spacing">
3838
<number>6</number>
3939
</property>
40-
<item row="1" column="3">
40+
<item row="2" column="3">
4141
<widget class="QPushButton" name="btnDelete">
4242
<property name="text">
4343
<string>Delete</string>
4444
</property>
4545
</widget>
4646
</item>
47-
<item row="1" column="2">
47+
<item row="2" column="2">
4848
<widget class="QPushButton" name="btnEdit">
4949
<property name="text">
5050
<string>Edit</string>
5151
</property>
5252
</widget>
5353
</item>
54-
<item row="1" column="1">
54+
<item row="2" column="1">
5555
<widget class="QPushButton" name="btnNew">
5656
<property name="text">
5757
<string>New</string>
5858
</property>
5959
</widget>
6060
</item>
61-
<item row="1" column="0">
61+
<item row="2" column="0">
6262
<widget class="QPushButton" name="btnConnect">
6363
<property name="text">
6464
<string>Connect</string>
@@ -71,6 +71,24 @@
7171
</layout>
7272
</widget>
7373
</item>
74+
<item>
75+
<layout class="QHBoxLayout" name="horizontalLayout">
76+
<item>
77+
<widget class="QPushButton" name="btnSave">
78+
<property name="text">
79+
<string>Save connections</string>
80+
</property>
81+
</widget>
82+
</item>
83+
<item>
84+
<widget class="QPushButton" name="btnLoad">
85+
<property name="text">
86+
<string>Load connections</string>
87+
</property>
88+
</widget>
89+
</item>
90+
</layout>
91+
</item>
7492
<item>
7593
<widget class="QTreeView" name="mTablesTreeView">
7694
<property name="selectionMode">

‎src/ui/qgswmssourceselectbase.ui‎

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>555</width>
10-
<height>508</height>
9+
<width>439</width>
10+
<height>539</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Add Layer(s) from a Server</string>
1515
</property>
1616
<property name="windowIcon">
1717
<iconset>
18-
<normaloff/>
19-
</iconset>
18+
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
2019
</property>
2120
<property name="sizeGripEnabled">
2221
<bool>true</bool>
2322
</property>
2423
<property name="modal">
2524
<bool>true</bool>
2625
</property>
27-
<layout class="QGridLayout">
28-
<item row="0" column="0" colspan="2">
26+
<layout class="QGridLayout" name="gridLayout_2">
27+
<item row="0" column="0">
2928
<widget class="QTabWidget" name="tabWidget">
3029
<property name="currentIndex">
3130
<number>0</number>
@@ -34,11 +33,11 @@
3433
<attribute name="title">
3534
<string>Servers</string>
3635
</attribute>
37-
<layout class="QGridLayout">
38-
<item row="0" column="0" colspan="6">
36+
<layout class="QGridLayout" name="gridLayout">
37+
<item row="0" column="0" colspan="8">
3938
<widget class="QComboBox" name="cmbConnections"/>
4039
</item>
41-
<item row="1" column="0">
40+
<item row="1" column="0" colspan="2">
4241
<widget class="QPushButton" name="btnConnect">
4342
<property name="enabled">
4443
<bool>false</bool>
@@ -48,14 +47,14 @@
4847
</property>
4948
</widget>
5049
</item>
51-
<item row="1" column="1">
50+
<item row="1" column="2" colspan="2">
5251
<widget class="QPushButton" name="btnNew">
5352
<property name="text">
5453
<string>&amp;New</string>
5554
</property>
5655
</widget>
5756
</item>
58-
<item row="1" column="2">
57+
<item row="1" column="4">
5958
<widget class="QPushButton" name="btnEdit">
6059
<property name="enabled">
6160
<bool>false</bool>
@@ -65,7 +64,7 @@
6564
</property>
6665
</widget>
6766
</item>
68-
<item row="1" column="3">
67+
<item row="1" column="5">
6968
<widget class="QPushButton" name="btnDelete">
7069
<property name="enabled">
7170
<bool>false</bool>
@@ -75,23 +74,20 @@
7574
</property>
7675
</widget>
7776
</item>
78-
<item row="1" column="4">
79-
<spacer>
77+
<item row="1" column="6">
78+
<spacer name="horizontalSpacer_2">
8079
<property name="orientation">
8180
<enum>Qt::Horizontal</enum>
8281
</property>
83-
<property name="sizeType">
84-
<enum>QSizePolicy::Expanding</enum>
85-
</property>
8682
<property name="sizeHint" stdset="0">
8783
<size>
88-
<width>16</width>
89-
<height>31</height>
84+
<width>8</width>
85+
<height>20</height>
9086
</size>
9187
</property>
9288
</spacer>
9389
</item>
94-
<item row="1" column="5">
90+
<item row="1" column="7">
9591
<widget class="QPushButton" name="btnAddDefault">
9692
<property name="statusTip">
9793
<string>Adds a few example WMS servers</string>
@@ -104,7 +100,7 @@
104100
</property>
105101
</widget>
106102
</item>
107-
<item row="2" column="0" colspan="6">
103+
<item row="2" column="0" colspan="8">
108104
<widget class="QTreeWidget" name="lstLayers">
109105
<property name="sizePolicy">
110106
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -140,6 +136,33 @@
140136
</column>
141137
</widget>
142138
</item>
139+
<item row="3" column="0">
140+
<widget class="QPushButton" name="btnSave">
141+
<property name="text">
142+
<string>Save</string>
143+
</property>
144+
</widget>
145+
</item>
146+
<item row="3" column="1" colspan="2">
147+
<widget class="QPushButton" name="btnLoad">
148+
<property name="text">
149+
<string>Load</string>
150+
</property>
151+
</widget>
152+
</item>
153+
<item row="3" column="3" colspan="5">
154+
<spacer name="horizontalSpacer">
155+
<property name="orientation">
156+
<enum>Qt::Horizontal</enum>
157+
</property>
158+
<property name="sizeHint" stdset="0">
159+
<size>
160+
<width>292</width>
161+
<height>20</height>
162+
</size>
163+
</property>
164+
</spacer>
165+
</item>
143166
</layout>
144167
</widget>
145168
<widget class="QWidget" name="tabLayerOrder">
@@ -250,7 +273,7 @@
250273
</widget>
251274
</widget>
252275
</item>
253-
<item row="1" column="0" colspan="2">
276+
<item row="1" column="0">
254277
<widget class="QGroupBox" name="btnGrpImageEncoding">
255278
<property name="sizePolicy">
256279
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -269,7 +292,7 @@
269292
</property>
270293
</widget>
271294
</item>
272-
<item row="2" column="0" colspan="2">
295+
<item row="2" column="0">
273296
<widget class="QGroupBox" name="gbCRS">
274297
<property name="title">
275298
<string>Options</string>
@@ -311,7 +334,14 @@
311334
</layout>
312335
</widget>
313336
</item>
314-
<item row="4" column="0" colspan="2">
337+
<item row="3" column="0">
338+
<widget class="QDialogButtonBox" name="buttonBox">
339+
<property name="standardButtons">
340+
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
341+
</property>
342+
</widget>
343+
</item>
344+
<item row="4" column="0">
315345
<widget class="QLabel" name="labelStatus">
316346
<property name="sizePolicy">
317347
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
@@ -327,13 +357,6 @@
327357
</property>
328358
</widget>
329359
</item>
330-
<item row="3" column="0" colspan="2">
331-
<widget class="QDialogButtonBox" name="buttonBox">
332-
<property name="standardButtons">
333-
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
334-
</property>
335-
</widget>
336-
</item>
337360
</layout>
338361
</widget>
339362
<layoutdefault spacing="6" margin="11"/>

0 commit comments

Comments
 (0)
Please sign in to comment.