Skip to content

Commit 4d5e753

Browse files
committed
Flip QgsPalLayerSettings to use QgsTextRenderer classes
1 parent 5f241d6 commit 4d5e753

27 files changed

+1243
-1462
lines changed

python/core/qgspallabeling.sip

+13-119
Original file line numberDiff line numberDiff line change
@@ -267,29 +267,6 @@ class QgsPalLayerSettings
267267
placing labels over any part of the polygon is avoided.*/
268268
};
269269

270-
enum ShapeType
271-
{
272-
ShapeRectangle,
273-
ShapeSquare,
274-
ShapeEllipse,
275-
ShapeCircle,
276-
ShapeSVG
277-
};
278-
279-
enum SizeType
280-
{
281-
SizeBuffer,
282-
SizeFixed,
283-
SizePercent
284-
};
285-
286-
enum RotationType
287-
{
288-
RotationSync,
289-
RotationOffset,
290-
RotationFixed
291-
};
292-
293270
/** Units used for option sizes, before being converted to rendered sizes */
294271
enum SizeUnit
295272
{
@@ -299,14 +276,6 @@ class QgsPalLayerSettings
299276
Percent
300277
};
301278

302-
enum ShadowType
303-
{
304-
ShadowLowest,
305-
ShadowText,
306-
ShadowBuffer,
307-
ShadowShape
308-
};
309-
310279
// update mDataDefinedNames QMap in constructor when adding/deleting enum value
311280
enum DataDefinedProperties
312281
{
@@ -443,13 +412,6 @@ class QgsPalLayerSettings
443412
*/
444413
QgsExpression* getLabelExpression();
445414

446-
QFont textFont;
447-
QString textNamedStyle;
448-
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
449-
QgsMapUnitScale fontSizeMapUnitScale; // scale range for map units for font size
450-
QColor textColor;
451-
int textTransp;
452-
QPainter::CompositionMode blendMode;
453415
QColor previewBkgrdColor;
454416

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

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

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

479-
//-- text buffer
480-
481-
bool bufferDraw;
482-
double bufferSize; // buffer size
483-
bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm)
484-
QgsMapUnitScale bufferSizeMapUnitScale; // scale range for map units for buffer size
485-
QColor bufferColor;
486-
bool bufferNoFill; //set interior of buffer to 100% transparent
487-
int bufferTransp;
488-
Qt::PenJoinStyle bufferJoinStyle;
489-
QPainter::CompositionMode bufferBlendMode;
490-
491-
//-- shape background
492-
493-
bool shapeDraw;
494-
ShapeType shapeType;
495-
QString shapeSVGFile;
496-
SizeType shapeSizeType;
497-
QPointF shapeSize;
498-
SizeUnit shapeSizeUnits;
499-
QgsMapUnitScale shapeSizeMapUnitScale;
500-
RotationType shapeRotationType;
501-
double shapeRotation;
502-
QPointF shapeOffset;
503-
SizeUnit shapeOffsetUnits;
504-
QgsMapUnitScale shapeOffsetMapUnitScale;
505-
QPointF shapeRadii;
506-
SizeUnit shapeRadiiUnits;
507-
QgsMapUnitScale shapeRadiiMapUnitScale;
508-
int shapeTransparency;
509-
QPainter::CompositionMode shapeBlendMode;
510-
QColor shapeFillColor;
511-
QColor shapeBorderColor;
512-
double shapeBorderWidth;
513-
SizeUnit shapeBorderWidthUnits;
514-
QgsMapUnitScale shapeBorderWidthMapUnitScale;
515-
Qt::PenJoinStyle shapeJoinStyle;
516-
517-
//-- drop shadow
518-
519-
bool shadowDraw;
520-
ShadowType shadowUnder;
521-
int shadowOffsetAngle;
522-
double shadowOffsetDist;
523-
SizeUnit shadowOffsetUnits;
524-
QgsMapUnitScale shadowOffsetMapUnitScale;
525-
bool shadowOffsetGlobal;
526-
double shadowRadius;
527-
SizeUnit shadowRadiusUnits;
528-
QgsMapUnitScale shadowRadiusMapUnitScale;
529-
bool shadowRadiusAlphaOnly;
530-
int shadowTransparency;
531-
int shadowScale;
532-
QColor shadowColor;
533-
QPainter::CompositionMode shadowBlendMode;
534-
535440
//-- placement
536441

537442
Placement placement;
@@ -700,33 +605,25 @@ class QgsPalLayerSettings
700605
*/
701606
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;
702607

