Skip to content

Commit 57ac8f8

Browse files
author
jef
committed
fix #2276
git-svn-id: http://svn.osgeo.org/qgis/trunk@12442 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8b0c041 commit 57ac8f8

6 files changed

+120
-143
lines changed

src/app/qgspgsourceselect.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
4646

4747
mAddButton = new QPushButton( tr( "&Add" ) );
4848
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
49-
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addClicked() ) );
49+
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addTables() ) );
5050

5151
mAddButton->setEnabled( false );
5252
populateConnectionList();
@@ -110,27 +110,20 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
110110
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
111111
.arg( cmbConnections->currentText() );
112112
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
113-
if ( result == QMessageBox::Ok )
114-
{
115-
settings.remove( key + "/host" );
116-
settings.remove( key + "/database" );
117-
settings.remove( key + "/username" );
118-
settings.remove( key + "/password" );
119-
settings.remove( key + "/port" );
120-
settings.remove( key + "/sslmode" );
121-
settings.remove( key + "/save" );
122-
settings.remove( key );
123-
//if(!success){
124-
// QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText());
125-
//}
126-
cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
127-
setConnectionListPosition();
128-
}
129-
}
130-
// Slot for performing action when the Add button is clicked
131-
void QgsPgSourceSelect::addClicked()
132-
{
133-
addTables();
113+
if ( result != QMessageBox::Ok )
114+
return;
115+
116+
settings.remove( key + "/host" );
117+
settings.remove( key + "/database" );
118+
settings.remove( key + "/username" );
119+
settings.remove( key + "/password" );
120+
settings.remove( key + "/port" );
121+
settings.remove( key + "/sslmode" );
122+
settings.remove( key + "/publicOnly" );
123+
settings.remove( key + "/geometryColumnsOnly" );
124+
settings.remove( key + "/save" );
125+
126+
populateConnectionList();
134127
}
135128

136129
// Slot for editing a connection
@@ -280,7 +273,13 @@ void QgsPgSourceSelect::populateConnectionList()
280273
++it;
281274
}
282275
settings.endGroup();
276+
283277
setConnectionListPosition();
278+
279+
btnEdit->setDisabled( cmbConnections->count() == 0 );
280+
btnDelete->setDisabled( cmbConnections->count() == 0 );
281+
btnConnect->setDisabled( cmbConnections->count() == 0 );
282+
cmbConnections->setDisabled( cmbConnections->count() == 0 );
284283
}
285284

286285
QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
@@ -337,6 +336,7 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
337336
return uri;
338337
}
339338

339+
// Slot for performing action when the Add button is clicked
340340
void QgsPgSourceSelect::addTables()
341341
{
342342
m_selectedTables.clear();

src/app/qgspgsourceselect.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
111111
~QgsPgSourceSelect();
112112
//! Populate the connection list combo box
113113
void populateConnectionList();
114-
//! Determines the tables the user selected and closes the dialog
115-
void addTables();
116114
//! String list containing the selected tables
117115
QStringList selectedTables();
118116
//! Connection info (database, host, user, password)
119117
QString connectionInfo();
120118

121119
public slots:
122-
void addClicked();
120+
//! Determines the tables the user selected and closes the dialog
121+
void addTables();
123122

124123
/*! Connects to the database using the stored connection parameters.
125124
* Once connected, available layers are displayed.

src/app/qgsspatialitesourceselect.cpp

+15-25
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,6 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags
7171
mSearchColumnComboBox->setCurrentIndex( 1 );
7272
}
7373

74-
/** Autoconnected SLOTS **/
75-
// Slot for adding a new connection
76-
void QgsSpatiaLiteSourceSelect::on_btnNew_clicked()
77-
{
78-
addNewConnection();
79-
}
80-
81-
// Slot for deleting an existing connection
82-
void QgsSpatiaLiteSourceSelect::on_btnDelete_clicked()
83-
{
84-
deleteConnection();
85-
}
86-
8774
// Slot for performing action when the Add button is clicked
8875
void QgsSpatiaLiteSourceSelect::addClicked()
8976
{
@@ -297,9 +284,14 @@ void QgsSpatiaLiteSourceSelect::populateConnectionList()
297284
}
298285
settings.endGroup();
299286
setConnectionListPosition();
287+
288+
btnConnect->setDisabled( cmbConnections->count() == 0 );
289+
btnDelete->setDisabled( cmbConnections->count() == 0 );
290+
291+
cmbConnections->setDisabled( cmbConnections->count() == 0 );
300292
}
301293

