Merge branch 'master' into fix-advanced-digitizing-snapping

This commit is contained in:
Antoine Facchini 2022-02-22 12:56:59 +01:00 committed by GitHub
commit 7e3ea242d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -966,7 +966,7 @@ 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 );
@ -975,6 +975,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
QgsPoint pointXYToPoint( const QgsPointXY &point ) const;
friend class TestQgsAdvancedDigitizing;
friend class TestQgsAdvancedDigitizingDockWidget;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )

View File

@ -24,6 +24,7 @@ endif()
#ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)
set(TESTS
testqgsadvanceddigitizingdockwidget.cpp
testqgsannotationitemguiregistry.cpp
testqgsmaptoolzoom.cpp
testqgsmaptooledit.cpp

View 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"