Skip to content

Commit b2b365f

Browse files
committed
Replace VisualMargin with QgsMargins
1 parent a7be996 commit b2b365f

File tree

3 files changed

+26
-71
lines changed

3 files changed

+26
-71
lines changed

src/core/pal/feature.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ int FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x, double y
313313
double labelWidth = getLabelWidth();
314314
double labelHeight = getLabelHeight();
315315
double distanceToLabel = getLabelDistance();
316-
const QgsLabelFeature::VisualMargin& visualMargin = mLF->visualMargin();
316+
const QgsMargins& visualMargin = mLF->visualMargin();
317317

318318
double symbolWidthOffset = ( mLF->offsetType() == QgsPalLayerSettings::FromSymbolBounds ? mLF->symbolSize().width() / 2.0 : 0.0 );
319319
double symbolHeightOffset = ( mLF->offsetType() == QgsPalLayerSettings::FromSymbolBounds ? mLF->symbolSize().height() / 2.0 : 0.0 );
@@ -331,85 +331,85 @@ int FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x, double y
331331
case QgsPalLayerSettings::TopLeft:
332332
quadrant = LabelPosition::QuadrantAboveLeft;
333333
alpha = 3 * M_PI_4;
334-
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
335-
deltaY = -visualMargin.bottom + symbolHeightOffset;
334+
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
335+
deltaY = -visualMargin.bottom() + symbolHeightOffset;
336336
break;
337337

338338
case QgsPalLayerSettings::TopSlightlyLeft:
339339
quadrant = LabelPosition::QuadrantAboveRight; //right quadrant, so labels are left-aligned
340340
alpha = M_PI_2;
341-
deltaX = -labelWidth / 4.0 - visualMargin.left;
342-
deltaY = -visualMargin.bottom + symbolHeightOffset;
341+
deltaX = -labelWidth / 4.0 - visualMargin.left();
342+
deltaY = -visualMargin.bottom() + symbolHeightOffset;
343343
break;
344344

345345
case QgsPalLayerSettings::TopMiddle:
346346
quadrant = LabelPosition::QuadrantAbove;
347347
alpha = M_PI_2;
348348
deltaX = -labelWidth / 2.0;
349-
deltaY = -visualMargin.bottom + symbolHeightOffset;
349+
deltaY = -visualMargin.bottom() + symbolHeightOffset;
350350
break;
351351

352352
case QgsPalLayerSettings::TopSlightlyRight:
353353
quadrant = LabelPosition::QuadrantAboveLeft; //left quadrant, so labels are right-aligned
354354
alpha = M_PI_2;
355-
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right;
356-
deltaY = -visualMargin.bottom + symbolHeightOffset;
355+
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right();
356+
deltaY = -visualMargin.bottom() + symbolHeightOffset;
357357
break;
358358

359359
case QgsPalLayerSettings::TopRight:
360360
quadrant = LabelPosition::QuadrantAboveRight;
361361
alpha = M_PI_4;
362-
deltaX = - visualMargin.left + symbolWidthOffset;
363-
deltaY = -visualMargin.bottom + symbolHeightOffset;
362+
deltaX = - visualMargin.left() + symbolWidthOffset;
363+
deltaY = -visualMargin.bottom() + symbolHeightOffset;
364364
break;
365365

366366
case QgsPalLayerSettings::MiddleLeft:
367367
quadrant = LabelPosition::QuadrantLeft;
368368
alpha = M_PI;
369-
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
369+
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
370370
deltaY = -labelHeight / 2.0;// TODO - should this be adjusted by visual margin??
371371
break;
372372

373373
case QgsPalLayerSettings::MiddleRight:
374374
quadrant = LabelPosition::QuadrantRight;
375375
alpha = 0.0;
376-
deltaX = -visualMargin.left + symbolWidthOffset;
376+
deltaX = -visualMargin.left() + symbolWidthOffset;
377377
deltaY = -labelHeight / 2.0;// TODO - should this be adjusted by visual margin??
378378
break;
379379

380380
case QgsPalLayerSettings::BottomLeft:
381381
quadrant = LabelPosition::QuadrantBelowLeft;
382382
alpha = 5 * M_PI_4;
383-
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
384-
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
383+
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
384+
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
385385
break;
386386

387387
case QgsPalLayerSettings::BottomSlightlyLeft:
388388
quadrant = LabelPosition::QuadrantBelowRight; //right quadrant, so labels are left-aligned
389389
alpha = 3 * M_PI_2;
390-
deltaX = -labelWidth / 4.0 - visualMargin.left;
391-
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
390+
deltaX = -labelWidth / 4.0 - visualMargin.left();
391+
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
392392
break;
393393

