QGIS API Documentation 3.38.0-Grenoble (exported)
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"
20#include "qgsmapcanvas.h"
22#include "qgsmaplayermodel.h"
23#include "qgsexception.h"
24#include "qgsproject.h"
25#include "qgsdoublevalidator.h"
26#include "qgslayoutmanager.h"
27#include "qgslayoutitemmap.h"
28#include "qgsprintlayout.h"
29#include "qgsbookmarkmodel.h"
31
32#include <QMenu>
33#include <QAction>
34#include <QRegularExpression>
35
37 : QWidget( parent )
38{
39 setupUi( this );
40 connect( mXMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
41 connect( mXMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
42 connect( mYMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
43 connect( mYMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
44
45 mCondensedRe = QRegularExpression( QStringLiteral( "\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*(?:\\[(.*?)\\])?" ) );
46 mCondensedLineEdit->setValidator( new QRegularExpressionValidator( mCondensedRe, this ) );
47 mCondensedLineEdit->setShowClearButton( false );
48 connect( mCondensedLineEdit, &QgsFilterLineEdit::cleared, this, &QgsExtentWidget::clear );
49 connect( mCondensedLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
50
51 mLayerMenu = new QMenu( tr( "Calculate from Layer" ), this );
52 mButtonCalcFromLayer->setMenu( mLayerMenu );
53 connect( mLayerMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layerMenuAboutToShow );
54 mMapLayerModel = new QgsMapLayerProxyModel( this );
56
57 mLayoutMenu = new QMenu( tr( "Calculate from Layout Map" ), this );
58 mButtonCalcFromLayout->setMenu( mLayoutMenu );
59 connect( mLayoutMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layoutMenuAboutToShow );
60
61 mBookmarkMenu = new QMenu( tr( "Calculate from Bookmark" ), this );
62 mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
63 connect( mBookmarkMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::bookmarkMenuAboutToShow );
64
65 mMenu = new QMenu( this );
66 mUseCanvasExtentAction = new QAction( tr( "Use Current Map Canvas Extent" ), this );
67 mUseCanvasExtentAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
68 mUseCanvasExtentAction->setVisible( false );
69 connect( mUseCanvasExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
70
71 mUseCurrentExtentAction = new QAction( tr( "Use Current Layer/Default Extent" ), this );
72 mUseCurrentExtentAction->setVisible( false );
73 connect( mUseCurrentExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
74
75 mDrawOnCanvasAction = new QAction( tr( "Draw on Map Canvas" ), this );
76 mDrawOnCanvasAction->setVisible( false );
77 connect( mDrawOnCanvasAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
78
79 mMenu->addMenu( mLayerMenu );
80 mMenu->addMenu( mLayoutMenu );
81 mMenu->addMenu( mBookmarkMenu );
82 mMenu->addSeparator();
83 mMenu->addAction( mUseCanvasExtentAction );
84 mMenu->addAction( mDrawOnCanvasAction );
85 mMenu->addAction( mUseCurrentExtentAction );
86
87 mCondensedToolButton->setMenu( mMenu );
88 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
89
90 mXMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
91 mXMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
92 mYMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
93 mYMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
94
95 mOriginalExtentButton->setVisible( false );
96 mButtonDrawOnCanvas->setVisible( false );
97 mCurrentExtentButton->setVisible( false );
98
99 connect( mCurrentExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
100 connect( mOriginalExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromOriginal );
101 connect( mButtonDrawOnCanvas, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
102
103 switch ( style )
104 {
105 case CondensedStyle:
106 mExpandedWidget->hide();
107 break;
108
109 case ExpandedStyle:
110 mCondensedFrame->hide();
111 break;
112 }
113
114 setAcceptDrops( true );
115}
116
118{
119 if ( mMapToolExtent )
120 {
121 // disconnect from deactivated signal -- this will be called when the map tool is being destroyed,
122 // and we don't want to act on that anymore (the mapToolDeactivated slot tries to show the widget again, but
123 // that's being destroyed!)
124 disconnect( mMapToolExtent.get(), &QgsMapToolExtent::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
125 }
126}
127
128void QgsExtentWidget::setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs )
129{
130 mOriginalExtent = originalExtent;
131 mOriginalCrs = originalCrs;
132
133 mOriginalExtentButton->setVisible( true );
134}
135
136
138{
139 mCurrentExtent = currentExtent;
140 mCurrentCrs = currentCrs;
141
142 mCurrentExtentButton->setVisible( true );
143 mUseCurrentExtentAction->setVisible( true );
144}
145
147{
148 mHasFixedOutputCrs = true;
149 if ( mOutputCrs != outputCrs )
150 {
151 const bool prevExtentEnabled = mIsValid;
152 switch ( mExtentState )
153 {
154 case CurrentExtent:
155 mOutputCrs = outputCrs;
157 break;
158
159 case OriginalExtent:
160 mOutputCrs = outputCrs;
162 break;
163
165 mOutputCrs = outputCrs;
166 setOutputExtentFromLayer( mExtentLayer.data() );
167 break;
168
169 case DrawOnCanvas:
170 mOutputCrs = outputCrs;
171 extentDrawn( outputExtent() );
172 break;
173
174 case UserExtent:
175 try
176 {
179 const QgsRectangle extent = ct.transformBoundingBox( outputExtent() );
180 mOutputCrs = outputCrs;
182 }
183 catch ( QgsCsException & )
184 {
185 // can't reproject
186 mOutputCrs = outputCrs;
187 }
188 break;
189 }
190
191 if ( !prevExtentEnabled )
192 setValid( false );
193 }
194}
195
196void QgsExtentWidget::setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state )
197{
198 QgsRectangle extent;
199 if ( !mHasFixedOutputCrs )
200 {
201 mOutputCrs = srcCrs;
202 extent = r;
203 }
204 else
205 {
206 if ( mOutputCrs == srcCrs )
207 {
208 extent = r;
209 }
210 else
211 {
212 try
213 {
214 QgsCoordinateTransform ct( srcCrs, mOutputCrs, QgsProject::instance() );
215 ct.setBallparkTransformsAreAppropriate( true );
216 extent = ct.transformBoundingBox( r );
217 }
218 catch ( QgsCsException & )
219 {
220 // can't reproject
221 extent = r;
222 }
223 }
224 }
225
226 int decimals = 4;
227 switch ( mOutputCrs.mapUnits() )
228 {
231 decimals = 9;
232 break;
242 decimals = 4;
243 break;
244 }
245 mXMinLineEdit->setText( QLocale().toString( extent.xMinimum(), 'f', decimals ) );
246 mXMaxLineEdit->setText( QLocale().toString( extent.xMaximum(), 'f', decimals ) );
247 mYMinLineEdit->setText( QLocale().toString( extent.yMinimum(), 'f', decimals ) );
248 mYMaxLineEdit->setText( QLocale().toString( extent.yMaximum(), 'f', decimals ) );
249
250 QString condensed = QStringLiteral( "%1,%2,%3,%4" ).arg( QString::number( extent.xMinimum(), 'f', decimals ),
251 QString::number( extent.xMaximum(), 'f', decimals ),
252 QString::number( extent.yMinimum(), 'f', decimals ),
253 QString::number( extent.yMaximum(), 'f', decimals ) );
254 condensed += QStringLiteral( " [%1]" ).arg( mOutputCrs.userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
255 mCondensedLineEdit->setText( condensed );
256
257 mExtentState = state;
258
259 if ( !mIsValid )
260 setValid( true );
261
262 emit extentChanged( extent );
263}
264
265void QgsExtentWidget::setOutputExtentFromLineEdit()
266{
267 mExtentState = UserExtent;
268 emit extentChanged( outputExtent() );
269}
270
271void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
272{
273 const QString text = mCondensedLineEdit->text();
274 if ( text.isEmpty() )
275 {
276 clear();
277 }
278 else
279 {
280 const QRegularExpressionMatch match = mCondensedRe.match( text );
281 if ( match.hasMatch() )
282 {
283 // Localization
284 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble(), 'f', 10 ) );
285 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble(), 'f', 10 ) );
286 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble(), 'f', 10 ) );
287 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble(), 'f', 10 ) );
288 if ( !match.captured( 5 ).isEmpty() )
289 {
290 mOutputCrs = QgsCoordinateReferenceSystem( match.captured( 5 ) );
291 }
292
293 emit extentChanged( outputExtent() );
294 if ( !mIsValid )
295 setValid( true );
296 }
297 }
298}
299
301{
302 const bool prevWasNull = mIsValid;
303
304 whileBlocking( mXMinLineEdit )->clear();
305 whileBlocking( mXMaxLineEdit )->clear();
306 whileBlocking( mYMinLineEdit )->clear();
307 whileBlocking( mYMaxLineEdit )->clear();
308 whileBlocking( mCondensedLineEdit )->clearValue();
309 setValid( false );
310
311 if ( prevWasNull )
312 emit extentChanged( outputExtent() );
313}
314
316{
317 return mExtentLayerName;
318}
319
321{
322 return mIsValid;
323}
324
325void QgsExtentWidget::setNullValueAllowed( bool allowed, const QString &notSetText )
326{
327 mCondensedLineEdit->setShowClearButton( allowed );
328 mCondensedLineEdit->setNullValue( notSetText );
329}
330
331void QgsExtentWidget::setValid( bool valid )
332{
333 if ( valid == mIsValid )
334 return;
335
336 mIsValid = valid;
337 emit validationChanged( mIsValid );
338}
339
340void QgsExtentWidget::layerMenuAboutToShow()
341{
342 qDeleteAll( mLayerMenuActions );
343 mLayerMenuActions.clear();
344 mLayerMenu->clear();
345 for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
346 {
347 const QModelIndex index = mMapLayerModel->index( i, 0 );
348 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
349 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
350 QAction *act = new QAction( icon, text, mLayerMenu );
351 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
352 const QString layerId = mMapLayerModel->data( index, static_cast< int >( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
353 if ( mExtentState == ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
354 {
355 act->setCheckable( true );
356 act->setChecked( true );
357 }
358 connect( act, &QAction::triggered, this, [this, layerId]
359 {
360 setExtentToLayerExtent( layerId );
361 } );
362 mLayerMenu->addAction( act );
363 mLayerMenuActions << act;
364 }
365}
366
367void QgsExtentWidget::layoutMenuAboutToShow()
368{
369 mLayoutMenu->clear();
370
371 if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
372 {
373 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
374 for ( const QgsPrintLayout *layout : layouts )
375 {
376 QList< QgsLayoutItemMap * > maps;
377 layout->layoutItems( maps );
378 if ( maps.empty() )
379 continue;
380
381 QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
382 for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
383 {
384 QgsRectangle extent = map->extent();
386 QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
387 connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
388 layoutMenu->addAction( mapExtentAction );
389 }
390 mLayoutMenu->addMenu( layoutMenu );
391 }
392 }
393}
394
395void QgsExtentWidget::bookmarkMenuAboutToShow()
396{
397 mBookmarkMenu->clear();
398
399 if ( !mBookmarkModel )
400 mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );
401
402 QMap< QString, QMenu * > groupMenus;
403 for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
404 {
405 const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast< int >( QgsBookmarkManagerModel::CustomRole::Group ) ).toString();
406 QMenu *destMenu = mBookmarkMenu;
407 if ( !group.isEmpty() )
408 {
409 destMenu = groupMenus.value( group );
410 if ( !destMenu )
411 {
412 destMenu = new QMenu( group, mBookmarkMenu );
413 groupMenus[ group ] = destMenu;
414 }
415 }
416 QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast< int >( QgsBookmarkManagerModel::CustomRole::Name ) ).toString(), mBookmarkMenu );
417 const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast< int >( QgsBookmarkManagerModel::CustomRole::Extent ) ).value< QgsReferencedRectangle >();
418 connect( action, &QAction::triggered, this, [ = ] { setOutputExtentFromUser( extent, extent.crs() ); } );
419 destMenu->addAction( action );
420 }
421
422 QStringList groupKeys = groupMenus.keys();
423 groupKeys.sort( Qt::CaseInsensitive );
424 for ( int i = 0; i < groupKeys.count(); ++i )
425 {
426 if ( mBookmarkMenu->actions().value( i ) )
427 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
428 else
429 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
430 }
431}
432
433void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
434{
435 QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
436 if ( !layer )
437 return;
438
440}
441
442QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( const QMimeData *data ) const
443{
445 for ( const QgsMimeDataUtils::Uri &u : uriList )
446 {
447 // is this uri from the current project?
448 if ( QgsMapLayer *layer = u.mapLayer() )
449 {
450 return layer;
451 }
452 }
453 return nullptr;
454}
455
457{
458 if ( mCanvas )
459 {
460 // Use unrotated visible extent to insure output size and scale matches canvas
461 QgsMapSettings ms = mCanvas->mapSettings();
462 ms.setRotation( 0 );
463 setOutputExtent( ms.visibleExtent(), ms.destinationCrs(), CurrentExtent );
464 }
465 else
466 {
467 setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
468 }
469}
470
471
473{
474 setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
475}
476
478{
479 setOutputExtent( extent, crs, UserExtent );
480}
481
483{
484 if ( !layer )
485 return;
486
487 mExtentLayer = layer;
488 mExtentLayerName = layer->name();
489
490 setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
491}
492
494{
495 if ( mCanvas )
496 {
497 mMapToolPrevious = mCanvas->mapTool();
498 if ( !mMapToolExtent )
499 {
500 mMapToolExtent.reset( new QgsMapToolExtent( mCanvas ) );
501 connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
502 connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
503 }
504 mMapToolExtent->setRatio( mRatio );
505 mCanvas->setMapTool( mMapToolExtent.get() );
506
507 emit toggleDialogVisibility( false );
508 }
509}
510
511void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
512{
513 setOutputExtent( extent, mCanvas->mapSettings().destinationCrs(), DrawOnCanvas );
514 mCanvas->setMapTool( mMapToolPrevious );
515 emit toggleDialogVisibility( true );
516 mMapToolPrevious = nullptr;
517}
518
519void QgsExtentWidget::mapToolDeactivated()
520{
521 emit toggleDialogVisibility( true );
522 mMapToolPrevious = nullptr;
523}
524
526{
527 bool ok;
528 const double xmin = QgsDoubleValidator::toDouble( mXMinLineEdit->text(), &ok );
529 if ( ! ok ) return QgsRectangle();
530 const double ymin = QgsDoubleValidator::toDouble( mYMinLineEdit->text(), &ok );
531 if ( ! ok ) return QgsRectangle();
532 const double xmax = QgsDoubleValidator::toDouble( mXMaxLineEdit->text(), &ok );
533 if ( ! ok ) return QgsRectangle();
534 const double ymax = QgsDoubleValidator::toDouble( mYMaxLineEdit->text(), &ok );
535 if ( ! ok ) return QgsRectangle();
536
537 return QgsRectangle( xmin, ymin, xmax, ymax );
538}
539
540void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
541{
542 if ( canvas )
543 {
544 mCanvas = canvas;
545 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
546 mCurrentExtentButton->setVisible( true );
547
548 mUseCanvasExtentAction->setVisible( true );
549 if ( drawOnCanvasOption )
550 mDrawOnCanvasAction->setVisible( true );
551
552 mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
553 mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
554 connect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
555 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
556 }
557 else
558 {
559 mButtonDrawOnCanvas->setVisible( false );
560 mCurrentExtentButton->setVisible( false );
561 mUseCanvasExtentAction->setVisible( false );
562 mUseCanvasExtentAction->setVisible( false );
563
564 mCondensedToolButton->setToolTip( QString() );
565 mCondensedToolButton->setIcon( QIcon() );
566 disconnect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
567 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
568 }
569}
570
571void QgsExtentWidget::dragEnterEvent( QDragEnterEvent *event )
572{
573 if ( !( event->possibleActions() & Qt::CopyAction ) )
574 {
575 event->ignore();
576 return;
577 }
578
579 if ( mapLayerFromMimeData( event->mimeData() ) )
580 {
581 // dragged an acceptable layer, phew
582 event->setDropAction( Qt::CopyAction );
583 event->accept();
584 mCondensedLineEdit->setHighlighted( true );
585 update();
586 }
587 else
588 {
589 event->ignore();
590 }
591}
592
593void QgsExtentWidget::dragLeaveEvent( QDragLeaveEvent *event )
594{
595 if ( mCondensedLineEdit->isHighlighted() )
596 {
597 event->accept();
598 mCondensedLineEdit->setHighlighted( false );
599 update();
600 }
601 else
602 {
603 event->ignore();
604 }
605}
606
607void QgsExtentWidget::dropEvent( QDropEvent *event )
608{
609 if ( !( event->possibleActions() & Qt::CopyAction ) )
610 {
611 event->ignore();
612 return;
613 }
614
615 if ( QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
616 {
617 // dropped a map layer
618 setFocus( Qt::MouseFocusReason );
619 event->setDropAction( Qt::CopyAction );
620 event->accept();
621
623 }
624 else
625 {
626 event->ignore();
627 }
628 mCondensedLineEdit->setHighlighted( false );
629 update();
630}
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
@ 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.
@ Extent
Bookmark extent as a QgsReferencedRectangle.
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
This class represents a coordinate reference system (CRS).
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::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.
@ LayerId
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:75
QString name
Definition qgsmaplayer.h:79
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:82
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:5349
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs