1 #ifndef QGSPALGEOMETRY_H 2 #define QGSPALGEOMETRY_H 7 #include <QTextBoundaryFinder> 15 qreal ltrSpacing = 0.0, qreal wordSpacing = 0.0,
bool curvedLabeling =
false )
22 , mFontMetrics( NULL )
23 , mLetterSpacing( ltrSpacing )
24 , mWordSpacing( wordSpacing )
25 , mCurvedLabeling( curvedLabeling )
28 mDefinedFont = QFont();
50 const char*
strId() {
return mStrId.data(); }
51 QString
text() {
return mText; }
58 QString
text(
int partId )
const 63 return mClusters.at( partId );
71 mFontMetrics =
new QFontMetricsF( *fm );
74 if ( maxinangle < 20.0 )
76 if ( 60.0 < maxinangle )
78 if ( maxoutangle > -20.0 )
80 if ( -95.0 > maxoutangle )
85 double labelHeight = mapScale * fm->height() / fontScale;
93 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, mText );
94 int currentBoundary = -1;
95 int previousBoundary = 0;
96 while (( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
98 mClusters << mText.mid( previousBoundary, currentBoundary - previousBoundary );
99 previousBoundary = currentBoundary;
102 mInfo =
new pal::LabelInfo( mClusters.count(), labelHeight, maxinangle, maxoutangle );
103 for (
int i = 0; i < mClusters.count(); i++ )
110 charWidth = fm->width( mClusters[i] );
111 if ( mCurvedLabeling )
113 wordSpaceFix = qreal( 0.0 );
114 if ( mClusters[i] == QString(
" " ) )
118 wordSpaceFix = ( nxt < mClusters.count() && mClusters[nxt] != QString(
" " ) ) ? mWordSpacing : qreal( 0.0 );
122 if ( mClusters[i].length() == 1 &&
123 !
qgsDoubleNear( fm->width( QString( mClusters[i].at( 0 ) ) ), fm->width( mClusters[i].at( 0 ) ) + mLetterSpacing ) )
126 wordSpaceFix -= mWordSpacing;
129 charWidth = fm->width( QString( mClusters[i] ) ) + wordSpaceFix;
132 double labelWidth = mapScale * charWidth / fontScale;
133 mInfo->char_info[i].width = labelWidth;
138 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >&
dataDefinedValues()
const {
return mDataDefinedValues; }
188 #endif //QGSPALGEOMETRY_H const GEOSGeometry * getGeosGeometry() override
get the GEOSGeometry of the feature This method is called by Pal each time it needs a geom's coordina...
void addDataDefinedValue(QgsPalLayerSettings::DataDefinedProperties p, QVariant v)
void setDxfLayer(QString dxfLayer)
const QgsAttributes & diagramAttributes()
#define FID_TO_STRING(fid)
void setAttributes(const QgsAttributes &attrs)
QString text(int partId) const
Returns the text component corresponding to a specified label part.
void setIsDiagram(bool d)
QFontMetricsF * getLabelFontMetrics()
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > mDataDefinedValues
Stores attribute values for data defined properties.
Perform transforms between map coordinates and device coordinates.
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
void setFeatureId(QgsFeatureId id)
Set the feature id for this feature.
optional additional info about label (for curved labels)
double mapUnitsPerPixel() const
Return current map units per pixel.
QgsPalGeometry(QgsFeatureId id, QString text, GEOSGeometry *g, qreal ltrSpacing=0.0, qreal wordSpacing=0.0, bool curvedLabeling=false)
void setDiagramAttributes(const QgsAttributes &attrs)
void releaseGeosGeometry(const GEOSGeometry *) override
Called by Pal when it doesn't need the coordinates anymore.
void setValid(bool validity)
Set the validity of the feature.
void setDefinedFont(QFont f)
static GEOSContextHandle_t getGEOSHandler()
return GEOS context handle
QgsAttributes mDiagramAttributes
Stores attribute values for diagram rendering.
Interface that allows Pal to access user's geometries.
void feature(QgsFeature &feature)
QFontMetricsF * mFontMetrics
pal::LabelInfo * info(QFontMetricsF *fm, const QgsMapToPixel *xform, double fontScale, double maxinangle, double maxoutangle)