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