Skip to content

Commit

Permalink
Use QgsSettings and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and nyalldawson committed Jun 21, 2021
1 parent a544ba3 commit fe00f74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/core/project/qgsproject.cpp
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/src/core/testqgsproject.cpp
Expand Up @@ -54,6 +54,7 @@ class TestQgsProject : public QObject
void projectSaveUser();
void testCrsExpressions();
void testCrsValidAfterReadingProjectFile();
void testDefaultRelativePaths();
};

void TestQgsProject::init()
Expand Down Expand Up @@ -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.