diff --git a/src/gui/qgsmaplayer.cpp b/src/gui/qgsmaplayer.cpp index 93d5ca0ba5d..bdabe08c870 100644 --- a/src/gui/qgsmaplayer.cpp +++ b/src/gui/qgsmaplayer.cpp @@ -37,6 +37,7 @@ #include "qgsproject.h" #include "qgssymbol.h" #include "qgsmaplayer.h" +#include "qgslegend.h" #include "qgslegendlayerfile.h" @@ -105,6 +106,9 @@ void QgsMapLayer::setLayerName(const QString & _newVal) { QgsDebugMsg("QgsMapLayer::setLayerName: new name is '" + _newVal); layerName = _newVal; + // And update the legend if one exists + if (mLegend) + mLegend->setName(mLegendLayerFile, layerName); } /** Read property of QString layerName. */ diff --git a/src/legend/qgslegend.cpp b/src/legend/qgslegend.cpp index 706bfda7ae6..6938f9763df 100755 --- a/src/legend/qgslegend.cpp +++ b/src/legend/qgslegend.cpp @@ -1281,6 +1281,22 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std setCurrentItem(theCurrentItem); } +void QgsLegend::setName(QgsLegendLayerFile* legendLayerFile, + QString layerName) +{ + if (legendLayerFile) + { + QTreeWidgetItem* p = legendLayerFile->parent(); + if (p) + { + p = p->parent(); + if (p) + p->setText(0, layerName); + } + } + +} + void QgsLegend::handleItemChange(QTreeWidgetItem* item, int row) { if(!item) diff --git a/src/legend/qgslegend.h b/src/legend/qgslegend.h index d234091023a..a46f95c634c 100755 --- a/src/legend/qgslegend.h +++ b/src/legend/qgslegend.h @@ -26,6 +26,7 @@ class QgisApp; class QgsLegendLayer; +class QgsLegendLayerFile; class QgsLegendItem; class QgsMapLayer; class QgsMapCanvas; @@ -145,6 +146,10 @@ class QgsLegend : public QTreeWidget Note: the QIcon* are deleted and therefore need to be allocated by calling functions using operator new*/ void changeSymbologySettings(const QString& key, const std::list< std::pair >* newSymbologyItems); + /** Sets the name of the QgsLegendLayer that is the parent of + the given QgsLegendLayerFile */ + void setName(QgsLegendLayerFile* w, QString layerName); + public slots: /*!Adds a new layer group with the maplayer to the canvas*/