mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-30 00:29:39 -05:00
Merge pull request #47467 from elpaso/bugfix-47465-advanced-digitizing-decimal-separator
Advanced digitizing: be nice with non-dot locales
This commit is contained in:
commit
25588d2c6d
@ -616,9 +616,37 @@ double QgsAdvancedDigitizingDockWidget::parseUserInput( const QString &inputValu
|
||||
QgsExpression expr( inputValue );
|
||||
const QVariant result = expr.evaluate();
|
||||
if ( expr.hasEvalError() )
|
||||
{
|
||||
ok = false;
|
||||
QString inputValueC { inputValue };
|
||||
|
||||
// First: try removing group separator
|
||||
if ( inputValue.contains( QLocale().groupSeparator() ) )
|
||||
{
|
||||
inputValueC.remove( QLocale().groupSeparator() );
|
||||
QgsExpression exprC( inputValueC );
|
||||
const QVariant resultC = exprC.evaluate();
|
||||
if ( ! exprC.hasEvalError() )
|
||||
{
|
||||
value = resultC.toDouble( &ok );
|
||||
}
|
||||
}
|
||||
|
||||
// Second: be nice with non-dot locales
|
||||
if ( !ok && QLocale().decimalPoint() != QChar( '.' ) && inputValueC.contains( QLocale().decimalPoint() ) )
|
||||
{
|
||||
QgsExpression exprC( inputValueC .replace( QLocale().decimalPoint(), QChar( '.' ) ) );
|
||||
const QVariant resultC = exprC.evaluate();
|
||||
if ( ! exprC.hasEvalError() )
|
||||
{
|
||||
value = resultC.toDouble( &ok );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = result.toDouble( &ok );
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -960,13 +960,15 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
|
||||
// Snap indicator
|
||||
|
||||
QgsPointLocator::Match mSnapMatch;
|
||||
private:
|
||||
|
||||
#ifdef SIP_RUN
|
||||
//! event filter for line edits in the dock UI (angle/distance/x/y line edits)
|
||||
bool eventFilter( QObject *obj, QEvent *event );
|
||||
#endif
|
||||
//! Convenient method to convert a 2D Point to a QgsPoint
|
||||
QgsPoint pointXYToPoint( const QgsPointXY &point ) const;
|
||||
|
||||
friend class TestQgsAdvancedDigitizingDockWidget;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
|
||||
|
||||
@ -24,6 +24,7 @@ endif()
|
||||
#ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)
|
||||
|
||||
set(TESTS
|
||||
testqgsadvanceddigitizingdockwidget.cpp
|
||||
testqgsannotationitemguiregistry.cpp
|
||||
testqgsmaptoolzoom.cpp
|
||||
testqgsmaptooledit.cpp
|
||||
|
||||
107
tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp
Normal file
107
tests/src/gui/testqgsadvanceddigitizingdockwidget.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
testqgsadvanceddigitizingdockwidget.cpp
|
||||
--------------------------------------
|
||||
Date : February 2022
|
||||
Copyright : (C) 2022 Alessandro Pasotti
|
||||
Email : elpaso at itopen dot it
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
#include <QCoreApplication>
|
||||
#include <QLocale>
|
||||
|
||||
#include "qgstest.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsadvanceddigitizingdockwidget.h"
|
||||
|
||||
class TestQgsAdvancedDigitizingDockWidget : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TestQgsAdvancedDigitizingDockWidget() = default;
|
||||
|
||||
private slots:
|
||||
void initTestCase(); // will be called before the first testfunction is executed.
|
||||
void cleanupTestCase(); // will be called after the last testfunction was executed.
|
||||
void init(); // will be called before each testfunction is executed.
|
||||
void cleanup(); // will be called after every testfunction.
|
||||
|
||||
void parseUserInput();
|
||||
|
||||
};
|
||||
|
||||
void TestQgsAdvancedDigitizingDockWidget::initTestCase()
|
||||
{
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
QgsApplication::showSettings();
|
||||
}
|
||||
|
||||
void TestQgsAdvancedDigitizingDockWidget::cleanupTestCase()
|
||||
{
|
||||
QgsApplication::exitQgis();
|
||||
}
|
||||
|
||||
void TestQgsAdvancedDigitizingDockWidget::init()
|
||||
{
|
||||
}
|
||||
|
||||
void TestQgsAdvancedDigitizingDockWidget::cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
void TestQgsAdvancedDigitizingDockWidget::parseUserInput()
|
||||
{
|
||||
QgsProject::instance()->clear();
|
||||
QgsMapCanvas canvas;
|
||||
QgsAdvancedDigitizingDockWidget widget{ &canvas };
|
||||
|
||||
bool ok;
|
||||
double result;
|
||||
|
||||
QLocale::setDefault( QLocale::English );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1.2345" ), ok );
|
||||
QCOMPARE( result, 1.2345 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1,234.5" ), ok );
|
||||
QCOMPARE( result, 1234.5 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1,200.6/2" ), ok );
|
||||
QCOMPARE( result, 600.3 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1200.6/2" ), ok );
|
||||
QCOMPARE( result, 600.3 );
|
||||
QVERIFY( ok );
|
||||
|
||||
QLocale::setDefault( QLocale::Italian );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1,2345" ), ok );
|
||||
QCOMPARE( result, 1.2345 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1.234,5" ), ok );
|
||||
QCOMPARE( result, 1234.5 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1.200,6/2" ), ok );
|
||||
QCOMPARE( result, 600.3 );
|
||||
QVERIFY( ok );
|
||||
|
||||
result = widget.parseUserInput( QStringLiteral( "1200,6/2" ), ok );
|
||||
QCOMPARE( result, 600.3 );
|
||||
QVERIFY( ok );
|
||||
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsAdvancedDigitizingDockWidget )
|
||||
#include "testqgsadvanceddigitizingdockwidget.moc"
|
||||
Loading…
x
Reference in New Issue
Block a user