Skip to content

Commit 5a8ed1d

Browse files
committed
sipify QgsRange as template
1 parent 9a6235d commit 5a8ed1d

File tree

4 files changed

+223
-62
lines changed

4 files changed

+223
-62
lines changed

python/auto_sip.blacklist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
core/conversions.sip
22
core/qgsexception.sip
3-
core/qgsrange.sip
43
core/composer/qgsaddremoveitemcommand.sip
54
core/composer/qgsgroupungroupitemscommand.sip
65
core/composer/qgsaddremovemultiframecommand.sip

python/core/qgsrange.sip

Lines changed: 210 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,238 @@
1-
class QgsDoubleRange
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsrange.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
template <T> class QgsRange
213
{
3-
%TypeHeaderCode
4-
#include <qgsrange.h>
5-
%End
14+
%Docstring
15+
A template based class for storing ranges (lower to upper values).
616

17+
QgsRange classes represent a range of values of some element type. For instance,
18+
ranges of int might be used to represent integer ranges.
19+
20+
Ranges can indicate whether the upper and lower values are inclusive or exclusive.
21+
The inclusivity or exclusivity of bounds is considered when determining things like
22+
whether ranges overlap or during calculation of range intersections.
23+
24+
.. versionadded:: 3.0
25+
.. seealso:: QgsDoubleRange
26+
.. seealso:: QgsIntRange
27+
.. note::
28+
29+
not available in Python bindings (but class provided for template-based inheritance)
30+
%End
731
public:
832

9-
QgsDoubleRange( double lower, double upper, bool includeLower = true, bool includeUpper = true );
10-
double lower() const;
11-
double upper() const;
12-
bool includeLower() const;
13-
bool includeUpper() const;
14-
bool isEmpty() const;
15-
bool isSingleton() const;
16-
bool contains( const QgsDoubleRange &other ) const;
17-
bool contains( double element ) const;
18-
bool overlaps( const QgsDoubleRange &other ) const;
19-
};
33+
QgsRange( T lower, T upper, bool includeLower = true, bool includeUpper = true );
34+
%Docstring
35+
Constructor for QgsRange. The ``lower`` and ``upper`` bounds are specified,
36+
and optionally whether or not these bounds are included in the range.
37+
%End
2038

21-
class QgsIntRange
22-
{
23-
%TypeHeaderCode
24-
#include <qgsrange.h>
39+
T lower() const;
40+
%Docstring
41+
Returns the lower bound of the range.
42+
.. seealso:: upper()
43+
.. seealso:: includeLower()
44+
:rtype: T
2545
%End
2646

27-
public:
47+
T upper() const;
48+
%Docstring
49+
Returns the upper bound of the range.
50+
.. seealso:: lower()
51+
.. seealso:: includeUpper()
52+
:rtype: T
53+
%End
2854

29-
QgsIntRange( int lower, int upper, bool includeLower = true, bool includeUpper = true );
30-
int lower() const;
31-
int upper() const;
3255
bool includeLower() const;
56+
%Docstring
57+
Returns true if the lower bound is inclusive, or false if the lower
58+
bound is exclusive.
59+
.. seealso:: lower()
60+
.. seealso:: includeUpper()
61+
:rtype: bool
62+
%End
63+
3364
bool includeUpper() const;
65+
%Docstring
66+
Returns true if the upper bound is inclusive, or false if the upper
67+
bound is exclusive.
68+
.. seealso:: upper()
69+
.. seealso:: includeLower()
70+
:rtype: bool
71+
%End
72+
3473
bool isEmpty() const;
74+
%Docstring
75+
Returns true if the range is empty, ie the lower bound equals (or exceeds) the upper bound
76+
and either the bounds are exclusive.
77+
.. seealso:: isSingleton()
78+
:rtype: bool
79+
%End
80+
3581
bool isSingleton() const;
36-
bool contains( const QgsIntRange &other ) const;
37-
bool contains( int element ) const;
38-
bool overlaps( const QgsIntRange &other ) const;
39-
};
82+
%Docstring
83+
Returns true if the range consists only of a single value or instant.
84+
.. seealso:: isEmpty()
85+
:rtype: bool
86+
%End
4087

