Skip to content

Commit 713e22a

Browse files
committedJul 21, 2016
Move some methods out of Qgis class
1 parent 1a2231f commit 713e22a

File tree

6 files changed

+59
-56
lines changed

6 files changed

+59
-56
lines changed
 

‎doc/api_break.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ This page tries to maintain a list with incompatible changes that happened in pr
4545

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

5052
\subsection qgis_api_break_3_0_QgsAuthConfigUriEdit QgsAuthConfigUriEdit

‎python/core/qgis.sip

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,6 @@ class Qgis
180180
//! @deprecated use QgsUnitTyoes::fromUnitToUnitFactor() instead
181181
static double fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUnit ) /Deprecated/;
182182

183-
/** Converts a string to a double in a permissive way, eg allowing for incorrect
184-
* numbers of digits between thousand separators
185-
* @param string string to convert
186-
* @param ok will be set to true if conversion was successful
187-
* @returns string converted to double if possible
188-
* @note added in version 2.9
189-
* @see permissiveToInt
190-
*/
191-
static double permissiveToDouble( QString string, bool& ok );
192-
193-
/** Converts a string to an integer in a permissive way, eg allowing for incorrect
194-
* numbers of digits between thousand separators
195-
* @param string string to convert
196-
* @param ok will be set to true if conversion was successful
197-
* @returns string converted to int if possible
198-
* @note added in version 2.9
199-
* @see permissiveToDouble
200-
*/
201-
static int permissiveToInt( QString string, bool& ok );
202-
203183
//! User defined event types
204184
enum UserEvent
205185
{
@@ -243,6 +223,27 @@ class Qgis
243223
static double SCALE_PRECISION;
244224
};
245225

226+
227+
/** Converts a string to a double in a permissive way, eg allowing for incorrect
228+
* numbers of digits between thousand separators
229+
* @param string string to convert
230+
* @param ok will be set to true if conversion was successful
231+
* @returns string converted to double if possible
232+
* @note added in version 2.9
233+
* @see permissiveToInt
234+
*/
235+
double qgsPermissiveToDouble( QString string, bool& ok );
236+
237+
/** Converts a string to an integer in a permissive way, eg allowing for incorrect
238+
* numbers of digits between thousand separators
239+
* @param string string to convert
240+
* @param ok will be set to true if conversion was successful
241+
* @returns string converted to int if possible
242+
* @note added in version 2.9
243+
* @see permissiveToDouble
244+
*/
245+
int qgsPermissiveToInt( QString string, bool& ok );
246+
246247
//! Compares two QVariant values and returns whether the first is less than the second.
247248
//! Useful for sorting lists of variants, correctly handling sorting of the various
248249
//! QVariant data types (such as strings, numeric values, dates and times)

‎src/core/qgis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ double Qgis::fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUni
217217
return QgsUnitTypes::fromUnitToUnitFactor( fromUnit, toUnit );
218218
}
219219

220-
double Qgis::permissiveToDouble( QString string, bool &ok )
220+
double qgsPermissiveToDouble( QString string, bool &ok )
221221
{
222222
//remove any thousands separators
223223
string.remove( QLocale::system().groupSeparator() );
224224
return QLocale::system().toDouble( string, &ok );
225225
}
226226

