Skip to content

Commit

Permalink
Fix graduated classification label range
Browse files Browse the repository at this point in the history
Fix #51691
  • Loading branch information
elpaso authored and nyalldawson committed Feb 1, 2023
1 parent 9fb0da4 commit 9d7dae6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/classification/qgsclassificationmethod.cpp
Expand Up @@ -343,5 +343,5 @@ QString QgsClassificationMethod::labelForRange( const double lowerValue, const d
const QString lowerLabel = valueToLabel( lowerValue );
const QString upperLabel = valueToLabel( upperValue );

return labelFormat().arg( lowerLabel, upperLabel );
return labelFormat().replace( QStringLiteral( "%1" ), lowerLabel ).replace( QStringLiteral( "%2" ), upperLabel );
}
15 changes: 15 additions & 0 deletions tests/src/python/test_qgsclassificationmethod.py
Expand Up @@ -163,6 +163,21 @@ def testQgsClassificationFixedIntervalInvalidInterval(self):
self.assertEqual(QgsClassificationMethod.rangesToBreaks(r),
[57.0])

def testQgsClassificationFixedIntervalLabelForRange(self):

m = QgsClassificationFixedInterval()

# lowerValue, upperValue, labelFormat, expected
cases = (
(1, 2, '%1 - %2', '1 - 2'),
(1, 2, '%1', '1'),
(1, 2, '%2', '2'),
)

for lowerValue, upperValue, labelFormat, expected in cases:
m.setLabelFormat(labelFormat)
self.assertEqual(m.labelForRange(lowerValue, upperValue), expected)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/src/python/test_qgsgraduatedsymbolrenderer.py
Expand Up @@ -251,6 +251,7 @@ def testQgsRendererRangeLabelFormat_2(self):
("%1%1", "1.231.23"),
("from %1 to %2 meters", "from 1.23 to 2.34 meters"),
("from %2 to %1 meters", "from 2.34 to 1.23 meters"),
("< %2", "< 2.34"),
)
format.setPrecision(2)
format.setTrimTrailingZeroes(False)
Expand Down

0 comments on commit 9d7dae6

Please sign in to comment.