QGIS API Documentation  3.13.0-Master (788156190c)
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 
184 QString QgsExtentGroupBox::titleBase() const
185 {
186  return mTitleBase;
187 }
188 
190 {
191  mWidget->setMapCanvas( canvas );
192 }
193 
195 {
196  return mWidget->ratio();
197 }
QgsExtentGroupBox::setOutputExtentFromDrawOnCanvas
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
Definition: qgsextentgroupbox.cpp:121
QgsExtentWidget::currentCrs
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
Definition: qgsextentwidget.h:121
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:115
QgsExtentWidget::originalCrs
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
Definition: qgsextentwidget.h:97
QgsExtentWidget::CurrentExtent
@ CurrentExtent
Map canvas extent.
Definition: qgsextentwidget.h:60
QgsExtentGroupBox::setOutputExtentFromOriginal
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
Definition: qgsextentgroupbox.cpp:106
QgsExtentWidget::DrawOnCanvas
@ DrawOnCanvas
Extent taken from a rectangled drawn onto the map canvas.
Definition: qgsextentwidget.h:63
QgsExtentGroupBox::currentCrs
QgsCoordinateReferenceSystem currentCrs() const
Returns the coordinate reference system for the current extent set for the widget.
Definition: qgsextentgroupbox.cpp:63
QgsExtentWidget::OriginalExtent
@ OriginalExtent
Layer's extent.
Definition: qgsextentwidget.h:59
QgsExtentWidget::outputExtent
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
Definition: qgsextentwidget.cpp:411
QgsExtentWidget::setOutputExtentFromOriginal
void setOutputExtentFromOriginal()
Sets the output extent to be the same as original extent (may be transformed to output CRS).
Definition: qgsextentwidget.cpp:360
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsExtentGroupBox::setOriginalExtent
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
Definition: qgsextentgroupbox.cpp:38
QgsExtentWidget::ratio
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:157
QgsExtentWidget::extentState
QgsExtentWidget::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
Definition: qgsextentwidget.h:145
QgsExtentWidget::setCurrentExtent
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...
Definition: qgsextentwidget.cpp:102
QgsMapCanvas
Definition: qgsmapcanvas.h:78
QgsExtentGroupBox::setRatio
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentgroupbox.cpp:126
QgsExtentGroupBox::ratio
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentgroupbox.cpp:194
QgsExtentGroupBox::originalExtent
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
Definition: qgsextentgroupbox.cpp:43
QgsCollapsibleGroupBox
Definition: qgscollapsiblegroupbox.h:178
qgsextentwidget.h
QgsRectangle
Definition: qgsrectangle.h:41
QgsExtentWidget::UserExtent
@ UserExtent
Extent manually entered/modified by the user.
Definition: qgsextentwidget.h:61
QgsExtentGroupBox::setOutputExtentFromCurrent
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS).
Definition: qgsextentgroupbox.cpp:101
QgsExtentWidget::setOutputExtentFromDrawOnCanvas
void setOutputExtentFromDrawOnCanvas()
Sets the output extent by dragging on the canvas.
Definition: qgsextentwidget.cpp:381
qgsextentgroupbox.h
QgsExtentGroupBox::titleBase
QString titleBase
Definition: qgsextentgroupbox.h:50
QgsExtentGroupBox::outputExtent
QgsRectangle outputExtent() const
Returns the extent shown in the widget - in output CRS coordinates.
Definition: qgsextentgroupbox.cpp:160
QgsExtentWidget::outputCrs
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
Definition: qgsextentwidget.h:140
QgsExtentWidget::setOutputExtentFromUser
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
Definition: qgsextentwidget.cpp:365
QgsExtentWidget::setOutputCrs
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
Definition: qgsextentwidget.cpp:111
QgsExtentWidget::extentChanged
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
QgsExtentGroupBox::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas to enable dragging of extent on a canvas.
Definition: qgsextentgroupbox.cpp:189
QgsExtentWidget::toggleDialogVisibility
void toggleDialogVisibility(bool visible)
Emitted when the parent dialog visibility must be changed (e.g.
QgsExtentWidget::setOutputExtentFromCurrent
void setOutputExtentFromCurrent()
Sets the output extent to be the same as current extent (may be transformed to output CRS).
Definition: qgsextentwidget.cpp:344
QgsExtentWidget::ExpandedStyle
@ ExpandedStyle
Shows an expanded widget, for use when space is not constrained.
Definition: qgsextentwidget.h:70
QgsExtentWidget::setOriginalExtent
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Sets the original extent and coordinate reference system for the widget.
Definition: qgsextentwidget.cpp:93
QgsExtentGroupBox::setTitleBase
void setTitleBase(const QString &title)
Sets the base part of title of the group box (will be appended with extent state)
Definition: qgsextentgroupbox.cpp:178
QgsExtentWidget::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas to enable dragging of extent on a canvas.
Definition: qgsextentwidget.cpp:417
QgsExtentGroupBox::ExtentState
ExtentState
Available states for the current extent selection in the widget.
Definition: qgsextentgroupbox.h:57
QgsExtentGroupBox::extentState
QgsExtentGroupBox::ExtentState extentState() const
Returns the currently selected state for the widget's extent.
Definition: qgsextentgroupbox.cpp:173
QgsExtentGroupBox::originalCrs
QgsCoordinateReferenceSystem originalCrs() const
Returns the original coordinate reference system set for the widget.
Definition: qgsextentgroupbox.cpp:48
QgsExtentWidget
Definition: qgsextentwidget.h:50
QgsExtentWidget::extentLayerName
QString extentLayerName() const
Returns the name of the extent layer.
Definition: qgsextentwidget.cpp:269
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:209
QgsExtentGroupBox::setOutputCrs
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Sets the output CRS - may need to be used for transformation from original/current extent.
Definition: qgsextentgroupbox.cpp:68
QgsExtentWidget::setRatio
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Definition: qgsextentwidget.h:210
QgsExtentGroupBox::outputCrs
QgsCoordinateReferenceSystem outputCrs() const
Returns the current output CRS, used in the display.
Definition: qgsextentgroupbox.cpp:168
QgsMapLayer
Definition: qgsmaplayer.h:80
QgsExtentWidget::validationChanged
void validationChanged(bool valid)
Emitted when the widget's validation state changes.
QgsExtentGroupBox::currentExtent
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
Definition: qgsextentgroupbox.cpp:58
QgsExtentWidget::setOutputExtentFromLayer
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
Definition: qgsextentwidget.cpp:370
QgsExtentGroupBox::setCurrentExtent
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...
Definition: qgsextentgroupbox.cpp:53
QgsExtentGroupBox::setOutputExtentFromLayer
void setOutputExtentFromLayer(const QgsMapLayer *layer)
Sets the output extent to match a layer's extent (may be transformed to output CRS).
Definition: qgsextentgroupbox.cpp:116
QgsExtentWidget::originalExtent
QgsRectangle originalExtent() const
Returns the original extent set for the widget.
Definition: qgsextentwidget.h:90
QgsExtentWidget::currentExtent
QgsRectangle currentExtent() const
Returns the current extent set for the widget.
Definition: qgsextentwidget.h:113
QgsExtentGroupBox::QgsExtentGroupBox
QgsExtentGroupBox(QWidget *parent=nullptr)
Constructor for QgsExtentGroupBox.
Definition: qgsextentgroupbox.cpp:19
QgsExtentGroupBox::setOutputExtentFromUser
void setOutputExtentFromUser(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs)
Sets the output extent to a custom extent (may be transformed to output CRS).
Definition: qgsextentgroupbox.cpp:111
QgsExtentGroupBox::extentChanged
void extentChanged(const QgsRectangle &r)
Emitted when the widget's extent is changed.
QgsExtentWidget::ProjectLayerExtent
@ ProjectLayerExtent
Extent taken from a layer within the project.
Definition: qgsextentwidget.h:62