QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsextentwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsextentwidget.h
3  ---------------------
4  begin : March 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSEXTENTWIDGET_H
17 #define QGSEXTENTWIDGET_H
18 
19 #include "qgscollapsiblegroupbox.h"
20 #include "qgsmaptool.h"
21 #include "qgsmaptoolextent.h"
22 #include "qgis_sip.h"
23 
24 #include "ui_qgsextentgroupboxwidget.h"
25 
27 #include "qgsrectangle.h"
28 #include "qgis_gui.h"
29 
30 #include <memory>
31 #include <QRegularExpression>
32 
36 class QgsMapLayer;
37 
51 class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBoxWidget
52 {
53  Q_OBJECT
54 
55  public:
56 
59  {
65  };
66 
69  {
72  };
73 
77  explicit QgsExtentWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, WidgetStyle style = CondensedStyle );
78 
79  ~QgsExtentWidget() override;
80 
86  void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
87 
93  QgsRectangle originalExtent() const { return mOriginalExtent; }
94 
100  QgsCoordinateReferenceSystem originalCrs() const { return mOriginalCrs; }
101 
108  void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
109 
116  QgsRectangle currentExtent() const { return mCurrentExtent; }
117 
124  QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
125 
131  void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
132 
137  QgsRectangle outputExtent() const;
138 
143  QgsCoordinateReferenceSystem outputCrs() const { return mOutputCrs; }
144 
148  QgsExtentWidget::ExtentState extentState() const { return mExtentState; }
149 
155  void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
156 
161  QSize ratio() const { return mRatio; }
162 
166  QString extentLayerName() const;
167 
171  bool isValid() const;
172 
180  void setNullValueAllowed( bool allowed, const QString &notSetText = QString() );
181 
182  public slots:
183 
187  void setOutputExtentFromOriginal();
188 
192  void setOutputExtentFromCurrent();
193 
197  void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
198 
202  void setOutputExtentFromLayer( const QgsMapLayer *layer );
203 
207  void setOutputExtentFromDrawOnCanvas();
208 
214  void setRatio( QSize ratio ) { mRatio = ratio; }
215 
219  void clear();
220 
221  signals:
222 
226  void extentChanged( const QgsRectangle &r );
227 
231  void validationChanged( bool valid );
232 
237  void toggleDialogVisibility( bool visible );
238 
239  protected:
240 
241  void dragEnterEvent( QDragEnterEvent *event ) override;
242  void dragLeaveEvent( QDragLeaveEvent *event ) override;
243  void dropEvent( QDropEvent *event ) override;
244 
245  private slots:
246 
247  void layerMenuAboutToShow();
248  void layoutMenuAboutToShow();
249  void bookmarkMenuAboutToShow();
250 
251  void extentDrawn( const QgsRectangle &extent );
252  void mapToolDeactivated();
253 
254  private:
255  void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
256  void setOutputExtentFromLineEdit();
257  void setOutputExtentFromCondensedLineEdit();
258 
259  ExtentState mExtentState = OriginalExtent;
260 
261  QgsCoordinateReferenceSystem mOutputCrs;
262 
263  QgsRectangle mCurrentExtent;
264  QgsCoordinateReferenceSystem mCurrentCrs;
265 
266  QgsRectangle mOriginalExtent;
267  QgsCoordinateReferenceSystem mOriginalCrs;
268 
269  QMenu *mMenu = nullptr;
270 
271  QMenu *mLayerMenu = nullptr;
272  QMenu *mLayoutMenu = nullptr;
273  QMenu *mBookmarkMenu = nullptr;
274 
275  QgsMapLayerProxyModel *mMapLayerModel = nullptr;
276  QgsBookmarkManagerProxyModel *mBookmarkModel = nullptr;
277 
278  QList< QAction * > mLayerMenuActions;
279  QAction *mUseCanvasExtentAction = nullptr;
280  QAction *mUseCurrentExtentAction = nullptr;
281  QAction *mDrawOnCanvasAction = nullptr;
282 
283  QPointer< const QgsMapLayer > mExtentLayer;
284  QString mExtentLayerName;
285 
286  std::unique_ptr< QgsMapToolExtent > mMapToolExtent;
287  QPointer< QgsMapTool > mMapToolPrevious = nullptr;
288  QgsMapCanvas *mCanvas = nullptr;
289  QSize mRatio;
290 
291  bool mIsValid = false;
292  bool mHasFixedOutputCrs = false;
293 
294  QRegularExpression mCondensedRe;
295  void setValid( bool valid );
296 
297  void setExtentToLayerExtent( const QString &layerId );
298 
299  QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
300 
301  friend class TestProcessingGui;
302 
303 
304 };
305 
306 #endif // QGSEXTENTWIDGET_H
QgsExtentWidget::currentCrs
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
Definition: qgsextentwidget.h:124
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:115
qgscollapsiblegroupbox.h
QgsExtentWidget::originalCrs
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
Definition: qgsextentwidget.h:100
QgsExtentWidget::CurrentExtent
@ CurrentExtent
Map canvas extent.
Definition: qgsextentwidget.h:61
QgsExtentWidget::DrawOnCanvas
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
Definition: qgsextentwidget.h:64
qgsrectangle.h
QgsExtentWidget::OriginalExtent
@ OriginalExtent
Layer's extent.
Definition: qgsextentwidget.h:60
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsExtentWidget::ratio
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:161
QgsExtentWidget::extentState
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
Definition: qgsextentwidget.h:148
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsExtentWidget::ExtentState
ExtentState
Available states for the current extent selection in the widget.
Definition: qgsextentwidget.h:58
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsExtentWidget::UserExtent
@ UserExtent
Extent manually entered/modified by the user.
Definition: qgsextentwidget.h:62
QgsExtentWidget::CondensedStyle
@ CondensedStyle
Shows a compressed widget, for use when available space is minimal.
Definition: qgsextentwidget.h:70
QgsExtentWidget::outputCrs
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
Definition: qgsextentwidget.h:143
QgsMapLayerProxyModel
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
Definition: qgsmaplayerproxymodel.h:34
QgsExtentWidget::ExpandedStyle
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
Definition: qgsextentwidget.h:71
qgsmaptool.h
qgis_sip.h
QgsExtentWidget::WidgetStyle
WidgetStyle
Widget styles.
Definition: qgsextentwidget.h:68
QgsExtentWidget
A widget for configuration of a map extent.
Definition: qgsextentwidget.h:51
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsExtentWidget::setRatio
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:214
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
qgsmaptoolextent.h
QgsExtentWidget::originalExtent
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
Definition: qgsextentwidget.h:93
QgsExtentWidget::currentExtent
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
Definition: qgsextentwidget.h:116
QgsBookmarkManagerProxyModel
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
Definition: qgsbookmarkmodel.h:108
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
QgsExtentWidget::ProjectLayerExtent
@ ProjectLayerExtent
Extent taken from a layer within the project.
Definition: qgsextentwidget.h:63