17#include "moc_qgsextentwidget.cpp"
35#include <QRegularExpression>
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 );
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 );
50 connect( mCondensedLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
52 mLayerMenu =
new QMenu( tr(
"Calculate from Layer" ),
this );
53 mButtonCalcFromLayer->setMenu( mLayerMenu );
54 connect( mLayerMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::layerMenuAboutToShow );
58 mLayoutMenu =
new QMenu( tr(
"Calculate from Layout Map" ),
this );
59 mButtonCalcFromLayout->setMenu( mLayoutMenu );
60 connect( mLayoutMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::layoutMenuAboutToShow );
62 mBookmarkMenu =
new QMenu( tr(
"Calculate from Bookmark" ),
this );
63 mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
64 connect( mBookmarkMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::bookmarkMenuAboutToShow );
66 mMenu =
new QMenu(
this );
67 mUseCanvasExtentAction =
new QAction( tr(
"Use Current Map Canvas Extent" ),
this );
69 mUseCanvasExtentAction->setVisible(
false );
72 mUseCurrentExtentAction =
new QAction( tr(
"Use Current Layer/Default Extent" ),
this );
73 mUseCurrentExtentAction->setVisible(
false );
76 mDrawOnCanvasAction =
new QAction( tr(
"Draw on Map Canvas" ),
this );
77 mDrawOnCanvasAction->setVisible(
false );
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 );
88 mCondensedToolButton->setMenu( mMenu );
89 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
96 mOriginalExtentButton->setVisible(
false );
97 mButtonDrawOnCanvas->setVisible(
false );
98 mCurrentExtentButton->setVisible(
false );
107 mExpandedWidget->hide();
111 mCondensedFrame->hide();
115 setAcceptDrops(
true );
120 if ( mMapToolExtent )
134 mOriginalExtentButton->setVisible(
true );
143 mCurrentExtentButton->setVisible(
true );
144 mUseCurrentExtentAction->setVisible(
true );
149 mHasFixedOutputCrs =
true;
152 const bool prevExtentEnabled = mIsValid;
153 switch ( mExtentState )
192 if ( !prevExtentEnabled )
200 if ( !mHasFixedOutputCrs )
207 if ( mOutputCrs == srcCrs )
216 ct.setBallparkTransformsAreAppropriate(
true );
217 extent = ct.transformBoundingBox( r );
285 mXMinLineEdit->setText( QLocale().toString( extent.
xMinimum(),
'f', decimals ) );
286 mXMaxLineEdit->setText( QLocale().toString( extent.
xMaximum(),
'f', decimals ) );
287 mYMinLineEdit->setText( QLocale().toString( extent.
yMinimum(),
'f', decimals ) );
288 mYMaxLineEdit->setText( QLocale().toString( extent.
yMaximum(),
'f', decimals ) );
290 QString condensed = QStringLiteral(
"%1,%2,%3,%4" ).arg( QString::number( extent.
xMinimum(),
'f', decimals ), QString::number( extent.
xMaximum(),
'f', decimals ), QString::number( extent.
yMinimum(),
'f', decimals ), QString::number( extent.
yMaximum(),
'f', decimals ) );
292 mCondensedLineEdit->setText( condensed );
294 mExtentState = state;
302void QgsExtentWidget::setOutputExtentFromLineEdit()
308void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
310 const QString text = mCondensedLineEdit->text();
311 if ( text.isEmpty() )
317 const QRegularExpressionMatch match = mCondensedRe.match( text );
318 if ( match.hasMatch() )
321 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble(),
'f', 10 ) );
322 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble(),
'f', 10 ) );
323 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble(),
'f', 10 ) );
324 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble(),
'f', 10 ) );
325 if ( !match.captured( 5 ).isEmpty() )
339 const bool prevWasNull = mIsValid;
354 return mExtentLayerName;
364 mCondensedLineEdit->setShowClearButton( allowed );
365 mCondensedLineEdit->setNullValue( notSetText );
368void QgsExtentWidget::setValid(
bool valid )
370 if ( valid == mIsValid )
377void QgsExtentWidget::layerMenuAboutToShow()
379 qDeleteAll( mLayerMenuActions );
380 mLayerMenuActions.clear();
382 for (
int i = 0; i < mMapLayerModel->rowCount(); ++i )
384 const QModelIndex index = mMapLayerModel->index( i, 0 );
385 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
386 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
387 QAction *act =
new QAction( icon, text, mLayerMenu );
388 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
390 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
392 act->setCheckable(
true );
393 act->setChecked(
true );
395 connect( act, &QAction::triggered,
this, [
this, layerId] {
396 setExtentToLayerExtent( layerId );
398 mLayerMenu->addAction( act );
399 mLayerMenuActions << act;
403void QgsExtentWidget::layoutMenuAboutToShow()
405 mLayoutMenu->clear();
409 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
412 QList<QgsLayoutItemMap *> maps;
413 layout->layoutItems( maps );
417 QMenu *layoutMenu =
new QMenu( layout->name(), mMenu );
422 QAction *mapExtentAction =
new QAction( tr(
"%1" ).arg( map->displayName() ), mLayoutMenu );
424 layoutMenu->addAction( mapExtentAction );
426 mLayoutMenu->addMenu( layoutMenu );
431void QgsExtentWidget::bookmarkMenuAboutToShow()
433 mBookmarkMenu->clear();
435 if ( !mBookmarkModel )
438 QMap<QString, QMenu *> groupMenus;
439 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
442 QMenu *destMenu = mBookmarkMenu;
443 if ( !group.isEmpty() )
445 destMenu = groupMenus.value( group );
448 destMenu =
new QMenu( group, mBookmarkMenu );
449 groupMenus[group] = destMenu;
455 destMenu->addAction( action );
458 QStringList groupKeys = groupMenus.keys();
459 groupKeys.sort( Qt::CaseInsensitive );
460 for (
int i = 0; i < groupKeys.count(); ++i )
462 if ( mBookmarkMenu->actions().value( i ) )
463 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
465 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
469void QgsExtentWidget::setExtentToLayerExtent(
const QString &layerId )
478QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData(
const QMimeData *data )
const
503 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
523 mExtentLayer = layer;
524 mExtentLayerName = layer->
name();
533 mMapToolPrevious = mCanvas->
mapTool();
534 if ( !mMapToolExtent )
540 mMapToolExtent->setRatio( mRatio );
547void QgsExtentWidget::extentDrawn(
const QgsRectangle &extent )
552 mMapToolPrevious =
nullptr;
555void QgsExtentWidget::mapToolDeactivated()
558 mMapToolPrevious =
nullptr;
585 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
586 mCurrentExtentButton->setVisible(
true );
588 mUseCanvasExtentAction->setVisible(
true );
589 mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
591 mCondensedToolButton->setToolTip( tr(
"Set to current map canvas extent" ) );
594 mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
598 mButtonDrawOnCanvas->setVisible(
false );
599 mCurrentExtentButton->setVisible(
false );
600 mUseCanvasExtentAction->setVisible(
false );
601 mUseCanvasExtentAction->setVisible(
false );
603 mCondensedToolButton->setToolTip( QString() );
604 mCondensedToolButton->setIcon( QIcon() );
606 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
612 if ( !( event->possibleActions() & Qt::CopyAction ) )
618 if ( mapLayerFromMimeData( event->mimeData() ) )
621 event->setDropAction( Qt::CopyAction );
623 mCondensedLineEdit->setHighlighted(
true );
634 if ( mCondensedLineEdit->isHighlighted() )
637 mCondensedLineEdit->setHighlighted(
false );
648 if ( !( event->possibleActions() & Qt::CopyAction ) )
654 if (
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
657 setFocus( Qt::MouseFocusReason );
658 event->setDropAction( Qt::CopyAction );
667 mCondensedLineEdit->setHighlighted(
false );
676 if ( QWidget *parentWindow = window() )
678 if ( parentWindow->isModal() )
680 mBlockDrawOnCanvas =
true;
681 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.
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