[quick] add utility method to select feature using their IDs from QML (#32735)

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

* Update qgsquickutils.cpp
This commit is contained in:
Denis Rouzaud 2019-11-20 08:07:09 +01:00 committed by GitHub
parent 129165a100
commit f1e6745fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -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,