Skip to content

Commit d042304

Browse files
committed
[sipify] habndle python code snippets
1 parent 90e5196 commit d042304

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

python/core/qgscoordinatereferencesystem.sip

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ Transformations between coordinate reference systems are done using QgsCoordinat
4444

4545
For example, the following code will create and inspect "British national grid" CRS:
4646

47-
~~~{.py}
48-
crs = QgsCoordinateReferenceSystem("EPSG:27700")
49-
if crs.isValid():
50-
print("CRS Description: {}".format(crs.description()))
51-
print("CRS PROJ.4 text: {}".format(crs.toProj4()))
52-
else:
53-
print("Invalid CRS!")
54-
~~~
47+
.. code-block:: python
48+
49+
crs = QgsCoordinateReferenceSystem("EPSG:27700")
50+
if crs.isValid():
51+
print("CRS Description: {}".format(crs.description()))
52+
print("CRS PROJ.4 text: {}".format(crs.toProj4()))
53+
else:
54+
print("Invalid CRS!")
5555

5656
This will produce the following output:
5757

58-
~~~
59-
CRS Description: OSGB 1936 / British National Grid
60-
CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]
61-
~~~
58+
.. code-block:: python
59+
60+
CRS Description: OSGB 1936 / British National Grid
61+
CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]
6262

6363
CRS Definition Formats
6464
======================
@@ -149,6 +149,7 @@ There are two different flavors of WKT: one is defined by OGC, the other is the
149149
used by ESRI. They look very similar, but they are not the same. QGIS is able to consume
150150
both flavors.
151151

152+
152153
.. seealso:: :py:class:`QgsCoordinateTransform`
153154
%End
154155

python/core/symbology/qgsrenderer.sip

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ Returns details about internals of this renderer.
205205

206206
E.g. if you only want to deal with visible features:
207207

208-
~~~{.py}
209-
if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
210-
deal_with_my_feature()
211-
else:
212-
skip_the_curren_feature()
213-
~~~
208+
.. code-block:: python
209+
210+
if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
211+
deal_with_my_feature()
212+
else:
213+
skip_the_curren_feature()
214214
%End
215215

216216
virtual QgsSymbolList symbols( QgsRenderContext &context );

scripts/sipify.pl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
my $COMMENT = '';
4848
my $COMMENT_PARAM_LIST = 0;
49+
my $CODE_SNIPPET = 0;
4950
my $GLOB_IFDEF_NESTING_IDX = 0;
5051
my @GLOB_BRACKET_NESTING_IDX = (0);
5152
my $PRIVATE_SECTION_LINE = '';
@@ -119,6 +120,22 @@ sub write_header_footer {
119120

120121
sub processDoxygenLine {
121122
my $line = $_[0];
123+
124+
# detect code snipped
125+
if ( $line =~ m/\\code\{\.(\w+)\}/ ) {
126+
my $codelang = $1;
127+
$codelang =~ s/py/python/;
128+
$CODE_SNIPPET=1;
129+
return ".. code-block:: $codelang\n\n";
130+
}
131+
if ( $line =~ m/\\endcode/ ) {
132+
$CODE_SNIPPET = 0;
133+
return "\n";
134+
}
135+
if ($CODE_SNIPPET == 1){
136+
return " $line\n";
137+
}
138+
122139
# remove prepending spaces
123140
$line =~ s/^\s+//g;
124141
# remove \a formatting
@@ -130,6 +147,7 @@ sub processDoxygenLine {
130147
# replace \returns with :return:
131148
$line =~ s/\s*\\return(s)?/\n:return:/;
132149

150+
# params
133151
if ( $line =~ m/\\param / ){
134152
$line =~ s/\s*\\param (\w+)\b/:param $1:/g;
135153
if ( $COMMENT_PARAM_LIST == 0 )
@@ -139,7 +157,6 @@ sub processDoxygenLine {
139157
$COMMENT_PARAM_LIST = 1;
140158
}
141159

142-
143160
if ( $line =~ m/[\\@](ingroup|class)/ ) {
144161
return ""
145162
}
@@ -305,6 +322,7 @@ sub detect_comment_block{
305322
my %args = ( strict_mode => STRICT, @_ );
306323
# dbg_info("detect comment strict:" . $args{strict_mode} );
307324
$COMMENT_PARAM_LIST = 0;
325+
$CODE_SNIPPET = 0;
308326
if ( $LINE =~ m/^\s*\/\*/ || $args{strict_mode} == UNSTRICT && $LINE =~ m/\/\*/ ){
309327
dbg_info("found comment block");
310328
do {no warnings 'uninitialized';

src/core/qgscoordinatereferencesystem.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
7979
*
8080
* For example, the following code will create and inspect "British national grid" CRS:
8181
*
82-
* ~~~{.py}
82+
* \code{.py}
8383
* crs = QgsCoordinateReferenceSystem("EPSG:27700")
8484
* if crs.isValid():
8585
* print("CRS Description: {}".format(crs.description()))
8686
* print("CRS PROJ.4 text: {}".format(crs.toProj4()))
8787
* else:
8888
* print("Invalid CRS!")
89-
* ~~~
89+
* \endcode
9090
*
9191
* This will produce the following output:
9292
*
93-
* ~~~
93+
* \code{.py}
9494
* CRS Description: OSGB 1936 / British National Grid
9595
* CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]
96-
* ~~~
96+
* \endcode
9797
*
9898
* CRS Definition Formats
9999
* ======================

src/core/symbology/qgsrenderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ class CORE_EXPORT QgsFeatureRenderer
249249
*
250250
* E.g. if you only want to deal with visible features:
251251
*
252-
* ~~~{.py}
252+
* \code{.py}
253253
* if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
254254
* deal_with_my_feature()
255255
* else:
256256
* skip_the_curren_feature()
257-
* ~~~
257+
* \endcode
258258
*/
259259
virtual QgsFeatureRenderer::Capabilities capabilities() { return nullptr; }
260260

0 commit comments

Comments
 (0)