Skip to content

Commit ff64d11

Browse files
author
g_j_m
committed
Fix for ticket #72
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5273 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a3b000d commit ff64d11

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/gui/qgsmaplayer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgsproject.h"
3838
#include "qgssymbol.h"
3939
#include "qgsmaplayer.h"
40+
#include "qgslegend.h"
4041
#include "qgslegendlayerfile.h"
4142

4243

@@ -105,6 +106,9 @@ void QgsMapLayer::setLayerName(const QString & _newVal)
105106
{
106107
QgsDebugMsg("QgsMapLayer::setLayerName: new name is '" + _newVal);
107108
layerName = _newVal;
109+
// And update the legend if one exists
110+
if (mLegend)
111+
mLegend->setName(mLegendLayerFile, layerName);
108112
}
109113

110114
/** Read property of QString layerName. */

src/legend/qgslegend.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,22 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
12811281
setCurrentItem(theCurrentItem);
12821282
}
12831283

1284+
void QgsLegend::setName(QgsLegendLayerFile* legendLayerFile,
1285+
QString layerName)
1286+
{
1287+
if (legendLayerFile)
1288+
{
1289+
QTreeWidgetItem* p = legendLayerFile->parent();
1290+
if (p)
1291+
{
1292+
p = p->parent();
1293+
if (p)
1294+
p->setText(0, layerName);
1295+
}
1296+
}
1297+
1298+
}
1299+
12841300
void QgsLegend::handleItemChange(QTreeWidgetItem* item, int row)
12851301
{
12861302
if(!item)

src/legend/qgslegend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
class QgisApp;
2828
class QgsLegendLayer;
29+
class QgsLegendLayerFile;
2930
class QgsLegendItem;
3031
class QgsMapLayer;
3132
class QgsMapCanvas;
@@ -145,6 +146,10 @@ class QgsLegend : public QTreeWidget
145146
Note: the QIcon* are deleted and therefore need to be allocated by calling functions using operator new*/
146147
void changeSymbologySettings(const QString& key, const std::list< std::pair<QString, QIcon*> >* newSymbologyItems);
147148

149+
/** Sets the name of the QgsLegendLayer that is the parent of
150+
the given QgsLegendLayerFile */
151+
void setName(QgsLegendLayerFile* w, QString layerName);
152+
148153
public slots:
149154

150155
/*!Adds a new layer group with the maplayer to the canvas*/

0 commit comments

Comments
 (0)