Skip to content

Commit

Permalink
Merge pull request #9880 from troopa81/fix_pointpick_precision
Browse files Browse the repository at this point in the history
Fix point picking precision for point parameters in processing dialog
  • Loading branch information
luipir committed Apr 30, 2019
2 parents a665eac + 9cfaf10 commit 0f01359
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -2205,7 +2205,10 @@ void QgsProcessingPointPanel::clear()

void QgsProcessingPointPanel::setValue( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs )
{
QString newText = QStringLiteral( "%1,%2" ).arg( point.x() ).arg( point.y() );
QString newText = QStringLiteral( "%1,%2" )
.arg( QString::number( point.x(), 'f' ) )
.arg( QString::number( point.y(), 'f' ) );

mCrs = crs;
if ( mCrs.isValid() )
{
Expand Down
30 changes: 17 additions & 13 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -2834,26 +2834,30 @@ void TestProcessingGui::testPointPanel()
QSignalSpy spy( panel.get(), &QgsProcessingPointPanel::changed );

panel->setValue( QgsPointXY( 100, 150 ), QgsCoordinateReferenceSystem() );
QCOMPARE( panel->value().toString(), QStringLiteral( "100,150" ) );
QCOMPARE( panel->value().toString(), QStringLiteral( "100.000000,150.000000" ) );
QCOMPARE( spy.count(), 1 );

panel->setValue( QgsPointXY( 200, 250 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) );
QCOMPARE( panel->value().toString(), QStringLiteral( "200,250 [EPSG:3111]" ) );
QCOMPARE( panel->value().toString(), QStringLiteral( "200.000000,250.000000 [EPSG:3111]" ) );
QCOMPARE( spy.count(), 2 );

panel->setValue( QgsPointXY( 123456.123456789, 654321.987654321 ), QgsCoordinateReferenceSystem() );
QCOMPARE( panel->value().toString(), QStringLiteral( "123456.123457,654321.987654" ) );
QCOMPARE( spy.count(), 3 );

QVERIFY( !panel->mLineEdit->showClearButton() );
panel->setAllowNull( true );
QVERIFY( panel->mLineEdit->showClearButton() );
panel->clear();
QVERIFY( !panel->value().isValid() );
QCOMPARE( spy.count(), 3 );
QCOMPARE( spy.count(), 4 );

QgsMapCanvas canvas;
canvas.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) );
panel->setMapCanvas( &canvas );
panel->updatePoint( QgsPointXY( 1.5, -3.5 ) );
QCOMPARE( panel->value().toString(), QStringLiteral( "1.5,-3.5 [EPSG:28356]" ) );
QCOMPARE( spy.count(), 4 );
QCOMPARE( panel->value().toString(), QStringLiteral( "1.500000,-3.500000 [EPSG:28356]" ) );
QCOMPARE( spy.count(), 5 );

panel.reset();
}
Expand All @@ -2875,8 +2879,8 @@ void TestProcessingGui::testPointWrapper()
QCOMPARE( spy.count(), 1 );
if ( type != QgsProcessingGui::Modeler )
{
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "1,2" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1,2" ) );
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "1.000000,2.000000" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1.000000,2.000000" ) );
}
else
{
Expand All @@ -2887,8 +2891,8 @@ void TestProcessingGui::testPointWrapper()
QCOMPARE( spy.count(), 2 );
if ( type != QgsProcessingGui::Modeler )
{
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "1,2 [EPSG:3111]" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1,2 [EPSG:3111]" ) );
QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "1.000000,2.000000 [EPSG:3111]" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1.000000,2.000000 [EPSG:3111]" ) );
}
else
{
Expand Down Expand Up @@ -2935,8 +2939,8 @@ void TestProcessingGui::testPointWrapper()
QCOMPARE( spy2.count(), 1 );
if ( type != QgsProcessingGui::Modeler )
{
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper2.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1,2" ) );
QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "1,2" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper2.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1.000000,2.000000" ) );
QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "1.000000,2.000000" ) );
}
else
{
Expand All @@ -2948,8 +2952,8 @@ void TestProcessingGui::testPointWrapper()
QCOMPARE( spy2.count(), 2 );
if ( type != QgsProcessingGui::Modeler )
{
QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "1,2 [EPSG:3111]" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper2.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1,2 [EPSG:3111]" ) );
QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "1.000000,2.000000 [EPSG:3111]" ) );
QCOMPARE( static_cast< QgsProcessingPointPanel * >( wrapper2.wrappedWidget() )->mLineEdit->text(), QStringLiteral( "1.000000,2.000000 [EPSG:3111]" ) );
}
else
{
Expand Down

0 comments on commit 0f01359

Please sign in to comment.