Skip to content

Commit 421c030

Browse files
committed
Move dxf dash writing into separated function
1 parent 608b3ff commit 421c030

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

src/core/qgsdxfexport.cpp

+39-35
Original file line numberDiff line numberDiff line change
@@ -939,42 +939,8 @@ void QgsDxfExport::writeSymbolLayerLinestyle( QTextStream& stream, const QgsSymb
939939
{
940940
++mSymbolLayerCounter;
941941
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter );
942-
943942
QVector<qreal> dashPattern = simpleLine->customDashVector();
944-
double length = 0;
945-
QVector<qreal>::const_iterator dashIt = dashPattern.constBegin();
946-
for ( ; dashIt != dashPattern.constEnd(); ++dashIt )
947-
{
948-
length += *dashIt;
949-
}
950-
951-
stream << " 0\n";
952-
stream << "LTYPE\n";
953-
stream << " 2\n";
954-
stream << QString( "%1\n" ).arg( name );
955-
stream << " 70\n";
956-
stream << "64\n";
957-
stream << " 3\n";
958-
stream << "\n";
959-
stream << " 72\n";
960-
stream << "65\n";
961-
stream << " 73\n";
962-
stream << QString( "%1\n" ).arg( dashPattern.size() ); //number of segments
963-
stream << " 40\n"; //total length of segments
964-
stream << QString( "%1\n" ).arg( length );
965-
966-
dashIt = dashPattern.constBegin();
967-
bool isSpace = false;
968-
for ( ; dashIt != dashPattern.constEnd(); ++dashIt )
969-
{
970-
stream << " 49\n";
971-
972-
//map units or mm?
973-
double segmentLength = ( isSpace ? -*dashIt : *dashIt );
974-
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, simpleLine->customDashPatternUnit(), mMapUnits );
975-
stream << QString( "%1\n" ).arg( segmentLength );
976-
isSpace = !isSpace;
977-
}
943+
writeLinestyle( stream, name, dashPattern, simpleLine->customDashPatternUnit() );
978944
mLineStyles.insert( symbolLayer, name );
979945
}
980946
}
@@ -997,3 +963,41 @@ int QgsDxfExport::nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers )
997963
}
998964
return nLineTypes;
999965
}
966+
967+
void QgsDxfExport::writeLinestyle( QTextStream& stream, const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u )
968+
{
969+
double length = 0;
970+
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
971+
for ( ; dashIt != pattern.constEnd(); ++dashIt )
972+
{
973+
length += *dashIt;
974+
}
975+
976+
stream << " 0\n";
977+
stream << "LTYPE\n";
978+
stream << " 2\n";
979+
stream << QString( "%1\n" ).arg( styleName );
980+
stream << " 70\n";
981+
stream << "64\n";
982+
stream << " 3\n";
983+
stream << "\n";
984+
stream << " 72\n";
985+
stream << "65\n";
986+
stream << " 73\n";
987+
stream << QString( "%1\n" ).arg( pattern.size() ); //number of segments
988+
stream << " 40\n"; //total length of segments
989+
stream << QString( "%1\n" ).arg( length );
990+
991+
dashIt = pattern.constBegin();
992+
bool isSpace = false;
993+
for ( ; dashIt != pattern.constEnd(); ++dashIt )
994+
{
995+
stream << " 49\n";
996+
997+
//map units or mm?
998+
double segmentLength = ( isSpace ? -*dashIt : *dashIt );
999+
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits );
1000+
stream << QString( "%1\n" ).arg( segmentLength );
1001+
isSpace = !isSpace;
1002+
}
1003+
}

src/core/qgsdxfexport.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class QgsDxfExport
105105
static int nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers );
106106

107107
void writeSymbolLayerLinestyle( QTextStream& stream, const QgsSymbolLayerV2* symbolLayer );
108+
void writeLinestyle( QTextStream& stream, const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );
108109
};
109110

110111
#endif // QGSDXFEXPORT_H

0 commit comments

Comments
 (0)