Skip to content

Commit fbb1055

Browse files
authored
Fix #14489 (GUI: The platform files are not shown in the dropdown in ProjectFileDialog) (danmar#8214)
1 parent 1c65d48 commit fbb1055

File tree

9 files changed

+64
-28
lines changed

9 files changed

+64
-28
lines changed

gui/manualtest/projectfiledialog.md

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

66

7+
8+
## Test: Platform files
9+
10+
Ticket: #14489
11+
12+
EXPECTED: In the project file dialog it should be possible to select xml files i.e. pic8.xml
13+
14+
TODO: can this test be automated
15+
16+
17+
718
## Test: Misra C checkbox
819

20+
Ticket: #14488
21+
922
Matrix: Use both open source and premium
1023

1124
1. Load project file in trac ticket 14488

gui/projectfile.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <utility>
2828

29+
#include <QCoreApplication>
2930
#include <QFile>
3031
#include <QDir>
3132
#include <QIODevice>
@@ -1176,3 +1177,23 @@ QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon)
11761177

11771178
return QString();
11781179
}
1180+
1181+
QStringList ProjectFile::getSearchPaths(const QString& projectPath, const QString& appPath, const QString& datadir, const QString& dir) {
1182+
QStringList ret;
1183+
ret << appPath << (appPath + "/" + dir) << projectPath;
1184+
#ifdef FILESDIR
1185+
if (FILESDIR[0])
1186+
ret << FILESDIR << (FILESDIR "/" + dir);
1187+
#endif
1188+
if (!datadir.isEmpty())
1189+
ret << datadir << (datadir + "/" + dir);
1190+
return ret;
1191+
}
1192+
1193+
QStringList ProjectFile::getSearchPaths(const QString& dir) const {
1194+
const QFileInfo inf(mFilename);
1195+
const QString applicationFilePath = QCoreApplication::applicationFilePath();
1196+
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
1197+
const QString datadir = getDataDir();
1198+
return getSearchPaths(inf.canonicalFilePath(), appPath, datadir, dir);
1199+
}

gui/projectfile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ class ProjectFile : public QObject {
446446
/** Use Clang parser */
447447
bool clangParser;
448448

449+
/** Get paths where we should glob for certain files (dir="cfg"/"platforms"/etc */
450+
QStringList getSearchPaths(const QString& dir) const;
451+
static QStringList getSearchPaths(const QString& projectPath, const QString& appPath, const QString& datadir, const QString& dir);
452+
449453
protected:
450454

451455
/**

gui/projectfiledialog.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <QByteArray>
4141
#include <QCheckBox>
4242
#include <QComboBox>
43-
#include <QCoreApplication>
4443
#include <QDialogButtonBox>
4544
#include <QDir>
4645
#include <QFileDialog>
@@ -142,22 +141,10 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
142141

143142
mUI->premiumLicense->setVisible(false);
144143

145-
// Checkboxes for the libraries..
146-
const QString applicationFilePath = QCoreApplication::applicationFilePath();
147-
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
148-
const QString datadir = getDataDir();
149-
QStringList searchPaths;
150-
searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath();
151-
#ifdef FILESDIR
152-
if (FILESDIR[0])
153-
searchPaths << FILESDIR << FILESDIR "/cfg";
154-
#endif
155-
if (!datadir.isEmpty())
156-
searchPaths << datadir << datadir + "/cfg";
157144
QStringList libs;
158145
// Search the std.cfg first since other libraries could depend on it
159146
QString stdLibraryFilename;
160-
for (const QString &sp : searchPaths) {
147+
for (const QString &sp : projectFile->getSearchPaths("cfg")) {
161148
QDir dir(sp);
162149
dir.setSorting(QDir::Name);
163150
dir.setNameFilters(QStringList("*.cfg"));
@@ -179,7 +166,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
179166
break;
180167
}
181168
// Search other libraries
182-
for (const QString &sp : searchPaths) {
169+
for (const QString &sp : projectFile->getSearchPaths("cfg")) {
183170
QDir dir(sp);
184171
dir.setSorting(QDir::Name);
185172
dir.setNameFilters(QStringList("*.cfg"));
@@ -218,22 +205,15 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
218205
for (const Platform::Type builtinPlatform : builtinPlatforms)
219206
mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle);
220207
QStringList platformFiles;
221-
for (QString sp : searchPaths) {
222-
if (sp.endsWith("/cfg"))
223-
sp = sp.mid(0,sp.length()-3) + "platforms";
208+
for (const QString& sp : projectFile->getSearchPaths("platforms")) {
224209
QDir dir(sp);
225210
dir.setSorting(QDir::Name);
226211
dir.setNameFilters(QStringList("*.xml"));
227212
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
228213
for (const QFileInfo& item : dir.entryInfoList()) {
229214
const QString platformFile = item.fileName();
230-
231-
const std::vector<std::string> paths = {
232-
Path::getCurrentPath(), // TODO: do we want to look in CWD?
233-
applicationFilePath.toStdString(),
234-
};
235215
Platform plat2;
236-
if (!plat2.loadFromFile(paths, platformFile.toStdString()))
216+
if (!plat2.loadFromFile({sp.toStdString()}, platformFile.toStdString()))
237217
continue;
238218

239219
if (platformFiles.indexOf(platformFile) == -1)

gui/test/projectfile/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_dependencies(gui-build-deps build-projectfile-deps)
44
add_executable(test-projectfile
55
${test-projectfile_SRC}
66
testprojectfile.cpp
7+
${CMAKE_SOURCE_DIR}/gui/common.cpp
78
${CMAKE_SOURCE_DIR}/gui/projectfile.cpp
89
)
910
target_include_directories(test-projectfile PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)

gui/test/projectfile/testprojectfile.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ void TestProjectFile::getAddonFilePath() const
136136
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath);
137137
}
138138

139+
void TestProjectFile::getSearchPaths() const
140+
{
141+
#ifdef FILESDIR
142+
const QString f(FILESDIR "\n" // example: "/usr/local/share/cppcheck\n"
143+
FILESDIR "/dir\n"); // example: "/usr/local/share/cppcheck/dir\n"
144+
#else
145+
const QString f;
146+
#endif
147+
148+
QCOMPARE(ProjectFile::getSearchPaths("projectPath", "appPath", "datadir", "dir").join("\n"),
149+
"appPath\n"
150+
"appPath/dir\n"
151+
"projectPath\n" +
152+
f +
153+
"datadir\n"
154+
"datadir/dir");
155+
}
156+
139157
void TestProjectFile::getInlineSuppressionDefaultValue() const
140158
{
141159
ProjectFile projectFile;

gui/test/projectfile/testprojectfile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private slots:
2828
void loadSimpleNoroot() const;
2929

3030
void getAddonFilePath() const;
31+
void getSearchPaths() const;
3132

3233
void getInlineSuppressionDefaultValue() const;
3334
void getInlineSuppression() const;

gui/test/resultstree/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ qt_wrap_cpp(test-resultstree_SRC
33
${CMAKE_SOURCE_DIR}/gui/resultstree.h
44
${CMAKE_SOURCE_DIR}/gui/resultitem.h
55
${CMAKE_SOURCE_DIR}/gui/applicationlist.h
6+
${CMAKE_SOURCE_DIR}/gui/common.h
67
${CMAKE_SOURCE_DIR}/gui/projectfile.h
78
${CMAKE_SOURCE_DIR}/gui/threadhandler.h
89
${CMAKE_SOURCE_DIR}/gui/threadresult.h
@@ -14,6 +15,7 @@ add_executable(test-resultstree
1415
testresultstree.cpp
1516
${CMAKE_SOURCE_DIR}/gui/resultstree.cpp
1617
${CMAKE_SOURCE_DIR}/gui/resultitem.cpp
18+
${CMAKE_SOURCE_DIR}/gui/common.cpp
1719
${CMAKE_SOURCE_DIR}/gui/erroritem.cpp
1820
${CMAKE_SOURCE_DIR}/gui/showtypes.cpp
1921
${CMAKE_SOURCE_DIR}/gui/report.cpp

gui/test/resultstree/testresultstree.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ Application& ApplicationList::getApplication(const int /*unused*/) {
9999
const Application& ApplicationList::getApplication(const int index) const {
100100
return mApplications.at(index);
101101
}
102-
QString getPath(const QString &type) {
103-
return "/" + type;
104-
}
105-
void setPath(const QString & /*unused*/, const QString & /*unused*/) {}
106102
QString XmlReport::quoteMessage(const QString &message) {
107103
return message;
108104
}

0 commit comments

Comments
 (0)