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 switch ( mExtentState )
126 if ( mOutputCrs == srcCrs )
162 mXMinLineEdit->setText( QString::number( extent.
xMinimum(),
'f', decimals ) );
163 mXMaxLineEdit->setText( QString::number( extent.
xMaximum(),
'f', decimals ) );
164 mYMinLineEdit->setText( QString::number( extent.
yMinimum(),
'f', decimals ) );
165 mYMaxLineEdit->setText( QString::number( extent.
yMaximum(),
'f', decimals ) );
167 mExtentState = state;
169 if ( isCheckable() && !isChecked() )
178 void QgsExtentGroupBox::setOutputExtentFromLineEdit()
188 void QgsExtentGroupBox::updateTitle()
191 switch ( mExtentState )
197 msg = tr(
"map view" );
200 msg = tr(
"user defined" );
203 msg = mExtentLayerName;
206 msg = tr(
"drawn on canvas" );
209 if ( isCheckable() && !isChecked() )
211 msg = tr(
"%1 (current: %2)" ).arg( mTitleBase, msg );
216 void QgsExtentGroupBox::layerMenuAboutToShow()
218 qDeleteAll( mMenuActions );
219 mMenuActions.clear();
221 for (
int i = 0; i < mMapLayerModel->
rowCount(); ++i )
223 QModelIndex index = mMapLayerModel->
index( i, 0 );
224 QIcon icon = qvariant_cast<QIcon>( mMapLayerModel->
data( index, Qt::DecorationRole ) );
225 QString text = mMapLayerModel->
data( index, Qt::DisplayRole ).toString();
226 QAction *act =
new QAction( icon, text, mLayerMenu );
227 act->setToolTip( mMapLayerModel->
data( index, Qt::ToolTipRole ).toString() );
229 if ( mExtentState ==
ProjectLayerExtent && mExtentLayer && mExtentLayer->id() == layerId )
231 act->setCheckable(
true );
232 act->setChecked(
true );
234 connect( act, &QAction::triggered,
this, [
this, layerId]
236 setExtentToLayerExtent( layerId );
238 mLayerMenu->addAction( act );
243 void QgsExtentGroupBox::setExtentToLayerExtent(
const QString &layerId )
263 setOutputExtent( mCurrentExtent, mCurrentCrs,
CurrentExtent );
283 mExtentLayer = layer;
284 mExtentLayerName = layer->
name();
293 mMapToolPrevious = mCanvas->
mapTool();
294 if ( !mMapToolExtent )
300 window()->setVisible(
true );
301 mMapToolPrevious =
nullptr;
304 mMapToolExtent->setRatio( mRatio );
306 window()->setVisible(
false );
310 void QgsExtentGroupBox::extentDrawn(
const QgsRectangle &extent )
314 window()->setVisible(
true );
315 mMapToolPrevious =
nullptr;
318 void QgsExtentGroupBox::groupBoxClicked()
320 if ( !isCheckable() )
332 if ( isCheckable() && !isChecked() )
335 return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
336 mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
355 mButtonDrawOnCanvas->setVisible(
true );
356 mCurrentExtentButton->setVisible(
true );
360 mButtonDrawOnCanvas->setVisible(
false );
361 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.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
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.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
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
Get 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.