Skip to content
Permalink
Browse files

Make QgsMapLayer::name a Q_PROPERTY (#3259)

Make QgsMapLayer::name a Q_PROPERTY

And align setName / name / nameChanged

Deprecates setLayerName / layerNameChanged
  • Loading branch information
m-kuhn committed Jul 3, 2016
1 parent 143cfab commit 15c2f0a902c60b6d8e45f51ca0164e31c2b36d3c
@@ -64,7 +64,15 @@ class QgsMapLayer : QObject
/** Set the display name of the layer
* @param name New name for the layer
*/
void setLayerName( const QString & name );
void setLayerName( const QString & name ) /Deprecated/;

/**
* Set the display name of the layer
* @param name New name for the layer
*
* @note added in 2.16
*/
void setName( const QString& name );

/** Get the display name of the layer
* @return the layer name
@@ -631,9 +639,18 @@ class QgsMapLayer : QObject
/** Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) */
void statusChanged( const QString& theStatus );

/** Emit a signal that the layer name has been changed */
/** Emit a signal that the layer name has been changed
* @deprecated since 2.16 use nameChanged() instead
*/
void layerNameChanged();

/**
* Emitted when the name has been changed
*
* @note added in 2.16
*/
void nameChanged();

/** Emit a signal that layer's CRS has been reset */
void layerCrsChanged();

@@ -3568,7 +3568,7 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
Q_ASSERT( elements.size() >= 4 );
if ( layer->name() != elements.at( 1 ) )
{
layer->setLayerName( QString( "%1 %2 %3" ).arg( layer->name(), elements.at( 1 ), elements.at( 3 ) ) );
layer->setName( QString( "%1 %2 %3" ).arg( layer->name(), elements.at( 1 ), elements.at( 3 ) ) );
}

myList << layer;
@@ -7503,7 +7503,7 @@ QgsVectorLayer *QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
if ( !layer )
return nullptr;

layer->setLayerName( layerName );
layer->setName( layerName );

mMapCanvas->freeze();

@@ -8891,7 +8891,7 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
{
// if the layer capitalization has changed, we need to update all layer names
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
layer->setLayerName( layer->originalName() );
layer->setName( layer->originalName() );
}

//update any open compositions so they reflect new composer settings
@@ -11089,7 +11089,7 @@ QgsPluginLayer* QgisApp::addPluginLayer( const QString& uri, const QString& base
if ( !layer )
return nullptr;

layer->setLayerName( baseName );
layer->setName( baseName );

QgsMapLayerRegistry::instance()->addMapLayer( layer );

@@ -904,7 +904,7 @@ void QgsRasterLayerProperties::apply()
/*
* General Tab
*/
mRasterLayer->setLayerName( mLayerOrigNameLineEd->text() );
mRasterLayer->setName( mLayerOrigNameLineEd->text() );

// set up the scale based layer visibility stuff....
mRasterLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
@@ -613,7 +613,7 @@ void QgsVectorLayerProperties::apply()
}
Q_NOWARN_DEPRECATED_POP

mLayer->setLayerName( mLayerOrigNameLineEdit->text() );
mLayer->setName( mLayerOrigNameLineEdit->text() );

// Apply fields settings
mFieldsPropertiesDialog->apply();
@@ -79,7 +79,7 @@ QString QgsLayerTreeLayer::layerName() const
void QgsLayerTreeLayer::setLayerName( const QString& n )
{
if ( mLayer )
mLayer->setLayerName( n );
mLayer->setName( n );
else
mLayerName = n;
}
@@ -64,9 +64,7 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
, mStyleManager( new QgsMapLayerStyleManager( this ) )
{
// Set the display name = internal name
QgsDebugMsg( "original name: '" + mLayerOrigName + '\'' );
mLayerName = capitaliseLayerName( mLayerOrigName );
QgsDebugMsg( "display name: '" + mLayerName + '\'' );

mShortName = "";
//mShortName.replace( QRegExp( "[\\W]" ), "_" );
@@ -86,6 +84,8 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mMinScale = 0;
mMaxScale = 100000000;
mScaleBasedVisibility = false;

connect( this, SIGNAL( nameChanged() ), this, SIGNAL( layerNameChanged() ) );
}

QgsMapLayer::~QgsMapLayer()
@@ -105,16 +105,21 @@ QString QgsMapLayer::id() const
return mID;
}

/** Write property of QString layerName. */
void QgsMapLayer::setLayerName( const QString & name )
{
QgsDebugMsg( "new original name: '" + name + '\'' );
setName( name );
}

void QgsMapLayer::setName( const QString& name )
{
QString newName = capitaliseLayerName( name );
QgsDebugMsg( "new display name: '" + name + '\'' );
if ( name == mLayerOrigName && newName == mLayerName ) return;
if ( name == mLayerOrigName && newName == mLayerName )
return;

mLayerOrigName = name; // store the new original name
mLayerName = newName;
emit layerNameChanged();

emit nameChanged();
}

/** Read property of QString layerName. */
@@ -434,7 +439,7 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
// set name
mnl = layerElement.namedItem( "layername" );
mne = mnl.toElement();
setLayerName( mne.text() );
setName( mne.text() );

//short name
QDomElement shortNameElem = layerElement.firstChildElement( "shortname" );
@@ -50,6 +50,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
{
Q_OBJECT

Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )

public:
/** Layers enum defining the types of layers that can be added to a map */
enum LayerType
@@ -79,8 +81,17 @@ class CORE_EXPORT QgsMapLayer : public QObject

/** Set the display name of the layer
* @param name New name for the layer
* @deprecated Since 2.16, use setName instead
*/
Q_DECL_DEPRECATED void setLayerName( const QString & name );

/**
* Set the display name of the layer
* @param name New name for the layer
*
* @note added in 2.16
*/
void setLayerName( const QString & name );
void setName( const QString& name );

/** Get the display name of the layer
* @return the layer name
@@ -651,8 +662,17 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) */
void statusChanged( const QString& theStatus );

/** Emit a signal that the layer name has been changed */
void layerNameChanged();
/** Emit a signal that the layer name has been changed
* @deprecated since 2.16 use nameChanged() instead
*/
Q_DECL_DEPRECATED void layerNameChanged();

/**
* Emitted when the name has been changed
*
* @note added in 2.16
*/
void nameChanged();

/** Emit a signal that layer's CRS has been reset */
void layerCrsChanged();
@@ -1692,7 +1692,7 @@ void QgsVectorLayer::setDataSource( const QString& dataSource, const QString& ba

mDataSource = dataSource;
mLayerName = capitaliseLayerName( baseName );
setLayerName( mLayerName );
setName( mLayerName );
setDataProvider( provider );

if ( !mValid )
@@ -1791,7 +1791,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
}

if ( !lName.isEmpty() )
setLayerName( lName );
setName( lName );
}

QgsDebugMsg( "Beautified layer name " + name() );
@@ -646,7 +646,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
// set the layer name (uppercase first character)
if ( ! mLayerName.isEmpty() ) // XXX shouldn't this happen in parent?
{
setLayerName( mLayerName );
setName( mLayerName );
}

//mBandCount = 0;
@@ -960,7 +960,7 @@ QImage* QgsWMSServer::getLegendGraphics()
Q_FOREACH ( const QString& layerId, layerIds )
{
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
ml->setLayerName( layerNameMap[ layerId ] );
ml->setName( layerNameMap[ layerId ] );
}
// clear map layer registry
QgsMapLayerRegistry::instance()->removeAllMapLayers();

0 comments on commit 15c2f0a

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