Skip to content

Commit e056fce

Browse files
committedMay 3, 2014
layer selection identify: show feature count and add an option to get features
of all selected layers.
1 parent 6906cab commit e056fce

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed
 

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( int x, i
120120
QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt = mLayerIdResults.constBegin();
121121
for ( ; resultIt != mLayerIdResults.constEnd(); ++resultIt )
122122
{
123-
QAction* action = new QAction( resultIt.key()->name(), 0 );
123+
QAction* action = new QAction( QString( "%1 (%2)" ).arg( resultIt.key()->name() ).arg( resultIt.value().size() ), 0 );
124124
action->setData( resultIt.key()->id() );
125125
//add point/line/polygon icon
126126
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( resultIt.key() );
@@ -145,20 +145,31 @@ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( int x, i
145145
{
146146
action->setIcon( QgsApplication::getThemeIcon( "/mIconRaster.png" ) );
147147
}
148-
QObject::connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
148+
connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
149149
layerSelectionMenu.addAction( action );
150150
}
151151

152+
QAction *action = new QAction( tr( "All (%1)" ).arg( idResult.size() ), 0 );
153+
connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
154+
layerSelectionMenu.addAction( action );
155+
152156
// exec layer selection menu
153157
QPoint globalPos = mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
154158
QAction* selectedAction = layerSelectionMenu.exec( globalPos );
155159
if ( selectedAction )
156160
{
157-
QgsMapLayer* selectedLayer = QgsMapLayerRegistry::instance()->mapLayer( selectedAction->data().toString() );
158-
QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt = mLayerIdResults.find( selectedLayer );
159-
if ( sIt != mLayerIdResults.constEnd() )
161+
if( selectedAction->data().toString().isEmpty() )
160162
{
161-
results = sIt.value();
163+
results = idResult;
164+
}
165+
else
166+
{
167+
QgsMapLayer* selectedLayer = QgsMapLayerRegistry::instance()->mapLayer( selectedAction->data().toString() );
168+
QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt = mLayerIdResults.find( selectedLayer );
169+
if ( sIt != mLayerIdResults.constEnd() )
170+
{
171+
results = sIt.value();
172+
}
162173
}
163174
}
164175

@@ -658,6 +669,22 @@ void QgsMapToolIdentify::handleMenuHover()
658669
}
659670
}
660671
}
672+
else
673+
{
674+
for( QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator lIt = mLayerIdResults.constBegin(); lIt != mLayerIdResults.constEnd(); ++lIt )
675+
{
676+
const QList<IdentifyResult>& idList = lIt.value();
677+
QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
678+
for ( ; idListIt != idList.constEnd(); ++idListIt )
679+
{
680+
QgsHighlight *hl = new QgsHighlight( mCanvas, idListIt->mFeature.geometry(), lIt.key() );
681+
hl->setColor( QColor( 255, 0, 0 ) );
682+
hl->setWidth( 2 );
683+
mRubberBands.append( hl );
684+
connect( vl, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
685+
}
686+
}
687+
}
661688
}
662689
}
663690

0 commit comments

Comments
 (0)
Please sign in to comment.