Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change map layer display name if name is changed in the legend
git-svn-id: http://svn.osgeo.org/qgis/trunk@5859 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 22, 2006
1 parent d9f2c14 commit 76a2a8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/gui/qgsmaplayer.cpp
Expand Up @@ -112,12 +112,12 @@ QString const & QgsMapLayer::getLayerID() const
}

/** Write property of QString layerName. */
void QgsMapLayer::setLayerName(const QString & _newVal)
void QgsMapLayer::setLayerName(const QString & _newVal, bool updateLegend)
{
QgsDebugMsg("QgsMapLayer::setLayerName: new name is '" + _newVal);
layerName = capitaliseLayerName(_newVal);
// And update the legend if one exists
if (mLegend)
if (mLegend && updateLegend)
mLegend->setName(mLegendLayerFile, layerName);
}

Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgsmaplayer.h
Expand Up @@ -73,8 +73,10 @@ class QgsMapLayer : public QObject

/*! Set the display name of the layer
# @param name New name for the layer
# @param updateLegend false if legend should not be updated
(to avoid infinite recursion when this function is called from the legend itself)
*/
void setLayerName(const QString & name);
void setLayerName(const QString & name, bool updateLegend=true);

/*! Get the display name of the layer
* @return the layer name
Expand Down
11 changes: 11 additions & 0 deletions src/legend/qgslegend.cpp
Expand Up @@ -1478,7 +1478,18 @@ void QgsLegend::handleItemChange(QTreeWidgetItem* item, int row)
return;
}

//close the editor (for QgsLegendLayer and QgsLegendGroup)
closePersistentEditor(item, row);
//if the text of a QgsLegendLayer has changed, change the display names of all its maplayers
QgsLegendLayer* theLegendLayer = dynamic_cast<QgsLegendLayer*>(item); //item is a legend layer
if(theLegendLayer)
{
std::list<QgsMapLayer*> theMapLayers = theLegendLayer->mapLayers();
for(std::list<QgsMapLayer*>::iterator it = theMapLayers.begin(); it != theMapLayers.end(); ++it)
{
(*it)->setLayerName(theLegendLayer->text(0), false);
}
}

std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
if(it != mStateOfCheckBoxes.end())
Expand Down

0 comments on commit 76a2a8b

Please sign in to comment.