QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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"
19 #include "qgslogger.h"
20 #include "qgscoordinatetransform.h"
21 #include "qgsmapcanvas.h"
22 #include "qgsmaplayerproxymodel.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"
31 #include "qgsreferencedgeometry.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 );
56  mMapLayerModel->setFilters( QgsMapLayerProxyModel::Filter::SpatialLayer );
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 
129 void QgsExtentWidget::setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs )
130 {
131  mOriginalExtent = originalExtent;
132  mOriginalCrs = originalCrs;
133 
134  mOriginalExtentButton->setVisible( true );
135 }
136 
137 
138 void QgsExtentWidget::setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs )
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 
165  case ProjectLayerExtent:
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 
197 void 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;
242  decimals = 4;
243  break;
244  }
245  mXMinLineEdit->setText( QLocale().toString( extent.xMinimum(), 'f', decimals ) );
246  mXMaxLineEdit->setText( QLocale().toString( extent.xMaximum(), 'f', decimals ) );
247  mYMinLineEdit->setText( QLocale().toString( extent.yMinimum(), 'f', decimals ) );
248  mYMaxLineEdit->setText( QLocale().toString( extent.yMaximum(), 'f', decimals ) );
249 
250  QString condensed = QStringLiteral( "%1,%2,%3,%4" ).arg( QString::number( extent.xMinimum(), 'f', decimals ),
251  QString::number( extent.xMaximum(), 'f', decimals ),
252  QString::number( extent.yMinimum(), 'f', decimals ),
253  QString::number( extent.yMaximum(), 'f', decimals ) );
254  condensed += QStringLiteral( " [%1]" ).arg( mOutputCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );
255  mCondensedLineEdit->setText( condensed );
256 
257  mExtentState = state;
258 
259  if ( !mIsValid )
260  setValid( true );
261 
262  emit extentChanged( extent );
263 }
264 
265 void QgsExtentWidget::setOutputExtentFromLineEdit()
266 {
267  mExtentState = UserExtent;
268  emit extentChanged( outputExtent() );
269 }
270 
271 void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
272 {
273  const QString text = mCondensedLineEdit->text();
274  if ( text.isEmpty() )
275  {
276  clear();
277  }
278  else
279  {
280  const QRegularExpressionMatch match = mCondensedRe.match( text );
281  if ( match.hasMatch() )
282  {
283  // Localization
284  whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble() ) );
285  whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble() ) );
286  whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble() ) );
287  whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble() ) );
288  if ( !match.captured( 5 ).isEmpty() )
289  {
290  mOutputCrs = QgsCoordinateReferenceSystem( match.captured( 5 ) );
291  }
292 
293  emit extentChanged( outputExtent() );
294  if ( !mIsValid )
295  setValid( true );
296  }
297  }
298 }
299 
301 {
302  const bool prevWasNull = mIsValid;
303 
304  whileBlocking( mXMinLineEdit )->clear();
305  whileBlocking( mXMaxLineEdit )->clear();
306  whileBlocking( mYMinLineEdit )->clear();
307  whileBlocking( mYMaxLineEdit )->clear();
308  whileBlocking( mCondensedLineEdit )->clearValue();
309  setValid( false );
310 
311  if ( prevWasNull )
312  emit extentChanged( outputExtent() );
313 }
314 
316 {
317  return mExtentLayerName;
318 }
319 
321 {
322  return mIsValid;
323 }
324 
325 void QgsExtentWidget::setNullValueAllowed( bool allowed, const QString &notSetText )
326 {
327  mCondensedLineEdit->setShowClearButton( allowed );
328  mCondensedLineEdit->setNullValue( notSetText );
329 }
330 
331 void QgsExtentWidget::setValid( bool valid )
332 {
333  if ( valid == mIsValid )
334  return;
335 
336  mIsValid = valid;
337  emit validationChanged( mIsValid );
338 }
339 
340 void QgsExtentWidget::layerMenuAboutToShow()
341 {
342  qDeleteAll( mLayerMenuActions );
343  mLayerMenuActions.clear();
344  mLayerMenu->clear();
345  for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
346  {
347  const QModelIndex index = mMapLayerModel->index( i, 0 );
348  const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
349  const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
350  QAction *act = new QAction( icon, text, mLayerMenu );
351  act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
352  const QString layerId = mMapLayerModel->data( index, QgsMapLayerModel::LayerIdRole ).toString();
353  if ( mExtentState == ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
354  {
355  act->setCheckable( true );
356  act->setChecked( true );
357  }
358  connect( act, &QAction::triggered, this, [this, layerId]
359  {
360  setExtentToLayerExtent( layerId );
361  } );
362  mLayerMenu->addAction( act );
363  mLayerMenuActions << act;
364  }
365 }
366 
367 void QgsExtentWidget::layoutMenuAboutToShow()
368 {
369  mLayoutMenu->clear();
370 
371  if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
372  {
373  const QList<QgsPrintLayout *> layouts = manager->printLayouts();
374  for ( const QgsPrintLayout *layout : layouts )
375  {
376  QList< QgsLayoutItemMap * > maps;
377  layout->layoutItems( maps );
378  if ( maps.empty() )
379  continue;
380 
381  QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
382  for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
383  {
384  QgsRectangle extent = map->extent();
385  QgsCoordinateReferenceSystem crs = map->crs();
386  QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
387  connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
388  layoutMenu->addAction( mapExtentAction );
389  }
390  mLayoutMenu->addMenu( layoutMenu );
391  }
392  }
393 }
394 
395 void QgsExtentWidget::bookmarkMenuAboutToShow()
396 {
397  mBookmarkMenu->clear();
398 
399  if ( !mBookmarkModel )
400  mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );
401 
402  QMap< QString, QMenu * > groupMenus;
403  for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
404  {
405  const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleGroup ).toString();
406  QMenu *destMenu = mBookmarkMenu;
407  if ( !group.isEmpty() )
408  {
409  destMenu = groupMenus.value( group );
410  if ( !destMenu )
411  {
412  destMenu = new QMenu( group, mBookmarkMenu );
413  groupMenus[ group ] = destMenu;
414  }
415  }
416  QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleName ).toString(), mBookmarkMenu );
417  const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleExtent ).value< QgsReferencedRectangle >();
418  connect( action, &QAction::triggered, this, [ = ] { setOutputExtentFromUser( extent, extent.crs() ); } );
419  destMenu->addAction( action );
420  }
421 
422  QStringList groupKeys = groupMenus.keys();
423  groupKeys.sort( Qt::CaseInsensitive );
424  for ( int i = 0; i < groupKeys.count(); ++i )
425  {
426  if ( mBookmarkMenu->actions().value( i ) )
427  mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
428  else
429  mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
430  }
431 }
432 
433 void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
434 {
435  QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
436  if ( !layer )
437  return;
438 
439  setOutputExtentFromLayer( layer );
440 }
441 
442 QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( const QMimeData *data ) const
443 {
445  for ( const QgsMimeDataUtils::Uri &u : uriList )
446  {
447  // is this uri from the current project?
448  if ( QgsMapLayer *layer = u.mapLayer() )
449  {
450  return layer;
451  }
452  }
453  return nullptr;
454 }
455 
457 {
458  if ( mCanvas )
459  {
460  // Use unrotated visible extent to insure output size and scale matches canvas
461  QgsMapSettings ms = mCanvas->mapSettings();
462  ms.setRotation( 0 );
463  setOutputExtent( ms.visibleExtent(), ms.destinationCrs(), CurrentExtent );
464  }
465  else
466  {
467  setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
468  }
469 }
470 
471 
473 {
474  setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
475 }
476 
478 {
479  setOutputExtent( extent, crs, UserExtent );
480 }
481 
483 {
484  if ( !layer )
485  return;
486 
487  mExtentLayer = layer;
488  mExtentLayerName = layer->name();
489 
490  setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
491 }
492 
494 {
495  if ( mCanvas )
496  {
497  mMapToolPrevious = mCanvas->mapTool();
498  if ( !mMapToolExtent )
499  {
500  mMapToolExtent.reset( new QgsMapToolExtent( mCanvas ) );
501  connect( mMapToolExtent.get(), &QgsMapToolExtent::extentChanged, this, &QgsExtentWidget::extentDrawn );
502  connect( mMapToolExtent.get(), &QgsMapTool::deactivated, this, &QgsExtentWidget::mapToolDeactivated );
503  }
504  mMapToolExtent->setRatio( mRatio );
505  mCanvas->setMapTool( mMapToolExtent.get() );
506 
507  emit toggleDialogVisibility( false );
508  }
509 }
510 
511 void QgsExtentWidget::extentDrawn( const QgsRectangle &extent )
512 {
513  setOutputExtent( extent, mCanvas->mapSettings().destinationCrs(), DrawOnCanvas );
514  mCanvas->setMapTool( mMapToolPrevious );
515  emit toggleDialogVisibility( true );
516  mMapToolPrevious = nullptr;
517 }
518 
519 void QgsExtentWidget::mapToolDeactivated()
520 {
521  emit toggleDialogVisibility( true );
522  mMapToolPrevious = nullptr;
523 }
524 
526 {
527  return QgsRectangle( QgsDoubleValidator::toDouble( mXMinLineEdit->text() ), QgsDoubleValidator::toDouble( mYMinLineEdit->text() ),
528  QgsDoubleValidator::toDouble( mXMaxLineEdit->text() ), QgsDoubleValidator::toDouble( mYMaxLineEdit->text() ) );
529 }
530 
531 void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
532 {
533  if ( canvas )
534  {
535  mCanvas = canvas;
536  mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
537  mCurrentExtentButton->setVisible( true );
538 
539  mUseCanvasExtentAction->setVisible( true );
540  if ( drawOnCanvasOption )
541  mDrawOnCanvasAction->setVisible( true );
542 
543  mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
544  mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
545  connect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
546  mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
547  }
548  else
549  {
550  mButtonDrawOnCanvas->setVisible( false );
551  mCurrentExtentButton->setVisible( false );
552  mUseCanvasExtentAction->setVisible( false );
553  mUseCanvasExtentAction->setVisible( false );
554 
555  mCondensedToolButton->setToolTip( QString() );
556  mCondensedToolButton->setIcon( QIcon() );
557  disconnect( mCondensedToolButton, &QAbstractButton::clicked, this, &QgsExtentWidget::setOutputExtentFromCurrent );
558  mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
559  }
560 }
561 
562 void QgsExtentWidget::dragEnterEvent( QDragEnterEvent *event )
563 {
564  if ( !( event->possibleActions() & Qt::CopyAction ) )
565  {
566  event->ignore();
567  return;
568  }
569 
570  if ( mapLayerFromMimeData( event->mimeData() ) )
571  {
572  // dragged an acceptable layer, phew
573  event->setDropAction( Qt::CopyAction );
574  event->accept();
575  mCondensedLineEdit->setHighlighted( true );
576  update();
577  }
578  else
579  {
580  event->ignore();
581  }
582 }
583 
584 void QgsExtentWidget::dragLeaveEvent( QDragLeaveEvent *event )
585 {
586  if ( mCondensedLineEdit->isHighlighted() )
587  {
588  event->accept();
589  mCondensedLineEdit->setHighlighted( false );
590  update();
591  }
592  else
593  {
594  event->ignore();
595  }
596 }
597 
598 void QgsExtentWidget::dropEvent( QDropEvent *event )
599 {
600  if ( !( event->possibleActions() & Qt::CopyAction ) )
601  {
602  event->ignore();
603  return;
604  }
605 
606  if ( QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
607  {
608  // dropped a map layer
609  setFocus( Qt::MouseFocusReason );
610  event->setDropAction( Qt::CopyAction );
611  event->accept();
612 
613  setOutputExtentFromLayer( layer );
614  }
615  else
616  {
617  event->ignore();
618  }
619  mCondensedLineEdit->setHighlighted( false );
620  update();
621 }
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.
@ RoleName
Bookmark name.
@ RoleExtent
Bookmark extent as a QgsReferencedRectangle.
@ RoleGroup
Bookmark group.
A QSortFilterProxyModel subclass for sorting the entries in a QgsBookmarkManagerModel.
This class represents a coordinate reference system (CRS).
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
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 SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator and QRegularExpressionVali...
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS).
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
void setCurrentExtent(const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs)
Sets the current extent to show in the widget - should be called as part of initialization (or whenev...
bool isValid() const
Returns true if the widget is in a valid state, i.e.
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
void setNullValueAllowed(bool allowed, const QString &notSetText=QString())
Sets whether the widget can be set to a "not set" (null) state.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
void dragEnterEvent(QDragEnterEvent *event) override
@ UserExtent
Extent manually entered/modified by the user.
@ OriginalExtent
Layer's extent.
@ ProjectLayerExtent
Extent taken from a layer within the project.
@ CurrentExtent
Map canvas extent.
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
void validationChanged(bool valid)
Emitted when the widget's validation state changes.
void dropEvent(QDropEvent *event) override
void clear()
Clears the widget, setting it to a null value.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
void setMapCanvas(QgsMapCanvas *canvas, bool drawOnCanvasOption=true)
Sets the map canvas to enable dragging of extent on a canvas.
~QgsExtentWidget() override
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
WidgetStyle
Widget styles.
@ CondensedStyle
Shows a compressed widget, for use when available space is minimal.
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
QgsExtentWidget(QWidget *parent=nullptr, WidgetStyle style=CondensedStyle)
Constructor for QgsExtentWidget.
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
void dragLeaveEvent(QDragLeaveEvent *event) override
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
QString extentLayerName() const
Returns the name of the extent layer.
void cleared()
Emitted when the widget is cleared.
Layout graphical items for displaying a map.
Manages storage of a set of layouts.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
QgsMapTool * mapTool()
Returns the currently active tool.
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
@ LayerIdRole
Stores the map layer ID.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
QgsMapLayerProxyModel * setFilters(QgsMapLayerProxyModel::Filters filters)
Sets filter flags which affect how layers are filtered within the model.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
QString name
Definition: qgsmaplayer.h:76
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
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.
Definition: qgsproject.cpp:470
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
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.
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:1517
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs