@@ -213,6 +213,10 @@ QgsPalLayerSettings::QgsPalLayerSettings()
213
213
vectorScaleFactor = 1.0 ;
214
214
rasterCompressFactor = 1.0 ;
215
215
addDirectionSymbol = false ;
216
+ leftDirectionSymbol = QString ( " <" );
217
+ rightDirectionSymbol = QString ( " >" );
218
+ reverseDirectionSymbol = false ;
219
+ placeDirectionSymbol = SymbolLeftRight;
216
220
upsidedownLabels = Upright;
217
221
fontSizeInMapUnits = false ;
218
222
fontLimitPixelSize = false ;
@@ -266,6 +270,10 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
266
270
vectorScaleFactor = s.vectorScaleFactor ;
267
271
rasterCompressFactor = s.rasterCompressFactor ;
268
272
addDirectionSymbol = s.addDirectionSymbol ;
273
+ leftDirectionSymbol = s.leftDirectionSymbol ;
274
+ rightDirectionSymbol = s.rightDirectionSymbol ;
275
+ reverseDirectionSymbol = s.reverseDirectionSymbol ;
276
+ placeDirectionSymbol = s.placeDirectionSymbol ;
269
277
upsidedownLabels = s.upsidedownLabels ;
270
278
fontSizeInMapUnits = s.fontSizeInMapUnits ;
271
279
fontLimitPixelSize = s.fontLimitPixelSize ;
@@ -433,7 +441,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
433
441
textFont.setWordSpacing ( layer->customProperty ( " labeling/fontWordSpacing" , QVariant ( 0.0 ) ).toDouble () );
434
442
textColor = _readColor ( layer, " labeling/textColor" );
435
443
textTransp = layer->customProperty ( " labeling/textTransp" ).toInt ();
436
- previewBkgrdColor = QColor ( layer->customProperty ( " labeling/previewBkgrdColor" , " #ffffff" ).toString () );
444
+ previewBkgrdColor = QColor ( layer->customProperty ( " labeling/previewBkgrdColor" , QVariant ( " #ffffff" ) ).toString () );
437
445
enabled = layer->customProperty ( " labeling/enabled" ).toBool ();
438
446
priority = layer->customProperty ( " labeling/priority" ).toInt ();
439
447
obstacle = layer->customProperty ( " labeling/obstacle" ).toBool ();
@@ -452,6 +460,10 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
452
460
displayAll = layer->customProperty ( " labeling/displayAll" , QVariant ( false ) ).toBool ();
453
461
mergeLines = layer->customProperty ( " labeling/mergeLines" ).toBool ();
454
462
addDirectionSymbol = layer->customProperty ( " labeling/addDirectionSymbol" ).toBool ();
463
+ leftDirectionSymbol = layer->customProperty ( " labeling/leftDirectionSymbol" , QVariant ( " <" ) ).toString ();
464
+ rightDirectionSymbol = layer->customProperty ( " labeling/rightDirectionSymbol" , QVariant ( " >" ) ).toString ();
465
+ reverseDirectionSymbol = layer->customProperty ( " labeling/reverseDirectionSymbol" ).toBool ();
466
+ placeDirectionSymbol = ( DirectionSymbols ) layer->customProperty ( " labeling/placeDirectionSymbol" , QVariant ( SymbolLeftRight ) ).toUInt ();
455
467
upsidedownLabels = ( UpsideDownLabels ) layer->customProperty ( " labeling/upsidedownLabels" , QVariant ( Upright ) ).toUInt ();
456
468
minFeatureSize = layer->customProperty ( " labeling/minFeatureSize" ).toDouble ();
457
469
fontSizeInMapUnits = layer->customProperty ( " labeling/fontSizeInMapUnits" ).toBool ();
@@ -516,6 +528,10 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
516
528
layer->setCustomProperty ( " labeling/displayAll" , displayAll );
517
529
layer->setCustomProperty ( " labeling/mergeLines" , mergeLines );
518
530
layer->setCustomProperty ( " labeling/addDirectionSymbol" , addDirectionSymbol );
531
+ layer->setCustomProperty ( " labeling/leftDirectionSymbol" , leftDirectionSymbol );
532
+ layer->setCustomProperty ( " labeling/rightDirectionSymbol" , rightDirectionSymbol );
533
+ layer->setCustomProperty ( " labeling/reverseDirectionSymbol" , reverseDirectionSymbol );
534
+ layer->setCustomProperty ( " labeling/placeDirectionSymbol" , ( unsigned int )placeDirectionSymbol );
519
535
layer->setCustomProperty ( " labeling/upsidedownLabels" , ( unsigned int )upsidedownLabels );
520
536
layer->setCustomProperty ( " labeling/minFeatureSize" , minFeatureSize );
521
537
layer->setCustomProperty ( " labeling/fontSizeInMapUnits" , fontSizeInMapUnits );
@@ -587,18 +603,29 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
587
603
return ;
588
604
}
589
605
606
+ QString wrapchr = !wrapChar.isEmpty () ? wrapChar : QString ( " \n " );
607
+
590
608
// consider the space needed for the direction symbol
591
- if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line )
609
+ if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line
610
+ && ( !leftDirectionSymbol.isEmpty () || !rightDirectionSymbol.isEmpty () ) )
592
611
{
593
- text.append ( " >" );
612
+ QString dirSym = leftDirectionSymbol;
613
+
614
+ if ( fm->width ( rightDirectionSymbol ) > fm->width ( dirSym ) )
615
+ dirSym = rightDirectionSymbol;
616
+
617
+ if ( placeDirectionSymbol == QgsPalLayerSettings::SymbolLeftRight )
618
+ {
619
+ text.append ( dirSym );
620
+ }
621
+ else
622
+ {
623
+ text.append ( dirSym + wrapchr ); // SymbolAbove or SymbolBelow
624
+ }
594
625
}
595
626
596
627
double w = 0.0 , h = 0.0 ;
597
- QStringList multiLineSplit;
598
- if ( !wrapChar.isEmpty () )
599
- multiLineSplit = text.split ( wrapChar );
600
- else
601
- multiLineSplit = text.split ( " \n " );
628
+ QStringList multiLineSplit = text.split ( wrapchr );
602
629
int lines = multiLineSplit.size ();
603
630
604
631
double labelHeight = fm->ascent () + fm->descent (); // ignore +1 for baseline
@@ -1722,28 +1749,59 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
1722
1749
QString txt = ( label->getPartId () == -1 ? text : QString ( text[label->getPartId ()] ) );
1723
1750
QFontMetricsF* labelfm = (( QgsPalGeometry* )label->getFeaturePart ()->getUserGeometry () )->getLabelFontMetrics ();
1724
1751
1752
+ QString wrapchr = !lyr.wrapChar .isEmpty () ? lyr.wrapChar : QString ( " \n " );
1753
+
1725
1754
// add the direction symbol if needed
1726
1755
if ( !txt.isEmpty () && lyr.placement == QgsPalLayerSettings::Line &&
1727
1756
lyr.addDirectionSymbol )
1728
1757
{
1758
+ bool prependSymb = false ;
1759
+ QString symb = lyr.rightDirectionSymbol ;
1760
+
1729
1761
if ( label->getReversed () )
1730
1762
{
1731
- txt.prepend ( " <" );
1763
+ prependSymb = true ;
1764
+ symb = lyr.leftDirectionSymbol ;
1765
+ }
1766
+
1767
+ if ( lyr.reverseDirectionSymbol )
1768
+ {
1769
+ if ( symb == lyr.rightDirectionSymbol )
1770
+ {
1771
+ prependSymb = true ;
1772
+ symb = lyr.leftDirectionSymbol ;
1773
+ }
1774
+ else
1775
+ {
1776
+ prependSymb = false ;
1777
+ symb = lyr.rightDirectionSymbol ;
1778
+ }
1779
+ }
1780
+
1781
+ if ( lyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
1782
+ {
1783
+ prependSymb = true ;
1784
+ symb = symb + wrapchr;
1785
+ }
1786
+ else if ( lyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
1787
+ {
1788
+ prependSymb = false ;
1789
+ symb = wrapchr + symb;
1790
+ }
1791
+
1792
+ if ( prependSymb )
1793
+ {
1794
+ txt.prepend ( symb );
1732
1795
}
1733
1796
else
1734
1797
{
1735
- txt.append ( " > " );
1798
+ txt.append ( symb );
1736
1799
}
1737
1800
}
1738
1801
1739
1802
// QgsDebugMsg( "drawLabel " + QString::number( drawBuffer ) + " " + txt );
1740
1803
1741
- QStringList multiLineList;
1742
- if ( !lyr.wrapChar .isEmpty () )
1743
- multiLineList = txt.split ( lyr.wrapChar );
1744
- else
1745
- multiLineList = txt.split ( " \n " );
1746
-
1804
+ QStringList multiLineList = txt.split ( wrapchr );
1747
1805
int lines = multiLineList.size ();
1748
1806
1749
1807
double labelWidest = 0.0 ;
0 commit comments