Skip to content

Commit 8405ddb

Browse files
committed
Dxf export: modify layer name to be a valid dxf layer name
1 parent b1b7904 commit 8405ddb

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/core/dxf/qgsdxfexport.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void QgsDxfExport::writeTables()
467467
{
468468
writeGroup( 0, "LAYER" );
469469
QString layerName = *layerIt ? ( *layerIt )->name() : "";
470-
writeGroup( 2, layerName );
470+
writeGroup( 2, dxfLayerName( layerName ) );
471471
writeGroup( 70, 64 );
472472
writeGroup( 62, 1 );
473473
writeGroup( 6, "CONTINUOUS" );
@@ -577,7 +577,7 @@ void QgsDxfExport::writeEntities()
577577
{
578578
if ( mSymbologyExport == NoSymbology )
579579
{
580-
addFeature( fet, vl->name(), 0, 0 ); //no symbology at all
580+
addFeature( fet, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
581581
}
582582
else
583583
{
@@ -597,7 +597,7 @@ void QgsDxfExport::writeEntities()
597597
{
598598
continue;
599599
}
600-
addFeature( fet, vl->name(), s->symbolLayer( 0 ), s );
600+
addFeature( fet, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
601601
}
602602
}
603603
renderer->stopRender( ctx );
@@ -1331,6 +1331,38 @@ QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
13311331
}
13321332
}
13331333

1334+
QString QgsDxfExport::dxfLayerName( const QString& name )
1335+
{
1336+
//dxf layers can be max 31 characters long
1337+
QString layerName = name.left( 31 );
1338+
1339+
//allowed characters are 0-9, A-Z, $, -, _
1340+
for ( int i = 0; i < layerName.size(); ++i )
1341+
{
1342+
QChar c = layerName.at( i );
1343+
if ( c > 122 )
1344+
{
1345+
layerName[i] = '_';
1346+
continue;
1347+
}
1348+
1349+
if ( c.isNumber() )
1350+
{
1351+
continue;
1352+
}
1353+
if ( c == '$' || c == '-' || c == '_' )
1354+
{
1355+
continue;
1356+
}
1357+
1358+
if ( !c.isLetter() )
1359+
{
1360+
layerName[i] = '_';
1361+
}
1362+
}
1363+
return layerName;
1364+
}
1365+
13341366
/******************************************************Test with AC_1018 methods***************************************************************/
13351367

13361368
void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )

src/core/dxf/qgsdxfexport.h

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class CORE_EXPORT QgsDxfExport
160160
double dashSeparatorSize() const;
161161
double sizeToMapUnits( double s ) const;
162162
static QString lineNameFromPenStyle( Qt::PenStyle style );
163+
static QString dxfLayerName( const QString& name );
163164
};
164165

165166
#endif // QGSDXFEXPORT_H

0 commit comments

Comments
 (0)