Dxf export: modify layer name to be a valid dxf layer name

This commit is contained in:
Marco Hugentobler 2013-12-11 08:27:38 +01:00
parent b1b7904e14
commit 8405ddb876
2 changed files with 36 additions and 3 deletions

View File

@ -467,7 +467,7 @@ void QgsDxfExport::writeTables()
{
writeGroup( 0, "LAYER" );
QString layerName = *layerIt ? ( *layerIt )->name() : "";
writeGroup( 2, layerName );
writeGroup( 2, dxfLayerName( layerName ) );
writeGroup( 70, 64 );
writeGroup( 62, 1 );
writeGroup( 6, "CONTINUOUS" );
@ -577,7 +577,7 @@ void QgsDxfExport::writeEntities()
{
if ( mSymbologyExport == NoSymbology )
{
addFeature( fet, vl->name(), 0, 0 ); //no symbology at all
addFeature( fet, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
}
else
{
@ -597,7 +597,7 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( fet, vl->name(), s->symbolLayer( 0 ), s );
addFeature( fet, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
}
}
renderer->stopRender( ctx );
@ -1331,6 +1331,38 @@ QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
}
}
QString QgsDxfExport::dxfLayerName( const QString& name )
{
//dxf layers can be max 31 characters long
QString layerName = name.left( 31 );
//allowed characters are 0-9, A-Z, $, -, _
for ( int i = 0; i < layerName.size(); ++i )
{
QChar c = layerName.at( i );
if ( c > 122 )
{
layerName[i] = '_';
continue;
}
if ( c.isNumber() )
{
continue;
}
if ( c == '$' || c == '-' || c == '_' )
{
continue;
}
if ( !c.isLetter() )
{
layerName[i] = '_';
}
}
return layerName;
}
/******************************************************Test with AC_1018 methods***************************************************************/
void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )

View File

@ -160,6 +160,7 @@ class CORE_EXPORT QgsDxfExport
double dashSeparatorSize() const;
double sizeToMapUnits( double s ) const;
static QString lineNameFromPenStyle( Qt::PenStyle style );
static QString dxfLayerName( const QString& name );
};
#endif // QGSDXFEXPORT_H