ui: implemented prefilling indexed header paths for compilation database projects

* fixed header path detection in CompilationDatabase class
This commit is contained in:
mlangkabel
2017-10-11 17:08:13 +02:00
parent 85ab7d1e96
commit f0da5b630b
14 changed files with 153 additions and 71 deletions
@@ -32,7 +32,7 @@ void QtProjectWizzardContentCDBSource::load()
{
m_fileNames.clear();
const FilePath projectPath = m_settings->getProjectFileLocation();
const FilePath projectPath = m_settings->getProjectDirectoryPath();
std::vector<FilePath> excludePaths = m_settings->getExcludePathsExpandedAndAbsolute();
if (std::shared_ptr<SourceGroupSettingsCxxCdb> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(m_settings))
@@ -41,7 +41,7 @@ void QtProjectWizzardContentPath::populate(QGridLayout* layout, int& row)
if (m_makePathRelativeToProjectFileLocation)
{
m_picker->setRelativeRootDirectory(m_settings->getProjectFileLocation());
m_picker->setRelativeRootDirectory(m_settings->getProjectDirectoryPath());
}
layout->addWidget(m_picker, row, QtProjectWizzardWindow::BACK_COL);
@@ -263,7 +263,7 @@ std::vector<std::string> QtProjectWizzardContentPathSourceMaven::getFileNames()
m_settings->getSourceExtensions()
);
const FilePath projectPath = m_settings->getProjectFileLocation();
const FilePath projectPath = m_settings->getProjectDirectoryPath();
for (FilePath path: fileManager.getAllSourceFilePaths())
{
@@ -394,7 +394,7 @@ std::vector<std::string> QtProjectWizzardContentPathSourceGradle::getFileNames()
m_settings->getSourceExtensions()
);
const FilePath projectPath = m_settings->getProjectFileLocation();
const FilePath projectPath = m_settings->getProjectDirectoryPath();
for (FilePath path : fileManager.getAllSourceFilePaths())
{
@@ -19,6 +19,7 @@
#include "utility/file/FileManager.h"
#include "utility/ScopedFunctor.h"
#include "utility/utility.h"
#include "utility/utilityFile.h"
#include "utility/utilityPathDetection.h"
#include "Application.h"
@@ -43,7 +44,7 @@ void QtProjectWizzardContentPaths::populate(QGridLayout* layout, int& row)
if (m_makePathsRelativeToProjectFileLocation && m_settings)
{
m_list->setRelativeRootDirectory(m_settings->getProjectFileLocation());
m_list->setRelativeRootDirectory(m_settings->getProjectDirectoryPath());
}
layout->addWidget(m_list, row, QtProjectWizzardWindow::BACK_COL);
@@ -192,7 +193,7 @@ std::vector<std::string> QtProjectWizzardContentPathsSource::getFileNames() cons
m_settings->getSourceExtensions()
);
const std::set<FilePath> filePaths = fileManager.getAllSourceFilePathsRelative(m_settings->getProjectFileLocation());
const std::set<FilePath> filePaths = fileManager.getAllSourceFilePathsRelative(m_settings->getProjectDirectoryPath());
std::vector<std::string> list;
list.resize(filePaths.size());
@@ -211,6 +212,22 @@ QString QtProjectWizzardContentPathsSource::getFileNamesDescription() const
return " files will be indexed.";
}
std::vector<FilePath> QtProjectWizzardContentPathsCDBHeader::getTopLevelHeaderSearchPaths(
std::shared_ptr<SourceGroupSettingsCxxCdb> settings)
{
const FilePath cdbPath = settings->getCompilationDatabasePathExpandedAndAbsolute();
if (!cdbPath.exists())
{
LOG_WARNING("Unable to fetch top level header search directories. The provided Compilation Database path does not exist.");
return std::vector<FilePath>();
}
const std::vector<FilePath> sourcePaths = settings->getSourcePaths();
return utility::getTopLevelPaths(utility::unique(utility::concat(
sourcePaths, utility::CompilationDatabase(cdbPath).getAllHeaderPaths()
)));
}
QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader(
std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window
)
@@ -242,6 +259,25 @@ void QtProjectWizzardContentPathsCDBHeader::populate(QGridLayout* layout, int& r
row++;
}
void QtProjectWizzardContentPathsCDBHeader::load()
{
if (m_settings->getSourcePaths().empty())
{
std::shared_ptr<SourceGroupSettingsCxxCdb> cdbSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(m_settings);
std::vector<FilePath> sourcePaths;
for (const FilePath& path : getTopLevelHeaderSearchPaths(cdbSettings))
{
if (path.exists() && m_settings->getProjectDirectoryPath().contains(path))
{
sourcePaths.push_back(path);
}
}
m_settings->setSourcePaths(sourcePaths);
}
QtProjectWizzardContentPathsSource::load();
}
bool QtProjectWizzardContentPathsCDBHeader::check()
{
if (!m_list->getList().size())
@@ -269,7 +305,7 @@ void QtProjectWizzardContentPathsCDBHeader::buttonClicked()
if (!m_filesDialog)
{
FilePath cdbPath = dynamic_cast<SourceGroupSettingsCxxCdb*>(m_settings.get())->getCompilationDatabasePathExpandedAndAbsolute(); // TODO: remove this cast
const FilePath cdbPath = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(m_settings)->getCompilationDatabasePathExpandedAndAbsolute();
if (!cdbPath.exists())
{
QMessageBox msgBox;
@@ -287,31 +323,11 @@ void QtProjectWizzardContentPathsCDBHeader::buttonClicked()
connect(m_filesDialog.get(), &QtSelectPathsDialog::finished, this, &QtProjectWizzardContentPathsCDBHeader::savedFilesDialog);
connect(m_filesDialog.get(), &QtSelectPathsDialog::canceled, this, &QtProjectWizzardContentPathsCDBHeader::closedFilesDialog);
utility::CompilationDatabase cdb(cdbPath.str());
std::vector<FilePath> sourcePaths = m_settings->getSourcePaths();
std::vector<FilePath> cdbHeaderPaths;
for (const FilePath& path: utility::unique(utility::concat(sourcePaths, cdb.getAllHeaderPaths())))
{
bool addPath = true;
for (const FilePath& cdbHeaderPath: cdbHeaderPaths)
{
if (cdbHeaderPath.contains(path))
{
addPath = false;
break;
}
}
if (addPath)
{
cdbHeaderPaths.push_back(path);
}
}
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())->setPathsList(cdbHeaderPaths, sourcePaths);
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())->setPathsList(
getTopLevelHeaderSearchPaths(std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(m_settings)),
m_settings->getSourcePaths()
);
}
m_filesDialog->showWindow();
@@ -10,6 +10,7 @@ class QComboBox;
class QPushButton;
class QtDirectoryListBox;
class SourceGroupSettings;
class SourceGroupSettingsCxxCdb;
class QtProjectWizzardContentPaths
: public QtProjectWizzardContent
@@ -75,10 +76,14 @@ class QtProjectWizzardContentPathsCDBHeader
Q_OBJECT
public:
static std::vector<FilePath> getTopLevelHeaderSearchPaths(std::shared_ptr<SourceGroupSettingsCxxCdb> settings);
QtProjectWizzardContentPathsCDBHeader(std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window);
virtual void populate(QGridLayout* layout, int& row) override;
virtual void load() override;
virtual bool check() override;
private slots:
@@ -57,7 +57,7 @@ void QtProjectWizzardContentProjectData::populate(QGridLayout* layout, int& row)
void QtProjectWizzardContentProjectData::load()
{
m_projectName->setText(QString::fromStdString(m_projectSettings->getProjectName()));
m_projectFileLocation->setText(QString::fromStdString(m_projectSettings->getProjectFileLocation().str()));
m_projectFileLocation->setText(QString::fromStdString(m_projectSettings->getProjectDirectoryPath().str()));
}
void QtProjectWizzardContentProjectData::save()