41-
class QgsDateRange
42-
{
43-
%TypeHeaderCode
44-
#include <qgsrange.h>
88+
bool contains( const QgsRange<T> &other ) const;
89+
%Docstring
90+
Returns true if this range contains another range.
91+
.. seealso:: overlaps()
92+
:rtype: bool
93+
%End
94+
95+
bool contains( T element ) const;
96+
%Docstring
97+
Returns true if this range contains a specified ``element``.
98+
:rtype: bool
99+
%End
100+
101+
bool overlaps( const QgsRange<T> &other ) const;
102+
%Docstring
103+
Returns true if this range overlaps another range.
104+
.. seealso:: contains()
105+
:rtype: bool
45106
%End
46107

47-
public:
48108

49-
QgsDateRange( const QDate &lower = QDate(), const QDate &upper = QDate(), bool includeLower = true, bool includeUpper = true );
50-
QDate begin() const;
51-
QDate end() const;
52-
bool includeBeginning() const;
53-
bool includeEnd() const;
54-
bool isEmpty() const;
55-
bool isInstant() const;
56-
bool isInfinite() const;
57-
bool contains( const QgsDateRange &other ) const;
58-
bool contains( const QDate &element ) const;
59-
bool overlaps( const QgsDateRange &other ) const;
60109
};
61110

62-
class QgsDateTimeRange
111+
112+
typedef QgsRange< double > QgsDoubleRange;
113+
114+
115+
116+
117+
typedef QgsRange< int > QgsIntRange;
118+
119+
120+
template <T> class QgsTemporalRange
63121
{
64-
%TypeHeaderCode
65-
#include <qgsrange.h>
66-
%End
122+
%Docstring
123+
A template based class for storing temporal ranges (beginning to end values).
124+
125+
QgsTemporalRange classes represent a range of values of some temporal type. For instance,
126+
ranges of QDateTime might be used to represent datetime ranges.
127+
128+
Ranges can indicate whether the upper and lower values are inclusive or exclusive.
129+
The inclusivity or exclusivity of bounds is considered when determining things like
130+
whether ranges overlap or during calculation of range intersections.
67131

132+
.. versionadded:: 3.0
133+
.. seealso:: QgsDateRange
134+
.. note::
135+
136+
not available in Python bindings (but class provided for template-based inheritance)
137+
%End
68138
public:
69139

70-
QgsDateTimeRange( const QDateTime &lower = QDateTime(), const QDateTime &upper = QDateTime(), bool includeLower = true, bool includeUpper = true );
71-
QDateTime begin() const;
72-
QDateTime end() const;
140+
QgsTemporalRange( const T &begin, const T &end, bool includeBeginning = true, bool includeEnd = true );
141+
%Docstring
142+
Constructor for QgsTemporalRange. The ``begin`` and ``end`` are specified,
143+
and optionally whether or not these bounds are included in the range.
144+
.. note::
145+
146+
in Python ``begin`` and ``end`` must be provided.
147+
%End
148+
// default constructor as default value for templates is not handled in SIP
149+
150+
T begin() const;
151+
%Docstring
152+
Returns the beginning of the range.
153+
.. seealso:: end()
154+
.. seealso:: includeBeginning()
155+
:rtype: T
156+
%End
157+
158+
T end() const;
159+
%Docstring
160+
Returns the upper bound of the range.
161+
.. seealso:: begin()
162+
.. seealso:: includeEnd()
163+
:rtype: T
164+
%End
165+
73166
bool includeBeginning() const;
167+
%Docstring
168+
Returns true if the beginning is inclusive, or false if the beginning
169+
is exclusive.
170+
.. seealso:: begin()
171+
.. seealso:: includeEnd()
172+
:rtype: bool
173+
%End
174+
74175
bool includeEnd() const;
75-
bool isEmpty() const;
176+
%Docstring
177+
Returns true if the end is inclusive, or false if the end is exclusive.
178+
.. seealso:: end()
179+
.. seealso:: includeBeginning()
180+
:rtype: bool
181+
%End
182+
76183
bool isInstant() const;
184+
%Docstring
185+
Returns true if the range consists only of a single instant.
186+
.. seealso:: isEmpty()
187+
.. seealso:: isInfinite()
188+
:rtype: bool
189+
%End
190+
77191
bool isInfinite() const;
78-
bool contains( const QgsDateTimeRange &other ) const;
79-
bool contains( const QDateTime &element ) const;
80-
bool overlaps( const QgsDateTimeRange &other ) const;
192+
%Docstring
193+
Returns true if the range consists of all possible values.
194+
.. seealso:: isEmpty()
195+
.. seealso:: isInstant()
196+
:rtype: bool
197+
%End
198+
199+
bool isEmpty() const;
200+
%Docstring
201+
Returns true if the range is empty, ie the beginning equals (or exceeds) the end
202+
and either of the bounds are exclusive.
203+
A range with both invalid beginning and end is considered infinite and not empty.
204+
:rtype: bool
205+
%End
206+
207+
bool contains( const QgsTemporalRange<T> &other ) const;
208+
%Docstring
209+
Returns true if this range contains another range.
210+
:rtype: bool
211+
%End
212+
213+
bool contains( const T &element ) const;
214+
%Docstring
215+
Returns true if this range contains a specified ``element``.
216+
:rtype: bool
217+
%End
218+
219+
bool overlaps( const QgsTemporalRange<T> &other ) const;
220+
%Docstring
221+
Returns true if this range overlaps another range.
222+
:rtype: bool
223+
%End
224+
81225
};
82226

