@@ -633,17 +633,17 @@ static QVariant fcnTrim( const QVariantList& values, const QgsFeature* , QgsExpr
633
633
634
634
static QVariant fcnWordwrap ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
635
635
{
636
- if (values.length () > 1 )
636
+ if ( values.length () == 2 || values. length () == 3 )
637
637
{
638
638
QString str = getStringValue ( values.at ( 0 ), parent );
639
- int wrap = getIntValue ( values.at (1 ), parent );
639
+ int wrap = getIntValue ( values.at ( 1 ), parent );
640
640
641
- if (!str.isEmpty () && wrap != 0 )
641
+ if ( !str.isEmpty () && wrap != 0 )
642
642
{
643
643
QString newstr;
644
644
QString delimiterstr;
645
- if (values.length () == 3 ) delimiterstr = getStringValue ( values.at (2 ), parent );
646
- if (delimiterstr.isEmpty ()) delimiterstr = " " ;
645
+ if ( values.length () == 3 ) delimiterstr = getStringValue ( values.at ( 2 ), parent );
646
+ if ( delimiterstr.isEmpty () ) delimiterstr = " " ;
647
647
int delimiterlength = delimiterstr.length ();
648
648
649
649
QStringList lines = str.split ( " \n " );
@@ -656,32 +656,38 @@ static QVariant fcnWordwrap( const QVariantList& values, const QgsFeature* , Qgs
656
656
strhit = 0 ;
657
657
lasthit = 0 ;
658
658
659
- while (strcurrent < strlength)
659
+ while ( strcurrent < strlength )
660
660
{
661
661
// positive wrap value = desired maximum line width to wrap
662
662
// negative wrap value = desired minimum line width before wrap
663
- if (wrap > 0 )
663
+ if ( wrap > 0 )
664
664
{
665
665
// first try to locate delimiter backwards
666
- strhit = lines[i].lastIndexOf ( delimiterstr, strcurrent + wrap);
667
- if (strhit == lasthit || strhit == -1 ) {
666
+ strhit = lines[i].lastIndexOf ( delimiterstr, strcurrent + wrap );
667
+ if ( strhit == lasthit || strhit == -1 )
668
+ {
668
669
// if no new backward delimiter found, try to locate forward
669
- strhit = lines[i].indexOf ( delimiterstr, strcurrent + qAbs (wrap) );
670
- }
670
+ strhit = lines[i].indexOf ( delimiterstr, strcurrent + qAbs ( wrap ) );
671
+ }
671
672
lasthit = strhit;
672
- } else {
673
- strhit = lines[i].indexOf ( delimiterstr, strcurrent + qAbs (wrap) );
674
673
}
675
- if (strhit > -1 ) {
674
+ else
675
+ {
676
+ strhit = lines[i].indexOf ( delimiterstr, strcurrent + qAbs ( wrap ) );
677
+ }
678
+ if ( strhit > -1 )
679
+ {
676
680
newstr.append ( lines[i].midRef ( strcurrent , strhit - strcurrent ) );
677
681
newstr.append ( " \n " );
678
682
strcurrent = strhit + delimiterlength;
679
- } else {
683
+ }
684
+ else
685
+ {
680
686
newstr.append ( lines[i].midRef ( strcurrent ) );
681
687
strcurrent = strlength;
682
688
}
683
689
}
684
- if (i < lines.size () - 1 ) newstr.append ( " \n " );
690
+ if ( i < lines.size () - 1 ) newstr.append ( " \n " );
685
691
}
686
692
687
693
return QVariant ( newstr );
0 commit comments