Skip to content

Commit cada3a2

Browse files
committed
fix
1 parent 88eaa23 commit cada3a2

5 files changed

Lines changed: 29 additions & 17 deletions

File tree

gui/manualtest/projectfiledialog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
Some manual testing in the project file dialog interface
55

66

7+
## Test: Relative paths
8+
9+
Ticket: #14983
10+
11+
1. Configure files/paths in project folder:
12+
* import a projectfile
13+
* add include paths in project folder
14+
* exclude file/folder
15+
16+
2. Save project
17+
18+
EXPECTED: Relative paths should be used in the XML
19+
20+
721
## Test: Platform file pic8.xml
822

923
Ticket: #14489

gui/projectfile.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,7 @@ void ProjectFile::setCheckPaths(const QStringList &paths)
751751

752752
void ProjectFile::setExcludedPaths(const QStringList &paths)
753753
{
754-
mExcludedPaths.clear();
755-
for (const QString &path : paths)
756-
mExcludedPaths << (QFileInfo(path).isAbsolute() ? getRelativePath(path) : path);
754+
mExcludedPaths = paths;
757755
}
758756

759757
void ProjectFile::setLibraries(const QStringList &libraries)

gui/projectfiledialog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,10 @@ void ProjectFileDialog::addExcludeFile()
888888
QMap<QString,QString> filters;
889889
filters[tr("Source files")] = "*.c *.cpp";
890890
filters[tr("All files")] = "*.*";
891-
addExcludePath(QFileDialog::getOpenFileName(this, tr("Exclude file"), dir.canonicalPath(), toFilterString(filters)));
891+
QString fileName = QFileDialog::getOpenFileName(this, tr("Exclude file"), dir.canonicalPath(), toFilterString(filters));
892+
if (!fileName.isEmpty())
893+
fileName = mProjectFile->getRelativePath(fileName);
894+
addExcludePath(fileName);
892895
}
893896

894897
void ProjectFileDialog::editExcludePath()

gui/test/projectfile/testprojectfile.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,30 +215,27 @@ void TestProjectFile::emptyUserInclude() const
215215
}
216216

217217
// Absolute path is made relative when it does not require walking up more than 2 parent folders
218-
void TestProjectFile::setExcludedPathsRelative() const
218+
void TestProjectFile::getRelativePathRelative() const
219219
{
220220
ProjectFile projectFile;
221221
projectFile.setFilename("/some/path/123.cppcheck");
222-
projectFile.setExcludedPaths(QStringList() << "/some/externals/foo.cpp");
223-
QCOMPARE(projectFile.getExcludedPaths()[0], QString("../externals/foo.cpp"));
222+
QCOMPARE(projectFile.getRelativePath("/some/externals/foo.cpp"), QString("../externals/foo.cpp"));
224223
}
225224

226225
// Absolute path is kept as-is when making it relative would require walking up more than 2 parent folders
227-
void TestProjectFile::setExcludedPathsTooFarUp() const
226+
void TestProjectFile::getRelativePathTooFarUp() const
228227
{
229228
ProjectFile projectFile;
230229
projectFile.setFilename("/some/path/123.cppcheck");
231-
projectFile.setExcludedPaths(QStringList() << "/other/deep/foo.cpp");
232-
QCOMPARE(projectFile.getExcludedPaths()[0], QString("/other/deep/foo.cpp"));
230+
QCOMPARE(projectFile.getRelativePath("/other/deep/foo.cpp"), QString("/other/deep/foo.cpp"));
233231
}
234232

235-
// Paths that are already relative are kept unchanged
236-
void TestProjectFile::setExcludedPathsAlreadyRelative() const
233+
// Absolute path in a subfolder of the project path is made relative without walking up at all
234+
void TestProjectFile::getRelativePathSubfolder() const
237235
{
238236
ProjectFile projectFile;
239237
projectFile.setFilename("/some/path/123.cppcheck");
240-
projectFile.setExcludedPaths(QStringList() << "gui/temp/");
241-
QCOMPARE(projectFile.getExcludedPaths()[0], QString("gui/temp/"));
238+
QCOMPARE(projectFile.getRelativePath("/some/path/src/file1.c"), QString("src/file1.c"));
242239
}
243240

244241
QTEST_MAIN(TestProjectFile)

gui/test/projectfile/testprojectfile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private slots:
3939

4040
void emptyUserInclude() const;
4141

42-
void setExcludedPathsRelative() const;
43-
void setExcludedPathsTooFarUp() const;
44-
void setExcludedPathsAlreadyRelative() const;
42+
void getRelativePathRelative() const;
43+
void getRelativePathTooFarUp() const;
44+
void getRelativePathSubfolder() const;
4545
};

0 commit comments

Comments
 (0)