QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
38 connect( mActionSelect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelect_triggered );
39 connect( mActionAddToSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionAddToSelection_triggered );
40 connect( mActionRemoveFromSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered );
41 connect( mActionSelectIntersect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelectIntersect_triggered );
42 connect( mButtonZoomToFeatures, &QToolButton::clicked,
this, &QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked );
43 connect( mPbnClose, &QPushButton::clicked,
this, &QgsExpressionSelectionDialog::mPbnClose_clicked );
46 setWindowTitle( tr(
"%1 — Select by Expression" ).arg( layer->
name() ) );
53 mButtonSelect->addAction( mActionSelect );
54 mButtonSelect->addAction( mActionAddToSelection );
55 mButtonSelect->addAction( mActionRemoveFromSelection );
56 mButtonSelect->addAction( mActionSelectIntersect );
57 mButtonSelect->setDefaultAction( mActionSelect );
60 mExpressionBuilder->initWithLayer( layer, context, QStringLiteral(
"selection" ) );
61 mExpressionBuilder->setExpressionText( startText );
64 mButtonZoomToFeatures->setVisible(
false );
66 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsExpressionSelectionDialog::showHelp );
71 return mExpressionBuilder;
76 mExpressionBuilder->setExpressionText( text );
81 return mExpressionBuilder->expressionText();
87 mExpressionBuilder->setGeomCalculator( da );
92 mMessageBar = messageBar;
98 mButtonZoomToFeatures->setVisible(
true );
101 void QgsExpressionSelectionDialog::mActionSelect_triggered()
105 pushSelectedFeaturesMessage();
109 void QgsExpressionSelectionDialog::mActionAddToSelection_triggered()
113 pushSelectedFeaturesMessage();
117 void QgsExpressionSelectionDialog::mActionSelectIntersect_triggered()
121 pushSelectedFeaturesMessage();
125 void QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered()
129 pushSelectedFeaturesMessage();
133 void QgsExpressionSelectionDialog::pushSelectedFeaturesMessage()
142 tr(
"%n matching feature(s) selected",
"matching features", count ),
143 Qgis::MessageLevel::Info );
148 tr(
"No matching features found" ),
149 Qgis::MessageLevel::Info );
153 void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked()
155 if ( mExpressionBuilder->expressionText().isEmpty() || !mMapCanvas )
169 int featureCount = 0;
182 if ( featureCount > 0 )
188 tr(
"Zoomed to %n matching feature(s)",
"number of matching features", featureCount ),
189 Qgis::MessageLevel::Info );
192 else if ( mMessageBar )
195 tr(
"No matching features found" ),
196 Qgis::MessageLevel::Info );
206 void QgsExpressionSelectionDialog::mPbnClose_clicked()
217 void QgsExpressionSelectionDialog::saveRecent()
219 mExpressionBuilder->expressionTree()->saveToRecent( mExpressionBuilder->expressionText(), QStringLiteral(
"selection" ) );
222 void QgsExpressionSelectionDialog::showHelp()
224 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#automatic-selection" ) );
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
QgsExpressionSelectionDialog(QgsVectorLayer *layer, const QString &startText=QString(), QWidget *parent=nullptr)
Creates a new selection dialog.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas associated with the dialog.
Map canvas is a class for displaying all GIS data types on a canvas.
@ AddToSelection
Add selection to current selection.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
@ IntersectSelection
Modify current selection to include only select features which match.
QString expressionText()
Returns the current expression text.
A rectangle specified with double values.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
A bar for displaying non-blocking messages to the user.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
virtual bool isEmpty() const
Returns true if the geometry is empty.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void closeEvent(QCloseEvent *closeEvent) override
Implementation for closeEvent Saves the window geometry.
void zoomToFeatureExtent(QgsRectangle &rect)
Zooms to feature extent.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
void setExpressionText(const QString &text)
Sets the current expression text.
Represents a vector layer which manages a vector based data sets.
void done(int r) override
Implementation for done (default behavior when pressing esc) Calls close, so the window geometry gets...
void setMessageBar(QgsMessageBar *messageBar)
Sets the message bar to display feedback from the dialog.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
@ SetSelection
Set selection, removing any existing selection.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
@ RemoveFromSelection
Remove from current selection.
Wrapper for iterator of features from vector data provider or vector layer.
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.