QGIS API Documentation  2.99.0-Master (e077efd)
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 #include "qgsextentgroupbox.h"
16 
17 #include "qgscoordinatetransform.h"
18 #include "qgsrasterblock.h"
19 
21  : QgsCollapsibleGroupBox( parent )
22  , mTitleBase( tr( "Extent" ) )
23  , mExtentState( OriginalExtent )
24 {
25  setupUi( this );
26 
27  mXMinLineEdit->setValidator( new QDoubleValidator( this ) );
28  mXMaxLineEdit->setValidator( new QDoubleValidator( this ) );
29  mYMinLineEdit->setValidator( new QDoubleValidator( this ) );
30  mYMaxLineEdit->setValidator( new QDoubleValidator( this ) );
31 
32  connect( mCurrentExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromCurrent() ) );
33  connect( mOriginalExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromOriginal() ) );
34  connect( this, SIGNAL( clicked( bool ) ), this, SLOT( groupBoxClicked() ) );
35 }
36 
37 
39 {
42 }
43 
44 
46 {
49 }
50 
52 {
53  mOutputCrs = outputCrs;
54 }
55 
56 
58 {
59  QgsRectangle extent;
60  if ( mOutputCrs == srcCrs )
61  {
62  extent = r;
63  }
64  else
65  {
66  QgsCoordinateTransform ct( srcCrs, mOutputCrs );
67  extent = ct.transformBoundingBox( r );
68  }
69 
70  mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) );
71  mXMaxLineEdit->setText( QgsRasterBlock::printValue( extent.xMaximum() ) );
72  mYMinLineEdit->setText( QgsRasterBlock::printValue( extent.yMinimum() ) );
73  mYMaxLineEdit->setText( QgsRasterBlock::printValue( extent.yMaximum() ) );
74 
75  mExtentState = state;
76 
77  if ( isCheckable() && !isChecked() )
78  setChecked( true );
79 
80  updateTitle();
81 
82  emit extentChanged( extent );
83 }
84 
85 
87 {
89 
90  updateTitle();
91 
92  emit extentChanged( outputExtent() );
93 }
94 
95 
97 {
98  QString msg;
99  switch ( mExtentState )
100  {
101  case OriginalExtent:
102  msg = tr( "layer" );
103  break;
104  case CurrentExtent:
105  msg = tr( "map view" );
106  break;
107  case UserExtent:
108  msg = tr( "user defined" );
109  break;
110  default:
111  break;
112  }
113  if ( isCheckable() && !isChecked() )
114  msg = tr( "none" );
115  msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
116 
117  setTitle( msg );
118 }
119 
120 
122 {
124 }
125 
126 
128 {
130 }
131 
132 
134 {
135  setOutputExtent( extent, crs, UserExtent );
136 }
137 
139 {
140  if ( !isCheckable() )
141  return;
142 
143  updateTitle();
144 
145  // output extent just went from null to something (or vice versa)
146  emit extentChanged( outputExtent() );
147 }
148 
149 
151 {
152  if ( isCheckable() && !isChecked() )
153  return QgsRectangle();
154 
155  return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
156  mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
157 }
158 
159 void QgsExtentGroupBox::setTitleBase( const QString& title )
160 {
161  mTitleBase = title;
162  updateTitle();
163 }
164 
165 QString QgsExtentGroupBox::titleBase() const
166 {
167  return mTitleBase;
168 }
Extent manually entered/modified by the user.
ExtentState mExtentState
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsRectangle originalExtent() const
static QString printValue(double value)
Print double value with all necessary significant digits.
void setOutputExtentFromCurrent()
set output extent to be the same as current extent (may be transformed to output CRS) ...
void extentChanged(const QgsRectangle &r)
emitted when extent is changed
QString titleBase() const
Set 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)
set output extent to custom extent (may be transformed to output CRS)
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
QgsCoordinateReferenceSystem mOutputCrs
QgsCoordinateReferenceSystem mOriginalCrs
void setOutputExtent(const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state)
QString mTitleBase
Base part of the title used for the extent.
QgsRectangle mCurrentExtent
const QgsCoordinateReferenceSystem & currentCrs() const
void setOutputCrs(const QgsCoordinateReferenceSystem &outputCrs)
Set the output CRS - may need to be used for transformation from original/current extent...
void setCurrentExtent(const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs)
Setup current extent - should be called as part of initialization (or whenever current extent changes...
QgsRectangle currentExtent() const
QgsRectangle outputExtent() const
Get the resulting extent - in output CRS coordinates.
QgsExtentGroupBox(QWidget *parent=nullptr)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:206
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:191
void setTitleBase(const QString &title)
Set base part of title of the group box (will be appended with extent state)
const QgsCoordinateReferenceSystem & originalCrs() const
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:196
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:201
void setOutputExtentFromOriginal()
set output extent to be the same as original extent (may be transformed to output CRS) ...
QgsRectangle mOriginalExtent
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Setup original extent - should be called as part of initialization.
QgsCoordinateReferenceSystem mCurrentCrs