Skip to content

Commit

Permalink
As per discussion with @nyalldawson , move away from isChrDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 7, 2023
1 parent 9cbb32b commit 238e280
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
33 changes: 14 additions & 19 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3478,18 +3478,13 @@ QgsSymbolLayer *QgsFontMarkerSymbolLayer::create( const QVariantMap &props )
if ( props.contains( QStringLiteral( "chr" ) ) && props[QStringLiteral( "chr" )].toString().length() > 0 )
{
string = props["chr"].toString();
if ( props.contains( QStringLiteral( "chrIsDecimal" ) ) && props["chrIsDecimal"].toBool() )
const thread_local QRegularExpression charRegExp( QStringLiteral( "%1([0-9]+)%1" ).arg( FONTMARKER_CHR_FIX ) );
QRegularExpressionMatch match = charRegExp.match( string );
while ( match.hasMatch() )
{
string = QChar( props["chr"].toString().toUShort() );
}
else
{
const thread_local QRegularExpression charRegExp( QStringLiteral( "%1([0-9]+)%1" ).arg( FONTMARKER_CHR_FIX ) );
const QRegularExpressionMatch charMatch = charRegExp.match( string );
if ( charMatch.hasMatch() )
{
string = QChar( charMatch.captured( 1 ).toUShort() );
}
QChar replacement = QChar( match.captured( 1 ).toUShort() );
string = string.mid( 0, match.capturedStart( 0 ) ) + replacement + string.mid( match.capturedEnd( 0 ) );
match = charRegExp.match( string );
}
}

Expand Down Expand Up @@ -3815,16 +3810,16 @@ QVariantMap QgsFontMarkerSymbolLayer::properties() const
QVariantMap props;
props[QStringLiteral( "font" )] = mFontFamily;
props[QStringLiteral( "font_style" )] = mFontStyle;
if ( mString.size() == 1 )
QString chr = mString;
for ( int i = 0; i < 32; i++ )
{
props[QStringLiteral( "chr" )] = QString::number( mString.at( 0 ).unicode() );
props[QStringLiteral( "chrIsDecimal" )] = true;
}
else
{
props[QStringLiteral( "chr" )] = mString;
props["chrIsDecimal"] = false;
if ( i == 9 || i == 10 || i == 13 )
{
continue;
}
chr.replace( QChar( i ), QStringLiteral( "%1%2%1" ).arg( FONTMARKER_CHR_FIX, QString::number( i ) ) );
}
props[QStringLiteral( "chr" )] = chr;
props[QStringLiteral( "size" )] = QString::number( mSize );
props[QStringLiteral( "size_unit" )] = QgsUnitTypes::encodeUnit( mSizeUnit );
props[QStringLiteral( "size_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mSizeMapUnitScale );
Expand Down
7 changes: 3 additions & 4 deletions tests/src/python/test_qgssymbollayerutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,7 @@ def test_font_marker_load(self):
<layer pass="0" id="{2aefc556-4eb1-4f56-b96b-e1dea6b58f69}" locked="0" class="FontMarker" enabled="1">
<Option type="Map">
<Option value="0" type="QString" name="angle"/>
<Option value="14" type="int" name="chr"/>
<Option value="true" type="bool" name="chrIsDecimal"/>
<Option value="~!_#!#_!~14~!_#!#_!~" type="QString" name="chr"/>
<Option value="0,0,255,255" type="QString" name="color"/>
<Option value="Arial" type="QString" name="font"/>
<Option value="Italic" type="QString" name="font_style"/>
Expand Down Expand Up @@ -797,7 +796,7 @@ def test_font_marker_load(self):
<layer pass="0" id="{2aefc556-4eb1-4f56-b96b-e1dea6b58f69}" locked="0" class="FontMarker" enabled="1">
<Option type="Map">
<Option value="0" type="QString" name="angle"/>
<Option value="~!_#!#_!~14~!_#!#_!~" type="QString" name="chr"/>
<Option value="~!_#!#_!~40~!_#!#_!~~!_#!#_!~41~!_#!#_!~" type="QString" name="chr"/>
<Option value="0,0,255,255" type="QString" name="color"/>
<Option value="Arial" type="QString" name="font"/>
<Option value="Italic" type="QString" name="font_style"/>
Expand All @@ -821,7 +820,7 @@ def test_font_marker_load(self):
doc.setContent(font_marker_xml_string)
elem = doc.documentElement()
font_marker = QgsSymbolLayerUtils.loadSymbol(elem, QgsReadWriteContext())
self.assertEqual(font_marker.symbolLayers()[0].character(), chr(14))
self.assertEqual(font_marker.symbolLayers()[0].character(), "()")


if __name__ == '__main__':
Expand Down

0 comments on commit 238e280

Please sign in to comment.