QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsextentwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsextentwidget.cpp
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#include "qgsextentwidget.h"
17
18#include "qgsapplication.h"
19#include "qgslogger.h"
21#include "qgsmapcanvas.h"
23#include "qgsmaplayermodel.h"
24#include "qgsexception.h"
25#include "qgsproject.h"
26#include "qgsdoublevalidator.h"
27#include "qgslayoutmanager.h"
28#include "qgslayoutitemmap.h"
29#include "qgsprintlayout.h"
30#include "qgsbookmarkmodel.h"
32
33#include <QMenu>
34#include <QAction>
35#include <QRegularExpression>
36
38 : QWidget( parent )
39{
40 setupUi( this );
41 connect( mXMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
42 connect( mXMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
43 connect( mYMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
44 connect( mYMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
45
46 mCondensedRe = QRegularExpression( QStringLiteral( "\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*(?:\\[(.*?)\\])?" ) );
47 mCondensedLineEdit->setValidator( new QRegularExpressionValidator( mCondensedRe, this ) );
48 mCondensedLineEdit->setShowClearButton( false );
49 connect( mCondensedLineEdit, &QgsFilterLineEdit::cleared, this, &QgsExtentWidget::clear );
50 connect( mCondensedLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
51
52 mLayerMenu = new QMenu( tr( "Calculate from Layer" ), this );
53 mButtonCalcFromLayer->setMenu( mLayerMenu );
54 connect( mLayerMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layerMenuAboutToShow );
55 mMapLayerModel = new QgsMapLayerProxyModel( this );
57
58 mLayoutMenu = new QMenu( tr( "Calculate from Layout Map" ), this );
59 mButtonCalcFromLayout->setMenu( mLayoutMenu );
60 connect( mLayoutMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layoutMenuAboutToShow );
61
62 mBookmarkMenu = new QMenu( tr( "Calculate from Bookmark" ), this );
63 mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
64 connect( mBookmarkMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::bookmarkMenuAboutToShow );
65
66 mMenu = new QMenu( this );
67 mUseCanvasExtentAction = new QAction( tr( "Use Current Map Canvas Extent" ), this );
68 mUseCanvasExtentAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
69 mUseCanvasExtentAction->setVisible( false );
70 connect( mUseCanvasExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
71
72 mUseCurrentExtentAction = new QAction( tr( "Use Current Layer/Default Extent" ), this );
73 mUseCurrentExtentAction->setVisible( false );
74 connect( mUseCurrentExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
75
76 mDrawOnCanvasAction = new QAction( tr( "Draw on Map Canvas" ), this );
77 mDrawOnCanvasAction->setVisible( false );
78 connect( mDrawOnCanvasAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
79
80 mMenu->addMenu( mLayerMenu );
81 mMenu->addMenu( mLayoutMenu );
82 mMenu->addMenu( mBookmarkMenu );
83 mMenu->addSeparator();
84 mMenu->addAction( mUseCanvasExtentAction );
85 mMenu->addAction( mDrawOnCanvasAction );
86 mMenu->addAction( mUseCurrentExtentAction );
87
88 mCondensedToolButton->setMenu( mMenu );
89 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
90
91 mXMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
92 mXMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
93 mYMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
94 mYMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
95
96 mOriginalExtentButton->setVisible( false );
97 mButtonDrawOnCanvas->setVisible( false );
98 mCurrentExtentButton->setVisible( false );
99
100 connect( mCurrentExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
101 connect( mOriginalExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromOriginal );
102 connect( mButtonDrawOnCanvas, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
103
104 switch ( style )
105 {
106 case CondensedStyle:
107 mExpandedWidget->hide();
108 break;
109
110 case ExpandedStyle:
111 mCondensedFrame->hide();
112 break;
113 }
114
115 setAcceptDrops( true );
116}
117
119{
120 if ( mMapToolExtent )
121 {
122 // disconnect from deactivated signal -- this will be called when the map tool is being destroyed,
123 // and we don't want to act on that anymore (the mapToolDeactivated slot tries to show the widget again, but
124 // that's being destroyed!)
125 disconnect( mMapToolExtent.get(), &QgsMapToolExtent::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
126 }
127}
128
129void QgsExtentWidget::setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs )
130{
131 mOriginalExtent = originalExtent;
132 mOriginalCrs = originalCrs;
133
134 mOriginalExtentButton->setVisible( true );
135}
136
137
139{
140 mCurrentExtent = currentExtent;
141 mCurrentCrs = currentCrs;
142
143 mCurrentExtentButton->setVisible( true );
144 mUseCurrentExtentAction->setVisible( true );
145}
146
148{
149 mHasFixedOutputCrs = true;
150 if ( mOutputCrs != outputCrs )
151 {
152 const bool prevExtentEnabled = mIsValid;
153 switch ( mExtentState )
154 {
155 case CurrentExtent:
156 mOutputCrs = outputCrs;
158 break;
159
160 case OriginalExtent:
161 mOutputCrs = outputCrs;
163 break;
164
166 mOutputCrs = outputCrs;
167 setOutputExtentFromLayer( mExtentLayer.data() );
168 break;
169
170 case DrawOnCanvas:
171 mOutputCrs = outputCrs;
172 extentDrawn( outputExtent() );
173 break;
174
175 case UserExtent:
176 try
177 {
180 const QgsRectangle extent = ct.transformBoundingBox( outputExtent() );
181 mOutputCrs = outputCrs;
183 }
184 catch ( QgsCsException & )
185 {
186 // can't reproject
187 mOutputCrs = outputCrs;
188 }
189 break;
190 }
191
192 if ( !prevExtentEnabled )
193 setValid( false );
194 }
195}
196
197void QgsExtentWidget::setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state )
198{
199 QgsRectangle extent;
200 if ( !mHasFixedOutputCrs )
201 {
202 mOutputCrs = srcCrs;
203 extent = r;
204 }
205 else
206 {
207 if ( mOutputCrs == srcCrs )
208 {
209 extent = r;
210 }
211 else
212 {
213 try
214 {
215 QgsCoordinateTransform ct( srcCrs, mOutputCrs, QgsProject::instance() );
216 ct.setBallparkTransformsAreAppropriate( true );
217 extent = ct.transformBoundingBox( r );
218 }
219 catch ( QgsCsException & )
220 {
221 // can't reproject
222 extent = r;
223 }
224 }
225 }
226
227 int decimals = 4;
228 switch ( mOutputCrs.mapUnits() )
229 {
232 decimals = 9;
233 break;
243 decimals = 4;
244 break;
245 }
246 mXMinLineEdit->setText( QLocale().toString( extent.xMinimum(), 'f', decimals ) );
247 mXMaxLineEdit->setText( QLocale().toString( extent.xMaximum(), 'f', decimals ) );
248 mYMinLineEdit->setText( QLocale().toString( extent.yMinimum(), 'f', decimals ) );
249 mYMaxLineEdit->setText( QLocale().toString( extent.yMaximum(), 'f', decimals ) );
250
251 QString condensed = QStringLiteral( "%1,%2,%3,%4" ).arg( QString::number( extent.xMinimum(), 'f', decimals ),
252 QString::number( extent.xMaximum(), 'f', decimals ),
253 QString::number( extent.yMinimum(), 'f', decimals ),
254 QString::number( extent.yMaximum(), 'f', decimals ) );
255 condensed += QStringLiteral( " [%1]" ).arg( mOutputCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );
256 mCondensedLineEdit->setText( condensed );
257
258 mExtentState = state;
259
260 if ( !mIsValid )
261 setValid( true );
262
263 emit extentChanged( extent );
264}
265
266void QgsExtentWidget::setOutputExtentFromLineEdit()
267{
268 mExtentState = UserExtent;
269 emit extentChanged( outputExtent() );
270}
271
272void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
273{
274 const QString text = mCondensedLineEdit->text();
275 if ( text.isEmpty() )
276 {
277 clear();
278 }
279 else
280 {
281 const QRegularExpressionMatch match = mCondensedRe.match( text );
282 if ( match.hasMatch() )
283 {
284 // Localization
285 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble(), 'f', 10 ) );
286 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble(), 'f', 10 ) );
287 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble(), 'f', 10 ) );
288 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble(), 'f', 10 ) );
289 if ( !match.captured( 5 ).isEmpty() )
290 {
291 mOutputCrs = QgsCoordinateReferenceSystem( match.captured( 5 ) );
292 }
293
294 emit extentChanged( outputExtent() );
295 if ( !mIsValid )
296 setValid( true );
297 }
298 }
299}
300
302{
303 const bool prevWasNull = mIsValid;
304
305 whileBlocking( mXMinLineEdit )->clear();
306 whileBlocking( mXMaxLineEdit )->clear();
307 whileBlocking( mYMinLineEdit )->clear();
308 whileBlocking( mYMaxLineEdit )->clear();
309 whileBlocking( mCondensedLineEdit )->clearValue();
310 setValid( false );
311
312 if ( prevWasNull )
313 emit extentChanged( outputExtent() );
314}
315
317{
318 return mExtentLayerName;
319}
320
322{
323 return mIsValid;
324}
325
326void QgsExtentWidget::setNullValueAllowed( bool allowed, const QString &notSetText )
327{
328 mCondensedLineEdit->setShowClearButton( allowed );
329 mCondensedLineEdit->setNullValue( notSetText );
330}
331
332void QgsExtentWidget::setValid( bool valid )
333{
334 if ( valid == mIsValid )
335 return;
336
337 mIsValid = valid;
338 emit validationChanged( mIsValid );
339}
340
341void QgsExtentWidget::layerMenuAboutToShow()
342{
343 qDeleteAll( mLayerMenuActions );
344 mLayerMenuActions.clear();
345 mLayerMenu->clear();
346 for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
347 {
348 const QModelIndex index = mMapLayerModel->index( i, 0 );
349 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
350 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
351 QAction *act = new QAction( icon, text, mLayerMenu );
352 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
353 const QString layerId = mMapLayerModel->data( index, QgsMapLayerModel::LayerIdRole ).toString();
354 if ( mExtentState == ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
355 {
356 act->setCheckable( true );
357 act->setChecked( true );
358 }
359 connect( act, &QAction::triggered, this, [this, layerId]
360 {
361 setExtentToLayerExtent( layerId );
362 } );
363 mLayerMenu->addAction( act );
364 mLayerMenuActions << act;
365 }
366}
367
368void QgsExtentWidget::layoutMenuAboutToShow()
369{
370 mLayoutMenu->clear();
371
372 if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
373 {
374 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
375 for ( const QgsPrintLayout *layout : layouts )
376 {
377 QList< QgsLayoutItemMap * > maps;
378 layout->layoutItems( maps );
379 if ( maps.empty() )
380 continue;
381
382 QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
383 for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
384 {
385 QgsRectangle extent = map->extent();
387 QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
388 connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
389 layoutMenu->addAction( mapExtentAction );
390 }
391 mLayoutMenu->addMenu( layoutMenu );
392 }
393 }
394}
395
396void QgsExtentWidget::bookmarkMenuAboutToShow()
397{
398 mBookmarkMenu->clear();
399
400 if ( !mBookmarkModel )
401 mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );
402
403 QMap< QString, QMenu * > groupMenus;
404 for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
405 {
406 const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleGroup ).toString();
407 QMenu *destMenu = mBookmarkMenu;
408 if ( !group.isEmpty() )
409 {
410 destMenu = groupMenus.value( group );
411 if ( !destMenu )
412 {
413 destMenu = new QMenu( group, mBookmarkMenu );
414 groupMenus[ group ] = destMenu;
415 }
416 }
417 QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleName ).toString(), mBookmarkMenu );
418 const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleExtent ).value< QgsReferencedRectangle >();
419 connect( action, &QAction::triggered, this, [ = ] { setOutputExtentFromUser( extent, extent.crs() ); } );
420 destMenu->addAction( action );
421 }
422
423 QStringList groupKeys = groupMenus.keys();
424 groupKeys.sort( Qt::CaseInsensitive );
425 for ( int i = 0; i < groupKeys.count(); ++i )
426 {
427 if ( mBookmarkMenu->actions().value( i ) )
428 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
429 else
430 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
431 }
432}
433
434void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
435{
436 QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
437 if ( !layer )
438 return;
439
441}
442
443QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( const QMimeData *data ) const
444{
446 for ( const QgsMimeDataUtils::Uri &u : uriList )
447 {
448 // is this uri from the current project?
449 if ( QgsMapLayer *layer = u.mapLayer() )
450 {
451 return layer;
452 }
453 }
454 return nullptr;
455}
456
458{
459 if ( mCanvas )
460 {
461 // Use unrotated visible extent to insure output size and scale matches canvas
462 QgsMapSettings ms = mCanvas->mapSettings();
463 ms.setRotation( 0 );
464 setOutputExtent( ms.visibleExtent(), ms.destinationCrs(), CurrentExtent );
465 }
466 else
467 {
468 setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
469 }
470}
471
472
474{
475 setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
476}
477
479{
480 setOutputExtent( extent, crs, UserExtent );
481}
482
484{
485 if ( !layer )
486 return;
487
488 mExtentLayer = layer;
489 mExtentLayerName = layer->name();
490
491 setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
492}
493
495{
496 if ( mCanvas )
497 {
498 mMapToolPrevious = mCanvas->mapTool();
499 if ( !mMapToolExtent )
500 {
501 mMapToolExtent.reset( new QgsMapToolExtent( mCanvas ) );
502 connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
503 connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
504 }
505 mMapToolExtent->setRatio( mRatio );
506 mCanvas->setMapTool( mMapToolExtent.get() );
507
508 emit toggleDialogVisibility( false );
509 }
510}
511
512void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
513{
514 setOutputExtent( extent, mCanvas->mapSettings().destinationCrs(), DrawOnCanvas );
515 mCanvas->setMapTool( mMapToolPrevious );
516 emit toggleDialogVisibility( true );
517 mMapToolPrevious = nullptr;
518}
519
520void QgsExtentWidget::mapToolDeactivated()
521{
522 emit toggleDialogVisibility( true );
523 mMapToolPrevious = nullptr;
524}
525
527{
528 bool ok;
529 const double xmin = QgsDoubleValidator::toDouble( mXMinLineEdit->text(), &ok );
530 if ( ! ok ) return QgsRectangle();
531 const double ymin = QgsDoubleValidator::toDouble( mYMinLineEdit->text(), &ok );
532 if ( ! ok ) return QgsRectangle();
533 const double xmax = QgsDoubleValidator::toDouble( mXMaxLineEdit->text(), &ok );
534 if ( ! ok ) return QgsRectangle();
535 const double ymax = QgsDoubleValidator::toDouble( mYMaxLineEdit->text(), &ok );
536 if ( ! ok ) return QgsRectangle();
537
538 return QgsRectangle( xmin, ymin, xmax, ymax );
539}
540
541void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
542{
543 if ( canvas )
544 {
545 mCanvas = canvas;
546 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
547 mCurrentExtentButton->setVisible( true );
548
549 mUseCanvasExtentAction->setVisible( true );
550 if ( drawOnCanvasOption )
551 mDrawOnCanvasAction->setVisible( true );
552
553 mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
554 mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
555 connect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
556 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
557 }
558 else
559 {
560 mButtonDrawOnCanvas->setVisible( false );
561 mCurrentExtentButton->setVisible( false );
562 mUseCanvasExtentAction->setVisible( false );
563 mUseCanvasExtentAction->setVisible( false );
564
565 mCondensedToolButton->setToolTip( QString() );
566 mCondensedToolButton->setIcon( QIcon() );
567 disconnect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
568 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
569 }
570}
571
572void QgsExtentWidget::dragEnterEvent( QDragEnterEvent *event )
573{
574 if ( !( event->possibleActions() & Qt::CopyAction ) )
575 {
576 event->ignore();
577 return;
578 }
579
580 if ( mapLayerFromMimeData( event->mimeData() ) )
581 {
582 // dragged an acceptable layer, phew
583 event->setDropAction( Qt::CopyAction );
584 event->accept();
585 mCondensedLineEdit->setHighlighted( true );
586 update();
587 }
588 else
589 {
590 event->ignore();
591 }
592}
593
594void QgsExtentWidget::dragLeaveEvent( QDragLeaveEvent *event )
595{
596 if ( mCondensedLineEdit->isHighlighted() )
597 {
598 event->accept();
599 mCondensedLineEdit->setHighlighted( false );
600 update();
601 }
602 else
603 {
604 event->ignore();
605 }
606}
607
608void QgsExtentWidget::dropEvent( QDropEvent *event )
609{
610 if ( !( event->possibleActions() & Qt::CopyAction ) )
611 {
612 event->ignore();
613 return;
614 }
615
616 if ( QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
617 {
618 // dropped a map layer
619 setFocus( Qt::MouseFocusReason );
620 event->setDropAction( Qt::CopyAction );
621 event->accept();
622
624 }
625 else
626 {
627 event->ignore();
628 }
629 mCondensedLineEdit->setHighlighted( false );
630 update();
631}
@ Feet
Imperial feet.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ Inches
Inches (since QGIS 3.32)
@ NauticalMiles
Nautical miles.
@ Kilometers
Kilometers.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsBookmarkManager * bookmarkManager()
Returns the application's bookmark manager, used for storing installation-wide bookmarks.
@ RoleExtent
Bookmark extent as a QgsReferencedRectangle.
@ RoleGroup
Bookmark group.
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
This class represents a coordinate reference system (CRS).
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator and QRegularExpressionVali...
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS).
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
void setCurrentExtent(const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs)
Sets the current extent to show in the widget - should be called as part of initialization (or whenev...
bool isValid() const
Returns true if the widget is in a valid state, i.e.
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
void setNullValueAllowed(bool allowed, const QString &notSetText=QString())
Sets whether the widget can be set to a "not set" (null) state.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
void dragEnterEvent(QDragEnterEvent *event) override
@ 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
void clear()
Clears the widget, setting it to a null value.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
void setMapCanvas(QgsMapCanvas *canvas, bool drawOnCanvasOption=true)
Sets the map canvas to enable dragging of extent on a canvas.
~QgsExtentWidget() override
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.
QgsExtentWidget(QWidget *parent=nullptr, WidgetStyle style=CondensedStyle)
Constructor for QgsExtentWidget.
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
void dragLeaveEvent(QDragLeaveEvent *event) override
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
QString extentLayerName() const
Returns the name of the extent layer.
void cleared()
Emitted when the widget is cleared.
Layout graphical items for displaying a map.
Manages storage of a set of layouts.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsMapTool * mapTool()
Returns the currently active tool.
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
@ LayerIdRole
Stores the map layer ID.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
QgsMapLayerProxyModel * setFilters(Qgis::LayerFilters filters)
Sets filter flags which affect how layers are filtered within the model.
Base class for all map layer types.
Definition qgsmaplayer.h:74
QString name
Definition qgsmaplayer.h:77
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:80
The QgsMapSettings class contains configuration for rendering of the map.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
A map tool that emits an extent from a rectangle drawn onto the map canvas.
void extentChanged(const QgsRectangle &extent)
signal emitted on extent change
void deactivated()
signal emitted once the map tool is deactivated
QList< QgsMimeDataUtils::Uri > UriList
static UriList decodeUriList(const QMimeData *data)
Print layout, a QgsLayout subclass for static or atlas-based layouts.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsRectangle with associated coordinate reference system.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:4258
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs