Skip to content

Commit f216db1

Browse files
committed
Clean up QgsExtentGroupBox API
Make protected members private, improve documentation
1 parent 4e4f232 commit f216db1

3 files changed

Lines changed: 145 additions & 58 deletions

File tree

python/gui/qgsextentgroupbox.sip

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class QgsExtentGroupBox : QgsCollapsibleGroupBox
2727
#include "qgsextentgroupbox.h"
2828
%End
2929
public:
30-
explicit QgsExtentGroupBox( QWidget *parent /TransferThis/ = 0 );
3130

3231
enum ExtentState
3332
{
@@ -37,100 +36,119 @@ class QgsExtentGroupBox : QgsCollapsibleGroupBox
3736
ProjectLayerExtent,
3837
};
3938

39+
explicit QgsExtentGroupBox( QWidget *parent /TransferThis/ = 0 );
40+
%Docstring
41+
Constructor for QgsExtentGroupBox.
42+
%End
43+
4044
void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
4145
%Docstring
42-
Setup original extent - should be called as part of initialization
46+
Sets the original extent and coordinate reference system for the widget. This should be called as part of initialization.
47+
.. seealso:: originalExtent()
48+
.. seealso:: originalCrs()
4349
%End
4450

4551
QgsRectangle originalExtent() const;
4652
%Docstring
53+
Returns the original extent set for the widget.
54+
.. seealso:: setOriginalExtent()
55+
.. seealso:: originalCrs()
4756
:rtype: QgsRectangle
4857
%End
49-
const QgsCoordinateReferenceSystem &originalCrs() const;
58+
59+
QgsCoordinateReferenceSystem originalCrs() const;
5060
%Docstring
61+
Returns the original coordinate reference system set for the widget.
62+
.. seealso:: originalExtent()
63+
.. seealso:: setOriginalExtent()
5164
:rtype: QgsCoordinateReferenceSystem
5265
%End
5366

5467
void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
5568
%Docstring
56-
Setup current extent - should be called as part of initialization (or whenever current extent changes)
69+
Sets the current extent to show in the widget - should be called as part of initialization (or whenever current extent changes).
70+
.. seealso:: currentExtent()
71+
.. seealso:: currentCrs()
5772
%End
5873

5974
QgsRectangle currentExtent() const;
6075
%Docstring
76+
Returns the current extent set for the widget.
77+
.. seealso:: setCurrentExtent()
78+
.. seealso:: currentCrs()
6179
:rtype: QgsRectangle
6280
%End
63-
const QgsCoordinateReferenceSystem &currentCrs() const;
81+
82+
QgsCoordinateReferenceSystem currentCrs() const;
6483
%Docstring
84+
Returns the coordinate reference system for the current extent set for the widget.
85+
.. seealso:: setCurrentExtent()
86+
.. seealso:: currentExtent()
6587
:rtype: QgsCoordinateReferenceSystem
6688
%End
6789

6890
void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
6991
%Docstring
70-
Should be called as part of initialization and whenever the the output CRS is changed
92+
Sets the output CRS - may need to be used for transformation from original/current extent.
93+
Should be called as part of initialization and whenever the the output CRS is changed.
7194
%End
7295

7396
QgsRectangle outputExtent() const;
7497
%Docstring
75-
Get the resulting extent - in output CRS coordinates
98+
Returns the extent shown in the widget - in output CRS coordinates.
7699
:rtype: QgsRectangle
77100
%End
78101

79102
QgsExtentGroupBox::ExtentState extentState() const;
80103
%Docstring
104+
Returns the currently selected state for the widget's extent.
81105
:rtype: QgsExtentGroupBox.ExtentState
82106
%End
83107

84108
void setTitleBase( const QString &title );
85109
%Docstring
110+
Sets the base part of ``title`` of the group box (will be appended with extent state)
86111
.. versionadded:: 2.12
112+
.. seealso:: titleBase()
87113
%End
114+
88115
QString titleBase() const;
89116
%Docstring
117+
Returns the base part of title of the group box (will be appended with extent state).
90118
.. versionadded:: 2.12
119+
.. seealso:: setTitleBase()
91120
:rtype: str
92121
%End
93122

94123
public slots:
124+
95125
void setOutputExtentFromOriginal();
96126
%Docstring
97-
set output extent to be the same as original extent (may be transformed to output CRS)
127+
Sets the output extent to be the same as original extent (may be transformed to output CRS).
98128
%End
99129

100130
void setOutputExtentFromCurrent();
101131
%Docstring
102-
set output extent to be the same as current extent (may be transformed to output CRS)
132+
Sets the output extent to be the same as current extent (may be transformed to output CRS).
103133
%End
104134

105135
void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
106136
%Docstring
107-
set output extent to custom extent (may be transformed to output CRS)
137+
Sets the output extent to a custom extent (may be transformed to output CRS).
108138
%End
109139

110-
signals:
111-
void extentChanged( const QgsRectangle &r );
140+
void setOutputExtentFromLayer( const QgsMapLayer *layer );
112141
%Docstring
113-
emitted when extent is changed
142+
Sets the output extent to match a ``layer``'s extent (may be transformed to output CRS).
143+
.. versionadded:: 3.0
114144
%End
115145

116-
protected slots:
117-
118-
void on_mXMinLineEdit_textEdited( const QString & );
119-
void on_mXMaxLineEdit_textEdited( const QString & );
120-
void on_mYMinLineEdit_textEdited( const QString & );
121-
void on_mYMaxLineEdit_textEdited( const QString & );
122-
123-
void groupBoxClicked();
124-
125-
protected:
126-
void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentGroupBox::ExtentState state );
127-
void setOutputExtentFromLineEdit();
128-
void updateTitle();
129-
130-
131-
132-
146+
signals:
133147

148+
void extentChanged( const QgsRectangle &r );
149+
%Docstring
150+
Emitted when the widget's extent is changed.
151+
%End
134152

135153
};
136154

src/gui/qgsextentgroupbox.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ void QgsExtentGroupBox::setExtentToLayerExtent( const QString &layerId )
171171
if ( !layer )
172172
return;
173173

174-
mExtentLayerId = layerId;
175-
mExtentLayerName = layer->name();
176-
177-
setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
174+
setOutputExtentFromLayer( layer );
178175
}
179176

180177
void QgsExtentGroupBox::setOutputExtentFromCurrent()
@@ -193,6 +190,17 @@ void QgsExtentGroupBox::setOutputExtentFromUser( const QgsRectangle &extent, con
193190
setOutputExtent( extent, crs, UserExtent );
194191
}
195192

193+
void QgsExtentGroupBox::setOutputExtentFromLayer( const QgsMapLayer *layer )
194+
{
195+
if ( !layer )
196+
return;
197+
198+
mExtentLayerId = layer->id();
199+
mExtentLayerName = layer->name();
200+
201+
setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
202+
}
203+
196204
void QgsExtentGroupBox::groupBoxClicked()
197205
{
198206
if ( !isCheckable() )

src/gui/qgsextentgroupbox.h

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
class QgsCoordinateReferenceSystem;
2828
class QgsMapLayerModel;
29+
class QgsMapLayer;
2930

3031
/** \ingroup gui
3132
* Collapsible group box for configuration of extent, typically for a save operation.
@@ -43,8 +44,8 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
4344
Q_PROPERTY( QString titleBase READ titleBase WRITE setTitleBase )
4445

4546
public:
46-
explicit QgsExtentGroupBox( QWidget *parent SIP_TRANSFERTHIS = 0 );
4747

48+
//! Available states for the current extent selection in the widget
4849
enum ExtentState
4950
{
5051
OriginalExtent, //!< Layer's extent
@@ -53,58 +54,124 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
5354
ProjectLayerExtent, //!< Extent taken from a layer within the project
5455
};
5556

56-
//! Setup original extent - should be called as part of initialization
57+
/**
58+
* Constructor for QgsExtentGroupBox.
59+
*/
60+
explicit QgsExtentGroupBox( QWidget *parent SIP_TRANSFERTHIS = 0 );
61+
62+
/**
63+
* Sets the original extent and coordinate reference system for the widget. This should be called as part of initialization.
64+
* \see originalExtent()
65+
* \see originalCrs()
66+
*/
5767
void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
5868

69+
/**
70+
* Returns the original extent set for the widget.
71+
* \see setOriginalExtent()
72+
* \see originalCrs()
73+
*/
5974
QgsRectangle originalExtent() const { return mOriginalExtent; }
60-
const QgsCoordinateReferenceSystem &originalCrs() const { return mOriginalCrs; }
6175

62-
//! Setup current extent - should be called as part of initialization (or whenever current extent changes)
76+
/**
77+
* Returns the original coordinate reference system set for the widget.
78+
* \see originalExtent()
79+
* \see setOriginalExtent()
80+
*/
81+
QgsCoordinateReferenceSystem originalCrs() const { return mOriginalCrs; }
82+
83+
/**
84+
* Sets the current extent to show in the widget - should be called as part of initialization (or whenever current extent changes).
85+
* \see currentExtent()
86+
* \see currentCrs()
87+
*/
6388
void setCurrentExtent( const QgsRectangle &currentExtent, const QgsCoordinateReferenceSystem &currentCrs );
6489

90+
/**
91+
* Returns the current extent set for the widget.
92+
* \see setCurrentExtent()
93+
* \see currentCrs()
94+
*/
6595
QgsRectangle currentExtent() const { return mCurrentExtent; }
66-
const QgsCoordinateReferenceSystem &currentCrs() const { return mCurrentCrs; }
6796

68-
//! Set the output CRS - may need to be used for transformation from original/current extent.
69-
//! Should be called as part of initialization and whenever the the output CRS is changed
97+
/**
98+
* Returns the coordinate reference system for the current extent set for the widget.
99+
* \see setCurrentExtent()
100+
* \see currentExtent()
101+
*/
102+
QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
103+
104+
/**
105+
* Sets the output CRS - may need to be used for transformation from original/current extent.
106+
* Should be called as part of initialization and whenever the the output CRS is changed.
107+
*/
70108
void setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs );
71109

