Skip to content

Commit

Permalink
[FEATURE]: layer selection mode for info tool
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed May 14, 2013
1 parent 38d63d1 commit b093cfa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
44 changes: 42 additions & 2 deletions src/app/qgsmaptoolidentifyaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );

Expand Down
1 change: 1 addition & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaptoolidentify.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
DefaultQgsSetting = -1,
ActiveLayer,
TopDownStopAtFirst,
TopDownAll
TopDownAll,
LayerSelection
};

enum LayerType
Expand Down

0 comments on commit b093cfa

Please sign in to comment.