mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Replace VisualMargin with QgsMargins
This commit is contained in:
parent
a7be9968b8
commit
b2b365fc0b
@ -313,7 +313,7 @@ int FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x, double y
|
||||
double labelWidth = getLabelWidth();
|
||||
double labelHeight = getLabelHeight();
|
||||
double distanceToLabel = getLabelDistance();
|
||||
const QgsLabelFeature::VisualMargin& visualMargin = mLF->visualMargin();
|
||||
const QgsMargins& visualMargin = mLF->visualMargin();
|
||||
|
||||
double symbolWidthOffset = ( mLF->offsetType() == QgsPalLayerSettings::FromSymbolBounds ? mLF->symbolSize().width() / 2.0 : 0.0 );
|
||||
double symbolHeightOffset = ( mLF->offsetType() == QgsPalLayerSettings::FromSymbolBounds ? mLF->symbolSize().height() / 2.0 : 0.0 );
|
||||
@ -331,85 +331,85 @@ int FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x, double y
|
||||
case QgsPalLayerSettings::TopLeft:
|
||||
quadrant = LabelPosition::QuadrantAboveLeft;
|
||||
alpha = 3 * M_PI_4;
|
||||
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
|
||||
deltaY = -visualMargin.bottom + symbolHeightOffset;
|
||||
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
|
||||
deltaY = -visualMargin.bottom() + symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::TopSlightlyLeft:
|
||||
quadrant = LabelPosition::QuadrantAboveRight; //right quadrant, so labels are left-aligned
|
||||
alpha = M_PI_2;
|
||||
deltaX = -labelWidth / 4.0 - visualMargin.left;
|
||||
deltaY = -visualMargin.bottom + symbolHeightOffset;
|
||||
deltaX = -labelWidth / 4.0 - visualMargin.left();
|
||||
deltaY = -visualMargin.bottom() + symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::TopMiddle:
|
||||
quadrant = LabelPosition::QuadrantAbove;
|
||||
alpha = M_PI_2;
|
||||
deltaX = -labelWidth / 2.0;
|
||||
deltaY = -visualMargin.bottom + symbolHeightOffset;
|
||||
deltaY = -visualMargin.bottom() + symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::TopSlightlyRight:
|
||||
quadrant = LabelPosition::QuadrantAboveLeft; //left quadrant, so labels are right-aligned
|
||||
alpha = M_PI_2;
|
||||
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right;
|
||||
deltaY = -visualMargin.bottom + symbolHeightOffset;
|
||||
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right();
|
||||
deltaY = -visualMargin.bottom() + symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::TopRight:
|
||||
quadrant = LabelPosition::QuadrantAboveRight;
|
||||
alpha = M_PI_4;
|
||||
deltaX = - visualMargin.left + symbolWidthOffset;
|
||||
deltaY = -visualMargin.bottom + symbolHeightOffset;
|
||||
deltaX = - visualMargin.left() + symbolWidthOffset;
|
||||
deltaY = -visualMargin.bottom() + symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::MiddleLeft:
|
||||
quadrant = LabelPosition::QuadrantLeft;
|
||||
alpha = M_PI;
|
||||
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
|
||||
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
|
||||
deltaY = -labelHeight / 2.0;// TODO - should this be adjusted by visual margin??
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::MiddleRight:
|
||||
quadrant = LabelPosition::QuadrantRight;
|
||||
alpha = 0.0;
|
||||
deltaX = -visualMargin.left + symbolWidthOffset;
|
||||
deltaX = -visualMargin.left() + symbolWidthOffset;
|
||||
deltaY = -labelHeight / 2.0;// TODO - should this be adjusted by visual margin??
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::BottomLeft:
|
||||
quadrant = LabelPosition::QuadrantBelowLeft;
|
||||
alpha = 5 * M_PI_4;
|
||||
deltaX = -labelWidth + visualMargin.right - symbolWidthOffset;
|
||||
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
|
||||
deltaX = -labelWidth + visualMargin.right() - symbolWidthOffset;
|
||||
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::BottomSlightlyLeft:
|
||||
quadrant = LabelPosition::QuadrantBelowRight; //right quadrant, so labels are left-aligned
|
||||
alpha = 3 * M_PI_2;
|
||||
deltaX = -labelWidth / 4.0 - visualMargin.left;
|
||||
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
|
||||
deltaX = -labelWidth / 4.0 - visualMargin.left();
|
||||
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::BottomMiddle:
|
||||
quadrant = LabelPosition::QuadrantBelow;
|
||||
alpha = 3 * M_PI_2;
|
||||
deltaX = -labelWidth / 2.0;
|
||||
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
|
||||
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::BottomSlightlyRight:
|
||||
quadrant = LabelPosition::QuadrantBelowLeft; //left quadrant, so labels are right-aligned
|
||||
alpha = 3 * M_PI_2;
|
||||
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right;
|
||||
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
|
||||
deltaX = -labelWidth * 3.0 / 4.0 + visualMargin.right();
|
||||
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
|
||||
break;
|
||||
|
||||
case QgsPalLayerSettings::BottomRight:
|
||||
quadrant = LabelPosition::QuadrantBelowRight;
|
||||
alpha = 7 * M_PI_4;
|
||||
deltaX = -visualMargin.left + symbolWidthOffset;
|
||||
deltaY = -labelHeight + visualMargin.top - symbolHeightOffset;
|
||||
deltaX = -visualMargin.left() + symbolWidthOffset;
|
||||
deltaY = -labelHeight + visualMargin.top() - symbolHeightOffset;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "qgis_core.h"
|
||||
#include "qgspallabeling.h"
|
||||
#include "geos_c.h"
|
||||
#include "qgsmargins.h"
|
||||
|
||||
namespace pal
|
||||
{
|
||||
@ -35,52 +36,6 @@ class CORE_EXPORT QgsLabelFeature
|
||||
{
|
||||
public:
|
||||
|
||||
//! Stores visual margins for labels (left, right, top and bottom)
|
||||
//! @note not available in Python bindings
|
||||
struct VisualMargin
|
||||
{
|
||||
|
||||
/** Default constructor, all margins are set to 0.0
|
||||
*/
|
||||
VisualMargin()
|
||||
: left( 0.0 )
|
||||
, right( 0.0 )
|
||||
, top( 0.0 )
|
||||
, bottom( 0.0 )
|
||||
{}
|
||||
|
||||
/** Constructor allowing margins to be specified
|
||||
* @param top top margin
|
||||
* @param right right margin
|
||||
* @param bottom bottom margin
|
||||
* @param left left margin
|
||||
*/
|
||||
VisualMargin( double top, double right, double bottom, double left )
|
||||
: left( left )
|
||||
, right( right )
|
||||
, top( top )
|
||||
, bottom( bottom )
|
||||
{}
|
||||
|
||||
//! Left margin
|
||||
double left;
|
||||
//! Right margin
|
||||
double right;
|
||||
//! Top margin
|
||||
double top;
|
||||
//! Bottom margin
|
||||
double bottom;
|
||||
|
||||
VisualMargin& operator *=( double value )
|
||||
{
|
||||
left *= value;
|
||||
right *= value;
|
||||
top *= value;
|
||||
bottom *= value;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
//! Create label feature, takes ownership of the geometry instance
|
||||
QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, QSizeF size );
|
||||
//! Clean up geometry and curved label info (if present)
|
||||
@ -146,12 +101,12 @@ class CORE_EXPORT QgsLabelFeature
|
||||
* @param margin visual margins for label
|
||||
* @see visualMargin()
|
||||
*/
|
||||
void setVisualMargin( const VisualMargin& margin ) { mVisualMargin = margin; }
|
||||
void setVisualMargin( const QgsMargins& margin ) { mVisualMargin = margin; }
|
||||
|
||||
/** Returns the visual margin for the label feature.
|
||||
* @see setVisualMargin() for details
|
||||
*/
|
||||
const VisualMargin& visualMargin() const { return mVisualMargin; }
|
||||
const QgsMargins& visualMargin() const { return mVisualMargin; }
|
||||
|
||||
/** Sets the size of the rendered symbol associated with this feature. This size is taken into
|
||||
* account in certain label placement modes to avoid placing labels over the rendered
|
||||
@ -353,7 +308,7 @@ class CORE_EXPORT QgsLabelFeature
|
||||
//! Width and height of the label
|
||||
QSizeF mSize;
|
||||
//! Visual margin of label contents
|
||||
VisualMargin mVisualMargin;
|
||||
QgsMargins mVisualMargin;
|
||||
//! Size of associated rendered symbol, if applicable
|
||||
QSizeF mSymbolSize;
|
||||
//! Priority of the label
|
||||
|
@ -1792,7 +1792,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
|
||||
//this makes labels align to the font's baseline or highest character
|
||||
double topMargin = qMax( 0.25 * labelFontMetrics->ascent(), 0.0 );
|
||||
double bottomMargin = 1.0 + labelFontMetrics->descent();
|
||||
QgsLabelFeature::VisualMargin vm( topMargin, 0.0, bottomMargin, 0.0 );
|
||||
QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
|
||||
vm *= xform->mapUnitsPerPixel();
|
||||
( *labelFeature )->setVisualMargin( vm );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user