@@ -63,9 +63,10 @@ QgsLegend::QgsLegend(QgisApp* app, QWidget * parent, const char *name)
63
63
this , SLOT (handleItemChange (QTreeWidgetItem*, int )));
64
64
65
65
connect ( this , SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
66
- this , SLOT (handleCurrentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)));
66
+ this , SLOT (handleCurrentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)));
67
+
67
68
68
- setSortingEnabled (false );
69
+ setSortingEnabled (false );
69
70
setDragEnabled (false );
70
71
setAutoScroll (true );
71
72
QFont f (" Arial" , 10 , QFont::Normal);
@@ -509,32 +510,22 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
509
510
QgsMapLayer* QgsLegend::currentLayer ()
510
511
{
511
512
QgsLegendItem* citem=dynamic_cast <QgsLegendItem*>(currentItem ());
512
- /*
513
- // XXX commented out because QGIS crashed when switching projects [MD]
514
- QList<QTreeWidgetItem*> selItems = selectedItems();
515
- if(selItems.size() > 1)
516
- {
517
- return 0;
518
- }
519
- QList<QTreeWidgetItem*>::iterator it = selItems.begin();
520
- QgsLegendItem* citem=dynamic_cast<QgsLegendItem*>(*it);
521
- */
522
-
523
- if (citem)
513
+
514
+ if (citem)
524
515
{
525
- QgsLegendLayerFile* llf=dynamic_cast <QgsLegendLayerFile*>(citem);
526
- if (llf)
516
+ QgsLegendLayerFile* llf=dynamic_cast <QgsLegendLayerFile*>(citem);
517
+ if (llf)
527
518
{
528
519
return llf->layer (); // the current item is itself a legend layer file
529
520
}
530
- else
521
+ else
531
522
{
532
- QgsLegendLayer* ll = dynamic_cast <QgsLegendLayer*>(citem);
533
- if (ll)
523
+ QgsLegendLayer* ll = dynamic_cast <QgsLegendLayer*>(citem);
524
+ if (ll)
534
525
{
535
526
return ll->firstMapLayer (); // the current item is a legend layer, so return its first layer
536
527
}
537
- else
528
+ else
538
529
{
539
530
QgsLegendLayer* lpl = dynamic_cast <QgsLegendLayer*>(citem->parent ());
540
531
if (lpl)
@@ -548,9 +539,9 @@ QgsMapLayer* QgsLegend::currentLayer()
548
539
}
549
540
}
550
541
}
551
- else
542
+ else
552
543
{
553
- return 0 ;
544
+ return 0 ;
554
545
}
555
546
}
556
547
@@ -1268,6 +1259,9 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
1268
1259
{
1269
1260
return ;
1270
1261
}
1262
+
1263
+ // store the current item
1264
+ QTreeWidgetItem* theCurrentItem = currentItem ();
1271
1265
1272
1266
// remove the symbology items under the legend layer
1273
1267
for (int i = theLegendLayer->childCount (); i >= 0 ; --i)
@@ -1296,6 +1290,9 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
1296
1290
1297
1291
// copy the legend settings for the other layer files in the same legend layer
1298
1292
theLegendLayer->updateLayerSymbologySettings (theMapLayer);
1293
+
1294
+ // restore the current item again
1295
+ setCurrentItem (theCurrentItem);
1299
1296
}
1300
1297
1301
1298
void QgsLegend::handleItemChange (QTreeWidgetItem* item, int row)
0 commit comments