QGIS API Documentation 3.99.0-Master (a8f284845db)
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 <memory>
19
20#include "qgsapplication.h"
21#include "qgsbookmarkmodel.h"
23#include "qgsdoublevalidator.h"
24#include "qgsexception.h"
25#include "qgslayoutitemmap.h"
26#include "qgslayoutmanager.h"
27#include "qgsmapcanvas.h"
28#include "qgsmaplayermodel.h"
30#include "qgsprintlayout.h"
31#include "qgsproject.h"
33
34#include <QAction>
35#include <QMenu>
36#include <QRegularExpression>
37#include <QString>
38
39#include "moc_qgsextentwidget.cpp"
40
41using namespace Qt::StringLiterals;
42
44 : QWidget( parent )
45{
46 setupUi( this );
47 connect( mXMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
48 connect( mXMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
49 connect( mYMinLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
50 connect( mYMaxLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromLineEdit );
51
52 mCondensedRe = QRegularExpression( u"\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*(?:\\[(.*?)\\])?"_s );
53 mCondensedLineEdit->setValidator( new QRegularExpressionValidator( mCondensedRe, this ) );
54 mCondensedLineEdit->setShowClearButton( false );
55 connect( mCondensedLineEdit, &QgsFilterLineEdit::cleared, this, &QgsExtentWidget::clear );
56 connect( mCondensedLineEdit, &QLineEdit::textEdited, this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
57
58 mLayerMenu = new QMenu( tr( "Calculate from Layer" ), this );
59 mButtonCalcFromLayer->setMenu( mLayerMenu );
60 connect( mLayerMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layerMenuAboutToShow );
61 mMapLayerModel = new QgsMapLayerProxyModel( this );
62 mMapLayerModel->setFilters( Qgis::LayerFilter::SpatialLayer );
63
64 mLayoutMenu = new QMenu( tr( "Calculate from Layout Map" ), this );
65 mButtonCalcFromLayout->setMenu( mLayoutMenu );
66 connect( mLayoutMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layoutMenuAboutToShow );
67
68 mBookmarkMenu = new QMenu( tr( "Calculate from Bookmark" ), this );
69 mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
70 connect( mBookmarkMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::bookmarkMenuAboutToShow );
71
72 mMenu = new QMenu( this );
73 mUseCanvasExtentAction = new QAction( tr( "Use Current Map Canvas Extent" ), this );
74 mUseCanvasExtentAction->setIcon( QgsApplication::getThemeIcon( u"/mActionMapIdentification.svg"_s ) );
75 mUseCanvasExtentAction->setVisible( false );
76 connect( mUseCanvasExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
77
78 mUseCurrentExtentAction = new QAction( tr( "Use Current Layer/Default Extent" ), this );
79 mUseCurrentExtentAction->setVisible( false );
80 connect( mUseCurrentExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );
81
82 mDrawOnCanvasAction = new QAction( tr( "Draw on Map Canvas" ), this );
83 mDrawOnCanvasAction->setVisible( false );
84 connect( mDrawOnCanvasAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
85
86 mMenu->addMenu( mLayerMenu );
87 mMenu->addMenu( mLayoutMenu );
88 mMenu->addMenu( mBookmarkMenu );
89 mMenu->addSeparator();
90 mMenu->addAction( mUseCanvasExtentAction );
91 mMenu->addAction( mDrawOnCanvasAction );
92 mMenu->addAction( mUseCurrentExtentAction );
93
94 mCondensedToolButton->setMenu( mMenu );
95 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
96
97 mXMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
98 mXMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
99 mYMinLineEdit->setValidator( new QgsDoubleValidator( this ) );
100 mYMaxLineEdit->setValidator( new QgsDoubleValidator( this ) );
101
102 mOriginalExtentButton->setVisible( false );
103 mButtonDrawOnCanvas->setVisible( false );
104 mCurrentExtentButton->setVisible( false );
105
106 connect( mCurrentExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
107 connect( mOriginalExtentButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromOriginal );
108 connect( mButtonDrawOnCanvas, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );
109
110 switch ( style )
111 {
112 case CondensedStyle:
113 mExpandedWidget->hide();
114 break;
115
116 case ExpandedStyle:
117 mCondensedFrame->hide();
118 break;
119 }
120
121 setAcceptDrops( true );
122}
123
125{
126 if ( mMapToolExtent )
127 {
128 // disconnect from deactivated signal -- this will be called when the map tool is being destroyed,
129 // and we don't want to act on that anymore (the mapToolDeactivated slot tries to show the widget again, but
130 // that's being destroyed!)
131 disconnect( mMapToolExtent.get(), &QgsMapToolExtent::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
132 }
133}
134
136{
137 mOriginalExtent = originalExtent;
138 mOriginalCrs = originalCrs;
139
140 mOriginalExtentButton->setVisible( true );
141}
142
143
145{
146 mCurrentExtent = currentExtent;
147 mCurrentCrs = currentCrs;
148
149 mCurrentExtentButton->setVisible( true );
150 mUseCurrentExtentAction->setVisible( true );
151}
152
154{
155 mHasFixedOutputCrs = true;
156 if ( mOutputCrs != outputCrs )
157 {
158 const bool prevExtentEnabled = mIsValid;
159 switch ( mExtentState )
160 {
161 case CurrentExtent:
162 mOutputCrs = outputCrs;
164 break;
165
166 case OriginalExtent:
167 mOutputCrs = outputCrs;
169 break;
170
172 mOutputCrs = outputCrs;
173 setOutputExtentFromLayer( mExtentLayer.data() );
174 break;
175
176 case DrawOnCanvas:
177 mOutputCrs = outputCrs;
178 extentDrawn( outputExtent() );
179 break;
180
181 case UserExtent:
182 try
183 {
186 const QgsRectangle extent = ct.transformBoundingBox( outputExtent() );
187 mOutputCrs = outputCrs;
189 }
190 catch ( QgsCsException & )
191 {
192 // can't reproject
193 mOutputCrs = outputCrs;
194 }
195 break;
196 }
197
198 if ( !prevExtentEnabled )
199 setValid( false );
200 }
201}
202
203void QgsExtentWidget::setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state )
204{
205 if ( !mHasFixedOutputCrs )
206 {
207 mOutputCrs = srcCrs;
208 mOutputExtent = r;
209 }
210 else
211 {
212 if ( mOutputCrs == srcCrs )
213 {
214 mOutputExtent = r;
215 }
216 else
217 {
218 try
219 {
220 QgsCoordinateTransform ct( srcCrs, mOutputCrs, QgsProject::instance() );
221 ct.setBallparkTransformsAreAppropriate( true );
222 mOutputExtent = ct.transformBoundingBox( r );
223 }
224 catch ( QgsCsException & )
225 {
226 // can't reproject
227 mOutputExtent = r;
228 }
229 }
230 }
231
232 int decimals = 4;
233 switch ( mOutputCrs.mapUnits() )
234 {
237 decimals = 9;
238 break;
287 decimals = 4;
288 break;
289 }
290 mXMinLineEdit->setText( QLocale().toString( mOutputExtent.xMinimum(), 'f', decimals ) );
291 mXMaxLineEdit->setText( QLocale().toString( mOutputExtent.xMaximum(), 'f', decimals ) );
292 mYMinLineEdit->setText( QLocale().toString( mOutputExtent.yMinimum(), 'f', decimals ) );
293 mYMaxLineEdit->setText( QLocale().toString( mOutputExtent.yMaximum(), 'f', decimals ) );
294
295 QString condensed = u"%1,%2,%3,%4"_s.arg( QString::number( mOutputExtent.xMinimum(), 'f', decimals ), QString::number( mOutputExtent.xMaximum(), 'f', decimals ), QString::number( mOutputExtent.yMinimum(), 'f', decimals ), QString::number( mOutputExtent.yMaximum(), 'f', decimals ) );
296 condensed += u" [%1]"_s.arg( mOutputCrs.userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
297 mCondensedLineEdit->setText( condensed );
298
299 mExtentState = state;
300
301 if ( !mIsValid )
302 setValid( true );
303
304 emit extentChanged( mOutputExtent );
305}
306
307void QgsExtentWidget::setOutputExtentFromLineEdit()
308{
309 bool ok1, ok2, ok3, ok4;
310 const double xmin = QgsDoubleValidator::toDouble( mXMinLineEdit->text(), &ok1 );
311 const double ymin = QgsDoubleValidator::toDouble( mYMinLineEdit->text(), &ok2 );
312 const double xmax = QgsDoubleValidator::toDouble( mXMaxLineEdit->text(), &ok3 );
313 const double ymax = QgsDoubleValidator::toDouble( mYMaxLineEdit->text(), &ok4 );
314 if ( ok1 && ok2 && ok3 && ok4 )
315 {
316 mOutputExtent = QgsRectangle( xmin, ymin, xmax, ymax );
317 }
318 else
319 {
320 mOutputExtent.setNull();
321 }
322
323 mExtentState = UserExtent;
324 emit extentChanged( outputExtent() );
325}
326
327void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
328{
329 const QString text = mCondensedLineEdit->text();
330 if ( text.isEmpty() )
331 {
332 clear();
333 }
334 else
335 {
336 const QRegularExpressionMatch match = mCondensedRe.match( text );
337 if ( match.hasMatch() )
338 {
339 const double xMin = match.captured( 1 ).toDouble();
340 const double xMax = match.captured( 2 ).toDouble();
341 const double yMin = match.captured( 3 ).toDouble();
342 const double yMax = match.captured( 4 ).toDouble();
343 mOutputExtent = QgsRectangle( xMin, yMin, xMax, yMax );
344 // Localization
345 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( xMin, 'f', 10 ) );
346 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( xMax, 'f', 10 ) );
347 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( yMin, 'f', 10 ) );
348 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( yMax, 'f', 10 ) );
349 if ( !match.captured( 5 ).isEmpty() )
350 {
351 mOutputCrs = QgsCoordinateReferenceSystem( match.captured( 5 ) );
352 }
353
354 emit extentChanged( outputExtent() );
355 if ( !mIsValid )
356 setValid( true );
357 }
358 }
359}
360
362{
363 const bool prevWasNull = mIsValid;
364 mOutputExtent.setNull();
365
366 whileBlocking( mXMinLineEdit )->clear();
367 whileBlocking( mXMaxLineEdit )->clear();
368 whileBlocking( mYMinLineEdit )->clear();
369 whileBlocking( mYMaxLineEdit )->clear();
370 whileBlocking( mCondensedLineEdit )->clearValue();
371 setValid( false );
372
373 if ( prevWasNull )
374 emit extentChanged( outputExtent() );
375}
376
378{
379 return mExtentLayerName;
380}
381
383{
384 return mIsValid;
385}
386
387void QgsExtentWidget::setNullValueAllowed( bool allowed, const QString &notSetText )
388{
389 mCondensedLineEdit->setShowClearButton( allowed );
390 mCondensedLineEdit->setNullValue( notSetText );
391}
392
393void QgsExtentWidget::setValid( bool valid )
394{
395 if ( valid == mIsValid )
396 return;
397
398 mIsValid = valid;
399 emit validationChanged( mIsValid );
400}
401
402void QgsExtentWidget::layerMenuAboutToShow()
403{
404 qDeleteAll( mLayerMenuActions );
405 mLayerMenuActions.clear();
406 mLayerMenu->clear();
407 for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
408 {
409 const QModelIndex index = mMapLayerModel->index( i, 0 );
410 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
411 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
412 QAction *act = new QAction( icon, text, mLayerMenu );
413 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
414 const QString layerId = mMapLayerModel->data( index, static_cast<int>( QgsMapLayerModel::CustomRole::LayerId ) ).toString();
415 if ( mExtentState == ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
416 {
417 act->setCheckable( true );
418 act->setChecked( true );
419 }
420 connect( act, &QAction::triggered, this, [this, layerId] {
421 setExtentToLayerExtent( layerId );
422 } );
423 mLayerMenu->addAction( act );
424 mLayerMenuActions << act;
425 }
426}
427
428void QgsExtentWidget::layoutMenuAboutToShow()
429{
430 mLayoutMenu->clear();
431
432 if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
433 {
434 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
435 for ( const QgsPrintLayout *layout : layouts )
436 {
437 QList<QgsLayoutItemMap *> maps;
438 layout->layoutItems( maps );
439 if ( maps.empty() )
440 continue;
441
442 QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
443 for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
444 {
445 QgsRectangle extent = map->extent();
446 QgsCoordinateReferenceSystem crs = map->crs();
447 QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
448 connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
449 layoutMenu->addAction( mapExtentAction );
450 }
451 mLayoutMenu->addMenu( layoutMenu );
452 }
453 }
454}
455
456void QgsExtentWidget::bookmarkMenuAboutToShow()
457{
458 mBookmarkMenu->clear();
459
460 if ( !mBookmarkModel )
461 mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );
462
463 QMap<QString, QMenu *> groupMenus;
464 for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
465 {
466 const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Group ) ).toString();
467 QMenu *destMenu = mBookmarkMenu;
468 if ( !group.isEmpty() )
469 {
470 destMenu = groupMenus.value( group );
471 if ( !destMenu )
472 {
473 destMenu = new QMenu( group, mBookmarkMenu );
474 groupMenus[group] = destMenu;
475 }
476 }
477 QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Name ) ).toString(), mBookmarkMenu );
478 const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), static_cast<int>( QgsBookmarkManagerModel::CustomRole::Extent ) ).value<QgsReferencedRectangle>();
479 connect( action, &QAction::triggered, this, [this, extent] { setOutputExtentFromUser( extent, extent.crs() ); } );
480 destMenu->addAction( action );
481 }
482
483 QStringList groupKeys = groupMenus.keys();
484 groupKeys.sort( Qt::CaseInsensitive );
485 for ( int i = 0; i < groupKeys.count(); ++i )
486 {
487 if ( mBookmarkMenu->actions().value( i ) )
488 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
489 else
490 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
491 }
492}
493
494void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
495{
496 QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
497 if ( !layer )
498 return;
499
500 emit extentLayerChanged( layer );
502}
503
504QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( const QMimeData *data ) const
505{
507 for ( const QgsMimeDataUtils::Uri &u : uriList )
508 {
509 // is this uri from the current project?
510 if ( QgsMapLayer *layer = u.mapLayer() )
511 {
512 return layer;
513 }
514 }
515 return nullptr;
516}
517
519{
520 if ( mCanvas )
521 {
522 // Use unrotated visible extent to insure output size and scale matches canvas
523 QgsMapSettings ms = mCanvas->mapSettings();
524 ms.setRotation( 0 );
525 setOutputExtent( ms.visibleExtent(), ms.destinationCrs(), CurrentExtent );
526 }
527 else
528 {
529 setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
530 }
531}
532
533
535{
536 setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
537}
538
540{
541 setOutputExtent( extent, crs, UserExtent );
542}
543
545{
546 if ( !layer )
547 return;
548
549 mExtentLayer = layer;
550 mExtentLayerName = layer->name();
551
552 setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
553}
554
556{
557 if ( mCanvas )
558 {
559 mMapToolPrevious = mCanvas->mapTool();
560 if ( !mMapToolExtent )
561 {
562 mMapToolExtent = std::make_unique<QgsMapToolExtent>( mCanvas );
563 connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
564 connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
565 }
566 mMapToolExtent->setRatio( mRatio );
567 mCanvas->setMapTool( mMapToolExtent.get() );
568
569 emit toggleDialogVisibility( false );
570 }
571}
572
573void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
574{
575 setOutputExtent( extent, mCanvas->mapSettings().destinationCrs(), DrawOnCanvas );
576 mCanvas->setMapTool( mMapToolPrevious );
577 emit toggleDialogVisibility( true );
578 mMapToolPrevious = nullptr;
579}
580
581void QgsExtentWidget::mapToolDeactivated()
582{
583 emit toggleDialogVisibility( true );
584 mMapToolPrevious = nullptr;
585}
586
588{
589 return mOutputExtent;
590}
591
592void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
593{
594 if ( canvas )
595 {
596 mCanvas = canvas;
597 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
598 mCurrentExtentButton->setVisible( true );
599
600 mUseCanvasExtentAction->setVisible( true );
601 mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
602
603 mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
604 mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( u"/mActionMapIdentification.svg"_s ) );
605 connect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
606 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
607 }
608 else
609 {
610 mButtonDrawOnCanvas->setVisible( false );
611 mCurrentExtentButton->setVisible( false );
612 mUseCanvasExtentAction->setVisible( false );
613 mUseCanvasExtentAction->setVisible( false );
614
615 mCondensedToolButton->setToolTip( QString() );
616 mCondensedToolButton->setIcon( QIcon() );
617 disconnect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
618 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
619 }
620}
621
622void QgsExtentWidget::dragEnterEvent( QDragEnterEvent *event )
623{
624 if ( !( event->possibleActions() & Qt::CopyAction ) )
625 {
626 event->ignore();
627 return;
628 }
629
630 if ( mapLayerFromMimeData( event->mimeData() ) )
631 {
632 // dragged an acceptable layer, phew
633 event->setDropAction( Qt::CopyAction );
634 event->accept();
635 mCondensedLineEdit->setHighlighted( true );
636 update();
637 }
638 else
639 {
640 event->ignore();
641 }
642}
643
644void QgsExtentWidget::dragLeaveEvent( QDragLeaveEvent *event )
645{
646 if ( mCondensedLineEdit->isHighlighted() )
647 {
648 event->accept();
649 mCondensedLineEdit->setHighlighted( false );
650 update();
651 }
652 else
653 {
654 event->ignore();
655 }
656}
657
658void QgsExtentWidget::dropEvent( QDropEvent *event )
659{
660 if ( !( event->possibleActions() & Qt::CopyAction ) )
661 {
662 event->ignore();
663 return;
664 }
665
666 if ( QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
667 {
668 // dropped a map layer
669 setFocus( Qt::MouseFocusReason );
670 event->setDropAction( Qt::CopyAction );
671 event->accept();
672
674 }
675 else
676 {
677 event->ignore();
678 }
679 mCondensedLineEdit->setHighlighted( false );
680 update();
681}
682
683void QgsExtentWidget::showEvent( QShowEvent * )
684{
685 if ( mFirstShow )
686 {
687 // we don't support select on canvas if the dialog is modal
688 if ( QWidget *parentWindow = window() )
689 {
690 if ( parentWindow->isModal() )
691 {
692 mBlockDrawOnCanvas = true;
693 mDrawOnCanvasAction->setVisible( false );
694 }
695 }
696 mFirstShow = false;
697 }
698}
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
Definition qgis.h:2491
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated).
Definition qgis.h:5175
@ Feet
Imperial feet.
Definition qgis.h:5138
@ MilesUSSurvey
US Survey miles.
Definition qgis.h:5182
@ LinksBritishSears1922
British links (Sears 1922).
Definition qgis.h:5170
@ YardsBritishBenoit1895A
British yards (Benoit 1895 A).
Definition qgis.h:5173
@ LinksBritishBenoit1895A
British links (Benoit 1895 A).
Definition qgis.h:5167
@ Centimeters
Centimeters.
Definition qgis.h:5143
@ YardsIndian1975
Indian yards (1975).
Definition qgis.h:5181
@ FeetUSSurvey
US Survey feet.
Definition qgis.h:5165
@ Millimeters
Millimeters.
Definition qgis.h:5144
@ FeetBritishSears1922
British feet (Sears 1922).
Definition qgis.h:5158
@ YardsClarkes
Clarke's yards.
Definition qgis.h:5177
@ YardsIndian
Indian yards.
Definition qgis.h:5178
@ FeetBritishBenoit1895B
British feet (Benoit 1895 B).
Definition qgis.h:5156
@ Miles
Terrestrial miles.
Definition qgis.h:5141
@ LinksUSSurvey
US Survey links.
Definition qgis.h:5172
@ Meters
Meters.
Definition qgis.h:5136
@ ChainsUSSurvey
US Survey chains.
Definition qgis.h:5152
@ FeetClarkes
Clarke's feet.
Definition qgis.h:5159
@ Unknown
Unknown distance unit.
Definition qgis.h:5185
@ Yards
Imperial yards.
Definition qgis.h:5140
@ FeetBritish1936
British feet (1936).
Definition qgis.h:5154
@ FeetIndian1962
Indian feet (1962).
Definition qgis.h:5163
@ YardsBritishSears1922
British yards (Sears 1922).
Definition qgis.h:5176
@ FeetIndian1937
Indian feet (1937).
Definition qgis.h:5162
@ YardsIndian1937
Indian yards (1937).
Definition qgis.h:5179
@ Degrees
Degrees, for planar geographic CRS distance measurements.
Definition qgis.h:5142
@ ChainsBritishBenoit1895B
British chains (Benoit 1895 B).
Definition qgis.h:5148
@ LinksBritishSears1922Truncated
British links (Sears 1922 truncated).
Definition qgis.h:5169
@ ChainsBritishBenoit1895A
British chains (Benoit 1895 A).
Definition qgis.h:5147
@ YardsBritishBenoit1895B
British yards (Benoit 1895 B).
Definition qgis.h:5174
@ FeetBritish1865
British feet (1865).
Definition qgis.h:5153
@ YardsIndian1962
Indian yards (1962).
Definition qgis.h:5180
@ FeetBritishSears1922Truncated
British feet (Sears 1922 truncated).
Definition qgis.h:5157
@ MetersGermanLegal
German legal meter.
Definition qgis.h:5184
@ LinksBritishBenoit1895B
British links (Benoit 1895 B).
Definition qgis.h:5168
@ ChainsInternational
International chains.
Definition qgis.h:5146
@ Inches
Inches.
Definition qgis.h:5145
@ Fathoms
Fathoms.
Definition qgis.h:5183
@ LinksInternational
International links.
Definition qgis.h:5166
@ ChainsBritishSears1922Truncated
British chains (Sears 1922 truncated).
Definition qgis.h:5149
@ FeetIndian
Indian (geodetic) feet.
Definition qgis.h:5161
@ NauticalMiles
Nautical miles.
Definition qgis.h:5139
@ ChainsClarkes
Clarke's chains.
Definition qgis.h:5151
@ LinksClarkes
Clarke's links.
Definition qgis.h:5171
@ ChainsBritishSears1922
British chains (Sears 1922).
Definition qgis.h:5150
@ Kilometers
Kilometers.
Definition qgis.h:5137
@ FeetIndian1975
Indian feet (1975).
Definition qgis.h:5164
@ FeetGoldCoast
Gold Coast feet.
Definition qgis.h:5160
@ FeetBritishBenoit1895A
British feet (Benoit 1895 A).
Definition qgis.h:5155
@ SpatialLayer
All spatial layers.
Definition qgis.h:239
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.
Represents a coordinate reference system (CRS).
Handles coordinate transforms between two 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.
A custom validator which allows entry of doubles in a locale-tolerant way.
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 extentLayerChanged(QgsMapLayer *layer)
Emitted when the extent layer is changed.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
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.
A proxy model which provides an easy to use model to display the list of layers in widgets.
Base class for all map layer types.
Definition qgsmaplayer.h:83
QString name
Definition qgsmaplayer.h:87
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
Contains configuration for rendering maps.
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.
void extentChanged(const QgsRectangle &extent)
signal emitted on extent change
void deactivated()
Emitted when the map tool is deactivated.
QList< QgsMimeDataUtils::Uri > UriList
static UriList decodeUriList(const QMimeData *data)
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.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:6854