394394
case QgsPalLayerSettings::BottomMiddle:
395395
quadrant = LabelPosition::QuadrantBelow;
396396
alpha = 3 * M_PI_2;
397397
deltaX = -labelWidth / 2.0;
398-
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
398+
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
399399
break;
400400

401401
case QgsPalLayerSettings::BottomSlightlyRight:
402402
quadrant = LabelPosition::QuadrantBelowLeft; //left quadrant, so labels are right-aligned
403403
alpha = 3 * M_PI_2;
404-
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right;
405-
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
404+
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right();
405+
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
406406
break;
407407

408408
case QgsPalLayerSettings::BottomRight:
409409
quadrant = LabelPosition::QuadrantBelowRight;
410410
alpha = 7 * M_PI_4;
411-
deltaX = -visualMargin.left + symbolWidthOffset;
412-
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
411+
deltaX = -visualMargin.left() + symbolWidthOffset;
412+
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
413413
break;
414414
}
415415

src/core/qgslabelfeature.h

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "qgis_core.h"
55
#include "qgspallabeling.h"
66
#include "geos_c.h"
7+
#include "qgsmargins.h"
78

89
namespace pal
910
{
@@ -35,52 +36,6 @@ class CORE_EXPORT QgsLabelFeature
3536
{
3637
public:
3738

38-
//! Stores visual margins for labels (left, right, top and bottom)
39-
//! @note not available in Python bindings
40-
struct VisualMargin
41-
{
42-
43-
/** Default constructor, all margins are set to 0.0
44-
*/
45-
VisualMargin()
46-
: left( 0.0 )
47-
, right( 0.0 )
48-
, top( 0.0 )
49-
, bottom( 0.0 )
50-
{}
51-
52-
/** Constructor allowing margins to be specified
53-
* @param top top margin
54-
* @param right right margin
55-
* @param bottom bottom margin
56-
* @param left left margin
57-
*/
58-
VisualMargin( double top, double right, double bottom, double left )
59-
: left( left )
60-
, right( right )
61-
, top( top )
62-
, bottom( bottom )
63-
{}
64-
65-
//! Left margin
66-
double left;
67-
//! Right margin
68-
double right;
69-
//! Top margin
70-
double top;
71-
//! Bottom margin
72-
double bottom;
73-
74-
VisualMargin& operator *=( double value )
75-
{
76-
left *= value;
77-
right *= value;
78-
top *= value;
79-
bottom *= value;
80-
return *this;
81-
}
82-
};
83-
8439
//! Create label feature, takes ownership of the geometry instance
8540
QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, QSizeF size );
8641
//! Clean up geometry and curved label info (if present)
@@ -146,12 +101,12 @@ class CORE_EXPORT QgsLabelFeature
146101
* @param margin visual margins for label
147102
* @see visualMargin()
148103
*/
149-
void setVisualMargin( const VisualMargin& margin ) { mVisualMargin = margin; }
104+
void setVisualMargin( const QgsMargins& margin ) { mVisualMargin = margin; }
150105

151106
/** Returns the visual margin for the label feature.
152107
* @see setVisualMargin() for details
153108
*/
154-
const VisualMargin& visualMargin() const { return mVisualMargin; }
109+
const QgsMargins& visualMargin() const { return mVisualMargin; }
155110

156111
/** Sets the size of the rendered symbol associated with this feature. This size is taken into
157112
* account in certain label placement modes to avoid placing labels over the rendered
@@ -353,7 +308,7 @@ class CORE_EXPORT QgsLabelFeature
353308
//! Width and height of the label
354309
QSizeF mSize;
355310
//! Visual margin of label contents
356-
VisualMargin mVisualMargin;
311+
QgsMargins mVisualMargin;
357312
//! Size of associated rendered symbol, if applicable
358313
QSizeF mSymbolSize;
359314
//! Priority of the label

src/core/qgspallabeling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
17921792
//this makes labels align to the font's baseline or highest character
17931793
double topMargin = qMax( 0.25 * labelFontMetrics->ascent(), 0.0 );
17941794
double bottomMargin = 1.0 + labelFontMetrics->descent();
1795-
QgsLabelFeature::VisualMargin vm( topMargin, 0.0, bottomMargin, 0.0 );
1795+
QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
17961796
vm *= xform->mapUnitsPerPixel();
17971797
( *labelFeature )->setVisualMargin( vm );
17981798

0 commit comments

Comments
 (0)