QGIS API Documentation 3.99.0-Master (a8f284845db)
Loading...
Searching...
No Matches
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 "ui_qgsextentgroupboxwidget.h"
20
21#include <memory>
22
23#include "qgis_gui.h"
24#include "qgis_sip.h"
26#include "qgsmaptool.h"
27#include "qgsmaptoolextent.h"
28#include "qgsrectangle.h"
29
30#include <QRegularExpression>
31
35class QgsMapLayer;
36
50class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBoxWidget
51{
52 Q_OBJECT
53
54 public:
64
71
75 explicit QgsExtentWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, WidgetStyle style = CondensedStyle );
76
77 ~QgsExtentWidget() override;
78
84 void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
85
91 QgsRectangle originalExtent() const { return mOriginalExtent; }
92
98 QgsCoordinateReferenceSystem originalCrs() const { return mOriginalCrs; }
99
106 void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
107
114 QgsRectangle currentExtent() const { return mCurrentExtent; }
115
122 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
123
129 void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
130
135 QgsRectangle outputExtent() const;
136
141 QgsCoordinateReferenceSystem outputCrs() const { return mOutputCrs; }
142
146 QgsExtentWidget::ExtentState extentState() const { return mExtentState; }
147
153 void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
154
159 QSize ratio() const { return mRatio; }
160
164 QString extentLayerName() const;
165
169 bool isValid() const;
170
178 void setNullValueAllowed( bool allowed, const QString &notSetText = QString() );
179
180 public slots:
181
185 void setOutputExtentFromOriginal();
186
190 void setOutputExtentFromCurrent();
191
195 void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
196
200 void setOutputExtentFromLayer( const QgsMapLayer *layer );
201
205 void setOutputExtentFromDrawOnCanvas();
206
212 void setRatio( QSize ratio ) { mRatio = ratio; }
213
217 void clear();
218
219 signals:
220
224 void extentChanged( const QgsRectangle &r );
225
229 void validationChanged( bool valid );
230
235 void toggleDialogVisibility( bool visible );
236
242
243 protected:
244 void dragEnterEvent( QDragEnterEvent *event ) override;
245 void dragLeaveEvent( QDragLeaveEvent *event ) override;
246 void dropEvent( QDropEvent *event ) override;
247 void showEvent( QShowEvent *event ) override;
248
249 private slots:
250
251 void layerMenuAboutToShow();
252 void layoutMenuAboutToShow();
253 void bookmarkMenuAboutToShow();
254
255 void extentDrawn( const QgsRectangle &extent );
256 void mapToolDeactivated();
257
258 private:
259 void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
260 void setOutputExtentFromLineEdit();
261 void setOutputExtentFromCondensedLineEdit();
262
263 ExtentState mExtentState = OriginalExtent;
264
266
267 QgsRectangle mCurrentExtent;
269
270 QgsRectangle mOriginalExtent;
271 QgsCoordinateReferenceSystem mOriginalCrs;
272
273 QgsRectangle mOutputExtent;
274
275 QMenu *mMenu = nullptr;
276
277 QMenu *mLayerMenu = nullptr;
278 QMenu *mLayoutMenu = nullptr;
279 QMenu *mBookmarkMenu = nullptr;
280
281 QgsMapLayerProxyModel *mMapLayerModel = nullptr;
282 QgsBookmarkManagerProxyModel *mBookmarkModel = nullptr;
283
284 QList<QAction *> mLayerMenuActions;
285 QAction *mUseCanvasExtentAction = nullptr;
286 QAction *mUseCurrentExtentAction = nullptr;
287 QAction *mDrawOnCanvasAction = nullptr;
288
289 QPointer<const QgsMapLayer> mExtentLayer;
290 QString mExtentLayerName;
291
292 std::unique_ptr<QgsMapToolExtent> mMapToolExtent;
293 QPointer<QgsMapTool> mMapToolPrevious = nullptr;
294 QgsMapCanvas *mCanvas = nullptr;
295 QSize mRatio;
296
297 bool mIsValid = false;
298 bool mHasFixedOutputCrs = false;
299
300 QRegularExpression mCondensedRe;
301
302 bool mFirstShow = true;
303 bool mBlockDrawOnCanvas = false;
304
305 void setValid( bool valid );
306
307 void setExtentToLayerExtent( const QString &layerId );
308
309 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
310
311 friend class TestProcessingGui;
312};
313
314#endif // QGSEXTENTWIDGET_H
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
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 extentLayerChanged(QgsMapLayer *layer)
Emitted when the extent layer is changed.
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.
void dragEnterEvent(QDragEnterEvent *event) override
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.
void dropEvent(QDropEvent *event) override
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
friend class TestProcessingGui
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.
QgsExtentWidget(QWidget *parent=nullptr, WidgetStyle style=CondensedStyle)
Constructor for QgsExtentWidget.
void dragLeaveEvent(QDragLeaveEvent *event) override
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void showEvent(QShowEvent *event) override
Map canvas is a class for displaying all GIS data types on a canvas.
A proxy model which provides an easy to use model to display the list of layers in widgets.
Base class for all map layer types.
Definition qgsmaplayer.h:83
A rectangle specified with double values.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52