Skip to content

Commit

Permalink
[gui] do not automatically format name of added layers (fixes #17741)
Browse files Browse the repository at this point in the history
(users wanting to re-enable that behavior can do so by switching
qgis/formatLayerName to true)
  • Loading branch information
nirvn authored Jan 15, 2018
1 parent b9aa768 commit e3cfbb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion resources/qgis_global_settings.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[qgis]
# if formatLayerName is set to true, added layer names will be automatically capitalized and underscores replaced with spaces
formatLayerName=false
connections-xyz\OpenStreetMap\authcfg=
connections-xyz\OpenStreetMap\password=
connections-xyz\OpenStreetMap\referer=
connections-xyz\OpenStreetMap\url=http://a.tile.openstreetmap.org/{z}/{x}/{y}.png
connections-xyz\OpenStreetMap\username=
connections-xyz\OpenStreetMap\zmax=19
connections-xyz\OpenStreetMap\zmin=0
connections-xyz\OpenStreetMap\zmin=0
25 changes: 20 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4182,6 +4182,8 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
{
bool wasfrozen = mMapCanvas->isFrozen();
QList<QgsMapLayer *> myList;
QgsSettings settings;

Q_FOREACH ( QString src, layerQStringList )
{
src = src.trimmed();
Expand Down Expand Up @@ -4213,7 +4215,10 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
QFileInfo fi( src );
base = fi.completeBaseName();
}
base = QgsMapLayer::formatLayerName( base );
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
base = QgsMapLayer::formatLayerName( base );
}

QgsDebugMsg( "completeBaseName: " + base );

Expand Down Expand Up @@ -4257,7 +4262,11 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
{
//set friendly name for datasources with only one layer
QStringList elements = sublayers.at( 0 ).split( QgsDataProvider::SUBLAYER_SEPARATOR );
QString subLayerNameFormatted = elements.size() >= 2 ? QgsMapLayer::formatLayerName( elements.at( 1 ) ) : QString();
QString subLayerNameFormatted = elements.size() >= 2 ? elements.at( 1 ) : QString();
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
subLayerNameFormatted = QgsMapLayer::formatLayerName( subLayerNameFormatted );
}

if ( elements.size() >= 4 && layer->name().compare( elements.at( 1 ), Qt::CaseInsensitive ) != 0
&& layer->name().compare( subLayerNameFormatted, Qt::CaseInsensitive ) != 0 )
Expand Down Expand Up @@ -9998,10 +10007,11 @@ void QgisApp::showLayoutManager()
QgsVectorLayer *QgisApp::addVectorLayer( const QString &vectorLayerPath, const QString &name, const QString &providerKey )
{
bool wasfrozen = mMapCanvas->isFrozen();
QgsSettings settings;

freezeCanvases();

QString baseName = QgsMapLayer::formatLayerName( name );
QString baseName = settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() ? QgsMapLayer::formatLayerName( name ) : name;

/* Eliminate the need to instantiate the layer based on provider type.
The caller is responsible for cobbling together the needed information to
Expand Down Expand Up @@ -10056,7 +10066,11 @@ QgsVectorLayer *QgisApp::addVectorLayer( const QString &vectorLayerPath, const Q
if ( !sublayers.isEmpty() )
{
QStringList elements = sublayers.at( 0 ).split( QgsDataProvider::SUBLAYER_SEPARATOR );
QString subLayerNameFormatted = elements.size() >= 2 ? QgsMapLayer::formatLayerName( elements.at( 1 ) ) : QString();
QString subLayerNameFormatted = elements.size() >= 2 ? elements.at( 1 ) : QString();
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
subLayerNameFormatted = QgsMapLayer::formatLayerName( subLayerNameFormatted );
}

if ( elements.size() >= 4 && layer->name().compare( elements.at( 1 ), Qt::CaseInsensitive ) != 0
&& layer->name().compare( subLayerNameFormatted, Qt::CaseInsensitive ) != 0 )
Expand Down Expand Up @@ -11935,7 +11949,8 @@ QgsRasterLayer *QgisApp::addRasterLayerPrivate(
freezeCanvases();
}

QString baseName = QgsMapLayer::formatLayerName( name );
QgsSettings settings;
QString baseName = settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() ? QgsMapLayer::formatLayerName( name ) : name;

QgsDebugMsg( "Creating new raster layer using " + uri
+ " with baseName of " + baseName );
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsxmlutils.h"
#include "qgssettings.h" // TODO: get rid of it [MD]
#include "qgsstringutils.h"

QString QgsMapLayer::extensionPropertyType( QgsMapLayer::PropertyType type )
Expand Down

0 comments on commit e3cfbb0

Please sign in to comment.