@@ -919,6 +919,7 @@ void QgsDxfExport::writeEntities()
919
919
920
920
// label engine
921
921
QgsLabelingEngineV2 engine;
922
+ engine.readSettingsFromProject ();
922
923
engine.setMapSettings ( mapSettings );
923
924
924
925
// iterate through the maplayers
@@ -4209,63 +4210,98 @@ QString QgsDxfExport::layerName( QgsVectorLayer *vl ) const
4209
4210
void QgsDxfExport::drawLabel ( QString layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings )
4210
4211
{
4211
4212
Q_UNUSED ( context );
4212
- QgsTextLabelFeature* lf = dynamic_cast <QgsTextLabelFeature*>( label-> getFeaturePart ()-> feature () );
4213
- if ( !lf )
4213
+
4214
+ if ( !settings. drawLabels )
4214
4215
return ;
4215
4216
4216
- // label text
4217
- QString txt = lf->text ( label->getPartId () );
4217
+ QgsTextLabelFeature* lf = dynamic_cast <QgsTextLabelFeature*>( label->getFeaturePart ()->feature () );
4218
4218
4219
- // angle
4220
- double angle = label->getAlpha () * 180 / M_PI;
4219
+ // Copy to temp, editable layer settings
4220
+ // these settings will be changed by any data defined values, then used for rendering label components
4221
+ // settings may be adjusted during rendering of components
4222
+ QgsPalLayerSettings tmpLyr ( settings );
4221
4223
4222
- QgsFeatureId fid = label-> getFeaturePart ()-> featureId ();
4223
- QString dxfLayer = mDxfLayerNames [layerId][fid] ;
4224
+ // apply any previously applied data defined settings for the label
4225
+ const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues = lf-> dataDefinedValues () ;
4224
4226
4225
- // debug: show label rectangle
4226
- #if 0
4227
- QgsPolyline line;
4228
- for ( int i = 0; i < 4; ++i )
4227
+ // font
4228
+ QFont dFont = lf->definedFont ();
4229
+ QgsDebugMsgLevel ( QString ( " PAL font tmpLyr: %1, Style: %2" ).arg ( tmpLyr.textFont .toString (), tmpLyr.textFont .styleName () ), 4 );
4230
+ QgsDebugMsgLevel ( QString ( " PAL font definedFont: %1, Style: %2" ).arg ( dFont.toString (), dFont.styleName () ), 4 );
4231
+ tmpLyr.textFont = dFont;
4232
+
4233
+ if ( tmpLyr.multilineAlign == QgsPalLayerSettings::MultiFollowPlacement )
4229
4234
{
4230
- line.append( QgsPoint( label->getX( i ), label->getY( i ) ) );
4235
+ // calculate font alignment based on label quadrant
4236
+ switch ( label->getQuadrant () )
4237
+ {
4238
+ case pal::LabelPosition::QuadrantAboveLeft:
4239
+ case pal::LabelPosition::QuadrantLeft:
4240
+ case pal::LabelPosition::QuadrantBelowLeft:
4241
+ tmpLyr.multilineAlign = QgsPalLayerSettings::MultiRight;
4242
+ break ;
4243
+ case pal::LabelPosition::QuadrantAbove:
4244
+ case pal::LabelPosition::QuadrantOver:
4245
+ case pal::LabelPosition::QuadrantBelow:
4246
+ tmpLyr.multilineAlign = QgsPalLayerSettings::MultiCenter;
4247
+ break ;
4248
+ case pal::LabelPosition::QuadrantAboveRight:
4249
+ case pal::LabelPosition::QuadrantRight:
4250
+ case pal::LabelPosition::QuadrantBelowRight:
4251
+ tmpLyr.multilineAlign = QgsPalLayerSettings::MultiLeft;
4252
+ break ;
4253
+ }
4231
4254
}
4232
- writePolyline( line, dxfLayer, "CONTINUOUS", 1, 0.01, true );
4233
- #endif
4234
4255
4235
- QString wrapchr = settings.wrapChar .isEmpty () ? " \n " : settings.wrapChar ;
4256
+ // update tmpLyr with any data defined text style values
4257
+ QgsPalLabeling::dataDefinedTextStyle ( tmpLyr, ddValues );
4258
+
4259
+ // update tmpLyr with any data defined text buffer values
4260
+ QgsPalLabeling::dataDefinedTextBuffer ( tmpLyr, ddValues );
4261
+
4262
+ // update tmpLyr with any data defined text formatting values
4263
+ QgsPalLabeling::dataDefinedTextFormatting ( tmpLyr, ddValues );
4264
+
4265
+ // add to the results
4266
+ QString txt = label->getFeaturePart ()->feature ()->labelText ();
4267
+
4268
+ QgsFeatureId fid = label->getFeaturePart ()->featureId ();
4269
+ QString dxfLayer = mDxfLayerNames [layerId][fid];
4270
+
4271
+ QString wrapchr = tmpLyr.wrapChar .isEmpty () ? " \n " : tmpLyr.wrapChar ;
4236
4272
4237
4273
// add the direction symbol if needed
4238
- if ( !txt.isEmpty () && settings .placement == QgsPalLayerSettings::Line && settings .addDirectionSymbol )
4274
+ if ( !txt.isEmpty () && tmpLyr .placement == QgsPalLayerSettings::Line && tmpLyr .addDirectionSymbol )
4239
4275
{
4240
4276
bool prependSymb = false ;
4241
- QString symb = settings .rightDirectionSymbol ;
4277
+ QString symb = tmpLyr .rightDirectionSymbol ;
4242
4278
4243
4279
if ( label->getReversed () )
4244
4280
{
4245
4281
prependSymb = true ;
4246
- symb = settings .leftDirectionSymbol ;
4282
+ symb = tmpLyr .leftDirectionSymbol ;
4247
4283
}
4248
4284
4249
- if ( settings .reverseDirectionSymbol )
4285
+ if ( tmpLyr .reverseDirectionSymbol )
4250
4286
{
4251
- if ( symb == settings .rightDirectionSymbol )
4287
+ if ( symb == tmpLyr .rightDirectionSymbol )
4252
4288
{
4253
4289
prependSymb = true ;
4254
- symb = settings .leftDirectionSymbol ;
4290
+ symb = tmpLyr .leftDirectionSymbol ;
4255
4291
}
4256
4292
else
4257
4293
{
4258
4294
prependSymb = false ;
4259
- symb = settings .rightDirectionSymbol ;
4295
+ symb = tmpLyr .rightDirectionSymbol ;
4260
4296
}
4261
4297
}
4262
4298
4263
- if ( settings .placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
4299
+ if ( tmpLyr .placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
4264
4300
{
4265
4301
prependSymb = true ;
4266
4302
symb = symb + wrapchr;
4267
4303
}
4268
- else if ( settings .placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
4304
+ else if ( tmpLyr .placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
4269
4305
{
4270
4306
prependSymb = false ;
4271
4307
symb = wrapchr + symb;
@@ -4283,28 +4319,28 @@ void QgsDxfExport::drawLabel( QString layerId, QgsRenderContext& context, pal::L
4283
4319
4284
4320
txt = txt.replace ( wrapchr, " \\ P" );
4285
4321
4286
- if ( settings .textFont .underline () )
4322
+ if ( tmpLyr .textFont .underline () )
4287
4323
{
4288
4324
txt.prepend ( " \\ L" ).append ( " \\ l" );
4289
4325
}
4290
4326
4291
- if ( settings .textFont .overline () )
4327
+ if ( tmpLyr .textFont .overline () )
4292
4328
{
4293
4329
txt.prepend ( " \\ O" ).append ( " \\ o" );
4294
4330
}
4295
4331
4296
- if ( settings .textFont .strikeOut () )
4332
+ if ( tmpLyr .textFont .strikeOut () )
4297
4333
{
4298
4334
txt.prepend ( " \\ K" ).append ( " \\ k" );
4299
4335
}
4300
4336
4301
4337
txt.prepend ( QString ( " \\ f%1|i%2|b%3;\\ H%4;\\ W0.75;" )
4302
- .arg ( settings .textFont .family () )
4303
- .arg ( settings .textFont .italic () ? 1 : 0 )
4304
- .arg ( settings .textFont .bold () ? 1 : 0 )
4338
+ .arg ( tmpLyr .textFont .family () )
4339
+ .arg ( tmpLyr .textFont .italic () ? 1 : 0 )
4340
+ .arg ( tmpLyr .textFont .bold () ? 1 : 0 )
4305
4341
.arg ( label->getHeight () / ( 1 + txt.count ( " \\ P" ) ) * 0.75 ) );
4306
4342
4307
- writeMText ( dxfLayer, txt, QgsPoint ( label->getX (), label->getY () ), label->getWidth () * 1.1 , angle, settings .textColor );
4343
+ writeMText ( dxfLayer, txt, QgsPoint ( label->getX (), label->getY () ), label->getWidth (), label-> getAlpha () * 180.0 / M_PI, tmpLyr .textColor );
4308
4344
}
4309
4345
4310
4346
void QgsDxfExport::registerDxfLayer ( QString layerId, QgsFeatureId fid, QString layerName )
0 commit comments