34#include <QRegularExpression>
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 );
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 );
49 connect( mCondensedLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
51 mLayerMenu =
new QMenu( tr(
"Calculate from Layer" ),
this );
52 mButtonCalcFromLayer->setMenu( mLayerMenu );
53 connect( mLayerMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::layerMenuAboutToShow );
57 mLayoutMenu =
new QMenu( tr(
"Calculate from Layout Map" ),
this );
58 mButtonCalcFromLayout->setMenu( mLayoutMenu );
59 connect( mLayoutMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::layoutMenuAboutToShow );
61 mBookmarkMenu =
new QMenu( tr(
"Calculate from Bookmark" ),
this );
62 mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
63 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::bookmarkMenuAboutToShow );
65 mMenu =
new QMenu(
this );
66 mUseCanvasExtentAction =
new QAction( tr(
"Use Current Map Canvas Extent" ),
this );
68 mUseCanvasExtentAction->setVisible(
false );
71 mUseCurrentExtentAction =
new QAction( tr(
"Use Current Layer/Default Extent" ),
this );
72 mUseCurrentExtentAction->setVisible(
false );
75 mDrawOnCanvasAction =
new QAction( tr(
"Draw on Map Canvas" ),
this );
76 mDrawOnCanvasAction->setVisible(
false );
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 );
87 mCondensedToolButton->setMenu( mMenu );
88 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
95 mOriginalExtentButton->setVisible(
false );
96 mButtonDrawOnCanvas->setVisible(
false );
97 mCurrentExtentButton->setVisible(
false );
106 mExpandedWidget->hide();
110 mCondensedFrame->hide();
114 setAcceptDrops(
true );
119 if ( mMapToolExtent )
133 mOriginalExtentButton->setVisible(
true );
142 mCurrentExtentButton->setVisible(
true );
143 mUseCurrentExtentAction->setVisible(
true );
148 mHasFixedOutputCrs =
true;
151 const bool prevExtentEnabled = mIsValid;
152 switch ( mExtentState )
191 if ( !prevExtentEnabled )
199 if ( !mHasFixedOutputCrs )
206 if ( mOutputCrs == srcCrs )
215 ct.setBallparkTransformsAreAppropriate(
true );
216 extent = ct.transformBoundingBox( r );
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 ) );
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 ) );
294 mCondensedLineEdit->setText( condensed );
296 mExtentState = state;
304void QgsExtentWidget::setOutputExtentFromLineEdit()
310void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
312 const QString text = mCondensedLineEdit->text();
313 if ( text.isEmpty() )
319 const QRegularExpressionMatch match = mCondensedRe.match( text );
320 if ( match.hasMatch() )
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() )
341 const bool prevWasNull = mIsValid;
356 return mExtentLayerName;
366 mCondensedLineEdit->setShowClearButton( allowed );
367 mCondensedLineEdit->setNullValue( notSetText );
370void QgsExtentWidget::setValid(
bool valid )
372 if ( valid == mIsValid )
379void QgsExtentWidget::layerMenuAboutToShow()
381 qDeleteAll( mLayerMenuActions );
382 mLayerMenuActions.clear();
384 for (
int i = 0; i < mMapLayerModel->rowCount(); ++i )
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() );
392 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
394 act->setCheckable(
true );
395 act->setChecked(
true );
397 connect( act, &QAction::triggered,
this, [
this, layerId]
399 setExtentToLayerExtent( layerId );
401 mLayerMenu->addAction( act );
402 mLayerMenuActions << act;
406void QgsExtentWidget::layoutMenuAboutToShow()
408 mLayoutMenu->clear();
412 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
415 QList< QgsLayoutItemMap * > maps;
416 layout->layoutItems( maps );
420 QMenu *layoutMenu =
new QMenu( layout->name(), mMenu );
425 QAction *mapExtentAction =
new QAction( tr(
"%1" ).arg( map->displayName() ), mLayoutMenu );
427 layoutMenu->addAction( mapExtentAction );
429 mLayoutMenu->addMenu( layoutMenu );
434void QgsExtentWidget::bookmarkMenuAboutToShow()
436 mBookmarkMenu->clear();
438 if ( !mBookmarkModel )
441 QMap< QString, QMenu * > groupMenus;
442 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
445 QMenu *destMenu = mBookmarkMenu;
446 if ( !group.isEmpty() )
448 destMenu = groupMenus.value( group );
451 destMenu =
new QMenu( group, mBookmarkMenu );
452 groupMenus[ group ] = destMenu;
458 destMenu->addAction( action );
461 QStringList groupKeys = groupMenus.keys();
462 groupKeys.sort( Qt::CaseInsensitive );
463 for (
int i = 0; i < groupKeys.count(); ++i )
465 if ( mBookmarkMenu->actions().value( i ) )
466 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
468 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
472void QgsExtentWidget::setExtentToLayerExtent(
const QString &layerId )
481QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData(
const QMimeData *data )
const
506 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
526 mExtentLayer = layer;
527 mExtentLayerName = layer->
name();
536 mMapToolPrevious = mCanvas->
mapTool();
537 if ( !mMapToolExtent )
543 mMapToolExtent->setRatio( mRatio );
550void QgsExtentWidget::extentDrawn(
const QgsRectangle &extent )
555 mMapToolPrevious =
nullptr;
558void QgsExtentWidget::mapToolDeactivated()
561 mMapToolPrevious =
nullptr;
584 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
585 mCurrentExtentButton->setVisible(
true );
587 mUseCanvasExtentAction->setVisible(
true );
588 mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
590 mCondensedToolButton->setToolTip( tr(
"Set to current map canvas extent" ) );
593 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
597 mButtonDrawOnCanvas->setVisible(
false );
598 mCurrentExtentButton->setVisible(
false );
599 mUseCanvasExtentAction->setVisible(
false );
600 mUseCanvasExtentAction->setVisible(
false );
602 mCondensedToolButton->setToolTip( QString() );
603 mCondensedToolButton->setIcon( QIcon() );
605 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
611 if ( !( event->possibleActions() & Qt::CopyAction ) )
617 if ( mapLayerFromMimeData( event->mimeData() ) )
620 event->setDropAction( Qt::CopyAction );
622 mCondensedLineEdit->setHighlighted(
true );
633 if ( mCondensedLineEdit->isHighlighted() )
636 mCondensedLineEdit->setHighlighted(
false );
647 if ( !( event->possibleActions() & Qt::CopyAction ) )
653 if (
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
656 setFocus( Qt::MouseFocusReason );
657 event->setDropAction( Qt::CopyAction );
666 mCondensedLineEdit->setHighlighted(
false );
675 if ( QWidget *parentWindow = window() )
677 if ( parentWindow->isModal() )
679 mBlockDrawOnCanvas =
true;
680 mDrawOnCanvasAction->setVisible(
false );
@ ShortString
A heavily abbreviated string, for use when a compact representation is required.
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated)
@ 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.
@ 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)
@ 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.
Qgis::DistanceUnit mapUnits
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.
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.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
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.
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.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs