QGIS API Documentation  2.11.0-Master
qgsextentgroupbox.cpp
Go to the documentation of this file.
1 #include "qgsextentgroupbox.h"
2 
4 #include "qgsrasterblock.h"
5 
7  : QgsCollapsibleGroupBox( parent )
8  , mTitleBase( tr( "Extent" ) )
9  , mExtentState( OriginalExtent )
10 {
11  setupUi( this );
12 
13  mXMinLineEdit->setValidator( new QDoubleValidator( this ) );
14  mXMaxLineEdit->setValidator( new QDoubleValidator( this ) );
15  mYMinLineEdit->setValidator( new QDoubleValidator( this ) );
16  mYMaxLineEdit->setValidator( new QDoubleValidator( this ) );
17 
18  connect( mCurrentExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromCurrent() ) );
19  connect( mOriginalExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromOriginal() ) );
20  connect( this, SIGNAL( clicked( bool ) ), this, SLOT( groupBoxClicked() ) );
21 }
22 
23 
24 void QgsExtentGroupBox::setOriginalExtent( const QgsRectangle& originalExtent, const QgsCoordinateReferenceSystem& originalCrs )
25 {
28 }
29 
30 
31 void QgsExtentGroupBox::setCurrentExtent( const QgsRectangle& currentExtent, const QgsCoordinateReferenceSystem& currentCrs )
32 {
35 }
36 
38 {
39  mOutputCrs = outputCrs;
40 }
41 
42 
44 {
45  QgsRectangle extent;
46  if ( mOutputCrs == srcCrs )
47  {
48  extent = r;
49  }
50  else
51  {
52  QgsCoordinateTransform ct( srcCrs, mOutputCrs );
53  extent = ct.transformBoundingBox( r );
54  }
55 
56  mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) );
57  mXMaxLineEdit->setText( QgsRasterBlock::printValue( extent.xMaximum() ) );
58  mYMinLineEdit->setText( QgsRasterBlock::printValue( extent.yMinimum() ) );
59  mYMaxLineEdit->setText( QgsRasterBlock::printValue( extent.yMaximum() ) );
60 
61  mExtentState = state;
62 
63  if ( isCheckable() && !isChecked() )
64  setChecked( true );
65 
66  updateTitle();
67 
68  emit extentChanged( extent );
69 }
70 
71 
73 {
75 
76  updateTitle();
77 
78  emit extentChanged( outputExtent() );
79 }
80 
81 
83 {
84  QString msg;
85  switch ( mExtentState )
86  {
87  case OriginalExtent:
88  msg = tr( "layer" );
89  break;
90  case CurrentExtent:
91  msg = tr( "map view" );
92  break;
93  case UserExtent:
94  msg = tr( "user defined" );
95  break;
96  default:
97  break;
98  }
99  if ( isCheckable() && !isChecked() )
100  msg = tr( "none" );
101  msg = tr( "%1 (current: %2)" ).arg( mTitleBase ).arg( msg );
102 
103  setTitle( msg );
104 }
105 
106 
108 {
110 }
111 
112 
114 {
116 }
117 
118 
120 {
121  setOutputExtent( extent, crs, UserExtent );
122 }
123 
125 {
126  if ( !isCheckable() )
127  return;
128 
129  updateTitle();
130 
131  // output extent just went from null to something (or vice versa)
132  emit extentChanged( outputExtent() );
133 }
134 
135 
137 {
138  if ( isCheckable() && !isChecked() )
139  return QgsRectangle();
140 
141  return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
142  mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
143 }
144 
146 {
147  mTitleBase = title;
148  updateTitle();
149 }
150 
152 {
153  return mTitleBase;
154 }
extent manually entered/modified by the user
ExtentState mExtentState
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setupUi(QWidget *widget)
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
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 outut CRS)
void clicked(bool checked)
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:192
QgsExtentGroupBox(QWidget *parent=0)
QgsCoordinateReferenceSystem mOutputCrs
QString titleBase() const
Set base part of title of the group box (will be appended with extent state)
QgsCoordinateReferenceSystem mOriginalCrs
QString tr(const char *sourceText, const char *disambiguation, int n)
void setOutputExtent(const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, ExtentState state)
const QgsCoordinateReferenceSystem & currentCrs() const
QString mTitleBase
Base part of the title used for the extent.
QgsRectangle mCurrentExtent
QgsRectangle originalExtent() const
bool isChecked() const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:197
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:182
QgsRectangle outputExtent() const
Get the resulting extent - in output CRS coordinates.
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...
void setTitleBase(const QString &title)
Set base part of title of the group box (will be appended with extent state)
QgsRectangle currentExtent() const
void setTitle(const QString &title)
bool isCheckable() const
const QgsCoordinateReferenceSystem & originalCrs() const
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
void setOutputExtentFromOriginal()
set output extent to be the same as original extent (may be transformed to output CRS) ...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsRectangle mOriginalExtent
void setOriginalExtent(const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs)
Setup original extent - should be called as part of initialization.
QgsCoordinateReferenceSystem mCurrentCrs
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
QgsRectangle transformBoundingBox(const QgsRectangle &theRect, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
#define tr(sourceText)