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@10511 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2009-04-08 17:18:36 +00:00
parent 6df52dd023
commit 0e882933b0

View File

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