QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  window()->setVisible( visible );
35  } );
36 }
37 
38 void QgsExtentGroupBox::setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs )
39 {
41 }
42 
44 {
45  return mWidget->originalExtent();
46 }
47 
49 {
50  return mWidget->originalCrs();
51 }
52 
53 void QgsExtentGroupBox::setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs )
54 {
56 }
57 
59 {
60  return mWidget->currentExtent();
61 }
62 
64 {
65  return mWidget->currentCrs();
66 }
67 
69 {
70  mWidget->setOutputCrs( outputCrs );
71 }
72 
73 void QgsExtentGroupBox::updateTitle()
74 {
75  QString msg;
76  switch ( mWidget->extentState() )
77  {
79  msg = tr( "layer" );
80  break;
82  msg = tr( "map view" );
83  break;
85  msg = tr( "user defined" );
86  break;
88  msg = mWidget->extentLayerName();
89  break;
91  msg = tr( "drawn on canvas" );
92  break;
93  }
94  if ( isCheckable() && !isChecked() )
95  msg = tr( "none" );
96  msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
97 
98  setTitle( msg );
99 }
100 
102 {
103  mWidget->setOutputExtentFromCurrent();
104 }
105 
107 {
108  mWidget->setOutputExtentFromOriginal();
109 }
110 
112 {
113  mWidget->setOutputExtentFromUser( extent, crs );
114 }
115 
117 {
118  mWidget->setOutputExtentFromLayer( layer );
119 }
120 
122 {
124 }
125 
126 void QgsExtentGroupBox::setRatio( QSize ratio )
127 {
128  mWidget->setRatio( ratio );
129 }
130 
131 void QgsExtentGroupBox::groupBoxClicked()
132 {
133  if ( !isCheckable() )
134  return;
135 
136  updateTitle();
137 
138  // output extent just went from null to something (or vice versa)
139  emit extentChanged( outputExtent() );
140 }
141 
142 void QgsExtentGroupBox::widgetExtentChanged()
143 {
144  updateTitle();
145 
146  emit extentChanged( outputExtent() );
147 }
148 
149 void QgsExtentGroupBox::validationChanged( bool valid )
150 {
151  if ( valid )
152  {
153  if ( isCheckable() && !isChecked() )
154  setChecked( true );
155  }
156  else if ( isCheckable() && isChecked() )
157  setChecked( false );
158 }
159 
161 {
162  if ( isCheckable() && !isChecked() )
163  return QgsRectangle();
164 
165  return mWidget->outputExtent();
166 }
167 
169 {
170  return mWidget->outputCrs();
171 }
172 
174 {
175  return static_cast< QgsExtentGroupBox::ExtentState >( mWidget->extentState() );
176 }
177 
178 void QgsExtentGroupBox::setTitleBase( const QString &title )
179 {
180  mTitleBase = title;
181  updateTitle();
182 }
183 
185 {
186  return mTitleBase;
187 }
188 
189 void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
190 {
191  mWidget->setMapCanvas( canvas, drawOnCanvasOption );
192 }
193 
195 {
196  return mWidget->ratio();
197 }
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.
Definition: qgsmapcanvas.h:89
Base class for all map layer types.
Definition: qgsmaplayer.h:73
A rectangle specified with double values.
Definition: qgsrectangle.h:42
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs