Skip to content
Permalink
Browse files

Move some methods out of Qgis class

  • Loading branch information
nyalldawson committed Jul 21, 2016
1 parent 1a2231f commit 713e22a9f5a383201b7ccd3e4e3fb490554d5a58
Showing with 59 additions and 56 deletions.
  1. +2 −0 doc/api_break.dox
  2. +21 −20 python/core/qgis.sip
  3. +2 −2 src/core/qgis.cpp
  4. +20 −20 src/core/qgis.h
  5. +3 −3 src/gui/qgsscalecombobox.cpp
  6. +11 −11 tests/src/core/testqgis.cpp
@@ -45,6 +45,8 @@ This page tries to maintain a list with incompatible changes that happened in pr

<ul>
<li>The QGis class was renamed to Qgis for capitalisation consistency with other class names</li>
<li>permissiveToDouble() and permissiveToInt() where moved out of the QGis class and renamed to qgsPermissiveToDouble() and
qgsPermissiveToInt()</li>
</ul>

\subsection qgis_api_break_3_0_QgsAuthConfigUriEdit QgsAuthConfigUriEdit
@@ -180,26 +180,6 @@ class Qgis
//! @deprecated use QgsUnitTyoes::fromUnitToUnitFactor() instead
static double fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUnit ) /Deprecated/;

/** Converts a string to a double in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to double if possible
* @note added in version 2.9
* @see permissiveToInt
*/
static double permissiveToDouble( QString string, bool& ok );

/** Converts a string to an integer in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to int if possible
* @note added in version 2.9
* @see permissiveToDouble
*/
static int permissiveToInt( QString string, bool& ok );

//! User defined event types
enum UserEvent
{
@@ -243,6 +223,27 @@ class Qgis
static double SCALE_PRECISION;
};


/** Converts a string to a double in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to double if possible
* @note added in version 2.9
* @see permissiveToInt
*/
double qgsPermissiveToDouble( QString string, bool& ok );

/** Converts a string to an integer in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to int if possible
* @note added in version 2.9
* @see permissiveToDouble
*/
int qgsPermissiveToInt( QString string, bool& ok );

//! Compares two QVariant values and returns whether the first is less than the second.
//! Useful for sorting lists of variants, correctly handling sorting of the various
//! QVariant data types (such as strings, numeric values, dates and times)
@@ -217,14 +217,14 @@ double Qgis::fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUni
return QgsUnitTypes::fromUnitToUnitFactor( fromUnit, toUnit );
}

double Qgis::permissiveToDouble( QString string, bool &ok )
double qgsPermissiveToDouble( QString string, bool &ok )
{
//remove any thousands separators
string.remove( QLocale::system().groupSeparator() );
return QLocale::system().toDouble( string, &ok );
}

int Qgis::permissiveToInt( QString string, bool &ok )
int qgsPermissiveToInt( QString string, bool &ok )
{
//remove any thousands separators
string.remove( QLocale::system().groupSeparator() );
@@ -194,26 +194,6 @@ class CORE_EXPORT Qgis
//! @deprecated use QgsUnitTyoes::fromUnitToUnitFactor() instead
Q_DECL_DEPRECATED static double fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUnit );

/** Converts a string to a double in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to double if possible
* @note added in version 2.9
* @see permissiveToInt
*/
static double permissiveToDouble( QString string, bool& ok );

/** Converts a string to an integer in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to int if possible
* @note added in version 2.9
* @see permissiveToDouble
*/
static int permissiveToInt( QString string, bool& ok );

//! User defined event types
enum UserEvent
{
@@ -388,6 +368,26 @@ inline double qgsRound( double x )
return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
}

/** Converts a string to a double in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to double if possible
* @note added in version 2.9
* @see permissiveToInt
*/
CORE_EXPORT double qgsPermissiveToDouble( QString string, bool& ok );

/** Converts a string to an integer in a permissive way, eg allowing for incorrect
* numbers of digits between thousand separators
* @param string string to convert
* @param ok will be set to true if conversion was successful
* @returns string converted to int if possible
* @note added in version 2.9
* @see permissiveToDouble
*/
CORE_EXPORT int qgsPermissiveToInt( QString string, bool& ok );

