Skip to content

Commit

Permalink
[sipify] habndle python code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Dec 20, 2017
1 parent 90e5196 commit d042304
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
25 changes: 13 additions & 12 deletions python/core/qgscoordinatereferencesystem.sip
Expand Up @@ -44,21 +44,21 @@ Transformations between coordinate reference systems are done using QgsCoordinat

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

~~~{.py}
crs = QgsCoordinateReferenceSystem("EPSG:27700")
if crs.isValid():
print("CRS Description: {}".format(crs.description()))
print("CRS PROJ.4 text: {}".format(crs.toProj4()))
else:
print("Invalid CRS!")
~~~
.. code-block:: python

crs = QgsCoordinateReferenceSystem("EPSG:27700")
if crs.isValid():
print("CRS Description: {}".format(crs.description()))
print("CRS PROJ.4 text: {}".format(crs.toProj4()))
else:
print("Invalid CRS!")

This will produce the following output:

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

CRS Description: OSGB 1936 / British National Grid
CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]

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


.. seealso:: :py:class:`QgsCoordinateTransform`
%End

Expand Down
12 changes: 6 additions & 6 deletions python/core/symbology/qgsrenderer.sip
Expand Up @@ -205,12 +205,12 @@ Returns details about internals of this renderer.

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

~~~{.py}
if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
deal_with_my_feature()
else:
skip_the_curren_feature()
~~~
.. code-block:: python

if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
deal_with_my_feature()
else:
skip_the_curren_feature()
%End

virtual QgsSymbolList symbols( QgsRenderContext &context );
Expand Down
20 changes: 19 additions & 1 deletion scripts/sipify.pl
Expand Up @@ -46,6 +46,7 @@

my $COMMENT = '';
my $COMMENT_PARAM_LIST = 0;
my $CODE_SNIPPET = 0;
my $GLOB_IFDEF_NESTING_IDX = 0;
my @GLOB_BRACKET_NESTING_IDX = (0);
my $PRIVATE_SECTION_LINE = '';
Expand Down Expand Up @@ -119,6 +120,22 @@ sub write_header_footer {

sub processDoxygenLine {
my $line = $_[0];

# detect code snipped
if ( $line =~ m/\\code\{\.(\w+)\}/ ) {
my $codelang = $1;
$codelang =~ s/py/python/;
$CODE_SNIPPET=1;
return ".. code-block:: $codelang\n\n";
}
if ( $line =~ m/\\endcode/ ) {
$CODE_SNIPPET = 0;
return "\n";
}
if ($CODE_SNIPPET == 1){
return " $line\n";
}

# remove prepending spaces
$line =~ s/^\s+//g;
# remove \a formatting
Expand All @@ -130,6 +147,7 @@ sub processDoxygenLine {
# replace \returns with :return:
$line =~ s/\s*\\return(s)?/\n:return:/;

# params
if ( $line =~ m/\\param / ){
$line =~ s/\s*\\param (\w+)\b/:param $1:/g;
if ( $COMMENT_PARAM_LIST == 0 )
Expand All @@ -139,7 +157,6 @@ sub processDoxygenLine {
$COMMENT_PARAM_LIST = 1;
}


if ( $line =~ m/[\\@](ingroup|class)/ ) {
return ""
}
Expand Down Expand Up @@ -305,6 +322,7 @@ sub detect_comment_block{
my %args = ( strict_mode => STRICT, @_ );
# dbg_info("detect comment strict:" . $args{strict_mode} );
$COMMENT_PARAM_LIST = 0;
$CODE_SNIPPET = 0;
if ( $LINE =~ m/^\s*\/\*/ || $args{strict_mode} == UNSTRICT && $LINE =~ m/\/\*/ ){
dbg_info("found comment block");
do {no warnings 'uninitialized';
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -79,21 +79,21 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
*
* For example, the following code will create and inspect "British national grid" CRS:
*
* ~~~{.py}
* \code{.py}
* crs = QgsCoordinateReferenceSystem("EPSG:27700")
* if crs.isValid():
* print("CRS Description: {}".format(crs.description()))
* print("CRS PROJ.4 text: {}".format(crs.toProj4()))
* else:
* print("Invalid CRS!")
* ~~~
* \endcode
*
* This will produce the following output:
*
* ~~~
* \code{.py}
* CRS Description: OSGB 1936 / British National Grid
* CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]
* ~~~
* \endcode
*
* CRS Definition Formats
* ======================
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgsrenderer.h
Expand Up @@ -249,12 +249,12 @@ class CORE_EXPORT QgsFeatureRenderer
*
* E.g. if you only want to deal with visible features:
*
* ~~~{.py}
* \code{.py}
* if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
* deal_with_my_feature()
* else:
* skip_the_curren_feature()
* ~~~
* \endcode
*/
virtual QgsFeatureRenderer::Capabilities capabilities() { return nullptr; }

Expand Down

0 comments on commit d042304

Please sign in to comment.