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