72-
//! Get the resulting extent - in output CRS coordinates
110+
/**
111+
* Returns the extent shown in the widget - in output CRS coordinates.
112+
*/
73113
QgsRectangle outputExtent() const;
74114

115+
/**
116+
* Returns the currently selected state for the widget's extent.
117+
*/
75118
QgsExtentGroupBox::ExtentState extentState() const { return mExtentState; }
76119

77-
//! Set base part of title of the group box (will be appended with extent state)
78-
//! \since QGIS 2.12
120+
/**
121+
* Sets the base part of \a title of the group box (will be appended with extent state)
122+
* \since QGIS 2.12
123+
* \see titleBase()
124+
*/
79125
void setTitleBase( const QString &title );
80-
//! Set base part of title of the group box (will be appended with extent state)
81-
//! \since QGIS 2.12
126+
127+
/**
128+
* Returns the base part of title of the group box (will be appended with extent state).
129+
* \since QGIS 2.12
130+
* \see setTitleBase()
131+
*/
82132
QString titleBase() const;
83133

84134
public slots:
85-
//! set output extent to be the same as original extent (may be transformed to output CRS)
135+
136+
/**
137+
* Sets the output extent to be the same as original extent (may be transformed to output CRS).
138+
*/
86139
void setOutputExtentFromOriginal();
87140

88-
//! set output extent to be the same as current extent (may be transformed to output CRS)
141+
/**
142+
* Sets the output extent to be the same as current extent (may be transformed to output CRS).
143+
*/
89144
void setOutputExtentFromCurrent();
90145

91-
//! set output extent to custom extent (may be transformed to output CRS)
146+
/**
147+
* Sets the output extent to a custom extent (may be transformed to output CRS).
148+
*/
92149
void setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs );
93150

151+
/**
152+
* Sets the output extent to match a \a layer's extent (may be transformed to output CRS).
153+
* \since QGIS 3.0
154+
*/
155+
void setOutputExtentFromLayer( const QgsMapLayer *layer );
156+
94157
signals:
95-
//! emitted when extent is changed
158+
159+
/**
160+
* Emitted when the widget's extent is changed.
161+
*/
96162
void extentChanged( const QgsRectangle &r );
97163

98-
protected slots:
164+
private slots:
99165

100166
void on_mXMinLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
101167
void on_mXMaxLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
102168
void on_mYMinLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
103169
void on_mYMaxLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
104170

105171
void groupBoxClicked();
172+
void layerMenuAboutToShow();
106173

107-
protected:
174+
private:
108175
void setOutputExtent( const QgsRectangle &r, const QgsCoordinateReferenceSystem &srcCrs, QgsExtentGroupBox::ExtentState state );
109176
void setOutputExtentFromLineEdit();
110177
void updateTitle();
@@ -122,12 +189,6 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
122189
QgsRectangle mOriginalExtent;
123190
QgsCoordinateReferenceSystem mOriginalCrs;
124191

125-
private slots:
126-
127-
void layerMenuAboutToShow();
128-
129-
private:
130-
131192
QMenu *mLayerMenu = nullptr;
132193
QgsMapLayerModel *mMapLayerModel = nullptr;
133194
QList< QAction * > mMenuActions;

0 commit comments

Comments
 (0)