QGIS API Documentation 4.1.0-Master (4aad578bf8d)
Loading...
Searching...
No Matches
qgsmaptoolselectutils.h
Go to the documentation of this file.
1/***************************************************************************
2qgsmaptoolselectutils.h - Utility methods to help with select map tools
3---------------------
4begin : May 2010
5copyright : (C) 2010 by Jeremy Palmer
6email : jpalmer at linz dot govt dot nz
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
16#ifndef QGSMAPTOOLSELECTUTILS_H
17#define QGSMAPTOOLSELECTUTILS_H
18
19#include "qgis.h"
20#include "qgis_gui.h"
22#include "qgsrendercontext.h"
23#include "qgsvectorlayer.h"
24
25#include <QFutureWatcher>
26#include <QList>
27#include <QPoint>
28#include <QRect>
29
30#define SIP_NO_FILE
31
32class QMouseEvent;
33class QgsMapCanvas;
34class QgsVectorLayer;
36class QgsGeometry;
37class QgsRubberBand;
38class QMenu;
39class QgsHighlight;
40
48{
49
61 QgsFeatureIds getMatchingFeatures( QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, bool doContains, bool singleSelect );
62
75 QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qgis::SelectBehavior selectBehavior = Qgis::SelectBehavior::SetSelection, bool doContains = true, bool singleSelect = false
76 );
77
88 void selectMultipleFeatures( QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qt::KeyboardModifiers modifiers );
89
100 void selectSingleFeature( QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qt::KeyboardModifiers modifiers );
101
107
115 QgsRectangle GUI_EXPORT expandSelectRectangle( QgsPointXY mapPoint, QgsMapCanvas *canvas, QgsMapLayer *layer );
116
123 void GUI_EXPORT setRubberBand( QgsMapCanvas *canvas, QRect &selectRect, QgsRubberBand *rubberBand );
124
130 class QgsMapToolSelectMenuActions : public QObject
131 {
132 Q_OBJECT
133 public:
142 QgsMapToolSelectMenuActions( QgsMapCanvas *canvas, QgsVectorLayer *vectorLayer, Qgis::SelectBehavior behavior, const QgsGeometry &selectionGeometry, QObject *parent = nullptr );
143
145
150 void populateMenu( QMenu *menu );
151
152 private slots:
153 void chooseAllCandidateFeature();
154 void highlightAllFeatures();
155 void onLayerDestroyed();
156 void removeHighlight();
157 void onSearchFinished();
158
159 private:
160 QgsMapCanvas *mCanvas = nullptr;
161 QgsVectorLayer *mVectorLayer = nullptr;
163 QgsGeometry mSelectGeometry;
164 QAction *mActionChooseAll = nullptr;
165 QMenu *mMenuChooseOne = nullptr;
166 QFutureWatcher<QgsFeatureIds> *mFutureWatcher = nullptr;
167 QgsFeatureIds mAllFeatureIds;
168 QList<QgsHighlight *> mHighlight;
169
170 void startFeatureSearch();
171
172 QString textForChooseAll( qint64 featureCount = -1 ) const;
173 QString textForChooseOneMenu() const;
174 void populateChooseOneMenu( const QgsFeatureIds &ids );
175
176 static QgsFeatureIds filterIds( const QgsFeatureIds &ids, const QgsFeatureIds &existingSelection, Qgis::SelectBehavior behavior );
177
178 struct DataForSearchingJob
179 {
180 bool isCanceled;
181 std::unique_ptr<QgsVectorLayerFeatureSource> source;
182 QgsGeometry selectGeometry;
184 QgsRenderContext context;
185 std::unique_ptr<QgsFeatureRenderer> featureRenderer;
186 QString filterString;
187 Qgis::SelectBehavior selectBehavior;
188 QgsFeatureIds existingSelection;
189 };
190
191 std::shared_ptr<DataForSearchingJob> mJobData;
192
193 static QgsFeatureIds search( std::shared_ptr<DataForSearchingJob> data );
194
195 void chooseOneCandidateFeature( QgsFeatureId id );
196 void highlightOneFeature( QgsFeatureId id );
197 };
198} // namespace QgsMapToolSelectUtils
199
200#endif
SelectBehavior
Specifies how a selection should be applied.
Definition qgis.h:1891
@ SetSelection
Set selection, removing any existing selection.
Definition qgis.h:1892
Handles coordinate transforms between two coordinate systems.
A geometry is the spatial representation of a feature.
Highlights features on the map.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:83
void populateMenu(QMenu *menu)
Populates the menu with "All Feature" action and a empty menu that could contain later the "One Featu...
QgsMapToolSelectMenuActions(QgsMapCanvas *canvas, QgsVectorLayer *vectorLayer, Qgis::SelectBehavior behavior, const QgsGeometry &selectionGeometry, QObject *parent=nullptr)
Constructor.
Represents a 2D point.
Definition qgspointxy.h:62
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Responsible for drawing transient features (e.g.
Partial snapshot of vector layer's state (only the members necessary for access to features).
Represents a vector layer which manages a vector based dataset.
The QgsMapToolSelectUtils namespace containing methods which are useful for the select maptool widget...
void selectSingleFeature(QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qt::KeyboardModifiers modifiers)
Selects a single feature from within currently selected layer.
QgsFeatureIds getMatchingFeatures(QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, bool doContains, bool singleSelect)
Calculates a list of features matching a selection geometry and flags.
void selectMultipleFeatures(QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qt::KeyboardModifiers modifiers)
Selects multiple matching features from within currently selected layer.
QgsMapLayer * getCurrentTargetLayer(QgsMapCanvas *canvas)
Get the current selected canvas map layer.
QgsRectangle GUI_EXPORT expandSelectRectangle(QgsPointXY mapPoint, QgsMapCanvas *canvas, QgsMapLayer *layer)
Expands a point to a rectangle with minimum size for selection based on the layer.
void GUI_EXPORT setRubberBand(QgsMapCanvas *canvas, QRect &selectRect, QgsRubberBand *rubberBand)
Sets a QgsRubberband to rectangle in map units using a rectangle defined in device coords.
void setSelectedFeatures(QgsMapCanvas *canvas, const QgsGeometry &selectGeometry, Qgis::SelectBehavior selectBehavior=Qgis::SelectBehavior::SetSelection, bool doContains=true, bool singleSelect=false)
Selects the features within currently selected layer.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features