28 #include <QRegularExpression>
34 connect( mXMinLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromLineEdit );
35 connect( mXMaxLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromLineEdit );
36 connect( mYMinLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromLineEdit );
37 connect( mYMaxLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromLineEdit );
39 mCondensedRe = QRegularExpression( QStringLiteral(
"\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*,\\s*([\\d\\.\\-]+)\\s*(?:\\[(.*?)\\])?" ) );
40 mCondensedLineEdit->setValidator(
new QRegularExpressionValidator( mCondensedRe,
this ) );
41 mCondensedLineEdit->setShowClearButton(
false );
43 connect( mCondensedLineEdit, &QLineEdit::textEdited,
this, &QgsExtentWidget::setOutputExtentFromCondensedLineEdit );
45 mLayerMenu =
new QMenu( tr(
"Calculate from Layer" ),
this );
46 mButtonCalcFromLayer->setMenu( mLayerMenu );
47 connect( mLayerMenu, &QMenu::aboutToShow,
this, &QgsExtentWidget::layerMenuAboutToShow );
50 mMenu =
new QMenu(
this );
51 mUseCanvasExtentAction =
new QAction( tr(
"Use Map Canvas Extent" ),
this );
54 mUseCurrentExtentAction =
new QAction( tr(
"Use Current Layer Extent" ),
this );
57 mDrawOnCanvasAction =
new QAction( tr(
"Draw on Canvas" ),
this );
60 mMenu->addMenu( mLayerMenu );
62 mCondensedToolButton->setMenu( mMenu );
63 mCondensedToolButton->setPopupMode( QToolButton::InstantPopup );
70 mOriginalExtentButton->setVisible(
false );
71 mButtonDrawOnCanvas->setVisible(
false );
72 mCurrentExtentButton->setVisible(
false );
81 mExpandedWidget->hide();
85 mCondensedFrame->hide();
89 setAcceptDrops(
true );
97 mOriginalExtentButton->setVisible(
true );
106 mCurrentExtentButton->setVisible(
true );
107 mMenu->addAction( mUseCurrentExtentAction );
112 mHasFixedOutputCrs =
true;
115 bool prevExtentEnabled = mIsValid;
116 switch ( mExtentState )
154 if ( !prevExtentEnabled )
162 if ( !mHasFixedOutputCrs )
169 if ( mOutputCrs == srcCrs )
178 extent = ct.transformBoundingBox( r );
206 mXMinLineEdit->setText( QLocale().toString( extent.
xMinimum(),
'f', decimals ) );
207 mXMaxLineEdit->setText( QLocale().toString( extent.
xMaximum(),
'f', decimals ) );
208 mYMinLineEdit->setText( QLocale().toString( extent.
yMinimum(),
'f', decimals ) );
209 mYMaxLineEdit->setText( QLocale().toString( extent.
yMaximum(),
'f', decimals ) );
211 QString condensed = QStringLiteral(
"%1,%2,%3,%4" ).arg( QString::number( extent.
xMinimum(),
'f', decimals ),
212 QString::number( extent.
xMaximum(),
'f', decimals ),
213 QString::number( extent.
yMinimum(),
'f', decimals ),
214 QString::number( extent.
yMaximum(),
'f', decimals ) );
216 mCondensedLineEdit->setText( condensed );
218 mExtentState = state;
226 void QgsExtentWidget::setOutputExtentFromLineEdit()
232 void QgsExtentWidget::setOutputExtentFromCondensedLineEdit()
234 const QString text = mCondensedLineEdit->text();
235 if ( text.isEmpty() )
241 const QRegularExpressionMatch match = mCondensedRe.match( text );
242 if ( match.hasMatch() )
244 whileBlocking( mXMinLineEdit )->setText( match.captured( 1 ) );
245 whileBlocking( mXMaxLineEdit )->setText( match.captured( 2 ) );
246 whileBlocking( mYMinLineEdit )->setText( match.captured( 3 ) );
247 whileBlocking( mYMaxLineEdit )->setText( match.captured( 4 ) );
248 if ( !match.captured( 5 ).isEmpty() )
262 bool prevWasNull = mIsValid;
277 return mExtentLayerName;
287 mCondensedLineEdit->setShowClearButton( allowed );
288 mCondensedLineEdit->setNullValue( notSetText );
291 void QgsExtentWidget::setValid(
bool valid )
293 if ( valid == mIsValid )
300 void QgsExtentWidget::layerMenuAboutToShow()
302 qDeleteAll( mLayerMenuActions );
303 mLayerMenuActions.clear();
305 for (
int i = 0; i < mMapLayerModel->
rowCount(); ++i )
307 QModelIndex index = mMapLayerModel->
index( i, 0 );
308 QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->
data( index, Qt::DecorationRole ) );
309 QString text = mMapLayerModel->
data( index, Qt::DisplayRole ).toString();
310 QAction *act =
new QAction( icon, text, mLayerMenu );
311 act->setToolTip( mMapLayerModel->
data( index, Qt::ToolTipRole ).toString() );
313 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
315 act->setCheckable(
true );
316 act->setChecked(
true );
318 connect( act, &QAction::triggered,
this, [
this, layerId]
320 setExtentToLayerExtent( layerId );
322 mLayerMenu->addAction( act );
323 mLayerMenuActions << act;
327 void QgsExtentWidget::setExtentToLayerExtent(
const QString &layerId )
336 QgsMapLayer *QgsExtentWidget::mapLayerFromMimeData(
const QMimeData *data )
const
361 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
381 mExtentLayer = layer;
382 mExtentLayerName = layer->
name();
391 mMapToolPrevious = mCanvas->
mapTool();
392 if ( !mMapToolExtent )
398 emit toggleDialogVisibility( true );
399 mMapToolPrevious = nullptr;
402 mMapToolExtent->setRatio( mRatio );
409 void QgsExtentWidget::extentDrawn(
const QgsRectangle &extent )
414 mMapToolPrevious =
nullptr;
428 mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
429 mCurrentExtentButton->setVisible(
true );
431 mMenu->addAction( mUseCanvasExtentAction );
432 if ( drawOnCanvasOption )
433 mMenu->addAction( mDrawOnCanvasAction );
437 mButtonDrawOnCanvas->setVisible(
false );
438 mCurrentExtentButton->setVisible(
false );
439 mMenu->removeAction( mUseCanvasExtentAction );
440 mMenu->removeAction( mDrawOnCanvasAction );
446 if ( !( event->possibleActions() & Qt::CopyAction ) )
452 if ( mapLayerFromMimeData( event->mimeData() ) )
455 event->setDropAction( Qt::CopyAction );
457 mCondensedLineEdit->setHighlighted(
true );
468 if ( mCondensedLineEdit->isHighlighted() )
471 mCondensedLineEdit->setHighlighted(
false );
482 if ( !( event->possibleActions() & Qt::CopyAction ) )
488 if (
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
491 setFocus( Qt::MouseFocusReason );
492 event->setDropAction( Qt::CopyAction );
501 mCondensedLineEdit->setHighlighted(
false );
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
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.
Map canvas is a class for displaying all GIS data types on a canvas.
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.
The QgsMapLayerModel class is a model to display layers in widgets.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
@ LayerIdRole
Stores the map layer ID.
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 takes output image size into accou...
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)
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 yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceKilometers
Kilometers.
@ DistanceMiles
Terrestrial miles.
@ DistanceUnknownUnit
Unknown distance unit.
@ DistanceMillimeters
Millimeters.
@ DistanceYards
Imperial yards.
@ DistanceFeet
Imperial feet.
@ DistanceNauticalMiles
Nautical miles.
@ DistanceCentimeters
Centimeters.
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