27 #include <QDoubleValidator> 31 , mTitleBase( tr(
"Extent" ) )
34 connect( mXMinLineEdit, &QLineEdit::textEdited,
this, &QgsExtentGroupBox::setOutputExtentFromLineEdit );
35 connect( mXMaxLineEdit, &QLineEdit::textEdited,
this, &QgsExtentGroupBox::setOutputExtentFromLineEdit );
36 connect( mYMinLineEdit, &QLineEdit::textEdited,
this, &QgsExtentGroupBox::setOutputExtentFromLineEdit );
37 connect( mYMaxLineEdit, &QLineEdit::textEdited,
this, &QgsExtentGroupBox::setOutputExtentFromLineEdit );
39 mLayerMenu =
new QMenu(
this );
40 mButtonCalcFromLayer->setMenu( mLayerMenu );
41 connect( mLayerMenu, &QMenu::aboutToShow,
this, &QgsExtentGroupBox::layerMenuAboutToShow );
44 mXMinLineEdit->setValidator(
new QDoubleValidator(
this ) );
45 mXMaxLineEdit->setValidator(
new QDoubleValidator(
this ) );
46 mYMinLineEdit->setValidator(
new QDoubleValidator(
this ) );
47 mYMaxLineEdit->setValidator(
new QDoubleValidator(
this ) );
49 mOriginalExtentButton->setVisible(
false );
50 mButtonDrawOnCanvas->setVisible(
false );
51 mCurrentExtentButton->setVisible(
false );
57 connect(
this, &QGroupBox::clicked,
this, &QgsExtentGroupBox::groupBoxClicked );
65 mOriginalExtentButton->setVisible(
true );
74 mCurrentExtentButton->setVisible(
true );
79 if ( mOutputCrs != outputCrs )
81 bool prevExtentEnabled = isChecked();
82 switch ( mExtentState )
120 if ( !prevExtentEnabled )
129 if ( mOutputCrs == srcCrs )
165 mXMinLineEdit->setText( QString::number( extent.
xMinimum(),
'f', decimals ) );
166 mXMaxLineEdit->setText( QString::number( extent.
xMaximum(),
'f', decimals ) );
167 mYMinLineEdit->setText( QString::number( extent.
yMinimum(),
'f', decimals ) );
168 mYMaxLineEdit->setText( QString::number( extent.
yMaximum(),
'f', decimals ) );
170 mExtentState = state;
172 if ( isCheckable() && !isChecked() )
181 void QgsExtentGroupBox::setOutputExtentFromLineEdit()
191 void QgsExtentGroupBox::updateTitle()
194 switch ( mExtentState )
200 msg = tr(
"map view" );
203 msg = tr(
"user defined" );
206 msg = mExtentLayerName;
209 msg = tr(
"drawn on canvas" );
212 if ( isCheckable() && !isChecked() )
214 msg = tr(
"%1 (current: %2)" ).arg( mTitleBase, msg );
219 void QgsExtentGroupBox::layerMenuAboutToShow()
221 qDeleteAll( mMenuActions );
222 mMenuActions.clear();
224 for (
int i = 0; i < mMapLayerModel->
rowCount(); ++i )
226 QModelIndex index = mMapLayerModel->
index( i, 0 );
227 QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->
data( index, Qt::DecorationRole ) );
228 QString text = mMapLayerModel->
data( index, Qt::DisplayRole ).toString();
229 QAction *act =
new QAction( icon, text, mLayerMenu );
230 act->setToolTip( mMapLayerModel->
data( index, Qt::ToolTipRole ).toString() );
232 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
234 act->setCheckable(
true );
235 act->setChecked(
true );
237 connect( act, &QAction::triggered,
this, [
this, layerId]
239 setExtentToLayerExtent( layerId );
241 mLayerMenu->addAction( act );
246 void QgsExtentGroupBox::setExtentToLayerExtent(
const QString &layerId )
266 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
286 mExtentLayer = layer;
287 mExtentLayerName = layer->
name();
296 mMapToolPrevious = mCanvas->
mapTool();
297 if ( !mMapToolExtent )
303 window()->setVisible(
true );
304 mMapToolPrevious =
nullptr;
307 mMapToolExtent->setRatio( mRatio );
309 window()->setVisible(
false );
313 void QgsExtentGroupBox::extentDrawn(
const QgsRectangle &extent )
317 window()->setVisible(
true );
318 mMapToolPrevious =
nullptr;
321 void QgsExtentGroupBox::groupBoxClicked()
323 if ( !isCheckable() )
335 if ( isCheckable() && !isChecked() )
338 return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
339 mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
358 mButtonDrawOnCanvas->setVisible(
true );
359 mCurrentExtentButton->setVisible(
true );
363 mButtonDrawOnCanvas->setVisible(
false );
364 mCurrentExtentButton->setVisible(
false );
Extent manually entered/modified by the user.
A rectangle specified with double values.
Base class for all map layer types.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS)...
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
QString titleBase() const
Returns the base part of title of the group box (will be appended with extent state).
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas to enable dragging of extent on a canvas.
QgsUnitTypes::DistanceUnit mapUnits
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
QgsMapTool * mapTool()
Returns the currently active tool.
const QgsCoordinateReferenceSystem & crs
Map canvas is a class for displaying all GIS data types on a canvas.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual QgsRectangle extent() const
Returns the extent of the layer.
ExtentState
Available states for the current extent selection in the widget.
The QgsMapSettings class contains configuration for rendering of the map.
Extent taken from a rectangled drawn onto the map canvas.
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
Extent taken from a layer within the project.
The QgsMapLayerModel class is a model to display layers in widgets.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Degrees, for planar geographic CRS distance measurements.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent...
void setCurrentExtent(const QgsRectangle ¤tExtent, const QgsCoordinateReferenceSystem ¤tCrs)
Sets the current extent to show in the widget - should be called as part of initialization (or whenev...
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
QgsExtentGroupBox(QWidget *parent=nullptr)
Constructor for QgsExtentGroupBox.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void setTitleBase(const QString &title)
Sets the base part of title of the group box (will be appended with extent state) ...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Custom exception class for Coordinate Reference System related exceptions.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS)...
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
QgsCoordinateReferenceSystem crs