QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
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
36class QgsMapLayer;
37
51class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBoxWidget
52{
53 Q_OBJECT
54
55 public:
65
72
76 explicit QgsExtentWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, WidgetStyle style = CondensedStyle );
77
78 ~QgsExtentWidget() override;
79
85 void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
86
92 QgsRectangle originalExtent() const { return mOriginalExtent; }
93
99 QgsCoordinateReferenceSystem originalCrs() const { return mOriginalCrs; }
100
107 void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
108
115 QgsRectangle currentExtent() const { return mCurrentExtent; }
116
123 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
124
130 void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
131
136 QgsRectangle outputExtent() const;
137
142 QgsCoordinateReferenceSystem outputCrs() const { return mOutputCrs; }
143
147 QgsExtentWidget::ExtentState extentState() const { return mExtentState; }
148
154 void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
155
160 QSize ratio() const { return mRatio; }
161
165 QString extentLayerName() const;
166
170 bool isValid() const;
171
179 void setNullValueAllowed( bool allowed, const QString &notSetText = QString() );
180
181 public slots:
182
186 void setOutputExtentFromOriginal();
187
191 void setOutputExtentFromCurrent();
192
196 void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
197
201 void setOutputExtentFromLayer( const QgsMapLayer *layer );
202
206 void setOutputExtentFromDrawOnCanvas();
207
213 void setRatio( QSize ratio ) { mRatio = ratio; }
214
218 void clear();
219
220 signals:
221
225 void extentChanged( const QgsRectangle &r );
226
230 void validationChanged( bool valid );
231
236 void toggleDialogVisibility( bool visible );
237
238 protected:
239 void dragEnterEvent( QDragEnterEvent *event ) override;
240 void dragLeaveEvent( QDragLeaveEvent *event ) override;
241 void dropEvent( QDropEvent *event ) override;
242 void showEvent( QShowEvent *event ) override;
243
244 private slots:
245
246 void layerMenuAboutToShow();
247 void layoutMenuAboutToShow();
248 void bookmarkMenuAboutToShow();
249
250 void extentDrawn( const QgsRectangle &extent );
251 void mapToolDeactivated();
252
253 private:
254 void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentWidget::ExtentState state );
255 void setOutputExtentFromLineEdit();
256 void setOutputExtentFromCondensedLineEdit();
257
258 ExtentState mExtentState = OriginalExtent;
259
261
262 QgsRectangle mCurrentExtent;
264
265 QgsRectangle mOriginalExtent;
266 QgsCoordinateReferenceSystem mOriginalCrs;
267
268 QMenu *mMenu = nullptr;
269
270 QMenu *mLayerMenu = nullptr;
271 QMenu *mLayoutMenu = nullptr;
272 QMenu *mBookmarkMenu = nullptr;
273
274 QgsMapLayerProxyModel *mMapLayerModel = nullptr;
275 QgsBookmarkManagerProxyModel *mBookmarkModel = nullptr;
276
277 QList<QAction *> mLayerMenuActions;
278 QAction *mUseCanvasExtentAction = nullptr;
279 QAction *mUseCurrentExtentAction = nullptr;
280 QAction *mDrawOnCanvasAction = nullptr;
281
282 QPointer<const QgsMapLayer> mExtentLayer;
283 QString mExtentLayerName;
284
285 std::unique_ptr<QgsMapToolExtent> mMapToolExtent;
286 QPointer<QgsMapTool> mMapToolPrevious = nullptr;
287 QgsMapCanvas *mCanvas = nullptr;
288 QSize mRatio;
289
290 bool mIsValid = false;
291 bool mHasFixedOutputCrs = false;
292
293 QRegularExpression mCondensedRe;
294
295 bool mFirstShow = true;
296 bool mBlockDrawOnCanvas = false;
297
298 void setValid( bool valid );
299
300 void setExtentToLayerExtent( const QString &layerId );
301
302 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
303
304 friend class TestProcessingGui;
305};
306
307#endif // QGSEXTENTWIDGET_H
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
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.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
Base class for all map layer types.
Definition qgsmaplayer.h:76
A rectangle specified with double values.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs