Bug report #8473

Cannot rename layers in composer legend

Added by Giovanni Manghi over 11 years ago. Updated about 11 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:Marco Hugentobler
Category:Map Composer/Printing
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:17241

Description

It seems a regression: in the print composer legend the name of rasters/wms layers cannot be changed. The dialog shows, it allows enter a new name but the operation has no effect. Works ok on 1.8.

12.png (234 KB) Giovanni Manghi, 2013-08-15 07:20 PM

22.png (235 KB) Giovanni Manghi, 2013-08-15 07:20 PM

11.png (176 KB) Giovanni Manghi, 2013-08-15 07:20 PM

History

#1 Updated by Giovanni Manghi over 11 years ago

I see another issue, this time only on Linux. See Attached screenshots.

On Windows if in the composer legend there is vector with "single symbol" symbology, then the (one) symbology class has no text associated, but this can be edited.

On Linux in the same situation, the (one) symbology class is given the layer name by default, and this cannot be edited.

#2 Updated by Salvatore Larosa over 11 years ago

I am not fairly sure but this patch has worked for me (please anyone who knows better the composer code might reviews it ?):

diff --git a/src/app/composer/qgscomposerlegendwidget.cpp b/src/app/composer/qgscomposerlegendwidget.cpp
index 613d394..5032ab7 100644
--- a/src/app/composer/qgscomposerlegendwidget.cpp
+++ b/src/app/composer/qgscomposerlegendwidget.cpp
@@ -740,8 +740,8 @@ void QgsComposerLegendWidget::on_mEditPushButton_clicked()
   QgsComposerLegendItemDialog itemDialog( currentItem );
   if ( itemDialog.exec() == QDialog::Accepted )
   {
-    currentItem->setUserText( itemDialog.itemText() );
-    mLegend->model()->updateItemText( currentItem );
+    currentItem->setText( itemDialog.itemText() );
+    //mLegend->model()->updateItemText( currentItem );
   }

   mLegend->beginCommand( tr( "Legend item edited" ) );

#3 Updated by Giovanni Manghi over 11 years ago

  • Pull Request or Patch supplied changed from No to Yes

#4 Updated by Anita Graser over 11 years ago

  • Subject changed from Cannot rename raster layers in composer legend to Cannot rename (raster) layers in composer legend

For me, this issue is not limited to raster layers. (Using today's OSGeo4W nightly - code rev 4408a8b.)

In a project with only one polygon layer, I can only rename the upper level item in the print composer legend - but not the sub-level item.

#5 Updated by Giovanni Manghi over 11 years ago

  • Subject changed from Cannot rename (raster) layers in composer legend to Cannot rename layers in composer legend

#6 Updated by René-Luc ReLuc over 11 years ago

  • Assignee set to René-Luc ReLuc

Thanks Salvatore for your patch, but it changes the way to manage text for all the layers and not only for raster layers.

I proposed this patch :

index 29b86f5..d958676 100644
--- a/src/core/composer/qgslegendmodel.cpp
+++ b/src/core/composer/qgslegendmodel.cpp
@@ -380,10 +380,9 @@ void QgsLegendModel::updateLayer( QStandardItem* layerItem )
     QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
     if ( mapLayer )
     {
-      QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
-
       updateLayerItemText( lItem );

+      QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
       if ( vLayer )
       {
         addVectorLayerItemsV2( lItem, vLayer );
@@ -406,11 +405,9 @@ void QgsLegendModel::updateLayerItemText( QStandardItem* layerItem )
   QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
   if ( !mapLayer ) return;

-  QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
-  if ( !vLayer ) return;
-
   QString label = lItem->userText().isEmpty() ? mapLayer->name() : lItem->userText();

+  QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
   if ( vLayer && lItem->showFeatureCount() )
   {
     label += QString( " [%1]" ).arg( vLayer->featureCount() );

#7 Updated by Salvatore Larosa over 11 years ago

Hi René, sadly I am not a C++ expert :-( so my patch might not be correct.

Anyway, I did try your patch but renaming sub-level has not worked for me, I see the same issue as Anita.
For raster layers works fine!

Thanks.

#8 Updated by René-Luc ReLuc over 11 years ago

  • % Done changed from 0 to 90

I have completed my patch and I proposed it through this pull request
https://github.com/qgis/Quantum-GIS/pull/824

#9 Updated by René-Luc ReLuc over 11 years ago

  • Assignee changed from René-Luc ReLuc to Radim Blazek

Hi Radim,

I assigne this issue to you for reviewing my patch.
Marco wrote that you did a lot of work on composer legend.

Regards,

#10 Updated by Radim Blazek over 11 years ago

I am offline until September 3, please ask someone else to apply the patch.

#11 Updated by Marco Hugentobler over 11 years ago

  • Assignee changed from Radim Blazek to Marco Hugentobler

Ok, in that case the ticket is assigned to me.

#12 Updated by Marco Hugentobler over 11 years ago

  • Status changed from Open to Closed

The changes are fine and the patch is applied in master branch. Thanks rldhont for fixing this issue!

#13 Updated by Lene Fischer about 11 years ago

I have just downloaded weekly (03-09-13) Still the same problem. Is the correction not in the weekly yet?
Regards
Lene Fischer

#14 Updated by Giovanni Manghi about 11 years ago

Lene Fischer wrote:

I have just downloaded weekly (03-09-13) Still the same problem. Is the correction not in the weekly yet?
Regards
Lene Fischer

it works fine here on Linux.

#15 Updated by Salvatore Larosa about 11 years ago

Hi Lene,

Which is the revision code ?
The fix has been introduced in 7f8b259, so I think the last weekly should include that fix.

#16 Updated by René-Luc ReLuc about 11 years ago

I've tested a today compliation on Ubuntu, qgis is named fef175b, and it works.

Also available in: Atom PDF