@@ -1038,13 +1038,15 @@ bool QgsPalLayerSettings::checkMinimumSizeMM( const QgsRenderContext &ct, const
1038
1038
return QgsPalLabeling::checkMinimumSizeMM ( ct, geom, minSize );
1039
1039
}
1040
1040
1041
- void QgsPalLayerSettings::calculateLabelSize ( const QFontMetricsF *fm, QString text, double &labelX, double &labelY, QgsFeature *f, QgsRenderContext *context )
1041
+ void QgsPalLayerSettings::calculateLabelSize ( const QFontMetricsF *fm, const QString & text, double &labelX, double &labelY, const QgsFeature *f, QgsRenderContext *context )
1042
1042
{
1043
1043
if ( !fm || !f )
1044
1044
{
1045
1045
return ;
1046
1046
}
1047
1047
1048
+ QString textCopy ( text );
1049
+
1048
1050
// try to keep < 2.12 API - handle no passed render context
1049
1051
std::unique_ptr< QgsRenderContext > scopedRc;
1050
1052
if ( !context )
@@ -1150,29 +1152,25 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF *fm, QString t
1150
1152
1151
1153
if ( placeDirSymb == QgsPalLayerSettings::SymbolLeftRight )
1152
1154
{
1153
- text .append ( dirSym );
1155
+ textCopy .append ( dirSym );
1154
1156
}
1155
1157
else
1156
1158
{
1157
- text .prepend ( dirSym + QStringLiteral ( " \n " ) ); // SymbolAbove or SymbolBelow
1159
+ textCopy .prepend ( dirSym + QStringLiteral ( " \n " ) ); // SymbolAbove or SymbolBelow
1158
1160
}
1159
1161
}
1160
1162
1161
1163
double w = 0.0 , h = 0.0 ;
1162
- QStringList multiLineSplit = QgsPalLabeling::splitToLines ( text , wrapchr, evalAutoWrapLength, useMaxLineLengthForAutoWrap );
1164
+ const QStringList multiLineSplit = QgsPalLabeling::splitToLines ( textCopy , wrapchr, evalAutoWrapLength, useMaxLineLengthForAutoWrap );
1163
1165
int lines = multiLineSplit.size ();
1164
1166
1165
1167
double labelHeight = fm->ascent () + fm->descent (); // ignore +1 for baseline
1166
1168
1167
1169
h += fm->height () + static_cast < double >( ( lines - 1 ) * labelHeight * multilineH );
1168
1170
1169
- for ( int i = 0 ; i < lines; ++i )
1171
+ for ( const QString &line : multiLineSplit )
1170
1172
{
1171
- double width = fm->width ( multiLineSplit.at ( i ) );
1172
- if ( width > w )
1173
- {
1174
- w = width;
1175
- }
1173
+ w = std::max ( w, fm->width ( line ) );
1176
1174
}
1177
1175
1178
1176
#if 0 // XXX strk
@@ -1186,7 +1184,7 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF *fm, QString t
1186
1184
#endif
1187
1185
}
1188
1186
1189
- void QgsPalLayerSettings::registerFeature ( QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature, QgsGeometry obstacleGeometry )
1187
+ void QgsPalLayerSettings::registerFeature ( const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature, QgsGeometry obstacleGeometry )
1190
1188
{
1191
1189
// either used in QgsPalLabeling (palLayer is set) or in QgsLabelingEngine (labelFeature is set)
1192
1190
Q_ASSERT ( labelFeature );
@@ -1995,7 +1993,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont
1995
1993
lf->setDataDefinedValues ( dataDefinedValues );
1996
1994
}
1997
1995
1998
- void QgsPalLayerSettings::registerObstacleFeature ( QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **obstacleFeature, const QgsGeometry &obstacleGeometry )
1996
+ void QgsPalLayerSettings::registerObstacleFeature ( const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **obstacleFeature, const QgsGeometry &obstacleGeometry )
1999
1997
{
2000
1998
mCurFeat = &f;
2001
1999
0 commit comments