Skip to content

Commit

Permalink
qualify default postgres layer name with column, if there would be a …
Browse files Browse the repository at this point in the history
…layer by the same name otherwise

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10511 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 8, 2009
1 parent e63494f commit d2e4498
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -69,6 +69,7 @@
#include "qgsvectordataprovider.h"
#include "qgsvectoroverlay.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"

#ifdef Q_WS_X11
#include "qgsclipper.h"
Expand Down Expand Up @@ -2181,12 +2182,24 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
if ( mProviderKey == "postgres" )
{
QgsDebugMsg( "Beautifying layer name " + name() );

// adjust the display name for postgres layers
QRegExp reg( "\"[^\"]+\"\\.\"([^\"]+)\"" );
QRegExp reg( "\"[^\"]+\"\\.\"([^\"]+)\" \\(([^)]+)\\)" );
reg.indexIn( name() );
QStringList stuff = reg.capturedTexts();
QString lName = stuff[1];
if ( lName.length() == 0 ) // fallback
if ( lName.length() == 3 )
{
const QMap<QString, QgsMapLayer*> &layers = QgsMapLayerRegistry::instance()->mapLayers();

QMap<QString, QgsMapLayer*>::const_iterator it;
for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; it++ )
;

if ( it != layers.constEnd() )
lName += "." + stuff[2];
}
else if ( lName.length() == 0 ) // fallback
lName = name();
setLayerName( lName );
QgsDebugMsg( "Beautifying layer name " + name() );
Expand Down

0 comments on commit d2e4498

Please sign in to comment.