Skip to content

Commit

Permalink
[FEATURE] add option to make layer with identified features active
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 23, 2013
1 parent ae39f34 commit b6344de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/qgsidentifyresultsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,10 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent* event )
mActionPopup->addAction( tr( "Highlight all" ), this, SLOT( highlightAll() ) );
mActionPopup->addAction( tr( "Highlight layer" ), this, SLOT( highlightLayer() ) );
if ( layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() )
{
mActionPopup->addAction( tr( "Activate layer" ), this, SLOT( activateLayer() ) );
mActionPopup->addAction( tr( "Layer properties..." ), this, SLOT( layerProperties() ) );
}
mActionPopup->addSeparator();
mActionPopup->addAction( tr( "Expand all" ), this, SLOT( expandAll() ) );
mActionPopup->addAction( tr( "Collapse all" ), this, SLOT( collapseAll() ) );
Expand Down Expand Up @@ -947,20 +950,27 @@ QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QTreeWidgetItem *item )
return item;
}

QgsMapLayer *QgsIdentifyResultsDialog::layer( QTreeWidgetItem *item )
{
item = layerItem( item );
if ( !item )
return 0;
return qobject_cast<QgsMapLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}

QgsVectorLayer *QgsIdentifyResultsDialog::vectorLayer( QTreeWidgetItem *item )
{
item = layerItem( item );
if ( !item )
return NULL;
return 0;
return qobject_cast<QgsVectorLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}

QgsRasterLayer *QgsIdentifyResultsDialog::rasterLayer( QTreeWidgetItem *item )
{
item = layerItem( item );
if ( !item )
return NULL;
return 0;
return qobject_cast<QgsRasterLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}

Expand Down Expand Up @@ -1280,6 +1290,13 @@ void QgsIdentifyResultsDialog::layerProperties()
layerProperties( lstResults->currentItem() );
}

void QgsIdentifyResultsDialog::activateLayer()
{
connect( this, SIGNAL( activateLayer( QgsMapLayer * ) ), QgisApp::instance(), SLOT( setActiveLayer( QgsMapLayer * ) ) );
emit activateLayer( layer( lstResults->currentItem() ) );
disconnect( this, SIGNAL( activateLayer( QgsMapLayer * ) ), QgisApp::instance(), SLOT( setActiveLayer( QgsMapLayer * ) ) );
}

void QgsIdentifyResultsDialog::layerProperties( QTreeWidgetItem *item )
{
QgsVectorLayer *vlayer = vectorLayer( item );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsidentifyresultsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti

void copyToClipboard( QgsFeatureStore& featureStore );

void activateLayer( QgsMapLayer * );

public slots:
/** Remove results */
void clear();
Expand All @@ -156,6 +158,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
void copyGetFeatureInfoUrl();
void highlightAll();
void highlightLayer();
void activateLayer();
void layerProperties();
void clearHighlights();
void expandAll();
Expand Down Expand Up @@ -196,6 +199,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QgsMapCanvas *mCanvas;
QList<QgsFeature> mFeatures;

QgsMapLayer *layer( QTreeWidgetItem *item );
QgsVectorLayer *vectorLayer( QTreeWidgetItem *item );
QgsRasterLayer *rasterLayer( QTreeWidgetItem *item );
QTreeWidgetItem *featureItem( QTreeWidgetItem *item );
Expand Down

0 comments on commit b6344de

Please sign in to comment.