QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "moc_qgsextentgroupbox.cpp"
18#include "qgsextentwidget.h"
19
21 : QgsCollapsibleGroupBox( parent )
22 , mTitleBase( tr( "Extent" ) )
23{
24 mWidget = new QgsExtentWidget( nullptr, QgsExtentWidget::ExpandedStyle );
25 QVBoxLayout *layout = new QVBoxLayout();
26 layout->addWidget( mWidget );
27 setLayout( layout );
28
29 connect( this, &QGroupBox::toggled, this, &QgsExtentGroupBox::groupBoxClicked );
30 connect( mWidget, &QgsExtentWidget::extentChanged, this, &QgsExtentGroupBox::widgetExtentChanged );
31 connect( mWidget, &QgsExtentWidget::validationChanged, this, &QgsExtentGroupBox::validationChanged );
32
33 connect( mWidget, &QgsExtentWidget::toggleDialogVisibility, this, [ = ]( bool visible )
34 {
35 QWidget *w = window();
36 // Don't hide the main window or we'll get locked outside!
37 if ( w->objectName() == QLatin1String( "QgisApp" ) )
38 return;
39 w->setVisible( visible );
40 } );
41}
42
44{
46}
47
52
57
59{
61}
62
64{
65 return mWidget->currentExtent();
66}
67
72
77
78void QgsExtentGroupBox::updateTitle()
79{
80 QString msg;
81 switch ( mWidget->extentState() )
82 {
84 msg = tr( "layer" );
85 break;
87 msg = tr( "map view" );
88 break;
90 msg = tr( "user defined" );
91 break;
93 msg = mWidget->extentLayerName();
94 break;
96 msg = tr( "drawn on canvas" );
97 break;
98 }
99 if ( isCheckable() && !isChecked() )
100 msg = tr( "none" );
101 msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
102
103 setTitle( msg );
104}
105
110
115
120
122{
123 mWidget->setOutputExtentFromLayer( layer );
124}
125
130
132{
133 mWidget->setRatio( ratio );
134}
135
136void QgsExtentGroupBox::groupBoxClicked()
137{
138 if ( !isCheckable() )
139 return;
140
141 updateTitle();
142
143 // output extent just went from null to something (or vice versa)
144 emit extentChanged( outputExtent() );
145}
146
147void QgsExtentGroupBox::widgetExtentChanged()
148{
149 updateTitle();
150
151 emit extentChanged( outputExtent() );
152}
153
154void QgsExtentGroupBox::validationChanged( bool valid )
155{
156 if ( valid )
157 {
158 if ( isCheckable() && !isChecked() )
159 setChecked( true );
160 }
161 else if ( isCheckable() && isChecked() )
162 setChecked( false );
163}
164
166{
167 if ( isCheckable() && !isChecked() )
168 return QgsRectangle();
169
170 return mWidget->outputExtent();
171}
172
177
182
183void QgsExtentGroupBox::setTitleBase( const QString &title )
184{
185 mTitleBase = title;
186 updateTitle();
187}
188
190{
191 return mTitleBase;
192}
193
194void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
195{
196 mWidget->setMapCanvas( canvas, drawOnCanvasOption );
197}
198
200{
201 return mWidget->ratio();
202}
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:76
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs