Skip to content

Commit 45cd895

Browse files
committedMay 20, 2014
[FEATURE] toggle feature selection from identify results (implements #10308)
1 parent 986ffd6 commit 45cd895

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
 

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent* event )
944944
{
945945
mActionPopup->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToFeature() ) );
946946
mActionPopup->addAction( tr( "Copy feature" ), this, SLOT( copyFeature() ) );
947+
mActionPopup->addAction( tr( "Toggle feature selection" ), this, SLOT( toggleFeatureSelection() ) );
947948
}
948949

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

1790+
void QgsIdentifyResultsDialog::toggleFeatureSelection()
1791+
{
1792+
QgsDebugMsg( "Entered" );
1793+
1794+
QgsIdentifyResultsFeatureItem *item = dynamic_cast<QgsIdentifyResultsFeatureItem *>( featureItem( lstResults->selectedItems().value( 0 ) ) );
1795+
1796+
if ( !item ) // should not happen
1797+
{
1798+
QgsDebugMsg( "Selected item is not feature" );
1799+
return;
1800+
}
1801+
1802+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( layer( item ) );
1803+
if ( !vl )
1804+
return;
1805+
1806+
if ( vl->selectedFeaturesIds().contains( item->feature().id() ) )
1807+
vl->deselect( item->feature().id() );
1808+
else
1809+
vl->select( item->feature().id() );
1810+
}
1811+
17891812
void QgsIdentifyResultsDialog::formatChanged( int index )
17901813
{
17911814
QgsDebugMsg( "Entered" );

‎src/app/qgsidentifyresultsdialog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class APP_EXPORT QgsIdentifyResultsFeatureItem: public QTreeWidgetItem
6666
{
6767
public:
6868
QgsIdentifyResultsFeatureItem( const QgsFields &fields, const QgsFeature &feature, const QgsCoordinateReferenceSystem &crs, const QStringList & strings = QStringList() );
69-
QgsFields fields() const { return mFields; }
70-
QgsFeature feature() const { return mFeature; }
71-
QgsCoordinateReferenceSystem crs() { return mCrs; }
69+
const QgsFields &fields() const { return mFields; }
70+
const QgsFeature &feature() const { return mFeature; }
71+
const QgsCoordinateReferenceSystem &crs() { return mCrs; }
7272

7373
private:
7474
QgsFields mFields;
@@ -169,6 +169,7 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
169169
void zoomToFeature();
170170
void copyAttributeValue();
171171
void copyFeature();
172+
void toggleFeatureSelection();
172173
void copyFeatureAttributes();
173174
void copyGetFeatureInfoUrl();
174175
void highlightAll();

0 commit comments

Comments
 (0)
Please sign in to comment.