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 )
 
  479QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData( 
const QMimeData *data )
 const 
  504    setOutputExtent( mCurrentExtent, mCurrentCrs, 
CurrentExtent );
 
 
  524  mExtentLayer = layer;
 
  525  mExtentLayerName = layer->
name();
 
 
  534    mMapToolPrevious = mCanvas->
mapTool();
 
  535    if ( !mMapToolExtent )
 
  541    mMapToolExtent->setRatio( mRatio );
 
 
  548void QgsExtentWidget::extentDrawn( 
const QgsRectangle &extent )
 
  553  mMapToolPrevious = 
nullptr;
 
  556void QgsExtentWidget::mapToolDeactivated()
 
  559  mMapToolPrevious = 
nullptr;
 
  586    mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
 
  587    mCurrentExtentButton->setVisible( 
true );
 
  589    mUseCanvasExtentAction->setVisible( 
true );
 
  590    mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
 
  592    mCondensedToolButton->setToolTip( tr( 
"Set to current map canvas extent" ) );
 
  595    mCondensedToolButton->setPopupMode( QToolButton::MenuButtonPopup );
 
  599    mButtonDrawOnCanvas->setVisible( 
false );
 
  600    mCurrentExtentButton->setVisible( 
false );
 
  601    mUseCanvasExtentAction->setVisible( 
false );
 
  602    mUseCanvasExtentAction->setVisible( 
false );
 
  604    mCondensedToolButton->setToolTip( QString() );
 
  605    mCondensedToolButton->setIcon( QIcon() );
 
  607    mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
 
 
  613  if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  619  if ( mapLayerFromMimeData( event->mimeData() ) )
 
  622    event->setDropAction( Qt::CopyAction );
 
  624    mCondensedLineEdit->setHighlighted( 
true );
 
 
  635  if ( mCondensedLineEdit->isHighlighted() )
 
  638    mCondensedLineEdit->setHighlighted( 
false );
 
 
  649  if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  655  if ( 
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
 
  658    setFocus( Qt::MouseFocusReason );
 
  659    event->setDropAction( Qt::CopyAction );
 
  668  mCondensedLineEdit->setHighlighted( 
false );
 
 
  677    if ( QWidget *parentWindow = window() )
 
  679      if ( parentWindow->isModal() )
 
  681        mBlockDrawOnCanvas = 
true;
 
  682        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.
 
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.
 
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.
 
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.
 
A proxy model which provides an easy to use model to display the list of layers in widgets.
 
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
 
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.
 
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