Skip to content

Commit bd51057

Browse files
author
g_j_m
committedAug 20, 2006
Provide an option to the user to constrain searches for spatial tables not
in the geometry_columns table to just those in the public schema. For some databases which have a lot of ancillary stuff out of the public schema this can significantly reduce the time that qgis takes to produce the list of tables to load. Also tidy up the cause of some console warning messages about unknown geometry types that happened when a spatial table not in the geometry_columns table had no non-null geometries in it. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5711 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

4 files changed

+118
-87
lines changed

4 files changed

+118
-87
lines changed
 

‎src/gui/qgsdbsourceselect.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void QgsDbSourceSelect::setLayerType(QString schema,
188188
}
189189
else
190190
{
191-
qDebug(("Unknown geometry type of " + type).toLocal8Bit().data());
191+
qDebug(("Unknown geometry type of ." + type + ",.").toLocal8Bit().data());
192192
p = &(mLayerIcons.value("UNKNOWN").second);
193193
toolTipText = mLayerIcons.value("UNKNOWN").first;
194194
}
@@ -313,6 +313,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
313313
QString username = settings.readEntry(key + "/username");
314314
connString += username;
315315
QString password = settings.readEntry(key + "/password");
316+
bool searchPublicOnly = settings.readBoolEntry(key + "/publicOnly");
316317
bool makeConnection = true;
317318
if (password == QString::null)
318319
{
@@ -393,7 +394,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
393394

394395
// get the list of suitable tables and columns and populate the UI
395396
geomCol details;
396-
if (getGeometryColumnInfo(pd, details))
397+
if (getGeometryColumnInfo(pd, details, searchPublicOnly))
397398
{
398399
details.sort();
399400
geomCol::const_iterator iter = details.begin();
@@ -409,7 +410,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
409410
}
410411
else
411412
{
412-
qDebug(("Unknown geometry type of " + iter->second).toLocal8Bit().data());
413+
qDebug(("Unknown geometry type of '" + iter->second + "'.").toLocal8Bit().data());
413414
p = &(mLayerIcons.value("UNKNOWN").second);
414415
toolTipText = mLayerIcons.value("UNKNOWN").first;
415416
}
@@ -518,7 +519,7 @@ void QgsDbSourceSelect::setSql(QTableWidgetItem *item)
518519
}
519520

520521
bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
521-
geomCol& details)
522+
geomCol& details, bool searchPublicOnly)
522523
{
523524
bool ok = false;
524525

@@ -579,8 +580,12 @@ bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
579580
sql = "select pg_class.relname, pg_namespace.nspname, pg_attribute.attname, "
580581
"pg_class.relkind from "
581582
"pg_attribute, pg_class, pg_type, pg_namespace where pg_type.typname = 'geometry' and "
582-
"pg_attribute.atttypid = pg_type.oid and pg_attribute.attrelid = pg_class.oid "
583-
"and cast(pg_class.relname as character varying) not in "
583+
"pg_attribute.atttypid = pg_type.oid and pg_attribute.attrelid = pg_class.oid ";
584+
585+
if (searchPublicOnly)
586+
sql += "and pg_namespace.nspname = 'public' ";
587+
588+
sql += "and cast(pg_class.relname as character varying) not in "
584589
"(select f_table_name from geometry_columns) "
585590
"and pg_namespace.oid = pg_class.relnamespace "
586591
"and pg_class.relkind in ('v', 'r')"; // only from views and relations (tables)
@@ -614,7 +619,7 @@ bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
614619
tr("\nhas failed. The database said:\n"));
615620
qDebug(myError + QString(PQresultErrorMessage(gresult)));
616621
}
617-
else
622+
else if (PQntuples(gresult) > 0)
618623
type = PQgetvalue(gresult, 0, 0); // GeometryType
619624
PQclear(gresult);
620625
}

‎src/gui/qgsdbsourceselect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
9797
typedef std::list<geomPair > geomCol;
9898

9999
bool getGeometryColumnInfo(PGconn *pd,
100-
geomCol& details);
100+
geomCol& details, bool searchPublicOnly);
101101
// Set the position of the database connection list to the last
102102
// used one.
103103
void setConnectionListPosition();