302-
void QgsSpatiaLiteSourceSelect::addNewConnection()
294+
void QgsSpatiaLiteSourceSelect::on_btnNew_clicked()
303295
{
304296
// Retrieve last used project dir from persistent settings
305297
sqlite3 *handle;
@@ -335,7 +327,8 @@ void QgsSpatiaLiteSourceSelect::addNewConnection()
335327
populateConnectionList();
336328
}
337329

338-
void QgsSpatiaLiteSourceSelect::deleteConnection()
330+
// Slot for deleting an existing connection
331+
void QgsSpatiaLiteSourceSelect::on_btnDelete_clicked()
339332
{
340333
QSettings settings;
341334
QString subKey = cmbConnections->currentText();
@@ -347,16 +340,13 @@ void QgsSpatiaLiteSourceSelect::deleteConnection()
347340
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" ).arg( subKey );
348341
QMessageBox::StandardButton result =
349342
QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
350-
if ( result == QMessageBox::Ok )
351-
{
352-
settings.remove( key + "/sqlitepath" );
353-
settings.remove( key );
354-
//if(!success){
355-
// QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText());
356-
//}
357-
cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
358-
setConnectionListPosition();
359-
}
343+
if ( result != QMessageBox::Ok )
344+
return;
345+
346+
settings.remove( key + "/sqlitepath" );
347+
settings.remove( key );
348+
349+
populateConnectionList();
360350
}
361351

362352
void QgsSpatiaLiteSourceSelect::addTables()

src/app/qgsspatialitesourceselect.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource
6060
//! Constructor
6161
QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags fl = QgisGui::ModalDialogFlags );
6262
//! Destructor
63-
~QgsSpatiaLiteSourceSelect()
64-
{
65-
;
66-
}
67-
//! Opens the create connection dialog to build a new connection
68-
void addNewConnection();
69-
//! Deletes the selected connection
70-
void deleteConnection();
63+
~QgsSpatiaLiteSourceSelect() {}
7164
//! Populate the connection list combo box
7265
void populateConnectionList();
7366
//! Determines the tables the user selected and closes the dialog
@@ -85,7 +78,9 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource
8578
*/
8679
void on_btnConnect_clicked();
8780
void addClicked();
81+
//! Opens the create connection dialog to build a new connection
8882
void on_btnNew_clicked();
83+
//! Deletes the selected connection
8984
void on_btnDelete_clicked();
9085
void on_mSearchOptionsButton_clicked();
9186
void on_mSearchTableEdit_textChanged( const QString & text );

src/plugins/spit/qgsspit.cpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ void QgsSpit::populateConnectionList()
115115
++it;
116116
}
117117
settings.endGroup();
118+
119+
btnConnect->setDisabled( cmbConnections->count() == 0 );
120+
btnEdit->setDisabled( cmbConnections->count() == 0 );
121+
btnRemove->setDisabled( cmbConnections->count() == 0 );
122+
123+
cmbConnections->setDisabled( cmbConnections->count() == 0 );
118124
}
119125

120126
void QgsSpit::newConnection()
@@ -141,19 +147,21 @@ void QgsSpit::removeConnection()
141147
QString key = "/PostgreSQL/connections/" + cmbConnections->currentText();
142148
QString msg = tr( "Are you sure you want to remove the [%1] connection and all associated settings?" ).arg( cmbConnections->currentText() );
143149
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
144-
if ( result == QMessageBox::Ok )
145-
{
146-
settings.remove( key + "/host" );
147-
settings.remove( key + "/database" );
148-
settings.remove( key + "/port" );
149-
settings.remove( key + "/username" );
150-
settings.remove( key + "/password" );
151-
settings.remove( key + "/sslmode" );
152-
settings.remove( key + "/save" );
153-
settings.remove( key );
154-
155-
cmbConnections->removeItem( cmbConnections->currentIndex() );
156-
}
150+
if ( result != QMessageBox::Ok )
151+
return;
152+
153+
settings.remove( key + "/host" );
154+
settings.remove( key + "/database" );
155+
settings.remove( key + "/port" );
156+
settings.remove( key + "/username" );
157+
settings.remove( key + "/password" );
158+
settings.remove( key + "/sslmode" );
159+
settings.remove( key + "/publicOnly" );
160+
settings.remove( key + "/geometryColumnsOnly" );
161+
settings.remove( key + "/save" );
162+
settings.remove( key );
163+
164+
populateConnectionList();
157165
}
158166

159167
void QgsSpit::addFile()

