Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flip QgsPalLayerSettings to use QgsTextRenderer classes
  • Loading branch information
nyalldawson committed Oct 24, 2016
1 parent 5f241d6 commit 4d5e753
Show file tree
Hide file tree
Showing 27 changed files with 1,243 additions and 1,462 deletions.
132 changes: 13 additions & 119 deletions python/core/qgspallabeling.sip
Expand Up @@ -267,29 +267,6 @@ class QgsPalLayerSettings
placing labels over any part of the polygon is avoided.*/
};

enum ShapeType
{
ShapeRectangle,
ShapeSquare,
ShapeEllipse,
ShapeCircle,
ShapeSVG
};

enum SizeType
{
SizeBuffer,
SizeFixed,
SizePercent
};

enum RotationType
{
RotationSync,
RotationOffset,
RotationFixed
};

/** Units used for option sizes, before being converted to rendered sizes */
enum SizeUnit
{
Expand All @@ -299,14 +276,6 @@ class QgsPalLayerSettings
Percent
};

enum ShadowType
{
ShadowLowest,
ShadowText,
ShadowBuffer,
ShadowShape
};

// update mDataDefinedNames QMap in constructor when adding/deleting enum value
enum DataDefinedProperties
{
Expand Down Expand Up @@ -443,13 +412,6 @@ class QgsPalLayerSettings
*/
QgsExpression* getLabelExpression();

QFont textFont;
QString textNamedStyle;
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
QgsMapUnitScale fontSizeMapUnitScale; // scale range for map units for font size
QColor textColor;
int textTransp;
QPainter::CompositionMode blendMode;
QColor previewBkgrdColor;

//! Substitution collection for automatic text substitution with labels
Expand All @@ -460,7 +422,6 @@ class QgsPalLayerSettings
//-- text formatting

QString wrapChar;
double multilineHeight; //0.0 to 10.0, leading between lines as multiplyer of line height
MultiLineAlign multilineAlign; // horizontal alignment of multi-line labels

// Adds '<' or '>', or user-defined symbol to the label string pointing to the
Expand All @@ -476,62 +437,6 @@ class QgsPalLayerSettings
int decimals;
bool plusSign;

//-- text buffer

bool bufferDraw;
double bufferSize; // buffer size
bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm)
QgsMapUnitScale bufferSizeMapUnitScale; // scale range for map units for buffer size
QColor bufferColor;
bool bufferNoFill; //set interior of buffer to 100% transparent
int bufferTransp;
Qt::PenJoinStyle bufferJoinStyle;
QPainter::CompositionMode bufferBlendMode;

//-- shape background

bool shapeDraw;
ShapeType shapeType;
QString shapeSVGFile;
SizeType shapeSizeType;
QPointF shapeSize;
SizeUnit shapeSizeUnits;
QgsMapUnitScale shapeSizeMapUnitScale;
RotationType shapeRotationType;
double shapeRotation;
QPointF shapeOffset;
SizeUnit shapeOffsetUnits;
QgsMapUnitScale shapeOffsetMapUnitScale;
QPointF shapeRadii;
SizeUnit shapeRadiiUnits;
QgsMapUnitScale shapeRadiiMapUnitScale;
int shapeTransparency;
QPainter::CompositionMode shapeBlendMode;
QColor shapeFillColor;
QColor shapeBorderColor;
double shapeBorderWidth;
SizeUnit shapeBorderWidthUnits;
QgsMapUnitScale shapeBorderWidthMapUnitScale;
Qt::PenJoinStyle shapeJoinStyle;

//-- drop shadow

bool shadowDraw;
ShadowType shadowUnder;
int shadowOffsetAngle;
double shadowOffsetDist;
SizeUnit shadowOffsetUnits;
QgsMapUnitScale shadowOffsetMapUnitScale;
bool shadowOffsetGlobal;
double shadowRadius;
SizeUnit shadowRadiusUnits;
QgsMapUnitScale shadowRadiusMapUnitScale;
bool shadowRadiusAlphaOnly;
int shadowTransparency;
int shadowScale;
QColor shadowColor;
QPainter::CompositionMode shadowBlendMode;

//-- placement

Placement placement;
Expand Down Expand Up @@ -700,33 +605,25 @@ class QgsPalLayerSettings
*/
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;


/** Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
* @param size size to convert
* @param c rendercontext
* @param unit SizeUnit enum value of size
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return font pixel size
*/
int sizeToPixel( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;

/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
* @param size size to convert
* @param c rendercontext
* @param unit SizeUnit enum value of size
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return size that will render, as double
*/
double scaleToPixelContext( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;

/** Map of data defined enum to names and old-style indecies
* The QPair contains a new string for layer property key, and a reference to old-style numeric key (< QGIS 2.0)
* @note not available in python bindings;
*/
// QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > dataDefinedNames() const;

/** Returns the label text formatting settings, eg font settings, buffer settings, etc.
* @see setFormat()
* @note added in QGIS 3.0
*/
const QgsTextFormat& format() const;

/** Sets the label text formatting settings, eg font settings, buffer settings, etc.
* @param format label text format
* @see format()
* @note added in QGIS 3.0
*/
void setFormat( const QgsTextFormat& format );

// temporary stuff: set when layer gets prepared or labeled
QgsFeature* mCurFeat;
QgsFields mCurFields;
Expand All @@ -741,9 +638,6 @@ class QgsPalLayerSettings
int mFeatsSendingToPal; // total features tested for sending into PAL (relative to maxNumLabels)
int mFeatsRegPal; // number of features registered in PAL, when using limitNumLabels

QString mTextFontFamily;
bool mTextFontFound;

bool showingShadowRects; // whether to show debug rectangles for drop shadows
};

Expand Down
49 changes: 49 additions & 0 deletions python/core/qgstextrenderer.sip
Expand Up @@ -992,4 +992,53 @@ class QgsTextFormat
*/
QDomElement writeXml( QDomDocument& doc ) const;

/** Returns true if any component of the font format requires advanced effects
* such as blend modes, which require output in raster formats to be fully respected.
*/
bool containsAdvancedEffects() const;

/** Returns true if the specified font was found on the system, or false
* if the font was not found and a replacement was used instead.
* @see resolvedFontFamily()
*/
bool fontFound() const;

/** Returns the family for the resolved font, ie if the specified font
* was not found on the system this will return the name of the replacement
* font.
* @see fontFound()
*/
QString resolvedFontFamily() const;

};


class QgsTextRenderer
{
%TypeHeaderCode
#include <qgstextrenderer.h>
%End

public:

/** Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
* @param size size to convert
* @param c rendercontext
* @param unit size units
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return font pixel size
*/
static int sizeToPixel( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );

/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
* @param size size to convert
* @param c rendercontext
* @param unit size units
* @param rasterfactor whether to consider oversampling
* @param mapUnitScale a mapUnitScale clamper
* @return size that will render, as double
*/
static double scaleToPixelContext( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );

};
36 changes: 35 additions & 1 deletion python/core/symbology-ng/qgssymbollayerutils.sip
Expand Up @@ -39,8 +39,31 @@ class QgsSymbolLayerUtils
static QString encodeSldBrushStyle( Qt::BrushStyle style );
static Qt::BrushStyle decodeSldBrushStyle( const QString& str );

/** Encodes a QPointF to a string.
* @see decodePoint()
* @see encodeSize()
*/
static QString encodePoint( QPointF point );
static QPointF decodePoint( const QString& str );

/** Decodes a QSizeF from a string.
* @see encodePoint()
* @see decodeSize()
*/
static QPointF decodePoint( const QString& string );

/** Encodes a QSizeF to a string.
* @see decodeSize()
* @see encodePoint()
* @note added in QGIS 3.0
*/
static QString encodeSize( QSizeF size );

/** Decodes a QSizeF from a string.
* @see encodeSize()
* @see decodePoint()
* @note added in QGIS 3.0
*/
static QSizeF decodeSize( const QString& string );

static QString encodeMapUnitScale( const QgsMapUnitScale& mapUnitScale );
static QgsMapUnitScale decodeMapUnitScale( const QString& str );
Expand Down Expand Up @@ -361,10 +384,21 @@ class QgsSymbolLayerUtils
* @param unit units for specified size
* @param scale map unit scale
* @note added in QGIS 2.16
* @see convertFromMapUnits()
* @see convertToPainterUnits()
*/
static double convertToMapUnits( const QgsRenderContext&c, double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() );

/** Converts a size from map units to the specied units.
* @param context render context
* @param sizeInMapUnits size (in map units) to convert
* @param outputUnit output units
* @note added in QGIS 3.0
* @see convertToMapUnits()
*/
static double convertFromMapUnits( const QgsRenderContext& context, double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit );


/** Returns scale factor painter units -> pixel dimensions*/
static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsUnitTypes::RenderUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );

Expand Down

0 comments on commit 4d5e753

Please sign in to comment.