Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore position of thousands seperators when editing scale combo box
... be more permissive about the conversion from string to number after a value is entered in the combo box (fix #12385)
- Loading branch information
1 parent
c98ae01
commit a4d17c0
Showing
7 changed files
with
212 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/*************************************************************************** | ||
testqgis.cpp | ||
------------ | ||
Date : March 2015 | ||
Copyright : (C) 2015 by Nyall Dawson | ||
Email : nyall.dawson@gmail.com | ||
*************************************************************************** | ||
* * | ||
* 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 <QtTest/QtTest> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QApplication> | ||
|
||
//qgis includes... | ||
#include <qgis.h> | ||
|
||
/** \ingroup UnitTests | ||
* Includes unit tests for the QGis namespace | ||
*/ | ||
class TestQGis : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
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 permissiveToDouble(); | ||
void permissiveToInt(); | ||
|
||
private: | ||
QString mReport; | ||
}; | ||
|
||
//runs before all tests | ||
void TestQGis::initTestCase() | ||
{ | ||
mReport = "<h1>QGis Tests</h1>\n"; | ||
} | ||
|
||
//runs after all tests | ||
void TestQGis::cleanupTestCase() | ||
{ | ||
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html"; | ||
QFile myFile( myReportFile ); | ||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) | ||
{ | ||
QTextStream myQTextStream( &myFile ); | ||
myQTextStream << mReport; | ||
myFile.close(); | ||
} | ||
} | ||
|
||
void TestQGis::permissiveToDouble() | ||
{ | ||
//good inputs | ||
bool ok = false; | ||
double result = QGis::permissiveToDouble( QString( "1000" ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000.0 ); | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000.0 ); | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "5.5" ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 5.5 ); | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "1%01000.5" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000.5 ); | ||
|
||
//bad input | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "a" ), ok ); | ||
QVERIFY( !ok ); | ||
|
||
//messy input (invalid thousand seperator position), should still be converted | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "10%0100" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000.0 ); | ||
ok = false; | ||
result = QGis::permissiveToDouble( QString( "10%0100.5" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000.5 ); | ||
} | ||
|
||
void TestQGis::permissiveToInt() | ||
{ | ||
//good inputs | ||
bool ok = false; | ||
int result = QGis::permissiveToInt( QString( "1000" ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000 ); | ||
ok = false; | ||
result = QGis::permissiveToInt( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000 ); | ||
|
||
//bad input | ||
ok = false; | ||
result = QGis::permissiveToInt( QString( "a" ), ok ); | ||
QVERIFY( !ok ); | ||
|
||
//messy input (invalid thousand seperator position), should still be converted | ||
ok = false; | ||
result = QGis::permissiveToInt( QString( "10%0100" ).arg( QLocale::system().groupSeparator() ), ok ); | ||
QVERIFY( ok ); | ||
QCOMPARE( result, 1000 ); | ||
} | ||
|
||
QTEST_MAIN( TestQGis ) | ||
#include "testqgis.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters