Skip to content

Commit

Permalink
[FEATURE] toggle feature selection from identify results (implements #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 20, 2014
1 parent 986ffd6 commit 45cd895
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -944,6 +944,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent* event )
{
mActionPopup->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToFeature() ) );
mActionPopup->addAction( tr( "Copy feature" ), this, SLOT( copyFeature() ) );
mActionPopup->addAction( tr( "Toggle feature selection" ), this, SLOT( toggleFeatureSelection() ) );
}

mActionPopup->addAction( tr( "Copy attribute value" ), this, SLOT( copyAttributeValue() ) );
Expand Down Expand Up @@ -1786,6 +1787,28 @@ void QgsIdentifyResultsDialog::copyFeature()
emit copyToClipboard( featureStore );
}

void QgsIdentifyResultsDialog::toggleFeatureSelection()
{
QgsDebugMsg( "Entered" );

QgsIdentifyResultsFeatureItem *item = dynamic_cast<QgsIdentifyResultsFeatureItem *>( featureItem( lstResults->selectedItems().value( 0 ) ) );

if ( !item ) // should not happen
{
QgsDebugMsg( "Selected item is not feature" );
return;
}

QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( layer( item ) );
if ( !vl )
return;

if ( vl->selectedFeaturesIds().contains( item->feature().id() ) )
vl->deselect( item->feature().id() );
else
vl->select( item->feature().id() );
}

void QgsIdentifyResultsDialog::formatChanged( int index )
{
QgsDebugMsg( "Entered" );
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsidentifyresultsdialog.h
Expand Up @@ -66,9 +66,9 @@ class APP_EXPORT QgsIdentifyResultsFeatureItem: public QTreeWidgetItem
{
public:
QgsIdentifyResultsFeatureItem( const QgsFields &fields, const QgsFeature &feature, const QgsCoordinateReferenceSystem &crs, const QStringList & strings = QStringList() );
QgsFields fields() const { return mFields; }
QgsFeature feature() const { return mFeature; }
QgsCoordinateReferenceSystem crs() { return mCrs; }
const QgsFields &fields() const { return mFields; }
const QgsFeature &feature() const { return mFeature; }
const QgsCoordinateReferenceSystem &crs() { return mCrs; }

private:
QgsFields mFields;
Expand Down Expand Up @@ -169,6 +169,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
void zoomToFeature();
void copyAttributeValue();
void copyFeature();
void toggleFeatureSelection();
void copyFeatureAttributes();
void copyGetFeatureInfoUrl();
void highlightAll();
Expand Down

0 comments on commit 45cd895

Please sign in to comment.