forked from qt-creator/qt-creator
CompilationDatabase: Ask for the root path and scan for headers
Let's use the same approach we have for CMake projects by using the same TreeScanner class. Compilation database does not have a concept of the root directory so let's show a file dialog and ask for it the first time the project is loaded. Next times we open it we take this path from settings. This root path can later be changed from the project tree context menu. Fixes: QTCREATORBUG-22031 Change-Id: I151aed8d0504b2e8aa14aa774cad25f8c86d5c17 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
@@ -177,6 +179,7 @@ public:
|
||||
Kit::Predicate m_preferredKitPredicate;
|
||||
|
||||
Utils::MacroExpander m_macroExpander;
|
||||
Utils::FileName m_rootProjectDirectory;
|
||||
mutable QVector<const Node *> m_sortedNodeList;
|
||||
};
|
||||
|
||||
@@ -653,13 +656,30 @@ Utils::FileName Project::projectDirectory(const Utils::FileName &top)
|
||||
return Utils::FileName::fromString(top.toFileInfo().absoluteDir().path());
|
||||
}
|
||||
|
||||
void Project::changeRootProjectDirectory()
|
||||
{
|
||||
Utils::FileName rootPath = Utils::FileName::fromString(
|
||||
QFileDialog::getExistingDirectory(Core::ICore::dialogParent(),
|
||||
tr("Select The Root Directory"),
|
||||
rootProjectDirectory().toString(),
|
||||
QFileDialog::ShowDirsOnly
|
||||
| QFileDialog::DontResolveSymlinks));
|
||||
if (rootPath != d->m_rootProjectDirectory) {
|
||||
d->m_rootProjectDirectory = rootPath;
|
||||
setNamedSettings(Constants::PROJECT_ROOT_PATH_KEY, d->m_rootProjectDirectory.toString());
|
||||
emit rootProjectDirectoryChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the common root directory that contains all files which belongs to a project.
|
||||
*/
|
||||
|
||||
Utils::FileName Project::rootProjectDirectory() const
|
||||
{
|
||||
return projectDirectory(); // TODO parse all files and find the common path
|
||||
if (!d->m_rootProjectDirectory.isEmpty())
|
||||
return d->m_rootProjectDirectory;
|
||||
|
||||
return projectDirectory();
|
||||
}
|
||||
|
||||
ProjectNode *Project::rootProjectNode() const
|
||||
@@ -701,6 +721,9 @@ Project::RestoreResult Project::fromMap(const QVariantMap &map, QString *errorMe
|
||||
createTargetFromMap(map, i);
|
||||
}
|
||||
|
||||
d->m_rootProjectDirectory = Utils::FileName::fromString(
|
||||
namedSettings(Constants::PROJECT_ROOT_PATH_KEY).toString());
|
||||
|
||||
return RestoreResult::Ok;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user