[QGIS Commit] r10511 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Apr 8 13:18:36 EDT 2009


Author: jef
Date: 2009-04-08 13:18:36 -0400 (Wed, 08 Apr 2009)
New Revision: 10511

Modified:
   trunk/qgis/src/core/qgsvectorlayer.cpp
Log:
qualify default postgres layer name with column, if there would be a layer by the same name otherwise

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2009-04-08 17:06:23 UTC (rev 10510)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2009-04-08 17:18:36 UTC (rev 10511)
@@ -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 @@
       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() );



More information about the QGIS-commit mailing list