Skip to content
Permalink
Browse files
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@5423 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed May 7, 2006
1 parent efddf4b commit 0eed881b33b893691c9f797cf038d13d61107970
@@ -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

@@ -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>
@@ -29,6 +29,7 @@
#include <QAction>
#include <QKeyEvent>
#include <QMenu>
#include <QRegExp>

#include "qgisapp.h"
#include "qgslogger.h"
@@ -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;
@@ -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;

@@ -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"));

@@ -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();
}
@@ -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();
@@ -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);
@@ -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();
@@ -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
@@ -8,7 +8,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>408</width>
<height>600</height>
</rect>
</property>
@@ -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>
@@ -140,7 +140,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab2" >
<attribute name="title" >
<string>General</string>
</attribute>
@@ -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" >
@@ -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" >
@@ -410,7 +375,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab3" >
<attribute name="title" >
<string>Metadata</string>
</attribute>
@@ -426,7 +391,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<widget class="QWidget" name="tab4" >
<attribute name="title" >
<string>Labels</string>
</attribute>
@@ -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>
@@ -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>

0 comments on commit 0eed881

Please sign in to comment.