Skip to content

Commit 46bce5f

Browse files
author
g_j_m
committed
Fix for ticket #108.
- Postgres provider: Remove some declared but not defined functions that were shadowing some inherited functions of the same name. - Provide a function to give a version of the layer source without passwords in it for use in user visible places. Altered relevant code to use this. - Moved the vector layer source text from the General tab into the Metadata tab in the vector properties box (fits better in there, particularly when the text is long). - Added the sql text to the vector layer source text in appropriate places and fixed a few cases of where it wasn't propagating to all of the places that it should of been. - Added a function to QgsDataSourceUri to give the uri in a single qstring for display purposes. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5423 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 026a94a commit 46bce5f

9 files changed

+57
-72
lines changed

src/core/qgsdatasourceuri.h

+12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ class QgsDataSourceURI
4747
QString username;
4848
//! password
4949
QString password;
50+
//! All in a single string
51+
QString text()
52+
{
53+
return QString("host=" + host +
54+
" dbname=" + database +
55+
" port=" + port +
56+
" user=" + username +
57+
" password=" + password +
58+
" table=" + schema + '.' + table +
59+
" (" + geometryColumn + ")" +
60+
" sql=" + sql);
61+
}
5062
};
5163
#endif //QGSDATASOURCEURI_H
5264

src/core/qgsvectordataprovider.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class QgsGeometry;
2323
#include <map>
2424
#include <vector>
2525
// XXX no signals or slots so not needed #include <qobject.h>
26-
#include <qtextcodec.h>
26+
#include <QTextCodec>
2727

2828
//QGIS Includes
2929
#include <qgsdataprovider.h>

src/gui/qgsmaplayer.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QAction>
3030
#include <QKeyEvent>
3131
#include <QMenu>
32+
#include <QRegExp>
3233

3334
#include "qgisapp.h"
3435
#include "qgslogger.h"
@@ -124,6 +125,16 @@ QString const & QgsMapLayer::source() const
124125
return dataSource;
125126
}
126127

