Skip to content

Commit

Permalink
[quick] add utility method to select feature using their IDs from QML (
Browse files Browse the repository at this point in the history
…#32735)

* [quick] add utility method to select feature using their IDs from QML

* Update qgsquickutils.cpp
  • Loading branch information
3nids committed Nov 20, 2019
1 parent 129165a commit f1e6745
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/quickgui/qgsquickutils.cpp
Expand Up @@ -375,6 +375,14 @@ QString QgsQuickUtils::evaluateExpression( const QgsQuickFeatureLayerPair &pair,
return expr.evaluate( &context ).toString();
}

void QgsQuickUtils::selectFeaturesInLayer( QgsVectorLayer *layer, const QList<int> &fids, QgsVectorLayer::SelectBehavior behavior )
{
QgsFeatureIds qgsFids;
for ( const int &fid : fids )
qgsFids << fid;
layer->selectByIds( qgsFids, behavior );
}

qreal QgsQuickUtils::screenDensity() const
{
return mScreenDensity;
Expand Down
11 changes: 11 additions & 0 deletions src/quickgui/qgsquickutils.h
Expand Up @@ -253,6 +253,17 @@ class QUICK_EXPORT QgsQuickUtils: public QObject
*/
Q_INVOKABLE static QString evaluateExpression( const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression );

/**
* Selects features in a layer
* This method is required since QML cannot perform the conversion of a feature ID to a QgsFeatureId (i.e. a qint64)
* \param layer the vector layer
* \param fids the list of feature IDs
* \param behavior the selection behavior
*
* \since QGIS 3.12
*/
Q_INVOKABLE static void selectFeaturesInLayer( QgsVectorLayer *layer, const QList<int> &fids, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );

private:
static void formatToMetricDistance( double srcDistance,
QgsUnitTypes::DistanceUnit srcUnits,
Expand Down

0 comments on commit f1e6745

Please sign in to comment.