Skip to content
Permalink
Browse files
Use QgsSettings and add unit test
  • Loading branch information
mhugent authored and nyalldawson committed Jun 21, 2021
1 parent a544ba3 commit fe00f74b86c14441fafb14e2296e70f8f93327da
Showing with 21 additions and 2 deletions.
  1. +1 −2 src/core/project/qgsproject.cpp
  2. +20 −0 tests/src/core/testqgsproject.cpp
@@ -844,8 +844,7 @@ void QgsProject::clear()
writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/Automatic" ), true );
writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DecimalPlaces" ), 2 );

QSettings s;
bool defaultRelativePaths = s.value( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), true ).toBool();
bool defaultRelativePaths = mSettings.value( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), true ).toBool();
writeEntry( QStringLiteral( "Paths" ), QStringLiteral( "/Absolute" ), !defaultRelativePaths );

//copy default units to project
@@ -54,6 +54,7 @@ class TestQgsProject : public QObject
void projectSaveUser();
void testCrsExpressions();
void testCrsValidAfterReadingProjectFile();
void testDefaultRelativePaths();
};

void TestQgsProject::init()
@@ -699,5 +700,24 @@ void TestQgsProject::testCrsExpressions()
QCOMPARE( r.toString(), QString( "EPSG:7030" ) );
}

void TestQgsProject::testDefaultRelativePaths()
{
QgsSettings s;
bool bk_defaultRelativePaths = s.value( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), QVariant( true ) ).toBool();

s.setValue( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), true );
QgsProject p1;
bool p1PathsAbsolute = p1.readBoolEntry( QStringLiteral( "Paths" ), QStringLiteral( "/Absolute" ), false );

s.setValue( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), false );
QgsProject p2;
bool p2PathsAbsolute = p2.readBoolEntry( QStringLiteral( "Paths" ), QStringLiteral( "/Absolute" ), false );

s.setValue( QStringLiteral( "/qgis/defaultProjectPathsRelative" ), bk_defaultRelativePaths );

QCOMPARE( p1PathsAbsolute, false );
QCOMPARE( p2PathsAbsolute, true );
}

QGSTEST_MAIN( TestQgsProject )
#include "testqgsproject.moc"

0 comments on commit fe00f74

Please sign in to comment.