QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
152  void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
153 
158  QSize ratio() const { return mRatio; }
159 
163  QString extentLayerName() const;
164 
168  bool isValid() const;
169 
177  void setNullValueAllowed( bool allowed, const QString &notSetText = QString() );
178 
179  public slots:
180 
184  void setOutputExtentFromOriginal();
185 
189  void setOutputExtentFromCurrent();
190 
194  void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
195 
199  void setOutputExtentFromLayer( const QgsMapLayer *layer );
200 
204  void setOutputExtentFromDrawOnCanvas();
205 
211  void setRatio( QSize ratio ) { mRatio = ratio; }
212 
216  void clear();
217 
218  signals:
219 
223  void extentChanged( const QgsRectangle &r );
224 
228  void validationChanged( bool valid );
229 
234  void toggleDialogVisibility( bool visible );
235 
236  protected:
237 
238  void dragEnterEvent( QDragEnterEvent *event ) override;
239  void dragLeaveEvent( QDragLeaveEvent *event ) override;
240  void dropEvent( QDropEvent *event ) override;
241 
242  private slots:
243 
244  void layerMenuAboutToShow();
245 
246  void extentDrawn( const QgsRectangle &extent );
247 
248  private:
249  void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
250  void setOutputExtentFromLineEdit();
251  void setOutputExtentFromCondensedLineEdit();
252 
253  ExtentState mExtentState = OriginalExtent;
254 
255  QgsCoordinateReferenceSystem mOutputCrs;
256 
257  QgsRectangle mCurrentExtent;
258  QgsCoordinateReferenceSystem mCurrentCrs;
259 
260  QgsRectangle mOriginalExtent;
261  QgsCoordinateReferenceSystem mOriginalCrs;
262 
263  QMenu *mMenu = nullptr;
264  QMenu *mLayerMenu = nullptr;
265  QgsMapLayerModel *mMapLayerModel = nullptr;
266  QList< QAction * > mLayerMenuActions;
267  QAction *mUseCanvasExtentAction = nullptr;
268  QAction *mUseCurrentExtentAction = nullptr;
269  QAction *mDrawOnCanvasAction = nullptr;
270 
271  QPointer< const QgsMapLayer > mExtentLayer;
272  QString mExtentLayerName;
273 
274  std::unique_ptr< QgsMapToolExtent > mMapToolExtent;
275  QPointer< QgsMapTool > mMapToolPrevious = nullptr;
276  QgsMapCanvas *mCanvas = nullptr;
277  QSize mRatio;
278 
279  bool mIsValid = false;
280  bool mHasFixedOutputCrs = false;
281 
282  QRegularExpression mCondensedRe;
283  void setValid( bool valid );
284 
285  void setExtentToLayerExtent( const QString &layerId );
286 
287  QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
288 
289 
290 };
291 
292 #endif // QGSEXTENTWIDGET_H
This class represents a coordinate reference system (CRS).
A widget for configuration of a map extent.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
ExtentState
Available states for the current extent selection in the widget.
@ UserExtent
Extent manually entered/modified by the user.
@ OriginalExtent
Layer's extent.
@ ProjectLayerExtent
Extent taken from a layer within the project.
@ CurrentExtent
Map canvas extent.
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
void validationChanged(bool valid)
Emitted when the widget's validation state changes.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
WidgetStyle
Widget styles.
@ CondensedStyle
Shows a compressed widget, for use when available space is minimal.
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
The QgsMapLayerModel class is a model to display layers in widgets.
Base class for all map layer types.
Definition: qgsmaplayer.h:70
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs