diff --git a/src/core/symbology/qgsrulebasedrenderer.cpp b/src/core/symbology/qgsrulebasedrenderer.cpp index 0e189903f5d..145afbe92a9 100644 --- a/src/core/symbology/qgsrulebasedrenderer.cpp +++ b/src/core/symbology/qgsrulebasedrenderer.cpp @@ -1636,23 +1636,25 @@ QgsRuleBasedRenderer *QgsRuleBasedRenderer::convertFromRenderer( const QgsFeatur auto rule = std::make_unique< QgsRuleBasedRenderer::Rule >( nullptr ); rule->setLabel( range.label() ); + const QString upperValue = QString::number( range.upperValue(), 'f', 16 ); + const QString lowerValue = QString::number( range.lowerValue(), 'f', 16 ); // Lower and upper boundaries have to be open-ended if ( i == 0 ) { expression = !isInverted ? - QStringLiteral( "%1 <= %2" ).arg( attr, QString::number( range.upperValue(), 'f' ) ) : - QStringLiteral( "%1 > %2" ).arg( attr, QString::number( range.lowerValue(), 'f' ) ); + QStringLiteral( "%1 <= %2" ).arg( attr, upperValue ) : + QStringLiteral( "%1 > %2" ).arg( attr, lowerValue ); } else if ( i == ranges.size() - 1 ) { expression = !isInverted ? - QStringLiteral( "%1 > %2" ).arg( attr, QString::number( range.lowerValue(), 'f' ) ) : - QStringLiteral( "%1 <= %2" ).arg( attr, QString::number( range.upperValue(), 'f' ) ); + QStringLiteral( "%1 > %2" ).arg( attr, lowerValue ) : + QStringLiteral( "%1 <= %2" ).arg( attr, upperValue ); } else { - expression = attr + " > " + QString::number( range.lowerValue(), 'f' ) + " AND " + \ - attr + " <= " + QString::number( range.upperValue(), 'f' ); + expression = attr + " > " + lowerValue + " AND " + \ + attr + " <= " + upperValue; } rule->setFilterExpression( expression ); diff --git a/tests/src/core/testqgsrulebasedrenderer.cpp b/tests/src/core/testqgsrulebasedrenderer.cpp index c5fd57367cb..e76ad39db64 100644 --- a/tests/src/core/testqgsrulebasedrenderer.cpp +++ b/tests/src/core/testqgsrulebasedrenderer.cpp @@ -978,9 +978,9 @@ class TestQgsRuleBasedRenderer : public QgsTest std::unique_ptr r( QgsRuleBasedRenderer::convertFromRenderer( c.get(), layer.get() ) ); QCOMPARE( r->rootRule()->children().size(), 3 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.000000 AND \"id\" <= 2.000000" ); - QCOMPARE( r->rootRule()->children()[2]->filterExpression(), "\"id\" > 2.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.0000000000000000 AND \"id\" <= 2.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[2]->filterExpression(), "\"id\" > 2.0000000000000000" ); // Next try the same with inverted ranges ranges.clear(); @@ -991,9 +991,9 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get(), layer.get() ) ); QCOMPARE( r->rootRule()->children().size(), 3 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" > 2.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.000000 AND \"id\" <= 2.000000" ); - QCOMPARE( r->rootRule()->children()[2]->filterExpression(), "\"id\" <= 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" > 2.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.0000000000000000 AND \"id\" <= 2.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[2]->filterExpression(), "\"id\" <= 1.0000000000000000" ); // Next try with an expression based range ranges.clear(); @@ -1003,8 +1003,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get(), layer.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(id / 2) <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(id / 2) > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(id / 2) <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(id / 2) > 1.0000000000000000" ); // Last try with an expression which is just a quoted field name ranges.clear(); @@ -1014,8 +1014,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get(), layer.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.0000000000000000" ); // Next try with a complex name ranges.clear(); @@ -1025,8 +1025,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get(), layer.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"fa_cy-fie+ld\" <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"fa_cy-fie+ld\" > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"fa_cy-fie+ld\" <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"fa_cy-fie+ld\" > 1.0000000000000000" ); } void testConvertFromGraduatedRendererNoLayer() @@ -1055,8 +1055,8 @@ class TestQgsRuleBasedRenderer : public QgsTest std::unique_ptr r( QgsRuleBasedRenderer::convertFromRenderer( c.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.0000000000000000" ); // Next try with an expression based range ranges.clear(); @@ -1066,8 +1066,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(id / 2) <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(id / 2) > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(id / 2) <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(id / 2) > 1.0000000000000000" ); // Last try with an expression which is just a quoted field name ranges.clear(); @@ -1077,8 +1077,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "\"id\" <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "\"id\" > 1.0000000000000000" ); // Next try with a complex name -- in this case since we don't have a layer or // actual field names available, we must assume the complex field name is actually an expression @@ -1089,8 +1089,8 @@ class TestQgsRuleBasedRenderer : public QgsTest r.reset( QgsRuleBasedRenderer::convertFromRenderer( c.get() ) ); QCOMPARE( r->rootRule()->children().size(), 2 ); - QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(fa_cy-fie+ld) <= 1.000000" ); - QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(fa_cy-fie+ld) > 1.000000" ); + QCOMPARE( r->rootRule()->children()[0]->filterExpression(), "(fa_cy-fie+ld) <= 1.0000000000000000" ); + QCOMPARE( r->rootRule()->children()[1]->filterExpression(), "(fa_cy-fie+ld) > 1.0000000000000000" ); } void testConvertFromEmbedded()