QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
34 class QgsMapLayerModel;
35 class QgsMapLayer;
36 
50 class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBoxWidget
51 {
52  Q_OBJECT
53 
54  public:
55 
58  {
64  };
65 
68  {
71  };
72 
76  explicit QgsExtentWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, WidgetStyle style = CondensedStyle );
77 
83  void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
84 
90  QgsRectangle originalExtent() const { return mOriginalExtent; }
91 
97  QgsCoordinateReferenceSystem originalCrs() const { return mOriginalCrs; }
98 
105  void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
106 
113  QgsRectangle currentExtent() const { return mCurrentExtent; }
114 
121  QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
122 
128  void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
129 
134  QgsRectangle outputExtent() const;
135 
140  QgsCoordinateReferenceSystem outputCrs() const { return mOutputCrs; }
141 
145  QgsExtentWidget::ExtentState extentState() const { return mExtentState; }
146 
151  void setMapCanvas( QgsMapCanvas *canvas );
152 
157  QSize ratio() const { return mRatio; }
158 
162  QString extentLayerName() const;
163 
167  bool isValid() const;
168 
176  void setNullValueAllowed( bool allowed, const QString &notSetText = QString() );
177 
178  public slots:
179 
183  void setOutputExtentFromOriginal();
184 
188  void setOutputExtentFromCurrent();
189 
193  void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
194 
198  void setOutputExtentFromLayer( const QgsMapLayer *layer );
199 
203  void setOutputExtentFromDrawOnCanvas();
204 
210  void setRatio( QSize ratio ) { mRatio = ratio; }
211 
215  void clear();
216 
217  signals:
218 
222  void extentChanged( const QgsRectangle &r );
223 
227  void validationChanged( bool valid );
228 
233  void toggleDialogVisibility( bool visible );
234 
235  protected:
236 
237  void dragEnterEvent( QDragEnterEvent *event ) override;
238  void dragLeaveEvent( QDragLeaveEvent *event ) override;
239  void dropEvent( QDropEvent *event ) override;
240 
241  private slots:
242 
243  void layerMenuAboutToShow();
244 
245  void extentDrawn( const QgsRectangle &extent );
246 
247  private:
248  void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
249  void setOutputExtentFromLineEdit();
250  void setOutputExtentFromCondensedLineEdit();
251 
252  ExtentState mExtentState = OriginalExtent;
253 
254  QgsCoordinateReferenceSystem mOutputCrs;
255 
256  QgsRectangle mCurrentExtent;
257  QgsCoordinateReferenceSystem mCurrentCrs;
258 
259  QgsRectangle mOriginalExtent;
260  QgsCoordinateReferenceSystem mOriginalCrs;
261 
262  QMenu *mMenu = nullptr;
263  QMenu *mLayerMenu = nullptr;
264  QgsMapLayerModel *mMapLayerModel = nullptr;
265  QList< QAction * > mLayerMenuActions;
266  QAction *mUseCanvasExtentAction = nullptr;
267  QAction *mUseCurrentExtentAction = nullptr;
268  QAction *mDrawOnCanvasAction = nullptr;
269 
270  QPointer< const QgsMapLayer > mExtentLayer;
271  QString mExtentLayerName;
272 
273  std::unique_ptr< QgsMapToolExtent > mMapToolExtent;
274  QPointer< QgsMapTool > mMapToolPrevious = nullptr;
275  QgsMapCanvas *mCanvas = nullptr;
276  QSize mRatio;
277 
278  bool mIsValid = false;
279  bool mHasFixedOutputCrs = false;
280 
281  QRegularExpression mCondensedRe;
282  void setValid( bool valid );
283 
284  void setExtentToLayerExtent( const QString &layerId );
285 
286  QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
287 
288 
289 };
290 
291 #endif // QGSEXTENTWIDGET_H
QgsExtentWidget::currentCrs
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
Definition: qgsextentwidget.h:121
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:61
qgscollapsiblegroupbox.h
QgsExtentWidget::originalCrs
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
Definition: qgsextentwidget.h:97
QgsExtentWidget::CurrentExtent
@ CurrentExtent
Map canvas extent.
Definition: qgsextentwidget.h:60
QgsExtentWidget::DrawOnCanvas
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
Definition: qgsextentwidget.h:63
qgsrectangle.h
QgsExtentWidget::OriginalExtent
@ OriginalExtent
Layer's extent.
Definition: qgsextentwidget.h:59
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsExtentWidget::ratio
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:157
QgsExtentWidget::extentState
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
Definition: qgsextentwidget.h:145
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
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:42
QgsExtentWidget::UserExtent
@ UserExtent
Extent manually entered/modified by the user.
Definition: qgsextentwidget.h:61
QgsExtentWidget::CondensedStyle
@ CondensedStyle
Shows a compressed widget, for use when available space is minimal.
Definition: qgsextentwidget.h:69
QgsExtentWidget::outputCrs
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
Definition: qgsextentwidget.h:140
QgsExtentWidget::extentChanged
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
QgsExtentWidget::toggleDialogVisibility
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
QgsExtentWidget::ExpandedStyle
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
Definition: qgsextentwidget.h:70
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:206
QgsExtentWidget::setRatio
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:210
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsExtentWidget::validationChanged
void validationChanged(bool valid)
Emitted when the widget's validation state changes.
qgsmaptoolextent.h
QgsExtentWidget::originalExtent
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
Definition: qgsextentwidget.h:90
QgsExtentWidget::currentExtent
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
Definition: qgsextentwidget.h:113
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:62
QgsMapLayerModel
The QgsMapLayerModel class is a model to display layers in widgets.
Definition: qgsmaplayermodel.h:37