227+
228+
typedef QgsTemporalRange< QDate > QgsDateRange;
229+
230+
typedef QgsTemporalRange< QDateTime > QgsDateTimeRange;
231+
232+
/************************************************************************
233+
* This file has been generated automatically from *
234+
* *
235+
* src/core/qgsrange.h *
236+
* *
237+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
238+
************************************************************************/

scripts/sipify.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ sub detect_comment_block{
694694

695695
# keyword fixes
696696
do {no warnings 'uninitialized';
697-
$LINE =~ s/^(\s*template<)(?:class|typename) (\w+>)(.*)$/$1$2$3/;
697+
$LINE =~ s/^(\s*template\s*<)(?:class|typename) (\w+>)(.*)$/$1$2$3/;
698698
$LINE =~ s/\s*\boverride\b//;
699699
$LINE =~ s/\s*\bextern \b//;
700700
$LINE =~ s/^(\s*)?(const )?(virtual |static )?inline /$1$2$3/;
@@ -712,7 +712,7 @@ sub detect_comment_block{
712712
# https://regex101.com/r/gUBZUk/10
713713
if ( $SIP_RUN != 1 &&
714714
$ACCESS[$#ACCESS] != PUBLIC &&
715-
$LINE =~ m/^\s*(?:template<\w+>\s+)?(?:(const|mutable|static|friend|unsigned)\s+)*\w+(::\w+)?(<([\w<> *&,()]|::)+>)?(,?\s+\*?\w+( = (-?\d+(\.\d+)?|(\w+::)*\w+(\([^()]+\))?)|\[\d+\])?)+;/){
715+
$LINE =~ m/^\s*(?:template\s*<\w+>\s+)?(?:(const|mutable|static|friend|unsigned)\s+)*\w+(::\w+)?(<([\w<> *&,()]|::)+>)?(,?\s+\*?\w+( = (-?\d+(\.\d+)?|(\w+::)*\w+(\([^()]+\))?)|\[\d+\])?)+;/){
716716
dbg_info("skip non-method member declaration in non-public sections");
717717
next;
718718
}
@@ -868,7 +868,7 @@ sub detect_comment_block{
868868
$IS_OVERRIDE = 0;
869869
next;
870870
}
871-
if ( $LINE =~ m/^\s*template<.*>/ ){
871+
if ( $LINE =~ m/^\s*template\s*<.*>/ ){
872872
# do not comment now for templates, wait for class definition
873873
next;
874874
}

src/core/qgsrange.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
* \since QGIS 3.0
3838
* \see QgsDoubleRange
3939
* \see QgsIntRange
40-
* \note not available in Python bindings
40+
* \note not available in Python bindings (but class provided for template-based inheritance)
4141
*/
42-
template <class T> class QgsRange SIP_SKIP
42+
template <class T> class QgsRange
4343
{
4444
public:
4545

@@ -211,22 +211,28 @@ typedef QgsRange< int > QgsIntRange;
211211
*
212212
* \since QGIS 3.0
213213
* \see QgsDateRange
214-
* \note not available in Python bindings
214+
* \note not available in Python bindings (but class provided for template-based inheritance)
215215
*/
216-
template <class T> class QgsTemporalRange SIP_SKIP
216+
template <class T> class QgsTemporalRange
217217
{
218218
public:
219219

220220
/**
221221
* Constructor for QgsTemporalRange. The \a begin and \a end are specified,
222222
* and optionally whether or not these bounds are included in the range.
223+
* \note in Python \a begin and \a end must be provided.
223224
*/
225+
#ifndef SIP_RUN
224226
QgsTemporalRange( const T &begin = T(), const T &end = T(), bool includeBeginning = true, bool includeEnd = true )
225227
: mLower( begin )
226228
, mUpper( end )
227229
, mIncludeLower( includeBeginning )
228230
, mIncludeUpper( includeEnd )
229231
{}
232+
#else
233+
QgsTemporalRange( const T &begin, const T &end, bool includeBeginning = true, bool includeEnd = true );
234+
// default constructor as default value for templates is not handled in SIP
235+
#endif
230236

231237
/**
232238
* Returns the beginning of the range.

0 commit comments

Comments
 (0)