30#include "moc_qgsexpressionselectiondialog.cpp"
32using namespace Qt::StringLiterals;
43 connect( mActionSelect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelect_triggered );
44 connect( mActionAddToSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionAddToSelection_triggered );
45 connect( mActionRemoveFromSelection, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered );
46 connect( mActionSelectIntersect, &QAction::triggered,
this, &QgsExpressionSelectionDialog::mActionSelectIntersect_triggered );
47 connect( mButtonZoomToFeatures, &QToolButton::clicked,
this, &QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked );
48 connect( mPbnClose, &QPushButton::clicked,
this, &QgsExpressionSelectionDialog::mPbnClose_clicked );
51 setWindowTitle( tr(
"%1 — Select by Expression" ).arg( layer->
name() ) );
58 mButtonSelect->addAction( mActionSelect );
59 mButtonSelect->addAction( mActionAddToSelection );
60 mButtonSelect->addAction( mActionRemoveFromSelection );
61 mButtonSelect->addAction( mActionSelectIntersect );
62 mButtonSelect->setDefaultAction( mActionSelect );
65 mExpressionBuilder->initWithLayer( layer, context, u
"selection"_s );
66 mExpressionBuilder->setExpressionText( startText );
69 mButtonZoomToFeatures->setVisible(
false );
71 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsExpressionSelectionDialog::showHelp );
76 return mExpressionBuilder;
86 return mExpressionBuilder->expressionText();
92 mExpressionBuilder->setGeomCalculator( da );
97 mMessageBar = messageBar;
103 mButtonZoomToFeatures->setVisible(
true );
106void QgsExpressionSelectionDialog::mActionSelect_triggered()
109 pushSelectedFeaturesMessage();
113void QgsExpressionSelectionDialog::mActionAddToSelection_triggered()
116 pushSelectedFeaturesMessage();
120void QgsExpressionSelectionDialog::mActionSelectIntersect_triggered()
123 pushSelectedFeaturesMessage();
127void QgsExpressionSelectionDialog::mActionRemoveFromSelection_triggered()
130 pushSelectedFeaturesMessage();
134void QgsExpressionSelectionDialog::pushSelectedFeaturesMessage()
139 const int count = mLayer->selectedFeatureCount();
142 mMessageBar->pushMessage( QString(), tr(
"%n matching feature(s) selected",
"matching features", count ),
Qgis::MessageLevel::Info );
150void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked()
152 if ( mExpressionBuilder->expressionText().isEmpty() || !mMapCanvas )
157 const QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( mExpressionBuilder->expressionText() ).setExpressionContext( context ).setNoAttributes();
159 QgsFeatureIterator features = mLayer->getFeatures( request );
164 int featureCount = 0;
167 const QgsGeometry geom = feat.
geometry();
171 const QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.
boundingBox() );
177 if ( featureCount > 0 )
179 mMapCanvas->zoomToFeatureExtent( bbox );
182 mMessageBar->pushMessage( QString(), tr(
"Zoomed to %n matching feature(s)",
"number of matching features", featureCount ),
Qgis::MessageLevel::Info );
185 else if ( mMessageBar )
197void QgsExpressionSelectionDialog::mPbnClose_clicked()
208void QgsExpressionSelectionDialog::saveRecent()
210 mExpressionBuilder->expressionTree()->saveToRecent( mExpressionBuilder->expressionText(), u
"selection"_s );
213void QgsExpressionSelectionDialog::showHelp()
@ 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.