Skip to content

Commit

Permalink
Fix for ticket #108.
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
g_j_m committed May 7, 2006
1 parent 026a94a commit 46bce5f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 72 deletions.
12 changes: 12 additions & 0 deletions src/core/qgsdatasourceuri.h
Expand Up @@ -47,6 +47,18 @@ class QgsDataSourceURI
QString username;
//! password
QString password;
//! All in a single string
QString text()
{
return QString("host=" + host +
" dbname=" + database +
" port=" + port +
" user=" + username +
" password=" + password +
" table=" + schema + '.' + table +
" (" + geometryColumn + ")" +
" sql=" + sql);
}
};
#endif //QGSDATASOURCEURI_H

2 changes: 1 addition & 1 deletion src/core/qgsvectordataprovider.h
Expand Up @@ -23,7 +23,7 @@ class QgsGeometry;
#include <map>
#include <vector>
// XXX no signals or slots so not needed #include <qobject.h>
#include <qtextcodec.h>
#include <QTextCodec>

//QGIS Includes
#include <qgsdataprovider.h>
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsmaplayer.cpp
Expand Up @@ -29,6 +29,7 @@
#include <QAction>
#include <QKeyEvent>
#include <QMenu>
#include <QRegExp>

#include "qgisapp.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -124,6 +125,16 @@ QString const & QgsMapLayer::source() const
return dataSource;
}

QString QgsMapLayer::publicSource() const
{
// Redo this every time we're asked for it, as we don't know if
// dataSource has changed.
static QRegExp regexp(" password=.* ");
regexp.setMinimal(true);
QString safeName(dataSource);
return safeName.replace(regexp, " ");
}

QString const & QgsMapLayer::sourceName() const
{
return internalName;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaplayer.h
Expand Up @@ -136,6 +136,12 @@ class QgsMapLayer : public QObject
//! Visibility of the layer
bool visible();

/*! Gets a version of the internal layer definition that has sensitive
* bits removed (for example, the password). This function should
* be used when displaying the source name for general viewing.
*/
QString publicSource() const;

//! Returns the source for the layer
QString const & source() const;

Expand Down
13 changes: 8 additions & 5 deletions src/gui/qgsvectorlayerproperties.cpp
Expand Up @@ -125,12 +125,7 @@ void QgsVectorLayerProperties::setDisplayField(QString name)
void QgsVectorLayerProperties::reset( void )
{
// populate the general information
QString source = layer->source();
source = source.left(source.find("password"));
lblSource->setText(source);
txtDisplayName->setText(layer->name());
// set whats this stuff
lblSource->setWhatsThis(tr("The source of the data (path name or database connection information)"));
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"));
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"));

Expand Down Expand Up @@ -258,6 +253,8 @@ void QgsVectorLayerProperties::on_pbnApply_clicked()
grpSubset->setEnabled(true);
// set the subset sql for the layer
layer->setSubsetString(txtSubsetSQL->text());
// update the metadata with the updated sql subset
teMetadata->setText(getMetadata());
// update the extents of the layer (fetched from the provider)
layer->updateExtents();
}
Expand Down Expand Up @@ -376,6 +373,12 @@ QString QgsVectorLayerProperties::getMetadata()
layer->storageType();
myMetadataQString += "</td></tr>";

// data source
myMetadataQString += "<tr><td bgcolor=\"white\">";
myMetadataQString += tr("Source for this layer : ") +
layer->publicSource();
myMetadataQString += "</td></tr>";

//geom type

QGis::VectorType vectorType = layer->vectorType();
Expand Down
2 changes: 1 addition & 1 deletion src/legend/qgslegend.cpp
Expand Up @@ -486,7 +486,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup(llayer,QString("Files"));
QgsLegendLayerFile * llfile = new QgsLegendLayerFile(llfgroup, QgsLegendLayerFile::nameFromLayer(layer), layer);
llayer->setLayerTypeIcon();
llayer->setToolTip(0, layer->source());
llayer->setToolTip(0, layer->publicSource());

//set the correct check states
blockSignals(true);
Expand Down
6 changes: 6 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -2151,6 +2151,12 @@ int QgsPostgresProvider::capabilities() const
void QgsPostgresProvider::setSubsetString(QString theSQL)
{
sqlWhereClause=theSQL;
// Update datasource uri too
mUri.sql=theSQL;
// Update yet another copy of the uri. Why are there 3 copies of the
// uri? Perhaps this needs some rationalisation.....
setDataSourceUri(mUri.text());

// need to recalculate the number of features...
getFeatureCount();
calculateExtents();
Expand Down
18 changes: 0 additions & 18 deletions src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -149,24 +149,6 @@ class QgsPostgresProvider:public QgsVectorDataProvider
*/
void setURI(QgsDataSourceURI &uri);

/**
* Set the data source specification. This must be a valid database
* connection string:
* host=localhost user=gsherman dbname=test password=xxx table=test.alaska (the_geom)
* @uri data source specification
*/
// TODO Deprecate this in favor of using the QgsDataSourceURI structure
void setDataSourceUri(QString uri);

/**
* Get the data source specification.
* @return data source specification as a string containing the host, user,
* dbname, password, and table
* @see setDataSourceUri
*/
// TODO Deprecate this in favor of returning the QgsDataSourceURI structure
QString getDataSourceUri();

/**
* Identify features within the search radius specified by rect
* @param rect Bounding rectangle of search radius
Expand Down
59 changes: 12 additions & 47 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -8,7 +8,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>408</width>
<height>600</height>
</rect>
</property>
Expand Down Expand Up @@ -39,7 +39,7 @@
<property name="tabShape" >
<enum>QTabWidget::Rounded</enum>
</property>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab1" >
<attribute name="title" >
<string>Symbology</string>
</attribute>
Expand Down Expand Up @@ -140,7 +140,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab2" >
<attribute name="title" >
<string>General</string>
</attribute>
Expand Down Expand Up @@ -277,25 +277,6 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="3" >
<widget class="QLabel" name="lblSource" >
<property name="maximumSize" >
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Sunken</enum>
</property>
<property name="text" >
<string>TextLabel2</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4" >
<widget class="QGroupBox" name="grpSubset" >
<property name="title" >
Expand Down Expand Up @@ -341,22 +322,6 @@
</layout>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel3_2" >
<property name="maximumSize" >
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string>Layer source</string>
</property>
<property name="buddy" >
<cstring></cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4" >
<widget class="QGroupBox" name="indexGroupBox" >
<property name="title" >
Expand Down Expand Up @@ -410,7 +375,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab3" >
<attribute name="title" >
<string>Metadata</string>
</attribute>
Expand All @@ -426,7 +391,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab4" >
<attribute name="title" >
<string>Labels</string>
</attribute>
Expand Down Expand Up @@ -557,6 +522,13 @@
<layoutdefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>Q3TextEdit</class>
<extends></extends>
<header>q3textedit.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>Q3WidgetStack</class>
<extends></extends>
Expand All @@ -571,13 +543,6 @@
<container>1</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>Q3TextEdit</class>
<extends></extends>
<header>q3textedit.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget2</tabstop>
Expand Down

0 comments on commit 46bce5f

Please sign in to comment.