Skip to content
Permalink
Browse files

qualify default postgres layer name with column, if there would be a …

…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
jef committed Apr 8, 2009
1 parent e63494f commit d2e449899eefdc35eb610d5db21247f928530548
Showing with 15 additions and 2 deletions.
  1. +15 −2 src/core/qgsvectorlayer.cpp
@@ -69,6 +69,7 @@
#include "qgsvectordataprovider.h"
#include "qgsvectoroverlay.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"

#ifdef Q_WS_X11
#include "qgsclipper.h"
@@ -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() );

0 comments on commit d2e4498

Please sign in to comment.
You can’t perform that action at this time.