Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Represents a patch shape for use in map legends.
- Loading branch information
1 parent
bd86add
commit 1b5f4dd
Showing
7 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
python/core/auto_generated/layertree/qgslegendpatchshape.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layertree/qgslegendpatchshape.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsLegendPatchShape | ||
{ | ||
%Docstring | ||
Represents a patch shape for use in map legends. | ||
|
||
.. versionadded:: 3.14 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslegendpatchshape.h" | ||
%End | ||
public: | ||
|
||
QgsLegendPatchShape( QgsSymbol::SymbolType type, | ||
const QgsGeometry &geometry, | ||
bool preserveAspectRatio = true ); | ||
%Docstring | ||
Constructor for QgsLegendPatchShape. | ||
|
||
The ``type`` argument specifies the symbol type associated with this patch. | ||
|
||
The ``geometry`` argument gives the shape of the patch to render. See setGeometry() | ||
for further details on the geometry requirements. | ||
|
||
If ``preserveAspectRatio`` is ``True``, then the patch shape should preserve its aspect ratio when | ||
it is resized to fit a desired legend patch size. | ||
%End | ||
|
||
QgsSymbol::SymbolType symbolType() const; | ||
%Docstring | ||
Returns the symbol type associated with this patch. | ||
|
||
.. seealso:: :py:func:`setSymbolType` | ||
%End | ||
|
||
void setSymbolType( QgsSymbol::SymbolType type ); | ||
%Docstring | ||
Sets the symbol ``type`` associated with this patch. | ||
|
||
.. seealso:: :py:func:`symbolType` | ||
%End | ||
|
||
QgsGeometry geometry() const; | ||
%Docstring | ||
Returns the geometry for the patch shape. | ||
|
||
.. seealso:: :py:func:`setGeometry` | ||
%End | ||
|
||
void setGeometry( const QgsGeometry &geometry ); | ||
%Docstring | ||
Sets the ``geometry`` for the patch shape. | ||
|
||
The origin and size of the ``geometry`` is not important, as the legend | ||
renderer will automatically scale and transform the geometry to match | ||
the desired overall patch bounds. | ||
|
||
Geometries for legend patches are rendered respecting the traditional | ||
"y values increase toward the top of the map" convention, as opposed | ||
to the standard computer graphics convention of "y values increase toward | ||
the bottom of the display". | ||
|
||
.. warning:: | ||
|
||
The geometry type should match the patch shape's symbolType(), | ||
e.g. a fill symbol type should only have Polygon or MultiPolygon geometries | ||
set, while a line symbol type must have LineString or MultiLineString geometries. | ||
|
||
.. seealso:: :py:func:`geometry` | ||
%End | ||
|
||
bool preserveAspectRatio() const; | ||
%Docstring | ||
Returns ``True`` if the patch shape should preserve its aspect ratio when | ||
it is resized to fit a desired legend patch size. | ||
|
||
.. seealso:: :py:func:`setPreserveAspectRatio` | ||
%End | ||
|
||
void setPreserveAspectRatio( bool preserve ); | ||
%Docstring | ||
Sets whether the patch shape should ``preserve`` its aspect ratio when | ||
it is resized to fit a desired legend patch size. | ||
|
||
The default behavior is to respect the geometry()'s aspect ratio. | ||
|
||
.. seealso:: :py:func:`setPreserveAspectRatio` | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layertree/qgslegendpatchshape.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgslegendpatchshape.cpp | ||
------------------- | ||
begin : April 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslegendpatchshape.h" | ||
|
||
|
||
QgsLegendPatchShape::QgsLegendPatchShape( QgsSymbol::SymbolType type, const QgsGeometry &geometry, bool preserveAspectRatio ) | ||
: mSymbolType( type ) | ||
, mGeometry( geometry ) | ||
, mPreserveAspectRatio( preserveAspectRatio ) | ||
{ | ||
|
||
} | ||
|
||
QgsGeometry QgsLegendPatchShape::geometry() const | ||
{ | ||
return mGeometry; | ||
} | ||
|
||
void QgsLegendPatchShape::setGeometry( const QgsGeometry &geometry ) | ||
{ | ||
mGeometry = geometry; | ||
} | ||
|
||
bool QgsLegendPatchShape::preserveAspectRatio() const | ||
{ | ||
return mPreserveAspectRatio; | ||
} | ||
|
||
void QgsLegendPatchShape::setPreserveAspectRatio( bool preserveAspectRatio ) | ||
{ | ||
mPreserveAspectRatio = preserveAspectRatio; | ||
} | ||
|
||
QgsSymbol::SymbolType QgsLegendPatchShape::symbolType() const | ||
{ | ||
return mSymbolType; | ||
} | ||
|
||
void QgsLegendPatchShape::setSymbolType( QgsSymbol::SymbolType type ) | ||
{ | ||
mSymbolType = type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*************************************************************************** | ||
qgslegendpatchshape.h | ||
------------------- | ||
begin : April 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSLEGENDPATCHSHAPE_H | ||
#define QGSLEGENDPATCHSHAPE_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
#include "qgssymbol.h" | ||
|
||
/** | ||
* \ingroup core | ||
* Represents a patch shape for use in map legends. | ||
* | ||
* \since QGIS 3.14 | ||
*/ | ||
class CORE_EXPORT QgsLegendPatchShape | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor for QgsLegendPatchShape. | ||
* | ||
* The \a type argument specifies the symbol type associated with this patch. | ||
* | ||
* The \a geometry argument gives the shape of the patch to render. See setGeometry() | ||
* for further details on the geometry requirements. | ||
* | ||
* If \a preserveAspectRatio is TRUE, then the patch shape should preserve its aspect ratio when | ||
* it is resized to fit a desired legend patch size. | ||
*/ | ||
QgsLegendPatchShape( QgsSymbol::SymbolType type, | ||
const QgsGeometry &geometry, | ||
bool preserveAspectRatio = true ); | ||
|
||
/** | ||
* Returns the symbol type associated with this patch. | ||
* | ||
* \see setSymbolType() | ||
*/ | ||
QgsSymbol::SymbolType symbolType() const; | ||
|
||
/** | ||
* Sets the symbol \a type associated with this patch. | ||
* | ||
* \see symbolType() | ||
*/ | ||
void setSymbolType( QgsSymbol::SymbolType type ); | ||
|
||
/** | ||
* Returns the geometry for the patch shape. | ||
* | ||
* \see setGeometry() | ||
*/ | ||
QgsGeometry geometry() const; | ||
|
||
/** | ||
* Sets the \a geometry for the patch shape. | ||
* | ||
* The origin and size of the \a geometry is not important, as the legend | ||
* renderer will automatically scale and transform the geometry to match | ||
* the desired overall patch bounds. | ||
* | ||
* Geometries for legend patches are rendered respecting the traditional | ||
* "y values increase toward the top of the map" convention, as opposed | ||
* to the standard computer graphics convention of "y values increase toward | ||
* the bottom of the display". | ||
* | ||
* \warning The geometry type should match the patch shape's symbolType(), | ||
* e.g. a fill symbol type should only have Polygon or MultiPolygon geometries | ||
* set, while a line symbol type must have LineString or MultiLineString geometries. | ||
* | ||
* \see geometry() | ||
*/ | ||
void setGeometry( const QgsGeometry &geometry ); | ||
|
||
/** | ||
* Returns TRUE if the patch shape should preserve its aspect ratio when | ||
* it is resized to fit a desired legend patch size. | ||
* | ||
* \see setPreserveAspectRatio() | ||
*/ | ||
bool preserveAspectRatio() const; | ||
|
||
/** | ||
* Sets whether the patch shape should \a preserve its aspect ratio when | ||
* it is resized to fit a desired legend patch size. | ||
* | ||
* The default behavior is to respect the geometry()'s aspect ratio. | ||
* | ||
* \see setPreserveAspectRatio() | ||
*/ | ||
void setPreserveAspectRatio( bool preserve ); | ||
|
||
private: | ||
QgsSymbol::SymbolType mSymbolType = QgsSymbol::Fill; | ||
QgsGeometry mGeometry; | ||
bool mPreserveAspectRatio = true; | ||
|
||
}; | ||
|
||
#endif // QGSLEGENDPATCHSHAPE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsLegendPatchShape. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = '(C) 2020 by Nyall Dawson' | ||
__date__ = '05/04/2020' | ||
__copyright__ = 'Copyright 2020, The QGIS Project' | ||
|
||
import qgis # NOQA | ||
|
||
from qgis.core import (QgsLegendPatchShape, | ||
QgsGeometry, | ||
QgsSymbol | ||
) | ||
from qgis.testing import start_app, unittest | ||
from utilities import unitTestDataPath | ||
|
||
|
||
start_app() | ||
TEST_DATA_DIR = unitTestDataPath() | ||
|
||
|
||
class TestQgsLegendPatchShape(unittest.TestCase): | ||
|
||
def testBasic(self): | ||
shape = QgsLegendPatchShape(QgsSymbol.Line, QgsGeometry.fromWkt('LineString( 0 0, 1 1)'), False) | ||
self.assertEqual(shape.symbolType(), QgsSymbol.Line) | ||
self.assertEqual(shape.geometry().asWkt(), 'LineString (0 0, 1 1)') | ||
self.assertFalse(shape.preserveAspectRatio()) | ||
|
||
shape.setSymbolType(QgsSymbol.Marker) | ||
self.assertEqual(shape.symbolType(), QgsSymbol.Marker) | ||
|
||
shape.setGeometry(QgsGeometry.fromWkt('Multipoint( 1 1, 2 2)')) | ||
self.assertEqual(shape.geometry().asWkt(), 'MultiPoint ((1 1),(2 2))') | ||
|
||
shape.setPreserveAspectRatio(True) | ||
self.assertTrue(shape.preserveAspectRatio()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |