Skip to content

Commit 6f2045f

Browse files
authored
fix QgsProject::readNumEntry() validity check (#4112)
1 parent 0f5b3fd commit 6f2045f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core/qgsproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ int QgsProject::readNumEntry( const QString& scope, const QString &key, int def,
14321432
value = property->value();
14331433
}
14341434

1435-
bool valid = value.canConvert( QVariant::String );
1435+
bool valid = value.canConvert( QVariant::Int );
14361436

14371437
if ( ok )
14381438
{

tests/src/python/test_qgsproject.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
# This will get replaced with a git SHA1 when you do a git archive
1515
__revision__ = '$Format:%H$'
1616

17+
import os
18+
1719
import qgis # NOQA
1820

1921
from qgis.core import QgsProject, QgsApplication, QgsUnitTypes, QgsCoordinateReferenceSystem
2022

2123
from qgis.testing import start_app, unittest
24+
from utilities import (unitTestDataPath)
2225

2326
start_app()
27+
TEST_DATA_DIR = unitTestDataPath()
2428

2529

2630
class TestQgsProject(unittest.TestCase):
@@ -140,5 +144,14 @@ def testAreaUnits(self):
140144
prj.setAreaUnits(QgsUnitTypes.AreaSquareFeet)
141145
self.assertEqual(prj.areaUnits(), QgsUnitTypes.AreaSquareFeet)
142146

147+
def testReadEntry(self):
148+
prj = QgsProject.instance()
149+
prj.read(os.path.join(TEST_DATA_DIR, 'labeling/test-labeling.qgs'))
150+
151+
#valid key, valid int value
152+
self.assertEqual(prj.readNumEntry("SpatialRefSys", "/ProjectionsEnabled", -1)[0], 0)
153+
#invalid key
154+
self.assertEqual(prj.readNumEntry("SpatialRefSys", "/InvalidKey", -1)[0], -1)
155+
143156
if __name__ == '__main__':
144157
unittest.main()

0 commit comments

Comments
 (0)