QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "moc_qgsextentgroupbox.cpp"
22
24 : QgsCollapsibleGroupBox( parent )
25 , mTitleBase( tr( "Extent" ) )
26{
27 mWidget = new QgsExtentWidget( nullptr, QgsExtentWidget::ExpandedStyle );
28 QVBoxLayout *layout = new QVBoxLayout();
29 layout->addWidget( mWidget );
30 setLayout( layout );
31
32 connect( this, &QGroupBox::toggled, this, &QgsExtentGroupBox::groupBoxClicked );
33 connect( mWidget, &QgsExtentWidget::extentChanged, this, &QgsExtentGroupBox::widgetExtentChanged );
34 connect( mWidget, &QgsExtentWidget::validationChanged, this, &QgsExtentGroupBox::validationChanged );
36
37 connect( mWidget, &QgsExtentWidget::toggleDialogVisibility, this, [this]( bool visible ) {
38 QWidget *w = window();
39 // Don't hide the main window or we'll get locked outside!
40 if ( w->objectName() == QLatin1String( "QgisApp" ) )
41 return;
42 w->setVisible( visible );
43 } );
44}
45
50
52{
53 return mWidget->originalExtent();
54}
55
57{
58 return mWidget->originalCrs();
59}
60
65
67{
68 return mWidget->currentExtent();
69}
70
72{
73 return mWidget->currentCrs();
74}
75
77{
78 mWidget->setOutputCrs( outputCrs );
79}
80
81void QgsExtentGroupBox::updateTitle()
82{
83 QString msg;
84 switch ( mWidget->extentState() )
85 {
87 msg = tr( "layer" );
88 break;
90 msg = tr( "map view" );
91 break;
93 msg = tr( "user defined" );
94 break;
96 msg = mWidget->extentLayerName();
97 break;
99 msg = tr( "drawn on canvas" );
100 break;
101 }
102 if ( isCheckable() && !isChecked() )
103 msg = tr( "none" );
104 msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
105
106 setTitle( msg );
107}
108
110{
111 mWidget->setOutputExtentFromCurrent();
112}
113
115{
116 mWidget->setOutputExtentFromOriginal();
117}
118
120{
121 mWidget->setOutputExtentFromUser( extent, crs );
122}
123
125{
126 mWidget->setOutputExtentFromLayer( layer );
127}
128
130{
131 mWidget->setOutputExtentFromDrawOnCanvas();
132}
133
135{
136 mWidget->setRatio( ratio );
137}
138
139void QgsExtentGroupBox::groupBoxClicked()
140{
141 if ( !isCheckable() )
142 return;
143
144 updateTitle();
145
146 // output extent just went from null to something (or vice versa)
147 emit extentChanged( outputExtent() );
148}
149
150void QgsExtentGroupBox::widgetExtentChanged()
151{
152 updateTitle();
153
154 emit extentChanged( outputExtent() );
155}
156
157void QgsExtentGroupBox::validationChanged( bool valid )
158{
159 if ( valid )
160 {
161 if ( isCheckable() && !isChecked() )
162 setChecked( true );
163 }
164 else if ( isCheckable() && isChecked() )
165 setChecked( false );
166}
167
169{
170 if ( isCheckable() && !isChecked() )
171 return QgsRectangle();
172
173 return mWidget->outputExtent();
174}
175
177{
178 return mWidget->outputCrs();
179}
180
182{
183 return static_cast<QgsExtentGroupBox::ExtentState>( mWidget->extentState() );
184}
185
186void QgsExtentGroupBox::setTitleBase( const QString &title )
187{
188 mTitleBase = title;
189 updateTitle();
190}
191
193{
194 return mTitleBase;
195}
196
197void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
198{
199 mWidget->setMapCanvas( canvas, drawOnCanvasOption );
200}
201
203{
204 return mWidget->ratio();
205}
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:80
A rectangle specified with double values.