227-
int Qgis::permissiveToInt( QString string, bool &ok )
227+
int qgsPermissiveToInt( QString string, bool &ok )
228228
{
229229
//remove any thousands separators
230230
string.remove( QLocale::system().groupSeparator() );

‎src/core/qgis.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,6 @@ class CORE_EXPORT Qgis
194194
//! @deprecated use QgsUnitTyoes::fromUnitToUnitFactor() instead
195195
Q_DECL_DEPRECATED static double fromUnitToUnitFactor( Qgis::UnitType fromUnit, Qgis::UnitType toUnit );
196196

197-
/** Converts a string to a double in a permissive way, eg allowing for incorrect
198-
* numbers of digits between thousand separators
199-
* @param string string to convert
200-
* @param ok will be set to true if conversion was successful
201-
* @returns string converted to double if possible
202-
* @note added in version 2.9
203-
* @see permissiveToInt
204-
*/
205-
static double permissiveToDouble( QString string, bool& ok );
206-
207-
/** Converts a string to an integer in a permissive way, eg allowing for incorrect
208-
* numbers of digits between thousand separators
209-
* @param string string to convert
210-
* @param ok will be set to true if conversion was successful
211-
* @returns string converted to int if possible
212-
* @note added in version 2.9
213-
* @see permissiveToDouble
214-
*/
215-
static int permissiveToInt( QString string, bool& ok );
216-
217197
//! User defined event types
218198
enum UserEvent
219199
{
@@ -388,6 +368,26 @@ inline double qgsRound( double x )
388368
return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
389369
}
390370

371+
/** Converts a string to a double in a permissive way, eg allowing for incorrect
372+
* numbers of digits between thousand separators
373+
* @param string string to convert
374+
* @param ok will be set to true if conversion was successful
375+
* @returns string converted to double if possible
376+
* @note added in version 2.9
377+
* @see permissiveToInt
378+
*/
379+
CORE_EXPORT double qgsPermissiveToDouble( QString string, bool& ok );
380+
381+
/** Converts a string to an integer in a permissive way, eg allowing for incorrect
382+
* numbers of digits between thousand separators
383+
* @param string string to convert
384+
* @param ok will be set to true if conversion was successful
385+
* @returns string converted to int if possible
386+
* @note added in version 2.9
387+
* @see permissiveToDouble
388+
*/
389+
CORE_EXPORT int qgsPermissiveToInt( QString string, bool& ok );
390+
391391
// Add missing qHash implementation for QDate, QTime, QDateTime
392392
// implementations taken from upstream Qt5 versions
393393
#if QT_VERSION < 0x050000

‎src/gui/qgsscalecombobox.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
209209
bool ok = false;
210210
QString scaleTxt( scaleString );
211211

212-
double scale = Qgis::permissiveToDouble( scaleTxt, ok );
212+
double scale = qgsPermissiveToDouble( scaleTxt, ok );
213213
if ( ok )
214214
{
215215
// Create a text version and set that text and rescan
@@ -224,8 +224,8 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
224224
{
225225
bool okX = false;
226226
bool okY = false;
227-
int x = Qgis::permissiveToInt( txtList[ 0 ], okX );
228-
int y = Qgis::permissiveToInt( txtList[ 1 ], okY );
227+
int x = qgsPermissiveToInt( txtList[ 0 ], okX );
228+
int y = qgsPermissiveToInt( txtList[ 1 ], okY );
229229
if ( okX && okY )
230230
{
231231
// Scale is fraction of x and y

‎tests/src/core/testqgis.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,34 @@ void TestQgis::permissiveToDouble()
6969
{
7070
//good inputs
7171
bool ok = false;
72-
double result = Qgis::permissiveToDouble( QString( "1000" ), ok );
72+
double result = qgsPermissiveToDouble( QString( "1000" ), ok );
7373
QVERIFY( ok );
7474
QCOMPARE( result, 1000.0 );
7575
ok = false;
76-
result = Qgis::permissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000", ok );
76+
result = qgsPermissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000", ok );
7777
QVERIFY( ok );
7878
QCOMPARE( result, 1000.0 );
7979
ok = false;
80-
result = Qgis::permissiveToDouble( QString( "5" ) + QLocale::system().decimalPoint() + "5", ok );
80+
result = qgsPermissiveToDouble( QString( "5" ) + QLocale::system().decimalPoint() + "5", ok );
8181
QVERIFY( ok );
8282
QCOMPARE( result, 5.5 );
8383
ok = false;
84-
result = Qgis::permissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000" + QLocale::system().decimalPoint() + "5", ok );
84+
result = qgsPermissiveToDouble( QString( "1" ) + QLocale::system().groupSeparator() + "000" + QLocale::system().decimalPoint() + "5", ok );
8585
QVERIFY( ok );
8686
QCOMPARE( result, 1000.5 );
8787

8888
//bad input
8989
ok = false;
90-
( void ) Qgis::permissiveToDouble( QString( "a" ), ok );
90+
( void ) qgsPermissiveToDouble( QString( "a" ), ok );
9191
QVERIFY( !ok );
9292

9393
//messy input (invalid thousand separator position), should still be converted
9494
ok = false;
95-
result = Qgis::permissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00", ok );
95+
result = qgsPermissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00", ok );
9696
QVERIFY( ok );
9797
QCOMPARE( result, 1000.0 );
9898
ok = false;
99-
result = Qgis::permissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00" + QLocale::system().decimalPoint() + "5", ok );
99+
result = qgsPermissiveToDouble( QString( "10" ) + QLocale::system().groupSeparator() + "00" + QLocale::system().decimalPoint() + "5", ok );
100100
QVERIFY( ok );
101101
QCOMPARE( result, 1000.5 );
102102
}
@@ -105,22 +105,22 @@ void TestQgis::permissiveToInt()
105105
{
106106
//good inputs
107107
bool ok = false;
108-
int result = Qgis::permissiveToInt( QString( "1000" ), ok );
108+
int result = qgsPermissiveToInt( QString( "1000" ), ok );
109109
QVERIFY( ok );
110110
QCOMPARE( result, 1000 );
111111
ok = false;
112-
result = Qgis::permissiveToInt( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok );
112+
result = qgsPermissiveToInt( QString( "1%01000" ).arg( QLocale::system().groupSeparator() ), ok );
113113
QVERIFY( ok );
114114
QCOMPARE( result, 1000 );
115115

116116
//bad input
117117
ok = false;
118-
( void ) Qgis::permissiveToInt( QString( "a" ), ok );
118+
( void ) qgsPermissiveToInt( QString( "a" ), ok );
119119
QVERIFY( !ok );
120120

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

0 commit comments

Comments
 (0)
Please sign in to comment.