QGIS API Documentation  3.17.0-Master (8af46bc54f)
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 
39 {
40  mWidget->setOriginalExtent( originalExtent, originalCrs );
41 }
42 
44 {
45  return mWidget->originalExtent();
46 }
47 
49 {
50  return mWidget->originalCrs();
51 }
52 
54 {
55  mWidget->setCurrentExtent( currentExtent, currentCrs );
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 
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 
184 QString QgsExtentGroupBox::titleBase() const
185 {
186  return mTitleBase;
187 }
188 
190 {
191  mWidget->setMapCanvas( canvas );
192 }
193 
195 {
196  return mWidget->ratio();
197 }
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS)...
Shows an expanded widget, for use when space is not constrained.
void extentChanged(const QgsRectangle &r)
Emitted when the widget&#39;s extent is changed.
QString titleBase() const
Returns the base part of title of the group box (will be appended with extent state).
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer&#39;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.
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget&#39;s extent.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas to enable dragging of extent on a 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.
const QgsCoordinateReferenceSystem & crs
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:84
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas to enable dragging of extent on a canvas.
ExtentState
Available states for the current extent selection in the widget.
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS)...
void validationChanged(bool valid)
Emitted when the widget&#39;s validation state changes.
Extent taken from a layer within the project.
QString extentLayerName() const
Returns the name of the extent layer.
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent...
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.
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on 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...
QgsRectangle currentExtent() const
Returns the current extent 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&#39;s extent (may be transformed to output CRS).
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
QgsExtentGroupBox(QWidget *parent=nullptr)
Constructor for QgsExtentGroupBox.
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom 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) ...
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
Extent manually entered/modified by the user.
This class represents a coordinate reference system (CRS).
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
QgsExtentGroupBox::ExtentState extentState() const
Returns the currently selected state for the widget&#39;s extent.
void extentChanged(const QgsRectangle &r)
Emitted when the widget&#39;s extent is changed.
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS)...
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
Extent taken from a rectangled drawn onto the map canvas.