src/plugins/spit/qgsspitbase.ui

+57-72
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,8 @@
4444
<property name="title">
4545
<string>PostgreSQL connections</string>
4646
</property>
47-
<layout class="QGridLayout">
48-
<property name="margin">
49-
<number>11</number>
50-
</property>
51-
<property name="spacing">
52-
<number>6</number>
53-
</property>
54-
<item row="1" column="0">
55-
<spacer>
56-
<property name="orientation">
57-
<enum>Qt::Horizontal</enum>
58-
</property>
59-
<property name="sizeHint" stdset="0">
60-
<size>
61-
<width>40</width>
62-
<height>20</height>
63-
</size>
64-
</property>
65-
</spacer>
66-
</item>
67-
<item row="0" column="0" colspan="4">
47+
<layout class="QVBoxLayout" name="verticalLayout_2">
48+
<item>
6849
<widget class="QComboBox" name="cmbConnections">
6950
<property name="minimumSize">
7051
<size>
@@ -74,57 +55,61 @@
7455
</property>
7556
</widget>
7657
</item>
77-
<item row="1" column="2">
78-
<widget class="QPushButton" name="btnEdit">
79-
<property name="toolTip">
80-
<string>Edit the current PostGIS connection</string>
81-
</property>
82-
<property name="whatsThis">
83-
<string>Edit the current PostGIS connection</string>
84-
</property>
85-
<property name="text">
86-
<string>Edit</string>
87-
</property>
88-
</widget>
89-
</item>
90-
<item row="1" column="3">
91-
<widget class="QPushButton" name="btnRemove">
92-
<property name="toolTip">
93-
<string>Remove the current PostGIS connection</string>
94-
</property>
95-
<property name="whatsThis">
96-
<string>Remove the current PostGIS connection</string>
97-
</property>
98-
<property name="text">
99-
<string>Remove</string>
100-
</property>
101-
</widget>
102-
</item>
103-
<item row="1" column="1">
104-
<widget class="QPushButton" name="btnNew">
105-
<property name="toolTip">
106-
<string>Create a new PostGIS connection</string>
107-
</property>
108-
<property name="whatsThis">
109-
<string>Create a new PostGIS connection</string>
110-
</property>
111-
<property name="text">
112-
<string>New</string>
113-
</property>
114-
</widget>
115-
</item>
116-
<item row="1" column="0">
117-
<widget class="QPushButton" name="btnConnect">
118-
<property name="toolTip">
119-
<string>Connect to PostGIS</string>
120-
</property>
121-
<property name="whatsThis">
122-
<string>Connect to PostGIS</string>
123-
</property>
124-
<property name="text">
125-
<string>Connect</string>
126-
</property>
127-
</widget>
58+
<item>
59+
<layout class="QHBoxLayout" name="horizontalLayout">
60+
<item>
61+
<widget class="QPushButton" name="btnConnect">
62+
<property name="toolTip">
63+
<string>Connect to PostGIS</string>
64+
</property>
65+
<property name="whatsThis">
66+
<string>Connect to PostGIS</string>
67+
</property>
68+
<property name="text">
69+
<string>Connect</string>
70+
</property>
71+
</widget>
72+
</item>
73+
<item>
74+
<widget class="QPushButton" name="btnNew">
75+
<property name="toolTip">
76+
<string>Create a new PostGIS connection</string>
77+
</property>
78+
<property name="whatsThis">
79+
<string>Create a new PostGIS connection</string>
80+
</property>
81+
<property name="text">
82+
<string>New</string>
83+
</property>
84+
</widget>
85+
</item>
86+
<item>
87+
<widget class="QPushButton" name="btnEdit">
88+
<property name="toolTip">
89+
<string>Edit the current PostGIS connection</string>
90+
</property>
91+
<property name="whatsThis">
92+
<string>Edit the current PostGIS connection</string>
93+
</property>
94+
<property name="text">
95+
<string>Edit</string>
96+
</property>
97+
</widget>
98+
</item>
99+
<item>
100+
<widget class="QPushButton" name="btnRemove">
101+
<property name="toolTip">
102+
<string>Remove the current PostGIS connection</string>
103+
</property>
104+
<property name="whatsThis">
105+
<string>Remove the current PostGIS connection</string>
106+
</property>
107+
<property name="text">
108+
<string>Remove</string>
109+
</property>
110+
</widget>
111+
</item>
112+
</layout>
128113
</item>
129114
</layout>
130115
</widget>

0 commit comments

Comments
 (0)