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 ),
291 QString::number( extent.
xMaximum(),
'f', decimals ),
292 QString::number( extent.
yMinimum(),
'f', decimals ),
293 QString::number( extent.
yMaximum(),
'f', decimals ) );
295 mCondensedLineEdit->setText( condensed );
297 mExtentState = state;
305void QgsExtentWidget::setOutputExtentFromLineEdit()
311void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
313 const QString text = mCondensedLineEdit->text();
314 if ( text.isEmpty() )
320 const QRegularExpressionMatch match = mCondensedRe.match( text );
321 if ( match.hasMatch() )
324 whileBlocking( mXMinLineEdit )->setText( QLocale().toString( match.captured( 1 ).toDouble(),
'f', 10 ) );
325 whileBlocking( mXMaxLineEdit )->setText( QLocale().toString( match.captured( 2 ).toDouble(),
'f', 10 ) );
326 whileBlocking( mYMinLineEdit )->setText( QLocale().toString( match.captured( 3 ).toDouble(),
'f', 10 ) );
327 whileBlocking( mYMaxLineEdit )->setText( QLocale().toString( match.captured( 4 ).toDouble(),
'f', 10 ) );
328 if ( !match.captured( 5 ).isEmpty() )
342 const bool prevWasNull = mIsValid;
357 return mExtentLayerName;
367 mCondensedLineEdit->setShowClearButton( allowed );
368 mCondensedLineEdit->setNullValue( notSetText );
371void QgsExtentWidget::setValid(
bool valid )
373 if ( valid == mIsValid )
380void QgsExtentWidget::layerMenuAboutToShow()
382 qDeleteAll( mLayerMenuActions );
383 mLayerMenuActions.clear();
385 for (
int i = 0; i < mMapLayerModel->rowCount(); ++i )
387 const QModelIndex index = mMapLayerModel->index( i, 0 );
388 const QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) );
389 const QString text = mMapLayerModel->data( index, Qt::DisplayRole ).toString();
390 QAction *act =
new QAction( icon, text, mLayerMenu );
391 act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
393 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
395 act->setCheckable(
true );
396 act->setChecked(
true );
398 connect( act, &QAction::triggered,
this, [
this, layerId]
400 setExtentToLayerExtent( layerId );
402 mLayerMenu->addAction( act );
403 mLayerMenuActions << act;
407void QgsExtentWidget::layoutMenuAboutToShow()
409 mLayoutMenu->clear();
413 const QList<QgsPrintLayout *> layouts = manager->printLayouts();
416 QList< QgsLayoutItemMap * > maps;
417 layout->layoutItems( maps );
421 QMenu *layoutMenu =
new QMenu( layout->name(), mMenu );
426 QAction *mapExtentAction =
new QAction( tr(
"%1" ).arg( map->displayName() ), mLayoutMenu );
428 layoutMenu->addAction( mapExtentAction );
430 mLayoutMenu->addMenu( layoutMenu );
435void QgsExtentWidget::bookmarkMenuAboutToShow()
437 mBookmarkMenu->clear();
439 if ( !mBookmarkModel )
442 QMap< QString, QMenu * > groupMenus;
443 for (
int i = 0; i < mBookmarkModel->rowCount(); ++i )
446 QMenu *destMenu = mBookmarkMenu;
447 if ( !group.isEmpty() )
449 destMenu = groupMenus.value( group );
452 destMenu =
new QMenu( group, mBookmarkMenu );
453 groupMenus[ group ] = destMenu;
459 destMenu->addAction( action );
462 QStringList groupKeys = groupMenus.keys();
463 groupKeys.sort( Qt::CaseInsensitive );
464 for (
int i = 0; i < groupKeys.count(); ++i )
466 if ( mBookmarkMenu->actions().value( i ) )
467 mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
469 mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
473void QgsExtentWidget::setExtentToLayerExtent(
const QString &layerId )
482QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData(
const QMimeData *data )
const
507 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
527 mExtentLayer = layer;
528 mExtentLayerName = layer->
name();
537 mMapToolPrevious = mCanvas->
mapTool();
538 if ( !mMapToolExtent )
544 mMapToolExtent->setRatio( mRatio );
551void QgsExtentWidget::extentDrawn(
const QgsRectangle &extent )
556 mMapToolPrevious =
nullptr;
559void QgsExtentWidget::mapToolDeactivated()
562 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