128+
QString QgsMapLayer::publicSource() const
129+
{
130+
// Redo this every time we're asked for it, as we don't know if
131+
// dataSource has changed.
132+
static QRegExp regexp(" password=.* ");
133+
regexp.setMinimal(true);
134+
QString safeName(dataSource);
135+
return safeName.replace(regexp, " ");
136+
}
137+
127138
QString const & QgsMapLayer::sourceName() const
128139
{
129140
return internalName;

src/gui/qgsmaplayer.h

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ class QgsMapLayer : public QObject
136136
//! Visibility of the layer
137137
bool visible();
138138

139+
/*! Gets a version of the internal layer definition that has sensitive
140+
* bits removed (for example, the password). This function should
141+
* be used when displaying the source name for general viewing.
142+
*/
143+
QString publicSource() const;
144+
139145
//! Returns the source for the layer
140146
QString const & source() const;
141147

src/gui/qgsvectorlayerproperties.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,7 @@ void QgsVectorLayerProperties::setDisplayField(QString name)
125125
void QgsVectorLayerProperties::reset( void )
126126
{
127127
// populate the general information
128-
QString source = layer->source();
129-
source = source.left(source.find("password"));
130-
lblSource->setText(source);
131128
txtDisplayName->setText(layer->name());
132-
// set whats this stuff
133-
lblSource->setWhatsThis(tr("The source of the data (path name or database connection information)"));
134129
pbnQueryBuilder->setWhatsThis(tr("This button opens the PostgreSQL query builder and allows you to create a subset of features to display on the map canvas rather than displaying all features in the layer"));
135130
txtSubsetSQL->setWhatsThis(tr("The query used to limit the features in the layer is shown here. This is currently only supported for PostgreSQL layers. To enter or modify the query, click on the Query Builder button"));
136131

@@ -258,6 +253,8 @@ void QgsVectorLayerProperties::on_pbnApply_clicked()
258253
grpSubset->setEnabled(true);
259254
// set the subset sql for the layer
260255
layer->setSubsetString(txtSubsetSQL->text());
256+
// update the metadata with the updated sql subset
257+
teMetadata->setText(getMetadata());
261258
// update the extents of the layer (fetched from the provider)
262259
layer->updateExtents();
263260
}
@@ -376,6 +373,12 @@ QString QgsVectorLayerProperties::getMetadata()
376373
layer->storageType();
377374
myMetadataQString += "</td></tr>";
378375

376+
// data source
377+
myMetadataQString += "<tr><td bgcolor=\"white\">";
378+
myMetadataQString += tr("Source for this layer : ") +
379+
layer->publicSource();
380+
myMetadataQString += "</td></tr>";
381+
379382
//geom type
380383

381384
QGis::VectorType vectorType = layer->vectorType();

src/legend/qgslegend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
486486
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup(llayer,QString("Files"));
487487
QgsLegendLayerFile * llfile = new QgsLegendLayerFile(llfgroup, QgsLegendLayerFile::nameFromLayer(layer), layer);
488488
llayer->setLayerTypeIcon();
489-
llayer->setToolTip(0, layer->source());
489+
llayer->setToolTip(0, layer->publicSource());
490490

491491
//set the correct check states
492492
blockSignals(true);

src/providers/postgres/qgspostgresprovider.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,12 @@ int QgsPostgresProvider::capabilities() const
21512151
void QgsPostgresProvider::setSubsetString(QString theSQL)
21522152
{
21532153
sqlWhereClause=theSQL;
2154+
// Update datasource uri too
2155+
mUri.sql=theSQL;
2156+
// Update yet another copy of the uri. Why are there 3 copies of the
2157+
// uri? Perhaps this needs some rationalisation.....
2158+
setDataSourceUri(mUri.text());
2159+
21542160
// need to recalculate the number of features...
21552161
getFeatureCount();
21562162
calculateExtents();

src/providers/postgres/qgspostgresprovider.h

-18
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,6 @@ class QgsPostgresProvider:public QgsVectorDataProvider
149149
*/
150150
void setURI(QgsDataSourceURI &uri);
151151

152-
/**
153-
* Set the data source specification. This must be a valid database
154-
* connection string:
155-
* host=localhost user=gsherman dbname=test password=xxx table=test.alaska (the_geom)
156-
* @uri data source specification
157-
*/
158-
// TODO Deprecate this in favor of using the QgsDataSourceURI structure
159-
void setDataSourceUri(QString uri);
160-
161-
/**
162-
* Get the data source specification.
163-
* @return data source specification as a string containing the host, user,
164-
* dbname, password, and table
165-
* @see setDataSourceUri
166-
*/
167-
// TODO Deprecate this in favor of returning the QgsDataSourceURI structure
168-
QString getDataSourceUri();
169-
170152
/**
171153
* Identify features within the search radius specified by rect
172154
* @param rect Bounding rectangle of search radius

src/ui/qgsvectorlayerpropertiesbase.ui

+12-47
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<rect>
99
<x>0</x>
1010
<y>0</y>
11-
<width>398</width>
11+
<width>408</width>
1212
<height>600</height>
1313
</rect>
1414
</property>
@@ -39,7 +39,7 @@
3939
<property name="tabShape" >
4040
<enum>QTabWidget::Rounded</enum>
4141
</property>
42-
<widget class="QWidget" name="tab" >
42+
<widget class="QWidget" name="tab1" >
4343
<attribute name="title" >
4444
<string>Symbology</string>
4545
</attribute>
@@ -140,7 +140,7 @@
140140
</item>
141141
</layout>
142142
</widget>
143-
<widget class="QWidget" name="tab" >
143+
<widget class="QWidget" name="tab2" >
144144
<attribute name="title" >
145145
<string>General</string>
146146
</attribute>
@@ -277,25 +277,6 @@
277277
</property>
278278
</widget>
279279
</item>
280-
<item row="0" column="1" colspan="3" >
281-
<widget class="QLabel" name="lblSource" >
282-
<property name="maximumSize" >
283-
<size>
284-
<width>32767</width>
285-
<height>22</height>
286-
</size>
287-
</property>
288-
<property name="frameShape" >
289-
<enum>QFrame::StyledPanel</enum>
290-
</property>
291-
<property name="frameShadow" >
292-
<enum>QFrame::Sunken</enum>
293-
</property>
294-
<property name="text" >
295-
<string>TextLabel2</string>
296-
</property>
297-
</widget>
298-
</item>
299280
<item row="5" column="0" colspan="4" >
300281
<widget class="QGroupBox" name="grpSubset" >
301282
<property name="title" >
@@ -341,22 +322,6 @@
341322
</layout>
342323
</widget>
343324
</item>
344-
<item row="0" column="0" >
345-
<widget class="QLabel" name="textLabel3_2" >
346-
<property name="maximumSize" >
347-
<size>
348-
<width>32767</width>
349-
<height>22</height>
350-
</size>
351-
</property>
352-
<property name="text" >
353-
<string>Layer source</string>
354-
</property>
355-
<property name="buddy" >
356-
<cstring></cstring>
357-
</property>
358-
</widget>
359-
</item>
360325
<item row="3" column="0" colspan="4" >
361326
<widget class="QGroupBox" name="indexGroupBox" >
362327
<property name="title" >
@@ -410,7 +375,7 @@
410375
</item>
411376
</layout>
412377
</widget>
413-
<widget class="QWidget" name="tab" >
378+
<widget class="QWidget" name="tab3" >
414379
<attribute name="title" >
415380
<string>Metadata</string>
416381
</attribute>
@@ -426,7 +391,7 @@
426391
</item>
427392
</layout>
428393
</widget>
429-
<widget class="QWidget" name="tab" >
394+
<widget class="QWidget" name="tab4" >
430395
<attribute name="title" >
431396
<string>Labels</string>
432397
</attribute>
@@ -557,6 +522,13 @@
557522
<layoutdefault spacing="6" margin="11" />
558523
<pixmapfunction></pixmapfunction>
559524
<customwidgets>
525+
<customwidget>
526+
<class>Q3TextEdit</class>
527+
<extends></extends>
528+
<header>q3textedit.h</header>
529+
<container>0</container>
530+
<pixmap></pixmap>
531+
</customwidget>
560532
<customwidget>
561533
<class>Q3WidgetStack</class>
562534
<extends></extends>
@@ -571,13 +543,6 @@
571543
<container>1</container>
572544
<pixmap></pixmap>
573545
</customwidget>
574-
<customwidget>
575-
<class>Q3TextEdit</class>
576-
<extends></extends>
577-
<header>q3textedit.h</header>
578-
<container>0</container>
579-
<pixmap></pixmap>
580-
</customwidget>
581546
</customwidgets>
582547
<tabstops>
583548
<tabstop>tabWidget2</tabstop>

0 commit comments

Comments
 (0)