Implicitly shared text settings classes

This commit is contained in:
Nyall Dawson 2015-09-15 16:10:55 +10:00
parent 687c66f5d6
commit 5f241d6288
8 changed files with 4236 additions and 0 deletions

View File

@ -135,6 +135,7 @@
%Include qgsstatisticalsummary.sip
%Include qgsstringstatisticalsummary.sip
%Include qgsstringutils.sip
%Include qgstextrenderer.sip
%Include qgstolerance.sip
%Include qgstracer.sip
%Include qgsunittypes.sip

View File

@ -0,0 +1,995 @@
/** \class QgsTextBufferSettings
* \ingroup core
* Container for settings relating to a text buffer.
* \note QgsTextBufferSettings objects are implicitly shared.
* \note added in QGIS 3.0
*/
class QgsTextBufferSettings
{
%TypeHeaderCode
#include <qgstextrenderer.h>
%End
public:
QgsTextBufferSettings();
QgsTextBufferSettings( const QgsTextBufferSettings& other );
~QgsTextBufferSettings();
/** Returns whether the buffer is enabled.
* @see setEnabled()
*/
bool enabled() const;
/** Sets whether the text buffer will be drawn.
* @param enabled set to true to draw buffer
* @see enabled()
*/
void setEnabled( bool enabled );
/** Returns the size of the buffer.
* @see sizeUnit()
* @see setSize()
*/
double size() const;
/** Sets the size of the buffer. The size units are specified using setSizeUnit().
* @param size buffer size
* @see size()
* @see setSizeUnit()
*/
void setSize( double size );
/** Returns the units for the buffer size.
* @see size()
* @see setSizeUnit()
*/
QgsUnitTypes::RenderUnit sizeUnit() const;
/** Sets the units used for the buffer size.
* @param unit size unit
* @see setSize()
* @see sizeUnit()
*/
void setSizeUnit( QgsUnitTypes::RenderUnit unit );
/** Returns the map unit scale object for the buffer size. This is only used if the
* buffer size is set to QgsUnitTypes::RenderMapUnit.
* @see setSizeMapUnitScale()
* @see sizeUnit()
*/
QgsMapUnitScale sizeMapUnitScale() const;
/** Sets the map unit scale object for the buffer size. This is only used if the
* buffer size is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for buffer size
* @see sizeMapUnitScale()
* @see setSizeUnit()
*/
void setSizeMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the color of the buffer.
* @see setColor()
*/
QColor color() const;
/** Sets the color for the buffer.
* @param color buffer color
* @see color()
*/
void setColor( const QColor& color );
/** Returns whether the interior of the buffer will be filled in. If false, only the outline
* of the text will be drawn as the buffer. The effect of this setting is only visible for
* semi-transparent text.
* @see setFillBufferInterior()
*/
bool fillBufferInterior() const;
/** Sets whether the interior of the buffer will be filled in.
* @param fill set to false to drawn only the outline of the text as the buffer, or true to also
* shade the area inside the text. The effect of this setting is only visible for semi-transparent text.
* @see fillBufferInterior()
*/
void setFillBufferInterior( bool fill );
/** Returns the buffer opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally
* opaque).
* @see setOpacity()
*/
double opacity() const;
/** Sets the buffer opacity.
* @param opacity opacity as a double value between 0 (fully transparent) and 1 (totally
* opaque)
* @see opacity()
*/
void setOpacity( double opacity );
/** Returns the buffer join style.
* @see setJoinStyle
*/
Qt::PenJoinStyle joinStyle() const;
/** Sets the join style used for drawing the buffer.
* @param style join style
* @see joinStyle()
*/
void setJoinStyle( Qt::PenJoinStyle style );
/** Returns the blending mode used for drawing the buffer.
* @see setBlendMode()
*/
QPainter::CompositionMode blendMode() const;
/** Sets the blending mode used for drawing the buffer.
* @param mode blending mode
* @see blendMode()
*/
void setBlendMode( QPainter::CompositionMode mode );
/** Reads settings from a layer's custom properties.
* @param layer source vector layer
* @see writeToLayer()
*/
void readFromLayer( QgsVectorLayer* layer );
/** Writes settings to a layer's custom properties.
* @param layer target vector layer
* @see readFromLayer()
*/
void writeToLayer( QgsVectorLayer* layer ) const;
/** Read settings from a DOM element.
* @see writeXml()
*/
void readXml( const QDomElement& elem );
/** Write settings into a DOM element.
* @see readXml()
*/
QDomElement writeXml( QDomDocument& doc ) const;
};
/** \class QgsTextBackgroundSettings
* \ingroup core
* Container for settings relating to a text background object.
* \note QgsTextBackgroundSettings objects are implicitly shared.
* \note added in QGIS 3.0
*/
class QgsTextBackgroundSettings
{
%TypeHeaderCode
#include <qgstextrenderer.h>
%End
public:
/** Background shape types.
*/
enum ShapeType
{
ShapeRectangle, /*!< rectangle */
ShapeSquare, /*!< square */
ShapeEllipse, /*!< ellipse */
ShapeCircle, /*!< circle */
ShapeSVG /*!< SVG file */
};
/** Methods for determining the background shape size.
*/
enum SizeType
{
SizeBuffer, /*!< shape size is determined by adding a buffer margin around text */
SizeFixed, /*!< fixed size */
SizePercent /*!< shape size is determined by percent of text size */
};
/** Methods for determining the rotation of the background shape.
*/
enum RotationType
{
RotationSync, /*!< shape rotation is synced with text rotation */
RotationOffset, /*!< shape rotation is offset from text rotation */
RotationFixed /*!< shape rotation is a fixed angle */
};
QgsTextBackgroundSettings();
QgsTextBackgroundSettings( const QgsTextBackgroundSettings& other );
~QgsTextBackgroundSettings();
/** Returns whether the background is enabled.
* @see setEnabled()
*/
bool enabled() const;
/** Sets whether the text background will be drawn.
* @param enabled set to true to draw background
* @see enabled()
*/
void setEnabled( bool enabled );
/** Returns the type of background shape (eg square, ellipse, SVG).
* @see setType()
*/
ShapeType type() const;
/** Sets the type of background shape to draw (eg square, ellipse, SVG).
* @param type shape type
* @see type()
*/
void setType( ShapeType type );
/** Returns the path to the background SVG file, if set.
* @see setSvgFile()
*/
QString svgFile() const;
/** Sets the path to the background SVG file. This is only used if type() is set to
* QgsTextBackgroundSettings::ShapeSVG.
* @param file SVG file path
* @see svgFile()
*/
void setSvgFile( const QString& file );
/** Returns the method used to determine the size of the background shape (eg fixed size or buffer
* around text).
* @see setSizeType()
* @see size()
*/
SizeType sizeType() const;
/** Sets the method used to determine the size of the background shape (eg fixed size or buffer
* around text).
* @param type size method
* @see sizeType()
* @see setSize()
*/
void setSizeType( SizeType type );
/** Returns the size of the background shape. The meaning of the size depends on the current sizeType()
* eg, for size types of QgsTextBackgroundSettings::SizeFixed the size will represent the actual width and
* height of the shape, for QgsTextBackgroundSettings::SizeBuffer the size will represent the horizontal
* and vertical margins to add to the text when calculating the size of the shape.
* @see setSize()
* @see sizeType()
*/
QSizeF size() const;
/** Sets the size of the background shape. The meaning of the size depends on the current sizeType()
* eg, for size types of QgsTextBackgroundSettings::SizeFixed the size will represent the actual width and
* height of the shape, for QgsTextBackgroundSettings::SizeBuffer the size will represent the horizontal
* and vertical margins to add to the text when calculating the size of the shape.
* @param size QSizeF representing horizontal and vertical size components for shape
* @see size()
* @see setSizeType()
*/
void setSize( const QSizeF& size );
/** Returns the units used for the shape's size. This value has no meaning if the sizeType() is set to
* QgsTextBackgroundSettings::SizePercent.
* @see setSizeUnit()
* @see sizeType()
* @see size()
*/
QgsUnitTypes::RenderUnit sizeUnit() const;
/** Sets the units used for the shape's size. This value has no meaning if the sizeType() is set to
* QgsTextBackgroundSettings::SizePercent.
* @param unit size units
* @see sizeUnit()
* @see setSizeType()
* @see setSize()
*/
void setSizeUnit( QgsUnitTypes::RenderUnit unit );
/** Returns the map unit scale object for the shape size. This is only used if the
* sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setSizeMapUnitScale()
* @see sizeUnit()
*/
QgsMapUnitScale sizeMapUnitScale() const;
/** Sets the map unit scale object for the shape size. This is only used if the
* sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shape size
* @see sizeMapUnitScale()
* @see setSizeUnit()
*/
void setSizeMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the method used for rotating the background shape.
* @see setRotationType()
* @see rotation()
*/
RotationType rotationType() const;
/** Sets the method used for rotating the background shape.
* @param type rotation method
* @see rotationType()
* @see setRotation()
*/
void setRotationType( RotationType type );
/** Returns the rotation for the background shape.
* @see rotationType()
* @see setRotation()
*/
double rotation() const;
/** Sets the rotation for the background shape.
* @param rotation angle in degrees to rotate
* @see rotation()
* @see setRotationType()
*/
void setRotation( double rotation );
/** Returns the offset used for drawing the background shape. Units are determined
* via offsetUnit().
* @see setOffset()
* @see offsetUnit()
*/
QPointF offset() const;
/** Sets the offset used for drawing the background shape. Units are specified using
* setOffsetUnit().
* @param offset offset for shape
* @see offset()
* @see setOffsetUnit()
*/
void setOffset( const QPointF& offset );
/** Returns the units used for the shape's offset.
* @see setOffsetUnit()
* @see offset()
*/
QgsUnitTypes::RenderUnit offsetUnit() const;
/** Sets the units used for the shape's offset.
* @param unit offset units
* @see offsetUnit()
* @see setOffset()
*/
void setOffsetUnit( QgsUnitTypes::RenderUnit units );
/** Returns the map unit scale object for the shape offset. This is only used if the
* offsetUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setOffsetMapUnitScale()
* @see offsetUnit()
*/
QgsMapUnitScale offsetMapUnitScale() const;
/** Sets the map unit scale object for the shape offset. This is only used if the
* offsetUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shape offset
* @see offsetMapUnitScale()
* @see setOffsetUnit()
*/
void setOffsetMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the radii used for rounding the corners of shapes. Units are retrieved
* through radiiUnit().
* @see setRadii()
* @see radiiUnit()
*/
QSizeF radii() const;
/** Sets the radii used for rounding the corners of shapes. This is only used if
* type() is set to QgsTextBackgroundSettings::ShapeRectangle or QgsTextBackgroundSettings::ShapeSquare.
* @param radii QSizeF representing horizontal and vertical radii for rounded corners. Units are
* specified through setRadiiUnit()
* @see radii()
* @see setRadiiUnit()
*/
void setRadii( const QSizeF& radii );
/** Returns the units used for the shape's radii.
* @see setRadiiUnit()
* @see radii()
*/
QgsUnitTypes::RenderUnit radiiUnit() const;
/** Sets the units used for the shape's radii.
* @param unit radii units
* @see radiiUnit()
* @see setRadii()
*/
void setRadiiUnit( QgsUnitTypes::RenderUnit units );
/** Returns the map unit scale object for the shape radii. This is only used if the
* radiiUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setRadiiMapUnitScale()
* @see radiiUnit()
*/
QgsMapUnitScale radiiMapUnitScale() const;
/** Sets the map unit scale object for the shape radii. This is only used if the
* radiiUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shape radii
* @see radiiMapUnitScale()
* @see setRadiiUnit()
*/
void setRadiiMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the background shape's opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally
* opaque).
* @see setOpacity()
*/
double opacity() const;
/** Sets the background shape's opacity.
* @param opacity opacity as a double value between 0 (fully transparent) and 1 (totally
* opaque)
* @see opacity()
*/
void setOpacity( double opacity );
/** Returns the blending mode used for drawing the background shape.
* @see setBlendMode()
*/
QPainter::CompositionMode blendMode() const;
/** Sets the blending mode used for drawing the background shape.
* @param mode blending mode
* @see blendMode()
*/
void setBlendMode( QPainter::CompositionMode mode );
/** Returns the color used for filing the background shape.
* @see setFillColor()
* @see borderColor()
*/
QColor fillColor() const;
/** Sets the color used for filing the background shape.
* @param color background color
* @see fillColor()
* @see setBorderColor()
*/
void setFillColor( const QColor& color );
/** Returns the color used for outlining the background shape.
* @see setBorderColor()
* @see fillColor()
*/
QColor borderColor() const;
/** Sets the color used for outlining the background shape.
* @param color outline color
* @see borderColor()
* @see setFillColor()
*/
void setBorderColor( const QColor& color );
/** Returns the width of the shape's border (outline). Units are retrieved through
* borderWidthUnit().
* @see setBorderWidth()
* @see borderWidthUnit()
*/
double borderWidth() const;
/** Sets the width of the shape's border (outline). Units are specified through
* setBorderWidthUnit().
* @see borderWidth()
* @see setBorderWidthUnit()
*/
void setBorderWidth( double width );
/** Returns the units used for the shape's border width.
* @see setBorderWidthUnit()
* @see borderWidth()
*/
QgsUnitTypes::RenderUnit borderWidthUnit() const;
/** Sets the units used for the shape's border width.
* @param unit border width units
* @see borderWidthUnit()
* @see setBorderWidth()
*/
void setBorderWidthUnit( QgsUnitTypes::RenderUnit units );
/** Returns the map unit scale object for the shape border width. This is only used if the
* borderWidthUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setBorderWidthMapUnitScale()
* @see borderWidthUnit()
*/
QgsMapUnitScale borderWidthMapUnitScale() const;
/** Sets the map unit scale object for the shape border width. This is only used if the
* borderWidthUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shape border width
* @see borderWidthMapUnitScale()
* @see setBorderWidthUnit()
*/
void setBorderWidthMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the join style used for drawing the background shape.
* @see setJoinStyle
*/
Qt::PenJoinStyle joinStyle() const;
/** Sets the join style used for drawing the background shape.
* @param style join style
* @see joinStyle()
*/
void setJoinStyle( Qt::PenJoinStyle style );
/** Reads settings from a layer's custom properties.
* @param layer source vector layer
* @see writeToLayer()
*/
void readFromLayer( QgsVectorLayer* layer );
/** Writes settings to a layer's custom properties.
* @param layer target vector layer
* @see readFromLayer()
*/
void writeToLayer( QgsVectorLayer* layer ) const;
/** Read settings from a DOM element.
* @see writeXml()
*/
void readXml( const QDomElement& elem );
/** Write settings into a DOM element.
* @see readXml()
*/
QDomElement writeXml( QDomDocument& doc ) const;
};
/** \class QgsTextShadowSettings
* \ingroup core
* Container for settings relating to a text shadow.
* \note QgsTextShadowSettings objects are implicitly shared.
* \note added in QGIS 3.0
*/
class QgsTextShadowSettings
{
%TypeHeaderCode
#include <qgstextrenderer.h>
%End
public:
/** Placement positions for text shadow.
*/
enum ShadowPlacement
{
ShadowLowest, /*!< draw shadow below all text components */
ShadowText, /*!< draw shadow under text */
ShadowBuffer, /*!< draw shadow under buffer */
ShadowShape /*!< draw shadow under background shape */
};
QgsTextShadowSettings();
QgsTextShadowSettings( const QgsTextShadowSettings& other );
~QgsTextShadowSettings();
/** Returns whether the shadow is enabled.
* @see setEnabled()
*/
bool enabled() const;
/** Sets whether the text shadow will be drawn.
* @param enabled set to true to draw shadow
* @see enabled()
*/
void setEnabled( bool enabled );
/** Returns the placement for the drop shadow. The placement determines
* both the z-order stacking position for the shadow and the what shape (eg text,
* background shape) is used for casting the shadow.
* @see setShadowPlacement()
*/
QgsTextShadowSettings::ShadowPlacement shadowPlacement() const;
/** Sets the placement for the drop shadow. The placement determines
* both the z-order stacking position for the shadow and the what shape (eg text,
* background shape) is used for casting the shadow.
* @param placement shadow placement
* @see shadowPlacement()
*/
void setShadowPlacement( QgsTextShadowSettings::ShadowPlacement placement );
/** Returns the angle for offsetting the position of the shadow from the text.
* @see setOffsetAngle
* @see offsetDistance()
*/
int offsetAngle() const;
/** Sets the angle for offseting the position of the shadow from the text.
* @param angle offset angle in degrees
* @see offsetAngle()
* @see setOffsetDistance()
*/
void setOffsetAngle( int angle );
/** Returns the distance for offsetting the position of the shadow from the text. Offset units
* are retrieved via offsetUnit().
* @see setOffsetDistance()
* @see offsetUnit()
*/
double offsetDistance() const;
/** Sets the distance for offsetting the position of the shadow from the text. Offset units
* are specified via setOffsetUnit().
* @param offset distance
* @see offsetDistance()
* @see setOffsetUnit()
*/
void setOffsetDistance( double distance );
/** Returns the units used for the shadow's offset.
* @see setOffsetUnit()
* @see offsetDistance()
*/
QgsUnitTypes::RenderUnit offsetUnit();
/** Sets the units used for the shadow's offset.
* @param units shadow distance units
* @see offsetUnit()
* @see setOffsetDistance()
*/
void setOffsetUnit( QgsUnitTypes::RenderUnit units );
/** Returns the map unit scale object for the shadow offset distance. This is only used if the
* offsetUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setOffsetMapUnitScale()
* @see offsetUnit()
*/
QgsMapUnitScale offsetMapUnitScale() const;
/** Sets the map unit scale object for the shadow offset distance. This is only used if the
* offsetUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shadow offset
* @see offsetMapUnitScale()
* @see setOffsetUnit()
*/
void setOffsetMapUnitScale( const QgsMapUnitScale& scale );
/** Returns true if the global shadow offset will be used.
* @see setOffsetGlobal()
*/
bool offsetGlobal() const;
/** Sets whether the global shadow offset should be used.
* @param global set to true to use global shadow offset.
*/
void setOffsetGlobal( bool global );
/** Returns the blur radius for the shadow. Radius units are retrieved via blurRadiusUnit().
* @see setBlurRadius()
* @see blurRadiusUnit()
*/
double blurRadius() const;
/** Sets the blur radius for the shadow. Radius units are specified via setBlurRadiusUnit().
* @param blurRadius blur radius
* @see blurRadius()
* @see setBlurRadiusUnit()
*/
void setBlurRadius( double blurRadius );
/** Returns the units used for the shadow's blur radius.
* @see setBlurRadiusUnit()
* @see blurRadius()
*/
QgsUnitTypes::RenderUnit blurRadiusUnit() const;
/** Sets the units used for the shadow's blur radius.
* @param units shadow blur radius units
* @see blurRadiusUnit()
* @see setBlurRadius()
*/
void setBlurRadiusUnit( QgsUnitTypes::RenderUnit units );
/** Returns the map unit scale object for the shadow blur radius. This is only used if the
* blurRadiusUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setBlurRadiusMapUnitScale()
* @see blurRadiusUnit()
*/
QgsMapUnitScale blurRadiusMapUnitScale() const;
/** Sets the map unit scale object for the shadow blur radius. This is only used if the
* blurRadiusUnit() is set to QgsUnitTypes::RenderMapUnit.
* @param scale scale for shadow blur radius
* @see blurRadiusMapUnitScale()
* @see setBlurRadiusUnit()
*/
void setBlurRadiusMapUnitScale( const QgsMapUnitScale& scale );
/** Returns whether only the alpha channel for the shadow will be blurred.
* @see setBlurAlphaOnly()
*/
bool blurAlphaOnly() const;
/** Sets whether only the alpha channel for the shadow should be blurred.
* @param alphaOnly set to true to blur only the alpha channel. If false, all channels (including
* red, green and blue channel) will be blurred.
* @see blurAlphaOnly()
*/
void setBlurAlphaOnly( bool alphaOnly );
/** Returns the shadow's opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally
* opaque).
* @see setOpacity()
*/
double opacity() const;
/** Sets the shadow's opacity.
* @param opacity opacity as a double value between 0 (fully transparent) and 1 (totally
* opaque)
* @see opacity()
*/
void setOpacity( double opacity );
/** Returns the scaling used for the drop shadow (in percentage of original size).
* @see setScale()
*/
int scale() const;
/** Sets the scaling used for the drop shadow (in percentage of original size).
* @param scale scale percent for drop shadow
* @see scale()
*/
void setScale( int scale );
/** Returns the color of the drop shadow.
* @see setColor()
*/
QColor color() const;
/** Sets the color for the drop shadow.
* @param color shadow color
* @see color()
*/
void setColor( const QColor& color );
/** Returns the blending mode used for drawing the drop shadow.
* @see setBlendMode()
*/
QPainter::CompositionMode blendMode() const;
/** Sets the blending mode used for drawing the drop shadow.
* @param mode blending mode
* @see blendMode()
*/
void setBlendMode( QPainter::CompositionMode mode );
/** Reads settings from a layer's custom properties.
* @param layer source vector layer
* @see writeToLayer()
*/
void readFromLayer( QgsVectorLayer* layer );
/** Writes settings to a layer's custom properties.
* @param layer target vector layer
* @see readFromLayer()
*/
void writeToLayer( QgsVectorLayer* layer ) const;
/** Read settings from a DOM element.
* @see writeXml()
*/
void readXml( const QDomElement& elem );
/** Write settings into a DOM element.
* @see readXml()
*/
QDomElement writeXml( QDomDocument& doc ) const;
};
/** \class QgsTextFormat
* \ingroup core
* Container for all settings relating to text rendering.
* \note QgsTextFormat objects are implicitly shared.
* \note added in QGIS 3.0
*/
class QgsTextFormat
{
%TypeHeaderCode
#include <qgstextrenderer.h>
%End
public:
QgsTextFormat();
QgsTextFormat( const QgsTextFormat& other );
~QgsTextFormat();
/** Returns a reference to the text buffer settings.
* @see setBuffer()
*/
QgsTextBufferSettings& buffer();
/** Sets the text's buffer settings.
* @param bufferSettings buffer settings
* @see buffer()
*/
void setBuffer( const QgsTextBufferSettings& bufferSettings );
/** Returns a reference to the text background settings.
* @see setBackground()
*/
QgsTextBackgroundSettings& background();
/** Sets the text's background settings.
* @param backgroundSettings background settings
* @see background()
*/
void setBackground( const QgsTextBackgroundSettings& backgroundSettings );
/** Returns a reference to the text drop shadow settings.
* @see setShadow()
*/
QgsTextShadowSettings& shadow();
/** Sets the text's drop shadow settings.
* @param shadowSettings shadow settings
* @see shadow()
*/
void setShadow( const QgsTextShadowSettings& shadowSettings );
/** Returns the font used for rendering text. Note that the size of the font
* is not used, and size() should be called instead to determine the size
* of rendered text.
* @see setFont()
* @see namedStyle()
*/
QFont font() const;
/** Sets the font used for rendering text. Note that the size of the font
* is not used, and setSize() should be called instead to explicitly set the size
* of rendered text.
* @param font desired font
* @see font()
* @see setNamedStyle()
*/
void setFont( const QFont& font );
/** Returns the named style for the font used for rendering text (eg "bold").
* @see setNamedStyle()
* @see font()
*/
QString namedStyle() const;
/** Sets the named style for the font used for rendering text.
* @param style named style, eg "bold"
* @see namedStyle()
* @see setFont()
*/
void setNamedStyle( const QString& style );
/** Returns the size for rendered text. Units are retrieved using sizeUnit().
* @see setSize()
* @see sizeUnit()
*/
double size() const;
/** Sets the size for rendered text.
* @param size size of rendered text. Units are set using setSizeUnit()
* @see size()
* @see setSizeUnit()
*/
void setSize( double size );
/** Returns the units for the size of rendered text.
* @see size()
* @see setSizeUnit()
* @see sizeMapUnitScale()
*/
QgsUnitTypes::RenderUnit sizeUnit() const;
/** Sets the units for the size of rendered text.
* @param unit size units
* @see setSize()
* @see sizeUnit()
* @see setSizeMapUnitScale()
*/
void setSizeUnit( QgsUnitTypes::RenderUnit unit );
/** Returns the map unit scale object for the size. This is only used if the
* sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see setSizeMapUnitScale()
* @see sizeUnit()
*/
QgsMapUnitScale sizeMapUnitScale() const;
/** Sets the map unit scale object for the size. This is only used if the
* sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
* @see sizeMapUnitScale()
* @see setSizeUnit()
*/
void setSizeMapUnitScale( const QgsMapUnitScale& scale );
/** Returns the color that text will be rendered in.
* @see setColor()
*/
QColor color() const;
/** Sets the color that text will be rendered in.
* @param color text color
* @see color()
*/
void setColor( const QColor& color );
/** Returns the text's opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally
* opaque).
* @see setOpacity()
*/
double opacity() const;
/** Sets the text's opacity.
* @param opacity opacity as a double value between 0 (fully transparent) and 1 (totally
* opaque)
* @see opacity()
*/
void setOpacity( double opacity );
/** Returns the blending mode used for drawing the text.
* @see setBlendMode()
*/
QPainter::CompositionMode blendMode() const;
/** Sets the blending mode used for drawing the text.
* @param mode blending mode
* @see blendMode()
*/
void setBlendMode( QPainter::CompositionMode mode );
/** Returns the line height for text. This is a number between
* 0.0 and 10.0 representing the leading between lines as a
* multiplier of line height.
* @see setLineHeight()
*/
double lineHeight() const;
/** Sets the line height for text.
* @param height a number between
* 0.0 and 10.0 representing the leading between lines as a
* multiplier of line height.
* @see lineHeight()
*/
void setLineHeight( double height );
/** Reads settings from a layer's custom properties.
* @param layer source vector layer
* @see writeToLayer()
*/
void readFromLayer( QgsVectorLayer* layer );
/** Writes settings to a layer's custom properties.
* @param layer target vector layer
* @see readFromLayer()
*/
void writeToLayer( QgsVectorLayer* layer ) const;
/** Read settings from a DOM element.
* @see writeXml()
*/
void readXml( const QDomElement& elem );
/** Write settings into a DOM element.
* @see readXml()
*/
QDomElement writeXml( QDomDocument& doc ) const;
};

