59 int QgsDxfExport::sDxfColors[][3] =
319 const char *QgsDxfExport::DXF_ENCODINGS[][2] =
322 {
"8859_1",
"ISO-8859-1" },
323 {
"8859_2",
"ISO-8859-2" },
324 {
"8859_3",
"ISO-8859-3" },
325 {
"8859_4",
"ISO-8859-4" },
326 {
"8859_5",
"ISO-8859-5" },
327 {
"8859_6",
"ISO-8859-6" },
328 {
"8859_7",
"ISO-8859-7" },
329 {
"8859_8",
"ISO-8859-8" },
330 {
"8859_9",
"ISO-8859-9" },
332 {
"DOS850",
"CP850" },
343 {
"MACINTOSH",
"MacRoman" },
345 {
"KSC5601",
"ksc5601.1987-0" },
347 {
"DOS866",
"CP866" },
348 {
"ANSI_1250",
"CP1250" },
349 {
"ANSI_1251",
"CP1251" },
350 {
"ANSI_1252",
"CP1252" },
351 {
"GB2312",
"GB2312" },
352 {
"ANSI_1253",
"CP1253" },
353 {
"ANSI_1254",
"CP1254" },
354 {
"ANSI_1255",
"CP1255" },
355 {
"ANSI_1256",
"CP1256" },
356 {
"ANSI_1257",
"CP1257" },
357 {
"ANSI_874",
"CP874" },
358 {
"ANSI_932",
"Shift_JIS" },
359 {
"ANSI_936",
"CP936" },
360 {
"ANSI_949",
"CP949" },
361 {
"ANSI_950",
"CP950" },
364 {
"ANSI_1258",
"CP1258" },
374 mMapSettings = dxfExport.mMapSettings;
375 mLayerNameAttribute = dxfExport.mLayerNameAttribute;
376 mSymbologyScale = dxfExport.mSymbologyScale;
377 mSymbologyExport = dxfExport.mSymbologyExport;
378 mMapUnits = dxfExport.mMapUnits;
379 mLayerTitleAsName = dxfExport.mLayerTitleAsName;
380 mSymbolLayerCounter = 0;
384 mFactor = dxfExport.mFactor;
385 mForce2d = dxfExport.mForce2d;
391 mMapSettings = settings;
406 QList<QgsMapLayer *> layerList;
408 mLayerNameAttribute.clear();
410 QList< DxfLayer >::const_iterator layerIt = layers.constBegin();
411 for ( ; layerIt != layers.constEnd(); ++layerIt )
413 layerList << layerIt->layer();
414 if ( layerIt->layerOutputAttributeIndex() >= 0 )
415 mLayerNameAttribute.insert( layerIt->layer()->id(), layerIt->layerOutputAttributeIndex() );
443 if ( !mForce2d && p.
is3D() && std::isfinite( p.
z() ) )
450 int minDist = std::numeric_limits<int>::max();
452 for (
int i = 1; i < static_cast< int >(
sizeof( sDxfColors ) /
sizeof( *sDxfColors ) ) && minDist > 0; ++i )
454 int dist = color_distance( color.rgba(), i );
455 if ( dist >= minDist )
462 if ( minDist == 0 && minDistAt != 7 )
466 if ( color.alpha() == 255 )
470 int c = ( color.red() & 0xff ) * 0x10000 + ( color.green() & 0xff ) * 0x100 + ( color.blue() & 0xff );
472 if ( transparencyCode != -1 && color.alpha() < 255 )
473 writeGroup( transparencyCode, 0x2000000 | color.alpha() );
478 mTextStream << QStringLiteral(
"%1\n" ).arg( code, 3, 10, QChar(
' ' ) );
483 mTextStream << QStringLiteral(
"%1\n" ).arg( i, 6, 10, QChar(
' ' ) );
489 if ( !s.contains(
'.' ) )
490 s += QLatin1String(
".0" );
491 mTextStream << s <<
'\n';
496 mTextStream << s <<
'\n';
506 if ( !d->isOpen() && !d->open( QIODevice::WriteOnly | QIODevice::Truncate ) )
511 mTextStream.setDevice( d );
512 mTextStream.setCodec( encoding.toLocal8Bit() );
519 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
534 mExtent = layerExtent;
565 void QgsDxfExport::writeHeader(
const QString &codepage )
567 writeGroup( 999, QStringLiteral(
"DXF created from QGIS" ) );
573 writeGroup( 9, QStringLiteral(
"$ACADVER" ) );
585 writeGroup( 9, QStringLiteral(
"$LTSCALE" ) );
597 writeGroup( 9, QStringLiteral(
"$PSLTSCALE" ) );
600 writeGroup( 9, QStringLiteral(
"$HANDSEED" ) );
603 writeGroup( 9, QStringLiteral(
"$DWGCODEPAGE" ) );
612 handle = mNextHandleId++;
614 Q_ASSERT_X( handle <
DXF_HANDMAX,
"QgsDxfExport::writeHandle(int, int)",
"DXF handle too large" );
616 writeGroup( code, QStringLiteral(
"%1" ).arg( handle, 0, 16 ) );
620 void QgsDxfExport::writeTables()
627 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > slList;
630 slList = symbolLayers( context );
638 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
641 writeDefaultLinetypes();
644 QList< QPair< QgsSymbolLayer *, QgsSymbol *> >::const_iterator slIt = slList.constBegin();
645 for ( ; slIt != slList.constEnd(); ++slIt )
647 writeSymbolLayerLinetype( slIt->first );
654 writeGroup( 2, QStringLiteral(
"BLOCK_RECORD" ) );
657 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
660 const QStringList blockStrings = QStringList() << QStringLiteral(
"*Model_Space" ) << QStringLiteral(
"*Paper_Space" ) << QStringLiteral(
"*Paper_Space0" );
661 for (
const QString &block : blockStrings )
663 writeGroup( 0, QStringLiteral(
"BLOCK_RECORD" ) );
665 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
666 writeGroup( 100, QStringLiteral(
"AcDbBlockTableRecord" ) );
671 slIt = slList.constBegin();
672 for ( ; slIt != slList.constEnd(); ++slIt )
678 if ( hasDataDefinedProperties( ml, slIt->second ) )
681 QString name = QStringLiteral(
"symbolLayer%1" ).arg( i++ );
682 writeGroup( 0, QStringLiteral(
"BLOCK_RECORD" ) );
684 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
685 writeGroup( 100, QStringLiteral(
"AcDbBlockTableRecord" ) );
695 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
699 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
700 writeGroup( 100, QStringLiteral(
"AcDbRegAppTableRecord" ) );
709 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
717 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
725 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
729 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
730 writeGroup( 100, QStringLiteral(
"AcDbViewportTableRecord" ) );
769 writeGroup( 2, QStringLiteral(
"DIMSTYLE" ) );
771 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
772 writeGroup( 100, QStringLiteral(
"AcDbDimStyleTable" ) );
776 QSet<QString> layerNames;
777 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
780 if ( !layerIsScaleBasedVisible( ml ) )
787 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
794 const QSet<QVariant> values = vl->
uniqueValues( attrIdx );
795 for (
const QVariant &v : values )
807 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
812 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
813 writeGroup( 100, QStringLiteral(
"AcDbLayerTableRecord" ) );
817 writeGroup( 6, QStringLiteral(
"CONTINUOUS" ) );
820 for (
const QString &
layerName : qgis::as_const( layerNames ) )
824 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
825 writeGroup( 100, QStringLiteral(
"AcDbLayerTableRecord" ) );
829 writeGroup( 6, QStringLiteral(
"CONTINUOUS" ) );
838 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
844 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
845 writeGroup( 100, QStringLiteral(
"AcDbTextStyleTableRecord" ) );
846 writeGroup( 2, QStringLiteral(
"STANDARD" ) );
853 writeGroup( 3, QStringLiteral(
"romans.shx" ) );
861 void QgsDxfExport::writeBlocks()
866 const QStringList blockStrings = QStringList() << QStringLiteral(
"*Model_Space" ) << QStringLiteral(
"*Paper_Space" ) << QStringLiteral(
"*Paper_Space0" );
867 for (
const QString &block : blockStrings )
871 writeGroup( 330, QStringLiteral(
"%1" ).arg( mBlockHandles[ block ], 0, 16 ) );
872 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
874 writeGroup( 100, QStringLiteral(
"AcDbBlockBegin" ) );
882 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
884 writeGroup( 100, QStringLiteral(
"AcDbBlockEnd" ) );
890 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > slList;
893 slList = symbolLayers( ct );
896 QList< QPair< QgsSymbolLayer *, QgsSymbol * > >::const_iterator slIt = slList.constBegin();
897 for ( ; slIt != slList.constEnd(); ++slIt )
908 if ( hasDataDefinedProperties( ml, slIt->second ) )
914 QString block( QStringLiteral(
"symbolLayer%1" ).arg( mBlockCounter++ ) );
915 mBlockHandle = QStringLiteral(
"%1" ).arg( mBlockHandles[ block ], 0, 16 );
920 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
922 writeGroup( 100, QStringLiteral(
"AcDbBlockBegin" ) );
935 ml->
writeDxf( *
this,
mapUnitScaleFactor( mSymbologyScale, ml->
sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), QStringLiteral(
"0" ), ctx );
939 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
941 writeGroup( 100, QStringLiteral(
"AcDbBlockEnd" ) );
943 mPointSymbolBlocks.insert( ml, block );
950 void QgsDxfExport::writeEntities()
953 writeGroup( 2, QStringLiteral(
"ENTITIES" ) );
955 mBlockHandle = QStringLiteral(
"%1" ).arg( mBlockHandles[ QStringLiteral(
"*Model_Space" )], 0, 16 );
957 QImage image( 10, 10, QImage::Format_ARGB32_Premultiplied );
958 image.setDotsPerMeterX( 96 / 25.4 * 1000 );
959 image.setDotsPerMeterY( 96 / 25.4 * 1000 );
960 QPainter painter( &image );
969 mExtent.
height() * mFactor, 0 ) );
979 const QList< QgsMapLayer *> layers = mMapSettings.
layers();
983 if ( !vl || !layerIsScaleBasedVisible( vl ) )
991 QgsDebugMsg( QStringLiteral(
"%1: apply override style" ).arg( vl->
id() ) );
996 QgsDebugMsg( QStringLiteral(
"%1: no override style" ).arg( vl->
id() ) );
1013 std::unique_ptr< QgsFeatureRenderer > renderer( vl->
renderer()->
clone() );
1014 renderer->startRender( ctx, vl->
fields() );
1016 QSet<QString> attributes = renderer->usedAttributes( ctx );
1017 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
1021 attributes << layerAttr;
1027 if (
const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( labeling ) )
1033 if ( !rblp->
prepare( ctx, attributes ) )
1039 else if ( labeling )
1045 if ( !lp->
prepare( ctx, attributes ) )
1054 renderer->usingSymbolLevels() )
1056 writeEntitiesSymbolLevels( vl );
1057 renderer->stopRender( ctx );
1077 if ( !renderer->willRenderFeature( fet, ctx ) )
1082 addFeature( sctx, ct, lName,
nullptr,
nullptr );
1086 QgsSymbolList symbolList = renderer->symbolsForFeature( fet, ctx );
1087 bool hasSymbology = symbolList.size() > 0;
1091 QgsSymbolList::iterator symbolIt = symbolList.begin();
1092 for ( ; symbolIt != symbolList.end(); ++symbolIt )
1094 int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
1095 for (
int i = 0; i < nSymbolLayers; ++i )
1103 bool isGeometryGenerator = ( sl->
layerType() == QLatin1String(
"GeometryGenerator" ) );
1104 if ( isGeometryGenerator )
1106 addGeometryGeneratorSymbolLayer( sctx, ct, lName, sl,
true );
1110 addFeature( sctx, ct, lName, sl, *symbolIt );
1115 else if ( hasSymbology )
1126 addGeometryGeneratorSymbolLayer( sctx, ct, lName, s->
symbolLayer( 0 ), false );
1130 addFeature( sctx, ct, lName, s->
symbolLayer( 0 ), s );
1145 renderer->stopRender( ctx );
1153 void QgsDxfExport::writeEntitiesSymbolLevels(
QgsVectorLayer *layer )
1165 std::unique_ptr< QgsFeatureRenderer > renderer( layer->
renderer()->
clone() );
1166 QHash< QgsSymbol *, QList<QgsFeature> > features;
1171 renderer->startRender( ctx, layer->
fields() );
1190 featureSymbol = renderer->symbolForFeature( fet, ctx );
1191 if ( !featureSymbol )
1196 QHash< QgsSymbol *, QList<QgsFeature> >::iterator it = features.find( featureSymbol );
1197 if ( it == features.end() )
1199 it = features.insert( featureSymbol, QList<QgsFeature>() );
1201 it.value().append( fet );
1207 for (
int i = 0; i < symbols.count(); i++ )
1213 if ( level < 0 || level >= 1000 )
1216 while ( level >= levels.count() )
1218 levels[level].append( item );
1225 for (
int l = 0; l < levels.count(); l++ )
1228 for (
int i = 0; i < level.count(); i++ )
1231 QHash< QgsSymbol *, QList<QgsFeature> >::iterator levelIt = features.find( item.
symbol() );
1232 if ( levelIt == features.end() )
1234 QgsDebugMsg( QStringLiteral(
"No feature found for symbol on %1 %2.%3" ).arg( layer->
id() ).arg( l ).arg( i ) );
1238 int llayer = item.
layer();
1239 QList<QgsFeature> &featureList = levelIt.value();
1240 QList<QgsFeature>::iterator featureIt = featureList.begin();
1241 for ( ; featureIt != featureList.end(); ++featureIt )
1244 addFeature( sctx, ct, layer->
name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
1248 renderer->stopRender( ctx );
1251 void QgsDxfExport::writeEndFile()
1278 ACAD_MLEADERSTYLE\n\ 1286 ACAD_PLOTSETTINGS\n\ 1290 ACAD_PLOTSTYLENAME\n\ 1398 ACDBDICTIONARYWDFLT\n\ 1418 AcDbDictionaryWithDefault\n\ 1614 1.000000000000000E+20\n\ 1616 1.000000000000000E+20\n\ 1618 1.000000000000000E+20\n\ 1620 -1.000000000000000E+20\n\ 1622 -1.000000000000000E+20\n\ 1624 -1.000000000000000E+20\n\ 1886 163.1318914119703\n\ 2054 AcDbSavedByObjectVersion\n\ 2144 AcDbSavedByObjectVersion\n\ 2234 AcDbSavedByObjectVersion\n\ 2324 AcDbSavedByObjectVersion\n\ 2414 AcDbSavedByObjectVersion\n\ 2506 AcDbSavedByObjectVersion\n\ 2596 AcDbSavedByObjectVersion\n\ 2686 AcDbSavedByObjectVersion\n\ 2776 AcDbSavedByObjectVersion\n\ 2866 AcDbSavedByObjectVersion\n\ 2956 AcDbSavedByObjectVersion\n\ 3046 AcDbSavedByObjectVersion\n\ 3136 AcDbSavedByObjectVersion\n\ 3226 AcDbSavedByObjectVersion\n\ 3318 AcDbSavedByObjectVersion\n\ 3408 AcDbSavedByObjectVersion\n\ 3418 void QgsDxfExport::startSection()
3420 writeGroup( 0, QStringLiteral(
"SECTION" ) );
3423 void QgsDxfExport::endSection()
3436 msl->
sizeUnit(), mMapUnits ) / 2.0;
3448 QHash< const QgsSymbolLayer *, QString >::const_iterator blockIt = mPointSymbolBlocks.constFind( symbolLayer );
3449 if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )
3453 if ( msl && symbol )
3467 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3468 writeGroup( 100, QStringLiteral(
"AcDbBlockReference" ) );
3478 int n = line.size();
3481 QgsDebugMsg( QStringLiteral(
"writePolyline: empty line layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3487 QgsDebugMsg( QStringLiteral(
"writePolyline: line too short layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3491 if ( mForce2d || !line.at( 0 ).is3D() )
3493 bool polygon = line[0] == line[ line.size() - 1 ];
3497 writeGroup( 0, QStringLiteral(
"LWPOLYLINE" ) );
3500 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3501 writeGroup( 100, QStringLiteral(
"AcDbPolyline" ) );
3509 for (
int i = 0; i < n; i++ )
3514 writeGroup( 0, QStringLiteral(
"POLYLINE" ) );
3517 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3521 writeGroup( 100, QStringLiteral(
"AcDb3dPolyline" ) );
3525 for (
int i = 0; i < n; i++ )
3530 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3533 writeGroup( 100, QStringLiteral(
"AcDbVertex" ) );
3534 writeGroup( 100, QStringLiteral(
"AcDb3dPolylineVertex" ) );
3542 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3553 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3556 writeGroup( 100, QStringLiteral(
"AcDbHatch" ) );
3562 writeGroup( 70, hatchPattern == QLatin1String(
"SOLID" ) );
3566 for (
int i = 0; i < polygon.size(); ++i )
3573 for (
int j = 0; j < polygon[i].size(); ++j )
3596 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3597 writeGroup( 100, QStringLiteral(
"AcDbPoint" ) );
3608 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3611 writeGroup( 100, QStringLiteral(
"AcDbHatch" ) );
3642 writeGroup( 0, QStringLiteral(
"LWPOLYLINE" ) );
3646 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3647 writeGroup( 100, QStringLiteral(
"AcDbPolyline" ) );
3666 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3667 writeGroup( 100, QStringLiteral(
"AcDbText" ) );
3674 writeGroup( 7, QStringLiteral(
"STANDARD" ) );
3675 writeGroup( 100, QStringLiteral(
"AcDbText" ) );
3680 if ( !mTextStream.codec()->canEncode( text ) )
3683 QgsDebugMsg( QStringLiteral(
"could not encode:%1" ).arg( text ) );
3689 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3690 writeGroup( 100, QStringLiteral(
"AcDbMText" ) );
3697 while ( t.length() > 250 )
3713 writeGroup( 7, QStringLiteral(
"STANDARD" ) );
3728 geom->transform( ct );
3735 if ( mSymbologyExport !=
NoSymbology && symbolLayer )
3737 penColor = colorFromSymbolLayer( symbolLayer, ctx );
3741 Qt::PenStyle penStyle( Qt::SolidLine );
3742 Qt::BrushStyle brushStyle( Qt::NoBrush );
3744 double offset = 0.0;
3746 if ( mSymbologyExport !=
NoSymbology && symbolLayer )
3748 width = symbolLayer->
dxfWidth( *
this, ctx );
3749 offset = symbolLayer->
dxfOffset( *
this, ctx );
3750 angle = symbolLayer->
dxfAngle( ctx );
3758 QString lineStyleName = QStringLiteral(
"CONTINUOUS" );
3761 lineStyleName = lineStyleFromSymbolLayer( symbolLayer );
3767 writePoint( geom->coordinateSequence().at( 0 ).at( 0 ).at( 0 ), layer, penColor, ctx, symbolLayer, symbol,
angle );
3774 for (
int i = 0; i < cs.size(); i++ )
3776 writePoint( cs.at( i ).at( 0 ).at( 0 ), layer, penColor, ctx, symbolLayer, symbol,
angle );
3781 if ( penStyle != Qt::NoPen )
3797 if ( tempGeom != geom.get() )
3799 tempGeom = geos.
offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3801 tempGeom = geom.get();
3818 if ( tempGeom != geom.get() )
3820 tempGeom = geos.
offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3822 tempGeom = geom.get();
3826 for (
int i = 0; i < cs.size(); i++ )
3828 writePolyline( cs.at( i ).at( 0 ), layer, lineStyleName, penColor, width );
3844 if ( tempGeom != geom.get() )
3846 tempGeom = geos.
buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3848 tempGeom = geom.get();
3852 for (
int i = 0; i < cs.at( 0 ).size(); i++ )
3854 writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
3865 if ( tempGeom != geom.get() )
3867 tempGeom = geos.
buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3869 tempGeom = geom.get();
3873 for (
int i = 0; i < cs.size(); i++ )
3874 for (
int j = 0; j < cs.at( i ).size(); j++ )
3875 writePolyline( cs.at( i ).at( j ), layer, lineStyleName, penColor, width );
3884 if ( tempGeom != geom.get() )
3888 if ( brushStyle != Qt::NoBrush )
3906 for (
int i = 0; i < cs.size(); i++ )
3908 writePolygon( cs.at( i ), layer, QStringLiteral(
"SOLID" ), brushColor );
3918 if ( tempGeom != geom.get() )
3928 return symbolLayer->
dxfColor( ctx );
3931 QString QgsDxfExport::lineStyleFromSymbolLayer(
const QgsSymbolLayer *symbolLayer )
3933 QString lineStyleName = QStringLiteral(
"CONTINUOUS" );
3936 return lineStyleName;
3939 QHash< const QgsSymbolLayer *, QString >::const_iterator lineTypeIt = mLineStyles.constFind( symbolLayer );
3940 if ( lineTypeIt != mLineStyles.constEnd() )
3942 lineStyleName = lineTypeIt.value();
3943 return lineStyleName;
3947 return lineNameFromPenStyle( symbolLayer->
dxfPenStyle() );
3954 int current_distance = std::numeric_limits<int>::max();
3955 for (
int i = 1; i < static_cast< int >(
sizeof( sDxfColors ) /
sizeof( *sDxfColors ) ); ++i )
3957 int dist = color_distance( pixel, i );
3958 if ( dist < current_distance )
3960 current_distance = dist;
3969 int QgsDxfExport::color_distance( QRgb p1,
int index )
3971 if ( index > 255 || index < 0 )
3976 double redDiff = qRed( p1 ) - sDxfColors[index][0];
3977 double greenDiff = qGreen( p1 ) - sDxfColors[index][1];
3978 double blueDiff = qBlue( p1 ) - sDxfColors[index][2];
3980 QgsDebugMsg( QStringLiteral(
"color_distance( r:%1 g:%2 b:%3 <=> i:%4 r:%5 g:%6 b:%7 ) => %8" )
3981 .arg( qRed( p1 ) ).arg( qGreen( p1 ) ).arg( qBlue( p1 ) )
3983 .arg( mDxfColors[index][0] )
3984 .arg( mDxfColors[index][1] )
3985 .arg( mDxfColors[index][2] )
3986 .arg( redDiff * redDiff + greenDiff * greenDiff + blueDiff * blueDiff ) );
3988 return redDiff * redDiff + greenDiff * greenDiff + blueDiff * blueDiff;
3991 QRgb QgsDxfExport::createRgbEntry( qreal r, qreal g, qreal b )
3993 return QColor::fromRgbF( r, g, b ).rgb();
4015 return mapUnitsPerPixel;
4029 double minSizeMU = std::numeric_limits<double>::lowest();
4032 minSizeMU = scale.
minSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4036 minSizeMU = std::max( minSizeMU, value );
4038 value = std::max( value, minSizeMU );
4040 double maxSizeMU = std::numeric_limits<double>::max();
4043 maxSizeMU = scale.
maxSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4047 maxSizeMU = std::min( maxSizeMU, value );
4049 value = std::min( value, maxSizeMU );
4052 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > QgsDxfExport::symbolLayers(
QgsRenderContext &context )
4054 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers;
4056 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
4074 QgsSymbolList::iterator symbolIt = symbols.begin();
4075 for ( ; symbolIt != symbols.end(); ++symbolIt )
4077 int maxSymbolLayers = ( *symbolIt )->symbolLayerCount();
4080 maxSymbolLayers = 1;
4082 for (
int i = 0; i < maxSymbolLayers; ++i )
4084 symbolLayers.append( qMakePair( ( *symbolIt )->symbolLayer( i ), *symbolIt ) );
4089 return symbolLayers;
4092 void QgsDxfExport::writeDefaultLinetypes()
4095 const QStringList blockStrings = QStringList() << QStringLiteral(
"ByLayer" ) << QStringLiteral(
"ByBlock" ) << QStringLiteral(
"CONTINUOUS" );
4096 for (
const QString <ype : blockStrings )
4100 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
4101 writeGroup( 100, QStringLiteral(
"AcDbLinetypeTableRecord" ) );
4104 writeGroup( 3, QStringLiteral(
"Defaultstyle" ) );
4110 double das = dashSize();
4111 double dss = dashSeparatorSize();
4112 double dos = dotSize();
4114 QVector<qreal> dashVector( 2 );
4115 dashVector[0] = das;
4116 dashVector[1] = dss;
4119 QVector<qreal> dotVector( 2 );
4124 QVector<qreal> dashDotVector( 4 );
4125 dashDotVector[0] = das;
4126 dashDotVector[1] = dss;
4127 dashDotVector[2] = dos;
4128 dashDotVector[3] = dss;
4131 QVector<qreal> dashDotDotVector( 6 );
4132 dashDotDotVector[0] = das;
4133 dashDotDotVector[1] = dss;
4134 dashDotDotVector[2] = dos;
4135 dashDotDotVector[3] = dss;
4136 dashDotDotVector[4] = dos;
4137 dashDotDotVector[5] = dss;
4141 void QgsDxfExport::writeSymbolLayerLinetype(
const QgsSymbolLayer *symbolLayer )
4150 if ( !customLinestyle.isEmpty() )
4152 QString name = QStringLiteral(
"symbolLayer%1" ).arg( mSymbolLayerCounter++ );
4153 writeLinetype( name, customLinestyle, unit );
4154 mLineStyles.insert( symbolLayer, name );
4158 int QgsDxfExport::nLineTypes(
const QList< QPair< QgsSymbolLayer *, QgsSymbol * > > &symbolLayers )
4161 QList< QPair< QgsSymbolLayer *, QgsSymbol *> >::const_iterator slIt = symbolLayers.constBegin();
4162 for ( ; slIt != symbolLayers.constEnd(); ++slIt )
4176 void QgsDxfExport::writeLinetype(
const QString &styleName,
const QVector<qreal> &pattern,
QgsUnitTypes::RenderUnit u )
4179 QVector<qreal>::const_iterator dashIt = pattern.constBegin();
4180 for ( ; dashIt != pattern.constEnd(); ++dashIt )
4188 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
4189 writeGroup( 100, QStringLiteral(
"AcDbLinetypeTableRecord" ) );
4197 dashIt = pattern.constBegin();
4199 for ( ; dashIt != pattern.constEnd(); ++dashIt )
4202 double segmentLength = ( isGap ? -*dashIt : *dashIt );
4228 geomExpr.
prepare( &expressionContext );
4236 symbolExpressionContextScope->
setFeature( f );
4241 for (
int i = 0; i < nSymbolLayers; ++i )
4243 addFeature( ctx, ct, layer, symbol->
symbolLayer( i ), symbol );
4252 if ( !sl || !symbol )
4265 double QgsDxfExport::dashSize()
const 4267 double size = mSymbologyScale * 0.002;
4268 return sizeToMapUnits( size );
4271 double QgsDxfExport::dotSize()
const 4273 double size = mSymbologyScale * 0.0006;
4274 return sizeToMapUnits( size );
4277 double QgsDxfExport::dashSeparatorSize()
const 4279 double size = mSymbologyScale * 0.0006;
4280 return sizeToMapUnits( size );
4283 double QgsDxfExport::sizeToMapUnits(
double s )
const 4289 QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
4294 return QStringLiteral(
"DASH" );
4296 return QStringLiteral(
"DOT" );
4297 case Qt::DashDotLine:
4298 return QStringLiteral(
"DASHDOT" );
4299 case Qt::DashDotDotLine:
4300 return QStringLiteral(
"DASHDOTDOT" );
4303 return QStringLiteral(
"CONTINUOUS" );
4309 if ( name.isEmpty() )
4310 return QStringLiteral(
"0" );
4318 layerName.replace(
'<',
'_' );
4319 layerName.replace(
'>',
'_' );
4320 layerName.replace(
'/',
'_' );
4321 layerName.replace(
'\\',
'_' );
4322 layerName.replace(
'\"',
'_' );
4323 layerName.replace(
':',
'_' );
4324 layerName.replace(
';',
'_' );
4325 layerName.replace(
'?',
'_' );
4326 layerName.replace(
'*',
'_' );
4327 layerName.replace(
'|',
'_' );
4328 layerName.replace(
'=',
'_' );
4329 layerName.replace(
'\'',
'_' );
4332 layerName.replace( QLatin1String(
"\r\n" ), QLatin1String(
"_" ) );
4333 layerName.replace(
'\r',
'_' );
4334 layerName.replace(
'\n',
'_' );
4336 return layerName.trimmed();
4339 bool QgsDxfExport::layerIsScaleBasedVisible(
const QgsMapLayer *layer )
const 4352 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
4356 if ( vl && vl->
id() == id )
4358 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
4363 return QStringLiteral(
"0" );
4368 const QList< QByteArray > codecs = QTextCodec::availableCodecs();
4369 for (
const QByteArray &codec : codecs )
4371 if ( name != codec )
4375 for ( i = 0; i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) && name != DXF_ENCODINGS[i][1]; ++i )
4378 if ( i == static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) )
4381 return DXF_ENCODINGS[i][0];
4390 const QList< QByteArray > codecs = QTextCodec::availableCodecs();
4391 for (
const QByteArray &codec : codecs )
4394 for ( i = 0; i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) && strcmp( codec.data(), DXF_ENCODINGS[i][1] ) != 0; ++i )
4397 if ( i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) )
4398 encodings << codec.data();
4406 return mLayerTitleAsName && !vl->
title().isEmpty() ? vl->
title() : vl->
name();
4411 Q_UNUSED( context );
4424 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues = lf->
dataDefinedValues();
4429 QgsDebugMsgLevel( QStringLiteral(
"PAL font definedFont: %1, Style: %2" ).arg( dFont.toString(), dFont.styleName() ), 4 );
4459 QgsPalLabeling::dataDefinedTextStyle( tmpLyr, ddValues );
4462 QgsPalLabeling::dataDefinedTextBuffer( tmpLyr, ddValues );
4465 QgsPalLabeling::dataDefinedTextFormatting( tmpLyr, ddValues );
4471 QString dxfLayer = mDxfLayerNames[layerId][fid];
4473 QString wrapchr = tmpLyr.
wrapChar.isEmpty() ? QStringLiteral(
"\n" ) : tmpLyr.
wrapChar;
4478 bool prependSymb =
false;
4496 prependSymb =
false;
4504 symb = symb + wrapchr;
4508 prependSymb =
false;
4509 symb = wrapchr + symb;
4514 txt.prepend( symb );
4528 txt = txt.replace( wrapchr, QLatin1String(
"\\P" ) );
4529 txt.replace(
" ",
"\\~" );
4533 txt.prepend(
"\\L" ).append(
"\\l" );
4538 txt.prepend(
"\\O" ).append(
"\\o" );
4543 txt.prepend(
"\\K" ).append(
"\\k" );
4546 txt.prepend( QStringLiteral(
"\\f%1|i%2|b%3;\\H%4;" )
4548 .arg( tmpLyr.
format().
font().italic() ? 1 : 0 )
4549 .arg( tmpLyr.
format().
font().bold() ? 1 : 0 )
4550 .arg( label->
getHeight() / ( 1 + txt.count( QStringLiteral(
"\\P" ) ) ) * 0.75 ) );
4558 if ( !mDxfLayerNames.contains( layerId ) )
4559 mDxfLayerNames[ layerId ] = QMap<QgsFeatureId, QString>();
4561 mDxfLayerNames[layerId][fid] =
layerName;
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsDxfExport()=default
Constructor for QgsDxfExport.
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
Wrapper for iterator of features from vector data provider or vector layer.
QString labelText() const
Text of the label.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Base class for all map layer types.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
QString leftDirectionSymbol
String to use for left direction arrows.
void writeLine(const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Write line (as a polyline)
void clipValueToMapUnitScale(double &value, const QgsMapUnitScale &scale, double pixelToMMFactor) const
Clips value to scale minimum/maximum.
void addProvider(QgsAbstractLabelProvider *provider)
Add provider of label features. Takes ownership of the provider.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
void removeProvider(QgsAbstractLabelProvider *provider)
Remove provider if the provider's initialization failed. Provider instance is deleted.
Abstract base class for all rendered symbols.
QgsLabelFeature * feature()
Returns the parent feature.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
Restore overridden layer style on destruction.
void writeGroup(int code, int i)
Write a tuple of group code and integer value.
void writePolyline(const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Draw dxf primitives (LWPOLYLINE)
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Place direction symbols on below label.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool exists(int i) const
Returns if a field index is valid.
QVector< QgsRingSequence > QgsCoordinateSequence
QString geometryExpression() const
Gets the expression to generate this geometry.
Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
double getY(int i=0) const
Returns the down-left y coordinate.
void startRender(QgsSymbolRenderContext &context) override
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Implements a derived label provider for rule based labels internally used for DXF export...
void setRendererScale(double scale)
Sets the renderer map scale.
void setFont(const QFont &font)
Sets the font used for rendering text.
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
Gets data-defined values.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const override
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
void registerDxfLayer(const QString &layerId, QgsFeatureId fid, const QString &layer)
Register name of layer for feature.
static int closestColorMatch(QRgb color)
Gets DXF palette index of nearest entry for given color.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QColor color() const
Returns the color that text will be rendered in.
Class that adds extra information to QgsLabelFeature for text labels.
static QStringList encodings()
Returns list of available DXF encodings.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
bool addDirectionSymbol
If true, '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be ...
void setMapSettings(const QgsMapSettings &mapSettings)
Associate map settings instance.
void registerDxfFeature(QgsFeature &feature, QgsRenderContext &context, const QString &dxfLayerName)
Registration method that keeps track of DXF layer names of individual features.
QgsDxfExport::Flags flags() const
Returns the export flags.
A geometry is the spatial representation of a feature.
bool drawLabels
Whether to draw labels for this layer.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
QgsUnitTypes::DistanceUnit mapUnits
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets line width.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
bool hasGeometry() const
Returns true if the feature has an associated geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
Rotation of symbol may be changed during rendering and symbol should not be cached.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
bool reverseDirectionSymbol
True if direction symbols should be reversed.
double maxScale
The maximum scale, or 0.0 if unset.
void setFlags(QgsDxfExport::Flags flags)
Sets the export flags.
void writeInt(int i)
Write an integer value.
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
void writePolygon(const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor &color)
Draw dxf filled polygon (HATCH)
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
QList< QgsSymbolLevel > QgsSymbolLevelOrder
The QgsMapSettings class contains configuration for rendering of the map.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
void setMapSettings(const QgsMapSettings &settings)
Set map settings and assign layer name attributes.
void writeString(const QString &s)
Write a string value.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
void reinit(QgsVectorLayer *layer)
Reinitialize the subproviders with QgsDxfLabelProviders.
int writeToFile(QIODevice *d, const QString &codec)
Export to a dxf file in the given encoding.
Perform transforms between map coordinates and device coordinates.
void writePoint(const QString &layer, const QColor &color, const QgsPoint &pt)
Write point.
int renderingPass() const
Type
The WKB type describes the number of dimensions a geometry has.
QList< QgsSymbol * > QgsSymbolList
void setOutputSize(QSize size)
Sets the size of the resulting map image.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Set destination CRS.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
double size() const
Returns the symbol size.
void writeGroupCode(int code)
Write a group code.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void registerDxfFeature(const QgsFeature &feature, QgsRenderContext &context, const QString &dxfLayerName)
Registration method that keeps track of DXF layer names of individual features.
virtual Qt::BrushStyle dxfBrushStyle() const
Gets brush/fill style.
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Quadrant getQuadrant() const
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
void writeFilledCircle(const QString &layer, const QColor &color, const QgsPoint &pt, double radius)
Write filled circle (as hatch)
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
QgsFeatureRenderer * renderer()
Returns renderer.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
bool useCustomDashPattern() const
Single scope for storing variables and functions for use within a QgsExpressionContext.
Abstract base class for all geometries.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Does vector analysis using the geos library and handles import, export, exception handling*...
void writeText(const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor &color)
Write text (TEXT)
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layer contained in the symbol.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS, or an invalid CRS if no reprojection will be done.
Point geometry type, with support for z-dimension and m-values.
const QgsMapToPixel & mapToPixel() const
static QString dxfEncoding(const QString &name)
Returns DXF encoding for Qt encoding.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
QString layerName(const QString &id, const QgsFeature &f) const
Gets layer name for feature.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
Gets brush/fill color.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Contains geos related utilities and functions.
Place direction symbols on above label.
void drawLabel(const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings)
Output the label.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsExpressionContext & expressionContext()
Gets the expression context.
DistanceUnit
Units of distance.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QVector< QgsPoint > QgsPointSequence
void setFeature(const QgsFeature *f)
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
QString wrapChar
Wrapping character string.
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
static QString dxfLayerName(const QString &name)
Returns cleaned layer name for use in DXF.
QVector< QgsPointSequence > QgsRingSequence
QgsAbstractGeometry * offsetCurve(double distance, int segments, int joinStyle, double miterLimit, QString *errorMsg=nullptr) const override
QString rightDirectionSymbol
String to use for right direction arrows.
The QgsLabelingEngine class provides map labeling functionality.
void run(QgsRenderContext &context)
compute the labeling with given map settings and providers
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
Contains information about the context of a rendering operation.
Abstract base class for marker symbol layers.
void writeCircle(const QString &layer, const QColor &color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width)
Write circle (as polyline)
QFont definedFont()
Font to be used for rendering.
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
const QgsMapToPixel & mapToPixel() const
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
QList< QgsSymbolLevelItem > QgsSymbolLevel
double getAlpha() const
Returns the angle to rotate text (in rad).
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
Struct for storing maximum and minimum scales for measurements in map units.
virtual double dxfAngle(QgsSymbolRenderContext &context) const
Gets angle.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol's size.
double getX(int i=0) const
Returns the down-left x coordinate.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
RenderHints renderHints() const
Returns the rendering hint flags for the symbol.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsFeature * feature() const
Current feature being rendered - may be null.
This class represents a coordinate reference system (CRS).
void writeDouble(double d)
Write a floating point value.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
void setMapToPixel(const QgsMapToPixel &mtp)
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
LabelPosition is a candidate feature label position.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
void stopRender(QgsSymbolRenderContext &context) override
QgsPointXY center() const
Returns the center point of the rectangle.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
Implements a derived label provider internally used for DXF export.
#define DXF_HANDPLOTSTYLE
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
Container for all settings relating to text rendering.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
int writeHandle(int code=5, int handle=0)
Write a tuple of group code and a handle.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Represents a vector layer which manages a vector based data sets.
double minScale
The minimum scale, or 0.0 if unset.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
static Type flatType(Type type)
Returns the flat type for a WKB type.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
QFont font() const
Returns the font used for rendering text.
void writeMText(const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor &color)
Write mtext (MTEXT)
void addLayers(const QList< QgsDxfExport::DxfLayer > &layers)
Add layers to export.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsDxfExport & operator=(const QgsDxfExport &dxfExport)
RenderUnit
Rendering size units.
double height() const
Returns the height of the rectangle.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
virtual QString layerType() const =0
Returns a string that represents this layer type.
DirectionSymbols placeDirectionSymbol
Placement option for direction symbols.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Exports one feature per symbol layer (considering symbol levels)
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.