‎src/gui/qgsnewconnection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ QgsNewConnection::QgsNewConnection(QWidget *parent, const QString& connName, Qt:
4545
}
4646
txtPort->setText(port);
4747
txtUsername->setText(settings.readEntry(key + "/username"));
48+
Qt::CheckState s = Qt::Checked;
49+
if ( ! settings.readBoolEntry(key + "/publicOnly", false))
50+
s = Qt::Unchecked;
51+
cb_publicSchemaOnly->setCheckState(s);
4852
if (settings.readEntry(key + "/save") == "true")
4953
{
5054
txtPassword->setText(settings.readEntry(key + "/password"));
@@ -114,6 +118,7 @@ void QgsNewConnection::saveConnection()
114118
settings.writeEntry(baseKey + "/port", txtPort->text());
115119
settings.writeEntry(baseKey + "/username", txtUsername->text());
116120
settings.writeEntry(baseKey + "/password", txtPassword->text());
121+
settings.writeEntry(baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked());
117122
if (chkStorePassword->isChecked())
118123
{
119124
settings.writeEntry(baseKey + "/save", "true");

‎src/ui/qgsnewconnectionbase.ui

Lines changed: 100 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
<rect>
99
<x>0</x>
1010
<y>0</y>
11-
<width>394</width>
12-
<height>282</height>
11+
<width>435</width>
12+
<height>389</height>
1313
</rect>
1414
</property>
15+
<property name="sizePolicy" >
16+
<sizepolicy>
17+
<hsizetype>3</hsizetype>
18+
<vsizetype>3</vsizetype>
19+
<horstretch>0</horstretch>
20+
<verstretch>0</verstretch>
21+
</sizepolicy>
22+
</property>
1523
<property name="windowTitle" >
1624
<string>Create a New PostGIS connection</string>
1725
</property>
@@ -20,82 +28,11 @@
2028
</property>
2129
<layout class="QGridLayout" >
2230
<property name="margin" >
23-
<number>11</number>
31+
<number>9</number>
2432
</property>
2533
<property name="spacing" >
2634
<number>6</number>
2735
</property>
28-
<item row="0" column="1" >
29-
<layout class="QVBoxLayout" >
30-
<property name="margin" >
31-
<number>0</number>
32-
</property>
33-
<property name="spacing" >
34-
<number>6</number>
35-
</property>
36-
<item>
37-
<widget class="QPushButton" name="btnOk" >
38-
<property name="text" >
39-
<string>OK</string>
40-
</property>
41-
<property name="shortcut" >
42-
<string/>
43-
</property>
44-
<property name="autoDefault" >
45-
<bool>true</bool>
46-
</property>
47-
<property name="default" >
48-
<bool>true</bool>
49-
</property>
50-
</widget>
51-
</item>
52-
<item>
53-
<widget class="QPushButton" name="btnCancel" >
54-
<property name="text" >
55-
<string>Cancel</string>
56-
</property>
57-
<property name="shortcut" >
58-
<string/>
59-
</property>
60-
<property name="autoDefault" >
61-
<bool>true</bool>
62-
</property>
63-
</widget>
64-
</item>
65-
<item>
66-
<widget class="QPushButton" name="btnHelp" >
67-
<property name="enabled" >
68-
<bool>true</bool>
69-
</property>
70-
<property name="text" >
71-
<string>Help</string>
72-
</property>
73-
<property name="shortcut" >
74-
<string>F1</string>
75-
</property>
76-
<property name="autoDefault" >
77-
<bool>true</bool>
78-
</property>
79-
</widget>
80-
</item>
81-
<item>
82-
<spacer>
83-
<property name="orientation" >
84-
<enum>Qt::Vertical</enum>
85-
</property>
86-
<property name="sizeType" >
87-
<enum>QSizePolicy::Expanding</enum>
88-
</property>
89-
<property name="sizeHint" >
90-
<size>
91-
<width>0</width>
92-
<height>20</height>
93-
</size>
94-
</property>
95-
</spacer>
96-
</item>
97-
</layout>
98-
</item>
9936
<item row="0" column="0" >
10037
<widget class="Q3GroupBox" name="GroupBox1" >
10138
<property name="title" >
@@ -104,14 +41,14 @@
10441
<property name="orientation" >
10542
<enum>Qt::Vertical</enum>
10643
</property>
107-
<layout class="QGridLayout" >
44+
<layout class="QVBoxLayout" >
10845
<property name="margin" >
109-
<number>11</number>
46+
<number>0</number>
11047
</property>
11148
<property name="spacing" >
112-
<number>6</number>
49+
<number>0</number>
11350
</property>
114-
<item row="0" column="0" >
51+
<item>
11552
<layout class="QHBoxLayout" >
11653
<property name="margin" >
11754
<number>0</number>
@@ -231,7 +168,7 @@
231168
</item>
232169
</layout>
233170
</item>
234-
<item row="1" column="0" >
171+
<item>
235172
<layout class="QHBoxLayout" >
236173
<property name="margin" >
237174
<number>0</number>
@@ -255,9 +192,93 @@
255192
</item>
256193
</layout>
257194
</item>
195+
<item>
196+
<widget class="QCheckBox" name="cb_publicSchemaOnly" >
197+
<property name="toolTip" >
198+
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:12pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Restrict the search to the public schema for spatial tables not in the geometry_columns table&lt;/p>&lt;/body>&lt;/html></string>
199+
</property>
200+
<property name="whatsThis" >
201+
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:12pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">When searching for spatial tables that are not in the geometry_columns tables, restrict the search to tables that are in the public schema (for some databases this can save lots of time)&lt;/p>&lt;/body>&lt;/html></string>
202+
</property>
203+
<property name="text" >
204+
<string>Only look in the 'public' schema</string>
205+
</property>
206+
</widget>
207+
</item>
258208
</layout>
259209
</widget>
260210
</item>
211+
<item row="0" column="1" >
212+
<layout class="QVBoxLayout" >
213+
<property name="margin" >
214+
<number>0</number>
215+
</property>
216+
<property name="spacing" >
217+
<number>6</number>
218+
</property>
219+
<item>
220+
<widget class="QPushButton" name="btnOk" >
221+
<property name="text" >
222+
<string>OK</string>
223+
</property>
224+
<property name="shortcut" >
225+
<string/>
226+
</property>
227+
<property name="autoDefault" >
228+
<bool>true</bool>
229+
</property>
230+
<property name="default" >
231+
<bool>true</bool>
232+
</property>
233+
</widget>
234+
</item>
235+
<item>
236+
<widget class="QPushButton" name="btnCancel" >
237+
<property name="text" >
238+
<string>Cancel</string>
239+
</property>
240+
<property name="shortcut" >
241+
<string/>
242+
</property>
243+
<property name="autoDefault" >
244+
<bool>true</bool>
245+
</property>
246+
</widget>
247+
</item>
248+
<item>
249+
<widget class="QPushButton" name="btnHelp" >
250+
<property name="enabled" >
251+
<bool>true</bool>
252+
</property>
253+
<property name="text" >
254+
<string>Help</string>
255+
</property>
256+
<property name="shortcut" >
257+
<string>F1</string>
258+
</property>
259+
<property name="autoDefault" >
260+
<bool>true</bool>
261+
</property>
262+
</widget>
263+
</item>
264+
<item>
265+
<spacer>
266+
<property name="orientation" >
267+
<enum>Qt::Vertical</enum>
268+
</property>
269+
<property name="sizeType" >
270+
<enum>QSizePolicy::Expanding</enum>
271+
</property>
272+
<property name="sizeHint" >
273+
<size>
274+
<width>87</width>
275+
<height>200</height>
276+
</size>
277+
</property>
278+
</spacer>
279+
</item>
280+
</layout>
281+
</item>
261282
</layout>
262283
</widget>
263284
<layoutdefault spacing="6" margin="11" />

0 commit comments

Comments
 (0)
Please sign in to comment.