Skip to content

Commit

Permalink
Added identify mode for identify tool
Browse files Browse the repository at this point in the history
Identification all features on all layers from Top to bottom down layers (TopDownAll) or only first non-empty list going from top to down layers.
  • Loading branch information
viktor.sklencar@lutraconsulting.co.uk authored and wonder-sk committed Aug 20, 2018
1 parent 683df59 commit 5f5499d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/quickgui/qgsquickidentifykit.cpp
Expand Up @@ -86,6 +86,12 @@ QgsQuickFeatureLayerPairs QgsQuickIdentifyKit::identify( const QPointF &point, Q
results.append( QgsQuickFeatureLayerPair( feature, vl ) );
}
}
if ( mIdentifyMode == IdentifyMode::TopDownStopAtFirst && !results.isEmpty() )
{
QgsDebugMsg( QStringLiteral( "IdentifyKit identified %1 results with TopDownStopAtFirst mode." ).arg( results.count() ) );
return results;
}

}

QgsDebugMsg( QStringLiteral( "IdentifyKit identified %1 results" ).arg( results.count() ) );
Expand Down
43 changes: 39 additions & 4 deletions src/quickgui/qgsquickidentifykit.h
Expand Up @@ -66,7 +66,35 @@ class QUICK_EXPORT QgsQuickIdentifyKit : public QObject
*/
Q_PROPERTY( int featuresLimit READ featuresLimit WRITE setFeaturesLimit NOTIFY featuresLimitChanged )

/**
* Defines behavior of the identify tool (See description of IdentifyMode enum).
*
* Default is TopDownAll.
*/
Q_PROPERTY( IdentifyMode identifyMode MEMBER mIdentifyMode NOTIFY identifyModeChanged )

public:

/**
* IdentifyMode enums used to define identify tool behavior on identifiable layers.
*/
enum IdentifyMode
{

/**
* Identification is performed from top to bottom down layers returning all
* identified features;
*/
TopDownAll = 0,

/**
* Identification is performed from top to bottom down layers and stops on the first layer
* returning non-empty list of identified features. Identification on rest layers is skipped.
*/
TopDownStopAtFirst
};
Q_ENUM( IdentifyMode )

//! Constructor of new identify kit.
explicit QgsQuickIdentifyKit( QObject *parent = nullptr );

Expand All @@ -91,8 +119,10 @@ class QUICK_EXPORT QgsQuickIdentifyKit : public QObject
/**
* Gets the closest feature to the point within the search radius
*
* If layer is nullptr, identifies the closest feature from all identifiable layers
* If layer is not nullptr, identifies the closest feature from given layer
* If layer is nullptr, identifies the closest feature from either
* all identifiable layers (IdentifyMode::TopDownAll) or the first layer from top to bottom layers
* with non-empty identified feature list (IdentifyMode::TopDownStopAtFirst)
* If layer is not nullptr, identifies the closest feature from given layer regardless identify mode.
*
* To modify search radius, use QgsQuickIdentifyKit::searchRadiusMm
*
Expand All @@ -104,8 +134,10 @@ class QUICK_EXPORT QgsQuickIdentifyKit : public QObject
/**
* Gets all features in the search radius
*
* If layer is nullptr, identifies features from all identifiable layers
* If layer is not nullptr, identifies only features from given layer
* If layer is nullptr, identifies features from either
* all identifiable layers (IdentifyMode::TopDownAll) or the first layer from top to bottom layers
* with non-empty identified feature list (IdentifyMode::TopDownStopAtFirst)
* If layer is not nullptr, identifies only features from given layer regardless identify mode.
*
* To limit number of results, use QgsQuickIdentifyKit::featuresLimit
* To modify search radius, use QgsQuickIdentifyKit::searchRadiusMm
Expand All @@ -122,6 +154,8 @@ class QUICK_EXPORT QgsQuickIdentifyKit : public QObject
void searchRadiusMmChanged();
//! \copydoc QgsQuickIdentifyKit::featuresLimit
void featuresLimitChanged();
//! \copydoc QgsQuickIdentifyKit::identifyMode
void identifyModeChanged();

private:
QgsQuickMapSettings *mMapSettings = nullptr; // not owned
Expand All @@ -134,6 +168,7 @@ class QUICK_EXPORT QgsQuickIdentifyKit : public QObject

double mSearchRadiusMm = 8;
int mFeaturesLimit = 100;
IdentifyMode mIdentifyMode = IdentifyMode::TopDownAll;
};

#endif // QGSQUICKIDENTIFYKIT_H

0 comments on commit 5f5499d

Please sign in to comment.