703-
704-
/** Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
705-
* @param size size to convert
706-
* @param c rendercontext
707-
* @param unit SizeUnit enum value of size
708-
* @param rasterfactor whether to consider oversampling
709-
* @param mapUnitScale a mapUnitScale clamper
710-
* @return font pixel size
711-
*/
712-
int sizeToPixel( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;
713-
714-
/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
715-
* @param size size to convert
716-
* @param c rendercontext
717-
* @param unit SizeUnit enum value of size
718-
* @param rasterfactor whether to consider oversampling
719-
* @param mapUnitScale a mapUnitScale clamper
720-
* @return size that will render, as double
721-
*/
722-
double scaleToPixelContext( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;
723-
724608
/** Map of data defined enum to names and old-style indecies
725609
* The QPair contains a new string for layer property key, and a reference to old-style numeric key (< QGIS 2.0)
726610
* @note not available in python bindings;
727611
*/
728612
// QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > dataDefinedNames() const;
729613

614+
/** Returns the label text formatting settings, eg font settings, buffer settings, etc.
615+
* @see setFormat()
616+
* @note added in QGIS 3.0
617+
*/
618+
const QgsTextFormat& format() const;
619+
620+
/** Sets the label text formatting settings, eg font settings, buffer settings, etc.
621+
* @param format label text format
622+
* @see format()
623+
* @note added in QGIS 3.0
624+
*/
625+
void setFormat( const QgsTextFormat& format );
626+
730627
// temporary stuff: set when layer gets prepared or labeled
731628
QgsFeature* mCurFeat;
732629
QgsFields mCurFields;
@@ -741,9 +638,6 @@ class QgsPalLayerSettings
741638
int mFeatsSendingToPal; // total features tested for sending into PAL (relative to maxNumLabels)
742639
int mFeatsRegPal; // number of features registered in PAL, when using limitNumLabels
743640

744-
QString mTextFontFamily;
745-
bool mTextFontFound;
746-
747641
bool showingShadowRects; // whether to show debug rectangles for drop shadows
748642
};
749643

python/core/qgstextrenderer.sip

+49
Original file line numberDiff line numberDiff line change
@@ -992,4 +992,53 @@ class QgsTextFormat
992992
*/
993993
QDomElement writeXml( QDomDocument& doc ) const;
994994

995+
/** Returns true if any component of the font format requires advanced effects
996+
* such as blend modes, which require output in raster formats to be fully respected.
997+
*/
998+
bool containsAdvancedEffects() const;
999+
1000+
/** Returns true if the specified font was found on the system, or false
1001+
* if the font was not found and a replacement was used instead.
1002+
* @see resolvedFontFamily()
1003+
*/
1004+
bool fontFound() const;
1005+
1006+
/** Returns the family for the resolved font, ie if the specified font
1007+
* was not found on the system this will return the name of the replacement
1008+
* font.
1009+
* @see fontFound()
1010+
*/
1011+
QString resolvedFontFamily() const;
1012+
1013+
};
1014+
1015+
1016+
class QgsTextRenderer
1017+
{
1018+
%TypeHeaderCode
1019+
#include <qgstextrenderer.h>
1020+
%End
1021+
1022+
public:
1023+
1024+
/** Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
1025+
* @param size size to convert
1026+
* @param c rendercontext
1027+
* @param unit size units
1028+
* @param rasterfactor whether to consider oversampling
1029+
* @param mapUnitScale a mapUnitScale clamper
1030+
* @return font pixel size
1031+
*/
1032+
static int sizeToPixel( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
1033+
1034+
/** Calculates size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
1035+
* @param size size to convert
1036+
* @param c rendercontext
1037+
* @param unit size units
1038+
* @param rasterfactor whether to consider oversampling
1039+
* @param mapUnitScale a mapUnitScale clamper
1040+
* @return size that will render, as double
1041+
*/
1042+
static double scaleToPixelContext( double size, const QgsRenderContext& c, QgsUnitTypes::RenderUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
1043+
9951044
};

python/core/symbology-ng/qgssymbollayerutils.sip

+35-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,31 @@ class QgsSymbolLayerUtils
3939
static QString encodeSldBrushStyle( Qt::BrushStyle style );
4040
static Qt::BrushStyle decodeSldBrushStyle( const QString& str );
4141

42+
/** Encodes a QPointF to a string.
43+
* @see decodePoint()
44+
* @see encodeSize()
45+
*/
4246
static QString encodePoint( QPointF point );
43-
static QPointF decodePoint( const QString& str );
47+
48+
/** Decodes a QSizeF from a string.
49+
* @see encodePoint()
50+
* @see decodeSize()
51+
*/
52+
static QPointF decodePoint( const QString& string );
53+
54+
/** Encodes a QSizeF to a string.
55+
* @see decodeSize()
56+
* @see encodePoint()
57+
* @note added in QGIS 3.0
58+
*/
59+
static QString encodeSize( QSizeF size );
60+
61+
/** Decodes a QSizeF from a string.
62+
* @see encodeSize()
63+
* @see decodePoint()
64+
* @note added in QGIS 3.0
65+
*/
66+
static QSizeF decodeSize( const QString& string );
4467

4568
static QString encodeMapUnitScale( const QgsMapUnitScale& mapUnitScale );
4669
static QgsMapUnitScale decodeMapUnitScale( const QString& str );
@@ -361,10 +384,21 @@ class QgsSymbolLayerUtils
361384
* @param unit units for specified size
362385
* @param scale map unit scale
363386
* @note added in QGIS 2.16
387+
* @see convertFromMapUnits()
364388
* @see convertToPainterUnits()
365389
*/
366390
static double convertToMapUnits( const QgsRenderContext&c, double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale& scale = QgsMapUnitScale() );
367391

392+
/** Converts a size from map units to the specied units.
393+
* @param context render context
394+
* @param sizeInMapUnits size (in map units) to convert
395+
* @param outputUnit output units
396+
* @note added in QGIS 3.0
397+
* @see convertToMapUnits()
398+
*/
399+
static double convertFromMapUnits( const QgsRenderContext& context, double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit );
400+
401+
368402
/** Returns scale factor painter units -> pixel dimensions*/
369403
static double pixelSizeScaleFactor( const QgsRenderContext& c, QgsUnitTypes::RenderUnit u, const QgsMapUnitScale& scale = QgsMapUnitScale() );
370404

0 commit comments

Comments
 (0)