// Add missing qHash implementation for QDate, QTime, QDateTime
// implementations taken from upstream Qt5 versions
#if QT_VERSION < 0x050000
@@ -209,7 +209,7 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
bool ok = false;
QString scaleTxt( scaleString );

double scale = Qgis::permissiveToDouble( scaleTxt, ok );
double scale = qgsPermissiveToDouble( scaleTxt, ok );
if ( ok )
{
// Create a text version and set that text and rescan
@@ -224,8 +224,8 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
{
bool okX = false;
bool okY = false;
int x = Qgis::permissiveToInt( txtList[ 0 ], okX );
int y = Qgis::permissiveToInt( txtList[ 1 ], okY );
int x = qgsPermissiveToInt( txtList[ 0 ], okX );
int y = qgsPermissiveToInt( txtList[ 1 ], okY );
if ( okX && okY )
{
// Scale is fraction of x and y
@@ -69,34 +69,34 @@ void TestQgis::permissiveToDouble()
{
//good inputs
bool ok = false;
double result = Qgis::permissiveToDouble( QString( "1000" ), ok );
double result = qgsPermissiveToDouble( QString( "1000" ), ok );
QVERIFY( ok );
QCOMPARE( result, 1000.0 );
ok = false;
result = Qgis::permissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000", ok );
result = qgsPermissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000", ok );
QVERIFY( ok );
QCOMPARE( result, 1000.0 );
ok = false;
result = Qgis::permissiveToDouble( QString( "5" ) + QLocale::system().decimalPoint() + "5", ok );
result = qgsPermissiveToDouble( QString( "5" ) + QLocale::system().decimalPoint() + "5", ok );
QVERIFY( ok );
QCOMPARE( result, 5.5 );
ok = false;
result = Qgis::permissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000" + QLocale::system().decimalPoint() + "5", ok );
result = qgsPermissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000" + QLocale::system().decimalPoint() + "5", ok );
QVERIFY( ok );
QCOMPARE( result, 1000.5 );

//bad input
ok = false;
( void ) Qgis::permissiveToDouble( QString( "a" ), ok );
( void ) qgsPermissiveToDouble( QString( "a" ), ok );
QVERIFY( !ok );

//messy input (invalid thousand separator position), should still be converted
ok = false;
result = Qgis::permissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00", ok );
result = qgsPermissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00", ok );
QVERIFY( ok );
QCOMPARE( result, 1000.0 );
ok = false;
result = Qgis::permissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00" + QLocale::system().decimalPoint() + "5", ok );
result = qgsPermissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00" + QLocale::system().decimalPoint() + "5", ok );
QVERIFY( ok );
QCOMPARE( result, 1000.5 );
}
@@ -105,22 +105,22 @@ void TestQgis::permissiveToInt()
{
//good inputs
bool ok = false;
int result = Qgis::permissiveToInt( QString( "1000" ), ok );
int result = qgsPermissiveToInt( QString( "1000" ), ok );
QVERIFY( ok );
QCOMPARE( result, 1000 );
ok = false;
result = Qgis::permissiveToInt( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok );
result = qgsPermissiveToInt( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok );
QVERIFY( ok );
QCOMPARE( result, 1000 );

//bad input
ok = false;
( void ) Qgis::permissiveToInt( QString( "a" ), ok );
( void ) qgsPermissiveToInt( QString( "a" ), ok );
QVERIFY( !ok );

//messy input (invalid thousand separator position), should still be converted
ok = false;
result = Qgis::permissiveToInt( QString( "10%0100" ).arg( QLocale::system().groupSeparator() ), ok );
result = qgsPermissiveToInt( QString( "10%0100" ).arg( QLocale::system().groupSeparator() ), ok );
QVERIFY( ok );
QCOMPARE( result, 1000 );
}

0 comments on commit 713e22a

Please sign in to comment.
You can’t perform that action at this time.