[sipify] habndle python code snippets

This commit is contained in:
Denis Rouzaud 2017-12-19 16:34:12 -04:00
parent 90e5196996
commit d042304cc3
5 changed files with 44 additions and 25 deletions

View File

@ -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
======================
@ -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

View File

@ -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 );

View File

@ -46,6 +46,7 @@ my $PYTHON_SIGNATURE = '';
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 = '';
@ -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
@ -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 )
@ -139,7 +157,6 @@ sub processDoxygenLine {
$COMMENT_PARAM_LIST = 1;
}
if ( $line =~ m/[\\@](ingroup|class)/ ) {
return ""
}
@ -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';

View File

@ -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
* ======================

View File

@ -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; }