Skip to content
Permalink
Browse files
Change map layer display name if name is changed in the legend
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5859 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 22, 2006
1 parent 67f8101 commit 4d9c9e195e78c352520312d6dfe1c5c5034a4a90
Showing with 16 additions and 3 deletions.
  1. +2 −2 src/gui/qgsmaplayer.cpp
  2. +3 −1 src/gui/qgsmaplayer.h
  3. +11 −0 src/legend/qgslegend.cpp
@@ -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);
}

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

0 comments on commit 4d9c9e1

Please sign in to comment.