28#include "moc_qgsexpressionselectiondialog.cpp"
39 connect( mActionSelect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelect_triggered );
40 connect( mActionAddToSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionAddToSelection_triggered );
41 connect( mActionRemoveFromSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered );
42 connect( mActionSelectIntersect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelectIntersect_triggered );
43 connect( mButtonZoomToFeatures, &QToolButton::clicked,
this, &QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked );
44 connect( mPbnClose, &QPushButton::clicked,
this, &QgsExpressionSelectionDialog::mPbnClose_clicked );
47 setWindowTitle( tr(
"%1 — Select by Expression" ).arg( layer->
name() ) );
54 mButtonSelect->addAction( mActionSelect );
55 mButtonSelect->addAction( mActionAddToSelection );
56 mButtonSelect->addAction( mActionRemoveFromSelection );
57 mButtonSelect->addAction( mActionSelectIntersect );
58 mButtonSelect->setDefaultAction( mActionSelect );
61 mExpressionBuilder->initWithLayer( layer, context, QStringLiteral(
"selection" ) );
62 mExpressionBuilder->setExpressionText( startText );
65 mButtonZoomToFeatures->setVisible(
false );
67 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsExpressionSelectionDialog::showHelp );
72 return mExpressionBuilder;
82 return mExpressionBuilder->expressionText();
88 mExpressionBuilder->setGeomCalculator( da );
93 mMessageBar = messageBar;
99 mButtonZoomToFeatures->setVisible(
true );
102void QgsExpressionSelectionDialog::mActionSelect_triggered()
105 pushSelectedFeaturesMessage();
109void QgsExpressionSelectionDialog::mActionAddToSelection_triggered()
112 pushSelectedFeaturesMessage();
116void QgsExpressionSelectionDialog::mActionSelectIntersect_triggered()
119 pushSelectedFeaturesMessage();
123void QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered()
126 pushSelectedFeaturesMessage();
130void QgsExpressionSelectionDialog::pushSelectedFeaturesMessage()
135 const int count = mLayer->selectedFeatureCount();
138 mMessageBar->pushMessage( QString(), tr(
"%n matching feature(s) selected",
"matching features", count ),
Qgis::MessageLevel::Info );
146void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked()
148 if ( mExpressionBuilder->expressionText().isEmpty() || !mMapCanvas )
153 const QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( mExpressionBuilder->expressionText() ).setExpressionContext( context ).setNoAttributes();
155 QgsFeatureIterator features = mLayer->getFeatures( request );
160 int featureCount = 0;
163 const QgsGeometry geom = feat.
geometry();
167 const QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.
boundingBox() );
173 if ( featureCount > 0 )
175 mMapCanvas->zoomToFeatureExtent( bbox );
178 mMessageBar->pushMessage( QString(), tr(
"Zoomed to %n matching feature(s)",
"number of matching features", featureCount ),
Qgis::MessageLevel::Info );
181 else if ( mMessageBar )
193void QgsExpressionSelectionDialog::mPbnClose_clicked()
204void QgsExpressionSelectionDialog::saveRecent()
206 mExpressionBuilder->expressionTree()->saveToRecent( mExpressionBuilder->expressionText(), QStringLiteral(
"selection" ) );
209void QgsExpressionSelectionDialog::showHelp()
211 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#automatic-selection" ) );
@ Info
Information message.
@ SetSelection
Set selection, removing any existing selection.
@ AddToSelection
Add selection to current selection.
@ IntersectSelection
Modify current selection to include only select features which match.
@ RemoveFromSelection
Remove from current selection.
virtual bool isEmpty() const
Returns true if the geometry is empty.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionBuilderWidget * expressionBuilder()
The builder widget that is used by the dialog.
QString expressionText()
Returns the current expression text.
void closeEvent(QCloseEvent *closeEvent) override
Implementation for closeEvent Saves the window geometry.
void setExpressionText(const QString &text)
Sets the current expression text.
QgsExpressionSelectionDialog(QgsVectorLayer *layer, const QString &startText=QString(), QWidget *parent=nullptr)
Creates a new selection dialog.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas associated with the dialog.
void setMessageBar(QgsMessageBar *messageBar)
Sets the message bar to display feedback from the dialog.
void setGeomCalculator(const QgsDistanceArea &da)
Sets geometry calculator used in distance/area calculations.
void done(int r) override
Implementation for done (default behavior when pressing esc) Calls close, so the window geometry gets...
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
bool close()
Call to end the iteration.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
A bar for displaying non-blocking messages to the user.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.