Skip to content

Commit 4c4ad05

Browse files
committed
dxf export: more adaptions to labeling changes (backported from b3bf4a1)
1 parent fad50ec commit 4c4ad05

File tree

3 files changed

+72
-34
lines changed

3 files changed

+72
-34
lines changed

src/core/dxf/qgsdxfexport.cpp

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ void QgsDxfExport::writeEntities()
919919

920920
// label engine
921921
QgsLabelingEngineV2 engine;
922+
engine.readSettingsFromProject();
922923
engine.setMapSettings( mapSettings );
923924

924925
// iterate through the maplayers
@@ -4209,63 +4210,98 @@ QString QgsDxfExport::layerName( QgsVectorLayer *vl ) const
42094210
void QgsDxfExport::drawLabel( QString layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings )
42104211
{
42114212
Q_UNUSED( context );
4212-
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
4213-
if ( !lf )
4213+
4214+
if ( !settings.drawLabels )
42144215
return;
42154216

4216-
//label text
4217-
QString txt = lf->text( label->getPartId() );
4217+
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
42184218

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 );
42214223

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();
42244226

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 )
42294234
{
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+
}
42314254
}
4232-
writePolyline( line, dxfLayer, "CONTINUOUS", 1, 0.01, true );
4233-
#endif
42344255

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;
42364272

42374273
//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 )
42394275
{
42404276
bool prependSymb = false;
4241-
QString symb = settings.rightDirectionSymbol;
4277+
QString symb = tmpLyr.rightDirectionSymbol;
42424278

42434279
if ( label->getReversed() )
42444280
{
42454281
prependSymb = true;
4246-
symb = settings.leftDirectionSymbol;
4282+
symb = tmpLyr.leftDirectionSymbol;
42474283
}
42484284

4249-
if ( settings.reverseDirectionSymbol )
4285+
if ( tmpLyr.reverseDirectionSymbol )
42504286
{
4251-
if ( symb == settings.rightDirectionSymbol )
4287+
if ( symb == tmpLyr.rightDirectionSymbol )
42524288
{
42534289
prependSymb = true;
4254-
symb = settings.leftDirectionSymbol;
4290+
symb = tmpLyr.leftDirectionSymbol;
42554291
}
42564292
else
42574293
{
42584294
prependSymb = false;
4259-
symb = settings.rightDirectionSymbol;
4295+
symb = tmpLyr.rightDirectionSymbol;
42604296
}
42614297
}
42624298

4263-
if ( settings.placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
4299+
if ( tmpLyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
42644300
{
42654301
prependSymb = true;
42664302
symb = symb + wrapchr;
42674303
}
4268-
else if ( settings.placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
4304+
else if ( tmpLyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
42694305
{
42704306
prependSymb = false;
42714307
symb = wrapchr + symb;
@@ -4283,28 +4319,28 @@ void QgsDxfExport::drawLabel( QString layerId, QgsRenderContext& context, pal::L
42834319

42844320
txt = txt.replace( wrapchr, "\\P" );
42854321

4286-
if ( settings.textFont.underline() )
4322+
if ( tmpLyr.textFont.underline() )
42874323
{
42884324
txt.prepend( "\\L" ).append( "\\l" );
42894325
}
42904326

4291-
if ( settings.textFont.overline() )
4327+
if ( tmpLyr.textFont.overline() )
42924328
{
42934329
txt.prepend( "\\O" ).append( "\\o" );
42944330
}
42954331

4296-
if ( settings.textFont.strikeOut() )
4332+
if ( tmpLyr.textFont.strikeOut() )
42974333
{
42984334
txt.prepend( "\\K" ).append( "\\k" );
42994335
}
43004336

43014337
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 )
43054341
.arg( label->getHeight() / ( 1 + txt.count( "\\P" ) ) * 0.75 ) );
43064342

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 );
43084344
}
43094345

43104346
void QgsDxfExport::registerDxfLayer( QString layerId, QgsFeatureId fid, QString layerName )

src/core/dxf/qgsdxfexport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class CORE_EXPORT QgsDxfExport
235235
* @param line polyline
236236
* @param layer layer name to use
237237
* @param lineStyleName line type to use
238-
* @param color coolor to use
238+
* @param color color to use
239239
* @param width line width to use
240240
*/
241241
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
@@ -245,7 +245,7 @@ class CORE_EXPORT QgsDxfExport
245245
* @param polygon polygon
246246
* @param layer layer name to use
247247
* @param hatchPattern hatchPattern to use
248-
* @param color coolor to use
248+
* @param color color to use
249249
*/
250250
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
251251

src/core/qgspallabeling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class QgsMapSettings;
5858
class QgsLabelFeature;
5959
class QgsLabelingEngineV2;
6060
class QgsVectorLayerLabelProvider;
61+
class QgsDxfExport;
6162
class QgsVectorLayerDiagramProvider;
6263

6364
class CORE_EXPORT QgsPalLayerSettings
@@ -1055,6 +1056,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
10551056
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
10561057

10571058
friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above
1059+
friend class QgsDxfExport; // to allow calling the static methods above
10581060

10591061
void deleteTemporaryData();
10601062

0 commit comments

Comments
 (0)