37 connect( mActionSelect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelect_triggered );
38 connect( mActionAddToSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionAddToSelection_triggered );
39 connect( mActionRemoveFromSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered );
40 connect( mActionSelectIntersect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelectIntersect_triggered );
41 connect( mButtonZoomToFeatures, &QToolButton::clicked,
this, &QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked );
42 connect( mPbnClose, &QPushButton::clicked,
this, &QgsExpressionSelectionDialog::mPbnClose_clicked );
44 setWindowTitle( QStringLiteral(
"Select by Expression - %1" ).arg( layer->
name() ) );
51 mButtonSelect->addAction( mActionSelect );
52 mButtonSelect->addAction( mActionAddToSelection );
53 mButtonSelect->addAction( mActionRemoveFromSelection );
54 mButtonSelect->addAction( mActionSelectIntersect );
55 mButtonSelect->setDefaultAction( mActionSelect );
57 mExpressionBuilder->setLayer( layer );
58 mExpressionBuilder->setExpressionText( startText );
59 mExpressionBuilder->loadFieldNames();
60 mExpressionBuilder->loadRecent( QStringLiteral(
"Selection" ) );
63 mExpressionBuilder->setExpressionContext( context );
66 mButtonZoomToFeatures->setVisible(
false );
68 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsExpressionSelectionDialog::showHelp );
73 return mExpressionBuilder;
78 mExpressionBuilder->setExpressionText( text );
83 return mExpressionBuilder->expressionText();
89 mExpressionBuilder->setGeomCalculator( da );
94 mMessageBar = messageBar;
100 mButtonZoomToFeatures->setVisible(
true );
103 void QgsExpressionSelectionDialog::mActionSelect_triggered()
107 pushSelectedFeaturesMessage();
111 void QgsExpressionSelectionDialog::mActionAddToSelection_triggered()
115 pushSelectedFeaturesMessage();
119 void QgsExpressionSelectionDialog::mActionSelectIntersect_triggered()
123 pushSelectedFeaturesMessage();
127 void QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered()
131 pushSelectedFeaturesMessage();
135 void QgsExpressionSelectionDialog::pushSelectedFeaturesMessage()
140 const int timeout =
QgsSettings().
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
145 tr(
"%1 matching %2 selected" ).arg( count )
146 .arg( count == 1 ? tr(
"feature" ) : tr(
"features" ) ),
152 tr(
"No matching features found" ),
157 void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked()
159 if ( mExpressionBuilder->expressionText().isEmpty() || !mMapCanvas )
165 .setExpressionContext( context )
173 int featureCount = 0;
187 int timeout = settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
188 if ( featureCount > 0 )
194 tr(
"Zoomed to %n matching feature(s)",
"number of matching features", featureCount ),
199 else if ( mMessageBar )
202 tr(
"No matching features found" ),
211 QDialog::closeEvent( closeEvent );
214 void QgsExpressionSelectionDialog::mPbnClose_clicked()
225 void QgsExpressionSelectionDialog::saveRecent()
227 mExpressionBuilder->saveToRecent( QStringLiteral(
"Selection" ) );
230 void QgsExpressionSelectionDialog::showHelp()
232 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#automatic-selection" ) );
Wrapper for iterator of features from vector data provider or vector layer.
virtual bool isEmpty() const
Returns true if the geometry is empty.
A rectangle specified with double values.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
This class is a composition of two QSettings instances:
QString expressionText()
Returns the current expression text.
void zoomToFeatureExtent(QgsRectangle &rect)
Zooms to feature extent.
Remove from current selection.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
A bar for displaying non-blocking messages to the user.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsExpressionSelectionDialog(QgsVectorLayer *layer, const QString &startText=QString(), QWidget *parent=nullptr)
Creates a new selection dialog.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void closeEvent(QCloseEvent *closeEvent) override
Implementation for closeEvent Saves the window geometry.
void done(int r) override
Implementation for done (default behavior when pressing esc) Calls close, so the window geometry gets...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setMessageBar(QgsMessageBar *messageBar)
Sets the message bar to display feedback from the dialog.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
Add selection to current selection.
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
void setExpressionText(const QString &text)
Sets the current expression text.
Set selection, removing any existing selection.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
Modify current selection to include only select features which match.
void selectByExpression(const QString &expression, SelectBehavior behavior=SetSelection)
Select matching features using an expression.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas associated with the dialog.