Skip to content
Permalink
Browse files

[FEATURE]: layer selection mode for info tool

  • Loading branch information
mhugent committed May 14, 2013
1 parent 38d63d1 commit b093cfaf568e319f8e14c12474797b8972bd699b
Showing with 45 additions and 3 deletions.
  1. +42 −2 src/app/qgsmaptoolidentifyaction.cpp
  2. +1 −0 src/app/qgsoptions.cpp
  3. +2 −1 src/gui/qgsmaptoolidentify.h
@@ -90,10 +90,50 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
}

resultsDialog()->clear();

connect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
connect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
QList<IdentifyResult> results = QgsMapToolIdentify::identify( e->x(), e->y() );

QList<IdentifyResult> results;
QSettings settings;
IdentifyMode mode = static_cast<IdentifyMode>( settings.value( "/Map/identifyMode", 0 ).toInt() );
if ( mode == LayerSelection )
{
QMap< QgsMapLayer*, QList<IdentifyResult> > layerIdResults;

QList<QgsMapLayer*> canvasLayers = mCanvas->layers();
QList<QgsMapLayer*>::iterator it = canvasLayers.begin();
for ( ; it != canvasLayers.end(); ++it )
{
QList<IdentifyResult> idResult = QgsMapToolIdentify::identify( e->x(), e->y(), QList<QgsMapLayer*>() << *it );
if ( !idResult.isEmpty() )
{
layerIdResults.insert( *it, idResult );
}
}

//show QMenu with available layers
QMenu layerSelectionMenu;
QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt = layerIdResults.constBegin();
for ( ; resultIt != layerIdResults.constEnd(); ++resultIt )
{
QAction* action = new QAction( resultIt.key()->name(), 0 );
action->setData( resultIt.key()->id() );
//QObject::connect( action, SIGNAL( hovered() ), this, SLOT( handleMenuHover() ) );
layerSelectionMenu.addAction( action );
}

QAction* selectedAction = layerSelectionMenu.exec( e->globalPos() );
if ( selectedAction )
{
QgsMapLayer* selectedLayer = QgsMapLayerRegistry::instance()->mapLayer( selectedAction->data().toString() );
results = layerIdResults[ selectedLayer ];
}
}
else
{
results = QgsMapToolIdentify::identify( e->x(), e->y() );
}

disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );

@@ -104,6 +104,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cmbIdentifyMode->addItem( tr( "Current layer" ), 0 );
cmbIdentifyMode->addItem( tr( "Top down, stop at first" ), 1 );
cmbIdentifyMode->addItem( tr( "Top down" ), 2 );
cmbIdentifyMode->addItem( tr( "Layer selection" ), 3 );

// read the current browser and set it
QSettings settings;
@@ -51,7 +51,8 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
DefaultQgsSetting = -1,
ActiveLayer,
TopDownStopAtFirst,
TopDownAll
TopDownAll,
LayerSelection
};

enum LayerType

0 comments on commit b093cfa

Please sign in to comment.
You can’t perform that action at this time.