QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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#include "moc_qgsextentwidget.cpp"
18
19#include "qgsapplication.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;
282 decimals = 4;
283 break;
284 }
285 mXMinLineEdit->setText( QLocale().toString( extent.xMinimum(), 'f', decimals ) );
286 mXMaxLineEdit->setText( QLocale().toString( extent.xMaximum(), 'f', decimals ) );
287 mYMinLineEdit->setText( QLocale().toString( extent.yMinimum(), 'f', decimals ) );
288 mYMaxLineEdit->setText( QLocale().toString( extent.yMaximum(), 'f', decimals ) );
289
290 QString condensed = QStringLiteral( "%1,%2,%3,%4" ).arg( QString::number( extent.xMinimum(), 'f', decimals ), QString::number( extent.xMaximum(), 'f', decimals ), QString::number( extent.yMinimum(), 'f', decimals ), QString::number( extent.yMaximum(), 'f', decimals ) );
291 condensed += QStringLiteral( " [%1]" ).arg( mOutputCrs.userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
292 mCondensedLineEdit->setText( condensed );
293
294 mExtentState = state;
295
296 if ( !mIsValid )
297 setValid( true );
298
299 emit extentChanged( extent );
300}
301
302void QgsExtentWidget::setOutputExtentFromLineEdit()
303{
304 mExtentState = UserExtent;
305 emit extentChanged( outputExtent() );
306}
307
308void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
309{
310 const QString text = mCondensedLineEdit->text();
311 if ( text.isEmpty() )
312 {
313 clear();
314 }
315 else
316 {
317 const QRegularExpressionMatch match = mCondensedRe.match( text );
318 if ( match.hasMatch() )
319 {
320 // Localization
321 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble(), 'f', 10 ) );
322 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble(), 'f', 10 ) );
323 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble(), 'f', 10 ) );
324 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble(), 'f', 10 ) );
325 if ( !match.captured( 5 ).isEmpty() )
326 {
327 mOutputCrs = QgsCoordinateReferenceSystem( match.captured( 5 ) );
328 }
329
330 emit extentChanged( outputExtent() );
331 if ( !mIsValid )
332 setValid( true );
333 }
334 }
335}
336
338{
339 const bool prevWasNull = mIsValid;
340
341 whileBlocking( mXMinLineEdit )->clear();
342 whileBlocking( mXMaxLineEdit )->clear();
343 whileBlocking( mYMinLineEdit )->clear();
344 whileBlocking( mYMaxLineEdit )->clear();
345 whileBlocking( mCondensedLineEdit )->clearValue();
346 setValid( false );
347
348 if ( prevWasNull )
349 emit extentChanged( outputExtent() );
350}
351
353{
354 return mExtentLayerName;
355}
356
358{
359 return mIsValid;
360}
361
362void QgsExtentWidget::setNullValueAllowed( bool allowed, const QString &notSetText )
363{
364 mCondensedLineEdit->setShowClearButton( allowed );
365 mCondensedLineEdit->setNullValue( notSetText );
366}
367
368void QgsExtentWidget::setValid( bool valid )
369{
370 if ( valid == mIsValid )
371 return;
372
373 mIsValid = valid;
374 emit validationChanged( mIsValid );
375}
376
377void QgsExtentWidget::layerMenuAboutToShow()
378{
379 qDeleteAll( mLayerMenuActions );
380 mLayerMenuActions.clear();
381 mLayerMenu->clear();
382 for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
383 {
384 const QModelIndex index = mMapLayerModel->index( i, 0 );
385 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
386 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
387 QAction *act = new QAction( icon, text, mLayerMenu );
388 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
389 const QString layerId = mMapLayerModel->data( index, static_cast<int>( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
390 if ( mExtentState == ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
391 {
392 act->setCheckable( true );
393 act->setChecked( true );
394 }
395 connect( act, &QAction::triggered, this, [this, layerId] {
396 setExtentToLayerExtent( layerId );
397 } );
398 mLayerMenu->addAction( act );
399 mLayerMenuActions << act;
400 }
401}
402
403void QgsExtentWidget::layoutMenuAboutToShow()
404{
405 mLayoutMenu->clear();
406
407 if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
408 {
409 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
410 for ( const QgsPrintLayout *layout : layouts )
411 {
412 QList<QgsLayoutItemMap *> maps;
413 layout->layoutItems( maps );
414 if ( maps.empty() )
415 continue;
416
417 QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
418 for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
419 {
420 QgsRectangle extent = map->extent();
422 QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
423 connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
424 layoutMenu->addAction( mapExtentAction );
425 }
426 mLayoutMenu->addMenu( layoutMenu );
427 }
428 }
429}
430
431void QgsExtentWidget::bookmarkMenuAboutToShow()
432{
433 mBookmarkMenu->clear();
434
435 if ( !mBookmarkModel )
436 mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );
437
438 QMap<QString, QMenu *> groupMenus;
439 for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
440 {
441 const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Group ) ).toString();
442 QMenu *destMenu = mBookmarkMenu;
443 if ( !group.isEmpty() )
444 {
445 destMenu = groupMenus.value( group );
446 if ( !destMenu )
447 {
448 destMenu = new QMenu( group, mBookmarkMenu );
449 groupMenus[group] = destMenu;
450 }
451 }
452 QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Name ) ).toString(), mBookmarkMenu );
453 const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Extent ) ).value<QgsReferencedRectangle>();
454 connect( action, &QAction::triggered, this, [this, extent] { setOutputExtentFromUser( extent, extent.crs() ); } );
455 destMenu->addAction( action );
456 }
457
458 QStringList groupKeys = groupMenus.keys();
459 groupKeys.sort( Qt::CaseInsensitive );
460 for ( int i = 0; i < groupKeys.count(); ++i )
461 {
462 if ( mBookmarkMenu->actions().value( i ) )
463 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
464 else
465 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
466 }
467}
468
469void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
470{
471 QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
472 if ( !layer )
473 return;
474
476}
477
478QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( const QMimeData *data ) const
479{
481 for ( const QgsMimeDataUtils::Uri &u : uriList )
482 {
483 // is this uri from the current project?
484 if ( QgsMapLayer *layer = u.mapLayer() )
485 {
486 return layer;
487 }
488 }
489 return nullptr;
490}
491
493{
494 if ( mCanvas )
495 {
496 // Use unrotated visible extent to insure output size and scale matches canvas
497 QgsMapSettings ms = mCanvas->mapSettings();
498 ms.setRotation( 0 );
499 setOutputExtent( ms.visibleExtent(), ms.destinationCrs(), CurrentExtent );
500 }
501 else
502 {
503 setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
504 }
505}
506
507
509{
510 setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
511}
512
514{
515 setOutputExtent( extent, crs, UserExtent );
516}
517
519{
520 if ( !layer )
521 return;
522
523 mExtentLayer = layer;
524 mExtentLayerName = layer->name();
525
526 setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
527}
528
530{
531 if ( mCanvas )
532 {
533 mMapToolPrevious = mCanvas->mapTool();
534 if ( !mMapToolExtent )
535 {
536 mMapToolExtent.reset( new QgsMapToolExtent( mCanvas ) );
537 connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
538 connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
539 }
540 mMapToolExtent->setRatio( mRatio );
541 mCanvas->setMapTool( mMapToolExtent.get() );
542
543 emit toggleDialogVisibility( false );
544 }
545}
546
547void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
548{
549 setOutputExtent( extent, mCanvas->mapSettings().destinationCrs(), DrawOnCanvas );
550 mCanvas->setMapTool( mMapToolPrevious );
551 emit toggleDialogVisibility( true );
552 mMapToolPrevious = nullptr;
553}
554
555void QgsExtentWidget::mapToolDeactivated()
556{
557 emit toggleDialogVisibility( true );
558 mMapToolPrevious = nullptr;
559}
560
562{
563 bool ok;
564 const double xmin = QgsDoubleValidator::toDouble( mXMinLineEdit->text(), &ok );
565 if ( !ok )
566 return QgsRectangle();
567 const double ymin = QgsDoubleValidator::toDouble( mYMinLineEdit->text(), &ok );
568 if ( !ok )
569 return QgsRectangle();
570 const double xmax = QgsDoubleValidator::toDouble( mXMaxLineEdit->text(), &ok );
571 if ( !ok )
572 return QgsRectangle();
573 const double ymax = QgsDoubleValidator::toDouble( mYMaxLineEdit->text(), &ok );
574 if ( !ok )
575 return QgsRectangle();
576
577 return QgsRectangle( xmin, ymin, xmax, ymax );
578}
579
580void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
581{
582 if ( canvas )
583 {
584 mCanvas = canvas;
585 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
586 mCurrentExtentButton->setVisible( true );
587
588 mUseCanvasExtentAction->setVisible( true );
589 mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
590
591 mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
592 mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
593 connect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
594 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
595 }
596 else
597 {
598 mButtonDrawOnCanvas->setVisible( false );
599 mCurrentExtentButton->setVisible( false );
600 mUseCanvasExtentAction->setVisible( false );
601 mUseCanvasExtentAction->setVisible( false );
602
603 mCondensedToolButton->setToolTip( QString() );
604 mCondensedToolButton->setIcon( QIcon() );
605 disconnect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
606 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
607 }
608}
609
610void QgsExtentWidget::dragEnterEvent( QDragEnterEvent *event )
611{
612 if ( !( event->possibleActions() & Qt::CopyAction ) )
613 {
614 event->ignore();
615 return;
616 }
617
618 if ( mapLayerFromMimeData( event->mimeData() ) )
619 {
620 // dragged an acceptable layer, phew
621 event->setDropAction( Qt::CopyAction );
622 event->accept();
623 mCondensedLineEdit->setHighlighted( true );
624 update();
625 }
626 else
627 {
628 event->ignore();
629 }
630}
631
632void QgsExtentWidget::dragLeaveEvent( QDragLeaveEvent *event )
633{
634 if ( mCondensedLineEdit->isHighlighted() )
635 {
636 event->accept();
637 mCondensedLineEdit->setHighlighted( false );
638 update();
639 }
640 else
641 {
642 event->ignore();
643 }
644}
645
646void QgsExtentWidget::dropEvent( QDropEvent *event )
647{
648 if ( !( event->possibleActions() & Qt::CopyAction ) )
649 {
650 event->ignore();
651 return;
652 }
653
654 if ( QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
655 {
656 // dropped a map layer
657 setFocus( Qt::MouseFocusReason );
658 event->setDropAction( Qt::CopyAction );
659 event->accept();
660
662 }
663 else
664 {
665 event->ignore();
666 }
667 mCondensedLineEdit->setHighlighted( false );
668 update();
669}
670
671void QgsExtentWidget::showEvent( QShowEvent * )
672{
673 if ( mFirstShow )
674 {
675 // we don't support select on canvas if the dialog is modal
676 if ( QWidget *parentWindow = window() )
677 {
678 if ( parentWindow->isModal() )
679 {
680 mBlockDrawOnCanvas = true;
681 mDrawOnCanvasAction->setVisible( false );
682 }
683 }
684 mFirstShow = false;
685 }
686}
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated)
@ Feet
Imperial feet.
@ MilesUSSurvey
US Survey miles.
@ LinksBritishSears1922
British links (Sears 1922)
@ YardsBritishBenoit1895A
British yards (Benoit 1895 A)
@ LinksBritishBenoit1895A
British links (Benoit 1895 A)
@ Centimeters
Centimeters.
@ YardsIndian1975
Indian yards (1975)
@ FeetUSSurvey
US Survey feet.
@ Millimeters
Millimeters.
@ FeetBritishSears1922
British feet (Sears 1922)
@ YardsClarkes
Clarke's yards.
@ YardsIndian
Indian yards.
@ FeetBritishBenoit1895B
British feet (Benoit 1895 B)
@ Miles
Terrestrial miles.
@ LinksUSSurvey
US Survey links.
@ ChainsUSSurvey
US Survey chains.
@ FeetClarkes
Clarke's feet.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ FeetBritish1936
British feet (1936)
@ FeetIndian1962
Indian feet (1962)
@ YardsBritishSears1922
British yards (Sears 1922)
@ FeetIndian1937
Indian feet (1937)
@ YardsIndian1937
Indian yards (1937)
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ ChainsBritishBenoit1895B
British chains (Benoit 1895 B)
@ LinksBritishSears1922Truncated
British links (Sears 1922 truncated)
@ ChainsBritishBenoit1895A
British chains (Benoit 1895 A)
@ YardsBritishBenoit1895B
British yards (Benoit 1895 B)
@ FeetBritish1865
British feet (1865)
@ YardsIndian1962
Indian yards (1962)
@ FeetBritishSears1922Truncated
British feet (Sears 1922 truncated)
@ MetersGermanLegal
German legal meter.
@ LinksBritishBenoit1895B
British links (Benoit 1895 B)
@ ChainsInternational
International chains.
@ LinksInternational
International links.
@ ChainsBritishSears1922Truncated
British chains (Sears 1922 truncated)
@ FeetIndian
Indian (geodetic) feet.
@ NauticalMiles
Nautical miles.
@ ChainsClarkes
Clarke's chains.
@ LinksClarkes
Clarke's links.
@ ChainsBritishSears1922
British chains (Sears 1922)
@ Kilometers
Kilometers.
@ FeetIndian1975
Indian feet (1975)
@ FeetGoldCoast
Gold Coast feet.
@ FeetBritishBenoit1895A
British feet (Benoit 1895 A)
@ SpatialLayer
All spatial layers.
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 showEvent(QShowEvent *event) override
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() const
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:76
QString name
Definition qgsmaplayer.h:80
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:83
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
double yMinimum
double xMaximum
double yMaximum
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:5970
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs