QGIS API Documentation  2.99.0-Master (d55fa22)
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  mOriginalExtentButton->setVisible( false );
33 
34  connect( mCurrentExtentButton, &QAbstractButton::clicked, this, &QgsExtentGroupBox::setOutputExtentFromCurrent );
35  connect( mOriginalExtentButton, &QAbstractButton::clicked, this, &QgsExtentGroupBox::setOutputExtentFromOriginal );
36  connect( this, &QGroupBox::clicked, this, &QgsExtentGroupBox::groupBoxClicked );
37 }
38 
39 
41 {
44 
45  mOriginalExtentButton->setVisible( true );
46 }
47 
48 
50 {
53 }
54 
56 {
57  mOutputCrs = outputCrs;
58 }
59 
60 
62 {
63  QgsRectangle extent;
64  if ( mOutputCrs == srcCrs )
65  {
66  extent = r;
67  }
68  else
69  {
70  QgsCoordinateTransform ct( srcCrs, mOutputCrs );
71  extent = ct.transformBoundingBox( r );
72  }
73 
74  mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) );
75  mXMaxLineEdit->setText( QgsRasterBlock::printValue( extent.xMaximum() ) );
76  mYMinLineEdit->setText( QgsRasterBlock::printValue( extent.yMinimum() ) );
77  mYMaxLineEdit->setText( QgsRasterBlock::printValue( extent.yMaximum() ) );
78 
79  mExtentState = state;
80 
81  if ( isCheckable() && !isChecked() )
82  setChecked( true );
83 
84  updateTitle();
85 
86  emit extentChanged( extent );
87 }
88 
89 
91 {
93 
94  updateTitle();
95 
96  emit extentChanged( outputExtent() );
97 }
98 
99 
101 {
102  QString msg;
103  switch ( mExtentState )
104  {
105  case OriginalExtent:
106  msg = tr( "layer" );
107  break;
108  case CurrentExtent:
109  msg = tr( "map view" );
110  break;
111  case UserExtent:
112  msg = tr( "user defined" );
113  break;
114  default:
115  break;
116  }
117  if ( isCheckable() && !isChecked() )
118  msg = tr( "none" );
119  msg = tr( "%1 (current: %2)" ).arg( mTitleBase, msg );
120 
121  setTitle( msg );
122 }
123 
124 
126 {
128 }
129 
130 
132 {
134 }
135 
136 
138 {
139  setOutputExtent( extent, crs, UserExtent );
140 }
141 
143 {
144  if ( !isCheckable() )
145  return;
146 
147  updateTitle();
148 
149  // output extent just went from null to something (or vice versa)
150  emit extentChanged( outputExtent() );
151 }
152 
153 
155 {
156  if ( isCheckable() && !isChecked() )
157  return QgsRectangle();
158 
159  return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
160  mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
161 }
162 
163 void QgsExtentGroupBox::setTitleBase( const QString &title )
164 {
165  mTitleBase = title;
166  updateTitle();
167 }
168 
169 QString QgsExtentGroupBox::titleBase() const
170 {
171  return mTitleBase;
172 }
Extent manually entered/modified by the user.
ExtentState mExtentState
A rectangle specified with double values.
Definition: qgsrectangle.h:38
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.
QgsExtentGroupBox(QWidget *parent=0)
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.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:106
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:91
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
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:96
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:101
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