diff --git a/src/app/qgsmaptoolidentifyaction.cpp b/src/app/qgsmaptoolidentifyaction.cpp index 8ea6fcadd12..95fb66d433c 100644 --- a/src/app/qgsmaptoolidentifyaction.cpp +++ b/src/app/qgsmaptoolidentifyaction.cpp @@ -90,7 +90,7 @@ void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer* layer, const QLi return; QString filter = "$id IN ("; - Q_FOREACH ( const QgsFeature feature, featureList ) + Q_FOREACH ( const QgsFeature &feature, featureList ) { filter.append( QString( "%1," ).arg( feature.id() ) ); } diff --git a/src/gui/qgsidentifymenu.cpp b/src/gui/qgsidentifymenu.cpp index e7cd80edea3..84ae65b4660 100644 --- a/src/gui/qgsidentifymenu.cpp +++ b/src/gui/qgsidentifymenu.cpp @@ -98,6 +98,7 @@ QList QgsIdentifyMenu::exec( const QList > it( mLayerIdResults ) ; while ( it.hasNext() ) @@ -116,12 +117,12 @@ QList QgsIdentifyMenu::exec( const QList( layer ); if ( !vl ) continue; - addVectorLayer( vl, it.value() ); + addVectorLayer( vl, it.value(), singleLayer ); } } // add an "identify all" action on the top level - if ( mAllowMultipleReturn && idResults.count() > 1 ) + if ( !singleLayer && mAllowMultipleReturn && idResults.count() > 1 ) { addSeparator(); QAction* allAction = new QAction( tr( "%1 for all (%2)" ).arg( mDefaultActionName ).arg( idResults.count() ), this ); @@ -204,12 +205,13 @@ void QgsIdentifyMenu::addRasterLayer( QgsMapLayer* layer ) } } -void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList results ) +void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList results, bool singleLayer ) { - QAction* layerAction; + QAction* layerAction = 0; QMenu* layerMenu = 0; - // do not add actions for multiple results if only 1 + // do not add actions with MultipleFeatures as target if only 1 feature is found for this layer + // targets defines which actions will be shown QgsMapLayerAction::Targets targets = results.count() > 1 ? QgsMapLayerAction::Layer | QgsMapLayerAction::MultipleFeatures : QgsMapLayerAction::Layer; QList separators = QList(); @@ -228,9 +230,15 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList just create an action + // 2. several features (2a) or display feature actions (2b) => create a menu + // 3. case 2 but only one layer (singeLayer) => do not create a menu, but give the top menu instead + bool createMenu = results.count() > 1 || layerActions.count() > 0; - // still create a menu for layer, if there is a sub-level for features + // case 2b: still create a menu for layer, if there is a sub-level for features // i.e custom actions or map layer actions at feature level if ( !createMenu ) { @@ -246,36 +254,50 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QListname(), this ); } else { - layerMenu = new QMenu( layer->name(), this ); - layerAction = layerMenu->menuAction(); + if ( singleLayer ) + { + // case 3 + layerMenu = this; + } + else + { + // case 2 + layerMenu = new QMenu( layer->name(), this ); + layerAction = layerMenu->menuAction(); + } } - // icons - switch ( layer->geometryType() ) + // case 1 or 2 + if ( layerAction ) { - case QGis::Point: - layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPointLayer.png" ) ); - break; - case QGis::Line: - layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconLineLayer.png" ) ); - break; - case QGis::Polygon: - layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPolygonLayer.png" ) ); - break; - default: - break; + // icons + switch ( layer->geometryType() ) + { + case QGis::Point: + layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPointLayer.png" ) ); + break; + case QGis::Line: + layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconLineLayer.png" ) ); + break; + case QGis::Polygon: + layerAction->setIcon( QgsApplication::getThemeIcon( "/mIconPolygonLayer.png" ) ); + break; + default: + break; + } + + // add layer action to the top menu + layerAction->setData( QVariant::fromValue( ActionData( layer ) ) ); + connect( layerAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) ); + addAction( layerAction ); } - // add layer action to the top menu - layerAction->setData( QVariant::fromValue( ActionData( layer ) ) ); - connect( layerAction, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) ); - addAction( layerAction ); - - // no need to go further if there is no menu + // case 1. no need to go further if ( !layerMenu ) return; @@ -315,7 +337,6 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList skip the feature level since there would be only a single entry // => give the layer menu as pointer instead of a new feature menu - featureAction = layerAction; featureMenu = layerMenu; } else diff --git a/src/gui/qgsidentifymenu.h b/src/gui/qgsidentifymenu.h index 9b241de5935..16d10460c6b 100644 --- a/src/gui/qgsidentifymenu.h +++ b/src/gui/qgsidentifymenu.h @@ -149,7 +149,8 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu void addRasterLayer( QgsMapLayer* layer ); //! adds a vector layer and its results in the menu being built - void addVectorLayer( QgsVectorLayer* layer, const QList results ); + //! if singleLayer is true, results will be displayed on the top level item (not in QMenu with the layer name) + void addVectorLayer( QgsVectorLayer* layer, const QList results , bool singleLayer = false ); //! get the lists of results corresponding to an action in the menu QList results( QAction* action, bool& externalAction );