View File

@ -209,6 +209,7 @@ SET(QGIS_CORE_SRCS
qgsstringstatisticalsummary.cpp
qgsstringutils.cpp
qgstextlabelfeature.cpp
qgstextrenderer.cpp
qgstolerance.cpp
qgstracer.cpp
qgstransaction.cpp
@ -705,6 +706,8 @@ SET(QGIS_CORE_HDRS
qgsstringutils.h
qgstestutils.h
qgstextlabelfeature.h
qgstextrenderer.h
qgstextrenderer_p.h
qgstolerance.h
qgstracer.h

1544
src/core/qgstextrenderer.cpp Normal file

File diff suppressed because it is too large Load Diff

1068
src/core/qgstextrenderer.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,276 @@
/***************************************************************************
qgstextrenderer.h
-----------------
begin : September 2015
copyright : (C) 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 QGSTEXTRENDERER_PRIVATE_H
#define QGSTEXTRENDERER_PRIVATE_H
#include "qgstextrenderer.h"
#include "qgsmapunitscale.h"
#include "qgsunittypes.h"
#include "qgsapplication.h"
#include <QSharedData>
#include <QPainter>
/// @cond
//
// W A R N I N G
// -------------
//
// This file is not part of the QGIS API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
class CORE_EXPORT QgsTextBufferSettingsPrivate : public QSharedData
{
public:
QgsTextBufferSettingsPrivate()
: enabled( false )
, size( 1 )
, sizeUnit( QgsUnitTypes::RenderMillimeters )
, color( Qt::white )
, fillBufferInterior( false )
, opacity( 1.0 )
, joinStyle( Qt::RoundJoin )
, blendMode( QPainter::CompositionMode_SourceOver )
{
}
QgsTextBufferSettingsPrivate( const QgsTextBufferSettingsPrivate& other )
: QSharedData( other )
, enabled( other.enabled )
, size( other.size )
, sizeUnit( other.sizeUnit )
, sizeMapUnitScale( other.sizeMapUnitScale )
, color( other.color )
, fillBufferInterior( other.fillBufferInterior )
, opacity( other.opacity )
, joinStyle( other.joinStyle )
, blendMode( other.blendMode )
{
}
~QgsTextBufferSettingsPrivate() {}
bool enabled;
double size;
QgsUnitTypes::RenderUnit sizeUnit;
QgsMapUnitScale sizeMapUnitScale;
QColor color;
bool fillBufferInterior;
double opacity;
Qt::PenJoinStyle joinStyle;
QPainter::CompositionMode blendMode;
};
class CORE_EXPORT QgsTextBackgroundSettingsPrivate : public QSharedData
{
public:
QgsTextBackgroundSettingsPrivate()
: enabled( false )
, type( QgsTextBackgroundSettings::ShapeRectangle )
, sizeType( QgsTextBackgroundSettings::SizeBuffer )
, size( QSizeF( 0.0, 0.0 ) )
, sizeUnits( QgsUnitTypes::RenderMillimeters )
, rotationType( QgsTextBackgroundSettings::RotationSync )
, rotation( 0.0 )
, offset( QPointF( 0.0, 0.0 ) )
, offsetUnits( QgsUnitTypes::RenderMillimeters )
, radii( QSizeF( 0.0, 0.0 ) )
, radiiUnits( QgsUnitTypes::RenderMillimeters )
, opacity( 1.0 )
, blendMode( QPainter::CompositionMode_SourceOver )
, fillColor( Qt::white )
, borderColor( Qt::darkGray )
, borderWidth( 0.0 )
, borderWidthUnits( QgsUnitTypes::RenderMillimeters )
, joinStyle( Qt::BevelJoin )
{
}
QgsTextBackgroundSettingsPrivate( const QgsTextBackgroundSettingsPrivate& other )
: QSharedData( other )
, enabled( other.enabled )
, type( other.type )
, svgFile( other.svgFile )
, sizeType( other.sizeType )
, size( other.size )
, sizeUnits( other.sizeUnits )
, sizeMapUnitScale( other.sizeMapUnitScale )
, rotationType( other.rotationType )
, rotation( other.rotation )
, offset( other.offset )
, offsetUnits( other.offsetUnits )
, offsetMapUnitScale( other.offsetMapUnitScale )
, radii( other.radii )
, radiiUnits( other.radiiUnits )
, radiiMapUnitScale( other.radiiMapUnitScale )
, opacity( other.opacity )
, blendMode( other.blendMode )
, fillColor( other.fillColor )
, borderColor( other.borderColor )
, borderWidth( other.borderWidth )
, borderWidthUnits( other.borderWidthUnits )
, borderWidthMapUnitScale( other.borderWidthMapUnitScale )
, joinStyle( other.joinStyle )
{
}
~QgsTextBackgroundSettingsPrivate() {}
bool enabled;
QgsTextBackgroundSettings::ShapeType type;
QString svgFile;
QgsTextBackgroundSettings::SizeType sizeType;
QSizeF size;
QgsUnitTypes::RenderUnit sizeUnits;
QgsMapUnitScale sizeMapUnitScale;
QgsTextBackgroundSettings::RotationType rotationType;
double rotation;
QPointF offset;
QgsUnitTypes::RenderUnit offsetUnits;
QgsMapUnitScale offsetMapUnitScale;
QSizeF radii;
QgsUnitTypes::RenderUnit radiiUnits;
QgsMapUnitScale radiiMapUnitScale;
double opacity;
QPainter::CompositionMode blendMode;
QColor fillColor;
QColor borderColor;
double borderWidth;
QgsUnitTypes::RenderUnit borderWidthUnits;
QgsMapUnitScale borderWidthMapUnitScale;
Qt::PenJoinStyle joinStyle;
};
class CORE_EXPORT QgsTextShadowSettingsPrivate : public QSharedData
{
public:
QgsTextShadowSettingsPrivate()
: enabled( false )
, shadowUnder( QgsTextShadowSettings::ShadowLowest )
, offsetAngle( 135 )
, offsetDist( 1.0 )
, offsetUnits( QgsUnitTypes::RenderMillimeters )
, offsetGlobal( true )
, radius( 1.5 )
, radiusUnits( QgsUnitTypes::RenderMillimeters )
, radiusAlphaOnly( false )
, opacity( 0.30 )
, scale( 100 )
, color( Qt::black )
, blendMode( QPainter::CompositionMode_Multiply )
{
}
QgsTextShadowSettingsPrivate( const QgsTextShadowSettingsPrivate& other )
: QSharedData( other )
, enabled( other.enabled )
, shadowUnder( other.shadowUnder )
, offsetAngle( other.offsetAngle )
, offsetDist( other.offsetDist )
, offsetUnits( other.offsetUnits )
, offsetMapUnitScale( other.offsetMapUnitScale )
, offsetGlobal( other.offsetGlobal )
, radius( other.radius )
, radiusUnits( other.radiusUnits )
, radiusMapUnitScale( other.radiusMapUnitScale )
, radiusAlphaOnly( other.radiusAlphaOnly )
, opacity( other.opacity )
, scale( other.scale )
, color( other.color )
, blendMode( other.blendMode )
{
}
~QgsTextShadowSettingsPrivate() {}
bool enabled;
QgsTextShadowSettings::ShadowPlacement shadowUnder;
int offsetAngle;
double offsetDist;
QgsUnitTypes::RenderUnit offsetUnits;
QgsMapUnitScale offsetMapUnitScale;
bool offsetGlobal;
double radius;
QgsUnitTypes::RenderUnit radiusUnits;
QgsMapUnitScale radiusMapUnitScale;
bool radiusAlphaOnly;
double opacity;
int scale;
QColor color;
QPainter::CompositionMode blendMode;
};
class CORE_EXPORT QgsTextSettingsPrivate : public QSharedData
{
public:
QgsTextSettingsPrivate()
: textFont( QApplication::font() )
, fontSizeUnits( QgsUnitTypes::RenderPoints )
, fontSize( 10 )
, textColor( Qt::black )
, opacity( 1.0 )
, blendMode( QPainter::CompositionMode_Multiply )
, multilineHeight( 1.0 )
{
}
QgsTextSettingsPrivate( const QgsTextSettingsPrivate& other )
: QSharedData( other )
, textFont( other.textFont )
, textNamedStyle( other.textNamedStyle )
, fontSizeUnits( other.fontSizeUnits )
, fontSizeMapUnitScale( other.fontSizeMapUnitScale )
, fontSize( other.fontSize )
, textColor( other.textColor )
, opacity( other.opacity )
, blendMode( other.blendMode )
, multilineHeight( other.multilineHeight )
{
}
~QgsTextSettingsPrivate() {}
QFont textFont;
QString textNamedStyle;
QgsUnitTypes::RenderUnit fontSizeUnits;
QgsMapUnitScale fontSizeMapUnitScale;
double fontSize; //may differ from size in textFont due to units (eg size in map units)
QColor textColor;
double opacity;
QPainter::CompositionMode blendMode;
double multilineHeight; //0.0 to 10.0, leading between lines as multiplyer of line height
};
/// @endcond
#endif // QGSTEXTRENDERER_PRIVATE_H

View File

@ -87,6 +87,7 @@ ADD_PYTHON_TEST(PyQgsSingleSymbolRenderer test_qgssinglesymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsShapefileProvider test_provider_shapefile.py)
ADD_PYTHON_TEST(PyQgsTabfileProvider test_provider_tabfile.py)
ADD_PYTHON_TEST(PyQgsTabWidget test_qgstabwidget.py)
ADD_PYTHON_TEST(PyQgsTextRenderer test_qgstextrenderer.py)
ADD_PYTHON_TEST(PyQgsOGRProvider test_provider_ogr.py)
ADD_PYTHON_TEST(PyQgsSearchWidgetToolButton test_qgssearchwidgettoolbutton.py)
ADD_PYTHON_TEST(PyQgsSearchWidgetWrapper test_qgssearchwidgetwrapper.py)

View File

@ -0,0 +1,348 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsTextRenderer.
.. 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__ = 'Nyall Dawson'
__date__ = '2016-09'
__copyright__ = 'Copyright 2016, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis # NOQA
from qgis.core import (QgsTextBufferSettings,
QgsTextBackgroundSettings,
QgsTextShadowSettings,
QgsTextFormat,
QgsUnitTypes,
QgsMapUnitScale,
QgsVectorLayer)
from qgis.PyQt.QtGui import (QColor, QPainter)
from qgis.PyQt.QtCore import (Qt, QSizeF, QPointF)
from qgis.PyQt.QtXml import (QDomDocument, QDomElement)
from qgis.testing import unittest, start_app
from utilities import getTestFont
start_app()
def createEmptyLayer():
layer = QgsVectorLayer("Point", "addfeat", "memory")
assert layer.isValid()
return layer
class PyQgsTextRenderer(unittest.TestCase):
def createBufferSettings(self):
s = QgsTextBufferSettings()
s.setEnabled(True)
s.setSize(5)
s.setSizeUnit(QgsUnitTypes.RenderPoints)
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
s.setColor(QColor(255, 0, 0))
s.setFillBufferInterior(True)
s.setOpacity(0.5)
s.setJoinStyle(Qt.RoundJoin)
s.setBlendMode(QPainter.CompositionMode_DestinationAtop)
return s
def checkBufferSettings(self, s):
""" test QgsTextBufferSettings """
self.assertTrue(s.enabled())
self.assertEqual(s.size(), 5)
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPoints)
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
self.assertEqual(s.color(), QColor(255, 0, 0))
self.assertTrue(s.fillBufferInterior())
self.assertEqual(s.opacity(), 0.5)
self.assertEqual(s.joinStyle(), Qt.RoundJoin)
self.assertEqual(s.blendMode(), QPainter.CompositionMode_DestinationAtop)
def testBufferGettersSetters(self):
s = self.createBufferSettings()
self.checkBufferSettings(s)
# some other checks
s.setEnabled(False)
self.assertFalse(s.enabled())
s.setEnabled(True)
self.assertTrue(s.enabled())
s.setFillBufferInterior(False)
self.assertFalse(s.fillBufferInterior())
s.setFillBufferInterior(True)
self.assertTrue(s.fillBufferInterior())
def testBufferReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBufferSettings()
s.writeToLayer(layer)
t = QgsTextBufferSettings()
t.readFromLayer(layer)
self.checkBufferSettings(t)
def testBufferReadWriteXml(self):
"""test saving and restoring state of a buffer to xml"""
doc = QDomDocument("testdoc")
s = self.createBufferSettings()
elem = s.writeXml(doc)
parent = doc.createElement("settings")
parent.appendChild(elem)
t = QgsTextBufferSettings()
t.readXml(parent)
self.checkBufferSettings(t)
def testBufferCopy(self):
s = self.createBufferSettings()
s2 = s
self.checkBufferSettings(s2)
s3 = QgsTextBufferSettings(s)
self.checkBufferSettings(s3)
def createBackgroundSettings(self):
s = QgsTextBackgroundSettings()
s.setEnabled(True)
s.setType(QgsTextBackgroundSettings.ShapeEllipse)
s.setSvgFile('svg.svg')
s.setSizeType(QgsTextBackgroundSettings.SizePercent)
s.setSize(QSizeF(1, 2))
s.setSizeUnit(QgsUnitTypes.RenderPoints)
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
s.setRotationType(QgsTextBackgroundSettings.RotationFixed)
s.setRotation(45)
s.setOffset(QPointF(3, 4))
s.setOffsetUnit(QgsUnitTypes.RenderMapUnits)
s.setOffsetMapUnitScale(QgsMapUnitScale(5, 6))
s.setRadii(QSizeF(11, 12))
s.setRadiiUnit(QgsUnitTypes.RenderPercentage)
s.setRadiiMapUnitScale(QgsMapUnitScale(15, 16))
s.setFillColor(QColor(255, 0, 0))
s.setBorderColor(QColor(0, 255, 0))
s.setOpacity(0.5)
s.setJoinStyle(Qt.RoundJoin)
s.setBlendMode(QPainter.CompositionMode_DestinationAtop)
s.setBorderWidth(7)
s.setBorderWidthUnit(QgsUnitTypes.RenderPoints)
s.setBorderWidthMapUnitScale(QgsMapUnitScale(QgsMapUnitScale(25, 26)))
return s
def checkBackgroundSettings(self, s):
""" test QgsTextBackgroundSettings """
self.assertTrue(s.enabled())
self.assertEqual(s.type(), QgsTextBackgroundSettings.ShapeEllipse)
self.assertEqual(s.svgFile(), 'svg.svg')
self.assertEqual(s.sizeType(), QgsTextBackgroundSettings.SizePercent)
self.assertEqual(s.size(), QSizeF(1, 2))
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPoints)
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
self.assertEqual(s.rotationType(), QgsTextBackgroundSettings.RotationFixed)
self.assertEqual(s.rotation(), 45)
self.assertEqual(s.offset(), QPointF(3, 4))
self.assertEqual(s.offsetUnit(), QgsUnitTypes.RenderMapUnits)
self.assertEqual(s.offsetMapUnitScale(), QgsMapUnitScale(5, 6))
self.assertEqual(s.radii(), QSizeF(11, 12))
self.assertEqual(s.radiiUnit(), QgsUnitTypes.RenderPercentage)
self.assertEqual(s.radiiMapUnitScale(), QgsMapUnitScale(15, 16))
self.assertEqual(s.fillColor(), QColor(255, 0, 0))
self.assertEqual(s.borderColor(), QColor(0, 255, 0))
self.assertEqual(s.opacity(), 0.5)
self.assertEqual(s.joinStyle(), Qt.RoundJoin)
self.assertEqual(s.blendMode(), QPainter.CompositionMode_DestinationAtop)
self.assertEqual(s.borderWidth(), 7)
self.assertEqual(s.borderWidthUnit(), QgsUnitTypes.RenderPoints)
self.assertEqual(s.borderWidthMapUnitScale(), QgsMapUnitScale(25, 26))
def testBackgroundGettersSetters(self):
s = self.createBackgroundSettings()
self.checkBackgroundSettings(s)
# some other checks
s.setEnabled(False)
self.assertFalse(s.enabled())
s.setEnabled(True)
self.assertTrue(s.enabled())
def testBackgroundCopy(self):
s = self.createBackgroundSettings()
s2 = s
self.checkBackgroundSettings(s2)
s3 = QgsTextBackgroundSettings(s)
self.checkBackgroundSettings(s3)
def testBackgroundReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBackgroundSettings()
s.writeToLayer(layer)
t = QgsTextBackgroundSettings()
t.readFromLayer(layer)
self.checkBackgroundSettings(t)
def testBackgroundReadWriteXml(self):
"""test saving and restoring state of a background to xml"""
doc = QDomDocument("testdoc")
s = self.createBackgroundSettings()
elem = s.writeXml(doc)
parent = doc.createElement("settings")
parent.appendChild(elem)
t = QgsTextBackgroundSettings()
t.readXml(parent)
self.checkBackgroundSettings(t)
def createShadowSettings(self):
s = QgsTextShadowSettings()
s.setEnabled(True)
s.setShadowPlacement(QgsTextShadowSettings.ShadowBuffer)
s.setOffsetAngle(45)
s.setOffsetDistance(75)
s.setOffsetUnit(QgsUnitTypes.RenderMapUnits)
s.setOffsetMapUnitScale(QgsMapUnitScale(5, 6))
s.setOffsetGlobal(True)
s.setBlurRadius(11)
s.setBlurRadiusUnit(QgsUnitTypes.RenderPercentage)
s.setBlurRadiusMapUnitScale(QgsMapUnitScale(15, 16))
s.setBlurAlphaOnly(True)
s.setColor(QColor(255, 0, 0))
s.setOpacity(0.5)
s.setScale(123)
s.setBlendMode(QPainter.CompositionMode_DestinationAtop)
return s
def checkShadowSettings(self, s):
""" test QgsTextShadowSettings """
self.assertTrue(s.enabled())
self.assertEqual(s.shadowPlacement(), QgsTextShadowSettings.ShadowBuffer)
self.assertEqual(s.offsetAngle(), 45)
self.assertEqual(s.offsetDistance(), 75)
self.assertEqual(s.offsetUnit(), QgsUnitTypes.RenderMapUnits)
self.assertEqual(s.offsetMapUnitScale(), QgsMapUnitScale(5, 6))
self.assertTrue(s.offsetGlobal())
self.assertEqual(s.blurRadius(), 11)
self.assertEqual(s.blurRadiusUnit(), QgsUnitTypes.RenderPercentage)
self.assertEqual(s.blurRadiusMapUnitScale(), QgsMapUnitScale(15, 16))
self.assertTrue(s.blurAlphaOnly())
self.assertEqual(s.color(), QColor(255, 0, 0))
self.assertEqual(s.opacity(), 0.5)
self.assertEqual(s.scale(), 123)
self.assertEqual(s.blendMode(), QPainter.CompositionMode_DestinationAtop)
def testShadowGettersSetters(self):
s = self.createShadowSettings()
self.checkShadowSettings(s)
# some other checks
s.setEnabled(False)
self.assertFalse(s.enabled())
s.setEnabled(True)
self.assertTrue(s.enabled())
s.setOffsetGlobal(False)
self.assertFalse(s.offsetGlobal())
s.setOffsetGlobal(True)
self.assertTrue(s.offsetGlobal())
s.setBlurAlphaOnly(False)
self.assertFalse(s.blurAlphaOnly())
s.setBlurAlphaOnly(True)
self.assertTrue(s.blurAlphaOnly())
def testShadowCopy(self):
s = self.createShadowSettings()
s2 = s
self.checkShadowSettings(s2)
s3 = QgsTextShadowSettings(s)
self.checkShadowSettings(s3)
def testShadowReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createShadowSettings()
s.writeToLayer(layer)
t = QgsTextShadowSettings()
t.readFromLayer(layer)
self.checkShadowSettings(t)
def testShadowReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")
s = self.createShadowSettings()
elem = s.writeXml(doc)
parent = doc.createElement("settings")
parent.appendChild(elem)
t = QgsTextShadowSettings()
t.readXml(parent)
self.checkShadowSettings(t)
def createFormatSettings(self):
s = QgsTextFormat()
s.buffer().setEnabled(True)
s.buffer().setSize(25)
s.background().setEnabled(True)
s.background().setSvgFile('test.svg')
s.shadow().setEnabled(True)
s.shadow().setOffsetAngle(223)
s.setFont(getTestFont())
s.setNamedStyle('Italic')
s.setSize(5)
s.setSizeUnit(QgsUnitTypes.RenderPoints)
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
s.setColor(QColor(255, 0, 0))
s.setOpacity(0.5)
s.setBlendMode(QPainter.CompositionMode_DestinationAtop)
s.setLineHeight(5)
return s
def checkTextFormat(self, s):
""" test QgsTextFormat """
self.assertTrue(s.buffer().enabled())
self.assertEqual(s.buffer().size(), 25)
self.assertTrue(s.background().enabled())
self.assertEqual(s.background().svgFile(), 'test.svg')
self.assertTrue(s.shadow().enabled())
self.assertEqual(s.shadow().offsetAngle(), 223)
self.assertEqual(s.font().family(), 'QGIS Vera Sans')
self.assertEqual(s.namedStyle(), 'Italic')
self.assertEqual(s.size(), 5)
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPoints)
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
self.assertEqual(s.color(), QColor(255, 0, 0))
self.assertEqual(s.opacity(), 0.5)
self.assertEqual(s.blendMode(), QPainter.CompositionMode_DestinationAtop)
self.assertEqual(s.lineHeight(), 5)
def testFormatGettersSetters(self):
s = self.createFormatSettings()
self.checkTextFormat(s)
def testFormatCopy(self):
s = self.createFormatSettings()
s2 = s
self.checkTextFormat(s2)
s3 = QgsTextFormat(s)
self.checkTextFormat(s3)
def testFormatReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createFormatSettings()
s.writeToLayer(layer)
t = QgsTextFormat()
t.readFromLayer(layer)
self.checkTextFormat(t)
def testFormatReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")
s = self.createFormatSettings()
elem = s.writeXml(doc)
parent = doc.createElement("settings")
parent.appendChild(elem)
t = QgsTextFormat()
t.readXml(parent)
self.checkTextFormat(t)
if __name__ == '__main__':
unittest.main()