@@ -92,7 +92,6 @@ class QgsIdentifyResultsDock : public QDockWidget
92
92
QgsIdentifyResults::QgsIdentifyResults ( QgsMapCanvas *canvas, QWidget *parent, Qt::WFlags f )
93
93
: QDialog( parent, f ),
94
94
mActionPopup( 0 ),
95
- mRubberBand( 0 ),
96
95
mCanvas( canvas ),
97
96
mDock( NULL )
98
97
{
@@ -215,6 +214,8 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
215
214
}
216
215
217
216
layItem->addChild ( featItem );
217
+
218
+ highlightFeature ( featItem );
218
219
}
219
220
220
221
void QgsIdentifyResults::editingToggled ()
@@ -263,13 +264,11 @@ void QgsIdentifyResults::show()
263
264
QTreeWidgetItem *layItem = lstResults->topLevelItem ( 0 );
264
265
QTreeWidgetItem *featItem = layItem->child ( 0 );
265
266
266
- if ( layItem->childCount () == 1 && QSettings ().value ( " /Map/identifyAutoFeatureForm" , false ).toBool () )
267
+ if ( lstResults-> topLevelItemCount () == 1 && layItem->childCount () == 1 && QSettings ().value ( " /Map/identifyAutoFeatureForm" , false ).toBool () )
267
268
{
268
269
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layItem->data ( 0 , Qt::UserRole ).value <QObject *>() );
269
270
if ( layer )
270
271
{
271
- highlightFeature ( featItem );
272
-
273
272
// if this is the only feature and it's on a vector layer
274
273
// don't show the form dialog instead of the results window
275
274
lstResults->setCurrentItem ( featItem );
@@ -341,6 +340,8 @@ void QgsIdentifyResults::contextMenuEvent( QContextMenuEvent* event )
341
340
mActionPopup ->addAction ( tr ( " Copy attribute value" ), this , SLOT ( copyAttributeValue () ) );
342
341
mActionPopup ->addAction ( tr ( " Copy feature attributes" ), this , SLOT ( copyFeatureAttributes () ) );
343
342
mActionPopup ->addSeparator ();
343
+ mActionPopup ->addAction ( tr ( " Highlight all" ), this , SLOT ( highlightAll () ) );
344
+ mActionPopup ->addAction ( tr ( " Highlight layer" ), this , SLOT ( highlightLayer () ) );
344
345
mActionPopup ->addAction ( tr ( " Expand all" ), this , SLOT ( expandAll () ) );
345
346
mActionPopup ->addAction ( tr ( " Collapse all" ), this , SLOT ( collapseAll () ) );
346
347
@@ -405,14 +406,14 @@ void QgsIdentifyResults::clear()
405
406
}
406
407
407
408
lstResults->clear ();
408
- clearRubberBand ();
409
+ mRubberBands . clear ();
409
410
}
410
411
411
412
void QgsIdentifyResults::activate ()
412
413
{
413
- if ( mRubberBand )
414
+ foreach ( QSharedPointer<QgsRubberBand> rb, mRubberBands )
414
415
{
415
- mRubberBand ->show ();
416
+ rb ->show ();
416
417
}
417
418
418
419
if ( lstResults->topLevelItemCount () > 0 )
@@ -424,23 +425,12 @@ void QgsIdentifyResults::activate()
424
425
425
426
void QgsIdentifyResults::deactivate ()
426
427
{
427
- if ( mRubberBand )
428
+ foreach ( QSharedPointer<QgsRubberBand> rb, mRubberBands )
428
429
{
429
- mRubberBand ->hide ();
430
+ rb ->hide ();
430
431
}
431
432
}
432
433
433
- void QgsIdentifyResults::clearRubberBand ()
434
- {
435
- if ( !mRubberBand )
436
- return ;
437
-
438
- delete mRubberBand ;
439
- mRubberBand = 0 ;
440
- mRubberBandLayer = 0 ;
441
- mRubberBandFid = 0 ;
442
- }
443
-
444
434
void QgsIdentifyResults::doAction ( QTreeWidgetItem *item, int action )
445
435
{
446
436
int idx;
@@ -507,13 +497,22 @@ QTreeWidgetItem *QgsIdentifyResults::featureItem( QTreeWidgetItem *item )
507
497
return featItem;
508
498
}
509
499
510
- QgsVectorLayer *QgsIdentifyResults::vectorLayer ( QTreeWidgetItem *item )
500
+ QTreeWidgetItem *QgsIdentifyResults::layerItem ( QTreeWidgetItem *item )
511
501
{
512
- if ( item->parent () )
502
+ if ( item && item ->parent () )
513
503
{
514
504
item = featureItem ( item )->parent ();
515
505
}
516
506
507
+ return item;
508
+ }
509
+
510
+
511
+ QgsVectorLayer *QgsIdentifyResults::vectorLayer ( QTreeWidgetItem *item )
512
+ {
513
+ item = layerItem ( item );
514
+ if ( !item )
515
+ return NULL ;
517
516
return qobject_cast<QgsVectorLayer *>( item->data ( 0 , Qt::UserRole ).value <QObject *>() );
518
517
}
519
518
@@ -543,24 +542,42 @@ void QgsIdentifyResults::itemExpanded( QTreeWidgetItem* item )
543
542
expandColumnsToFit ();
544
543
}
545
544
546
- void QgsIdentifyResults::handleCurrentItemChanged ( QTreeWidgetItem* current, QTreeWidgetItem* previous )
545
+ void QgsIdentifyResults::handleCurrentItemChanged ( QTreeWidgetItem * current, QTreeWidgetItem * previous )
547
546
{
548
547
if ( current == NULL )
549
548
{
550
549
emit selectedFeatureChanged ( 0 , 0 );
551
550
return ;
552
551
}
553
552
554
- highlightFeature ( current );
553
+ QTreeWidgetItem *layItem = layerItem ( current );
554
+
555
+ if ( current == layItem )
556
+ {
557
+ highlightLayer ( layItem );
558
+ }
559
+ else
560
+ {
561
+ mRubberBands .clear ();
562
+ highlightFeature ( current );
563
+ }
555
564
}
556
565
557
566
void QgsIdentifyResults::layerDestroyed ()
558
567
{
559
568
QObject *theSender = sender ();
560
569
561
- if ( mRubberBandLayer == theSender )
570
+ for ( int i = 0 ; i < lstResults-> topLevelItemCount (); i++ )
562
571
{
563
- clearRubberBand ();
572
+ QTreeWidgetItem *layItem = lstResults->topLevelItem ( i );
573
+
574
+ if ( layItem->data ( 0 , Qt::UserRole ).value <QObject *>() == sender () )
575
+ {
576
+ for ( int j = 0 ; j < layItem->childCount (); j++ )
577
+ {
578
+ mRubberBands .remove ( layItem->child ( i ) );
579
+ }
580
+ }
564
581
}
565
582
566
583
disconnectLayer ( theSender );
@@ -604,17 +621,13 @@ void QgsIdentifyResults::featureDeleted( int fid )
604
621
605
622
if ( featItem && featItem->data ( 0 , Qt::UserRole ).toInt () == fid )
606
623
{
607
- if ( mRubberBandLayer == sender () && mRubberBandFid == fid )
608
- clearRubberBand ();
609
- delete featItem;
624
+ mRubberBands .remove ( featItem );
610
625
break ;
611
626
}
612
627
}
613
628
614
629
if ( layItem->childCount () == 0 )
615
630
{
616
- if ( mRubberBandLayer == sender () )
617
- clearRubberBand ();
618
631
delete layItem;
619
632
}
620
633
@@ -634,9 +647,10 @@ void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
634
647
if ( !featItem )
635
648
return ;
636
649
637
- int fid = featItem->data ( 0 , Qt::UserRole ).toInt ();
650
+ if ( mRubberBands .contains ( featItem ) )
651
+ return ;
638
652
639
- clearRubberBand ();
653
+ int fid = featItem-> data ( 0 , Qt::UserRole ). toInt ();
640
654
641
655
QgsFeature feat;
642
656
if ( ! layer->featureAtId ( fid, feat, true , false ) )
@@ -649,15 +663,14 @@ void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
649
663
return ;
650
664
}
651
665
652
- mRubberBand = new QgsRubberBand ( mCanvas , feat.geometry ()->type () == QGis::Polygon );
653
- if ( mRubberBand )
666
+ QgsRubberBand *rb = new QgsRubberBand ( mCanvas , feat.geometry ()->type () == QGis::Polygon );
667
+ if ( rb )
654
668
{
655
- mRubberBandLayer = layer;
656
- mRubberBandFid = fid;
657
- mRubberBand ->setToGeometry ( feat.geometry (), layer );
658
- mRubberBand ->setWidth ( 2 );
659
- mRubberBand ->setColor ( Qt::red );
660
- mRubberBand ->show ();
669
+ rb->setToGeometry ( feat.geometry (), layer );
670
+ rb->setWidth ( 2 );
671
+ rb->setColor ( Qt::red );
672
+ rb->show ();
673
+ mRubberBands .insert ( featItem, QSharedPointer<QgsRubberBand>( rb ) );
661
674
}
662
675
}
663
676
@@ -768,6 +781,39 @@ void QgsIdentifyResults::featureForm()
768
781
mCanvas ->refresh ();
769
782
}
770
783
784
+ void QgsIdentifyResults::highlightAll ()
785
+ {
786
+ for ( int i = 0 ; i < lstResults->topLevelItemCount (); i++ )
787
+ {
788
+ QTreeWidgetItem *layItem = lstResults->topLevelItem ( i );
789
+
790
+ for ( int j = 0 ; j < layItem->childCount (); j++ )
791
+ {
792
+ highlightFeature ( layItem->child ( j ) );
793
+ }
794
+ }
795
+ }
796
+
797
+ void QgsIdentifyResults::highlightLayer ()
798
+ {
799
+ highlightLayer ( lstResults->currentItem () );
800
+ }
801
+
802
+ void QgsIdentifyResults::highlightLayer ( QTreeWidgetItem *item )
803
+ {
804
+ QTreeWidgetItem *layItem = layerItem ( item );
805
+ if ( !layItem )
806
+ return ;
807
+
808
+ mRubberBands .clear ();
809
+
810
+ for ( int i = 0 ; i < layItem->childCount (); i++ )
811
+ {
812
+ highlightFeature ( layItem->child ( i ) );
813
+ }
814
+ }
815
+
816
+
771
817
void QgsIdentifyResults::expandAll ()
772
818
{
773
819
lstResults->expandAll ();
0 commit comments