QGIS API Documentation 3.99.0-Master (09f76ad7019)
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
18#include "qgsextentwidget.h"
19#include "qgsmaplayer.h"
20
21#include <QString>
22
23#include "moc_qgsextentgroupbox.cpp"
24
25using namespace Qt::StringLiterals;
26
28 : QgsCollapsibleGroupBox( parent )
29 , mTitleBase( tr( "Extent" ) )
30{
31 mWidget = new QgsExtentWidget( nullptr, QgsExtentWidget::ExpandedStyle );
32 QVBoxLayout *layout = new QVBoxLayout();
33 layout->addWidget( mWidget );
34 setLayout( layout );
35
36 connect( this, &QGroupBox::toggled, this, &QgsExtentGroupBox::groupBoxClicked );
37 connect( mWidget, &QgsExtentWidget::extentChanged, this, &QgsExtentGroupBox::widgetExtentChanged );
38 connect( mWidget, &QgsExtentWidget::validationChanged, this, &QgsExtentGroupBox::validationChanged );
40
41 connect( mWidget, &QgsExtentWidget::toggleDialogVisibility, this, [this]( bool visible ) {
42 QWidget *w = window();
43 // Don't hide the main window or we'll get locked outside!
44 if ( w->objectName() == "QgisApp"_L1 )
45 return;
46 w->setVisible( visible );
47 } );
48}
49
54
56{
57 return mWidget->originalExtent();
58}
59
61{
62 return mWidget->originalCrs();
63}
64
69
71{
72 return mWidget->currentExtent();
73}
74
76{
77 return mWidget->currentCrs();
78}
79
81{
82 mWidget->setOutputCrs( outputCrs );
83}
84
85void QgsExtentGroupBox::updateTitle()
86{
87 QString msg;
88 switch ( mWidget->extentState() )
89 {
91 msg = tr( "layer" );
92 break;
94 msg = tr( "map view" );
95 break;
97 msg = tr( "user defined" );
98 break;
100 msg = mWidget->extentLayerName();
101 break;
103 msg = tr( "drawn on canvas" );
104 break;
105 }
106 if ( isCheckable() && !isChecked() )
107 msg = tr( "none" );
108 msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
109
110 setTitle( msg );
111}
112
114{
115 mWidget->setOutputExtentFromCurrent();
116}
117
119{
120 mWidget->setOutputExtentFromOriginal();
121}
122
124{
125 mWidget->setOutputExtentFromUser( extent, crs );
126}
127
129{
130 mWidget->setOutputExtentFromLayer( layer );
131}
132
134{
135 mWidget->setOutputExtentFromDrawOnCanvas();
136}
137
139{
140 mWidget->setRatio( ratio );
141}
142
143void QgsExtentGroupBox::groupBoxClicked()
144{
145 if ( !isCheckable() )
146 return;
147
148 updateTitle();
149
150 // output extent just went from null to something (or vice versa)
151 emit extentChanged( outputExtent() );
152}
153
154void QgsExtentGroupBox::widgetExtentChanged()
155{
156 updateTitle();
157
158 emit extentChanged( outputExtent() );
159}
160
161void QgsExtentGroupBox::validationChanged( bool valid )
162{
163 if ( valid )
164 {
165 if ( isCheckable() && !isChecked() )
166 setChecked( true );
167 }
168 else if ( isCheckable() && isChecked() )
169 setChecked( false );
170}
171
173{
174 if ( isCheckable() && !isChecked() )
175 return QgsRectangle();
176
177 return mWidget->outputExtent();
178}
179
181{
182 return mWidget->outputCrs();
183}
184
186{
187 return static_cast<QgsExtentGroupBox::ExtentState>( mWidget->extentState() );
188}
189
190void QgsExtentGroupBox::setTitleBase( const QString &title )
191{
192 mTitleBase = title;
193 updateTitle();
194}
195
197{
198 return mTitleBase;
199}
200
201void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
202{
203 mWidget->setMapCanvas( canvas, drawOnCanvasOption );
204}
205
207{
208 return mWidget->ratio();
209}
QgsCollapsibleGroupBox(QWidget *parent=nullptr, QgsSettings *settings=nullptr)
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 extentLayerChanged(QgsMapLayer *layer)
Emitted when the extent layer is changed.
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.
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
void extentLayerChanged(QgsMapLayer *layer)
Emitted when the extent layer is changed.
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
@ 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.
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.
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:83
A rectangle specified with double values.