QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsextentgroupbox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsextentgroupbox.cpp
3 ---------------------
4 begin : March 2014
5 copyright : (C) 2014 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsextentgroupbox.h"
17#include "qgsextentwidget.h"
18
20 : QgsCollapsibleGroupBox( parent )
21 , mTitleBase( tr( "Extent" ) )
22{
23 mWidget = new QgsExtentWidget( nullptr, QgsExtentWidget::ExpandedStyle );
24 QVBoxLayout *layout = new QVBoxLayout();
25 layout->addWidget( mWidget );
26 setLayout( layout );
27
28 connect( this, &QGroupBox::toggled, this, &QgsExtentGroupBox::groupBoxClicked );
29 connect( mWidget, &QgsExtentWidget::extentChanged, this, &QgsExtentGroupBox::widgetExtentChanged );
30 connect( mWidget, &QgsExtentWidget::validationChanged, this, &QgsExtentGroupBox::validationChanged );
31
32 connect( mWidget, &QgsExtentWidget::toggleDialogVisibility, this, [ = ]( bool visible )
33 {
34 QWidget *w = window();
35 // Don't hide the main window or we'll get locked outside!
36 if ( w->objectName() == QLatin1String( "QgisApp" ) )
37 return;
38 w->setVisible( visible );
39 } );
40}
41
43{
45}
46
51
56
58{
60}
61
63{
64 return mWidget->currentExtent();
65}
66
71
76
77void QgsExtentGroupBox::updateTitle()
78{
79 QString msg;
80 switch ( mWidget->extentState() )
81 {
83 msg = tr( "layer" );
84 break;
86 msg = tr( "map view" );
87 break;
89 msg = tr( "user defined" );
90 break;
92 msg = mWidget->extentLayerName();
93 break;
95 msg = tr( "drawn on canvas" );
96 break;
97 }
98 if ( isCheckable() && !isChecked() )
99 msg = tr( "none" );
100 msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
101
102 setTitle( msg );
103}
104
109
114
119
121{
122 mWidget->setOutputExtentFromLayer( layer );
123}
124
129
131{
132 mWidget->setRatio( ratio );
133}
134
135void QgsExtentGroupBox::groupBoxClicked()
136{
137 if ( !isCheckable() )
138 return;
139
140 updateTitle();
141
142 // output extent just went from null to something (or vice versa)
143 emit extentChanged( outputExtent() );
144}
145
146void QgsExtentGroupBox::widgetExtentChanged()
147{
148 updateTitle();
149
150 emit extentChanged( outputExtent() );
151}
152
153void QgsExtentGroupBox::validationChanged( bool valid )
154{
155 if ( valid )
156 {
157 if ( isCheckable() && !isChecked() )
158 setChecked( true );
159 }
160 else if ( isCheckable() && isChecked() )
161 setChecked( false );
162}
163
165{
166 if ( isCheckable() && !isChecked() )
167 return QgsRectangle();
168
169 return mWidget->outputExtent();
170}
171
176
181
182void QgsExtentGroupBox::setTitleBase( const QString &title )
183{
184 mTitleBase = title;
185 updateTitle();
186}
187
189{
190 return mTitleBase;
191}
192
193void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
194{
195 mWidget->setMapCanvas( canvas, drawOnCanvasOption );
196}
197
199{
200 return mWidget->ratio();
201}
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
This class represents a coordinate reference system (CRS).
ExtentState
Available states for the current extent selection in the widget.
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
QgsExtentGroupBox::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
QgsExtentGroupBox(QWidget *parent=nullptr)
Constructor for QgsExtentGroupBox.
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).
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
void setMapCanvas(QgsMapCanvas *canvas, bool drawOnCanvasOption=true)
Sets the map canvas to enable dragging of extent on a canvas.
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
void setTitleBase(const QString &title)
Sets the base part of title of the group box (will be appended with extent state)
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
void setCurrentExtent(const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs)
Sets the current extent to show in the widget - should be called as part of initialization (or whenev...
A widget for configuration of a map extent.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS).
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
void setCurrentExtent(const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs)
Sets the current extent to show in the widget - should be called as part of initialization (or whenev...
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
@ UserExtent
Extent manually entered/modified by the user.
@ OriginalExtent
Layer's extent.
@ ProjectLayerExtent
Extent taken from a layer within the project.
@ CurrentExtent
Map canvas extent.
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
void validationChanged(bool valid)
Emitted when the widget's validation state changes.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
void setMapCanvas(QgsMapCanvas *canvas, bool drawOnCanvasOption=true)
Sets the map canvas to enable dragging of extent on a canvas.
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
QString extentLayerName() const
Returns the name of the extent layer.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:74
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs