Skip to content

Commit d2e4498

Browse files
author
jef
committed
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
1 parent e63494f commit d2e4498

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/core/qgsvectorlayer.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "qgsvectordataprovider.h"
7070
#include "qgsvectoroverlay.h"
7171
#include "qgslogger.h"
72+
#include "qgsmaplayerregistry.h"
7273

7374
#ifdef Q_WS_X11
7475
#include "qgsclipper.h"
@@ -2181,12 +2182,24 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
21812182
if ( mProviderKey == "postgres" )
21822183
{
21832184
QgsDebugMsg( "Beautifying layer name " + name() );
2185+
21842186
// adjust the display name for postgres layers
2185-
QRegExp reg( "\"[^\"]+\"\\.\"([^\"]+)\"" );
2187+
QRegExp reg( "\"[^\"]+\"\\.\"([^\"]+)\" \\(([^)]+)\\)" );
21862188
reg.indexIn( name() );
21872189
QStringList stuff = reg.capturedTexts();
21882190
QString lName = stuff[1];
2189-
if ( lName.length() == 0 ) // fallback
2191+
if ( lName.length() == 3 )
2192+
{
2193+
const QMap<QString, QgsMapLayer*> &layers = QgsMapLayerRegistry::instance()->mapLayers();
2194+
2195+
QMap<QString, QgsMapLayer*>::const_iterator it;
2196+
for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; it++ )
2197+
;
2198+
2199+
if ( it != layers.constEnd() )
2200+
lName += "." + stuff[2];
2201+
}
2202+
else if ( lName.length() == 0 ) // fallback
21902203
lName = name();
21912204
setLayerName( lName );
21922205
QgsDebugMsg( "Beautifying layer name " + name() );

0 commit comments

Comments
 (0)