From b07d03692dccb77760fa27d29b019a3d4db720ef Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 13 Jun 2016 16:43:37 +0200 Subject: [PATCH] logic: Reworked CDB project setup * added separate step for project name, project location and cdb path * added description that project stays up-to-date under cdb path picker. * added include and framework paths to advanced settings * disregard source extensions for cdb projects bug id = 70 --- bin/app/data/gui/window/window.css | 4 + src/lib/Project.cpp | 8 +- src/lib/utility/file/FileManager.cpp | 17 +- src/lib/utility/file/FileManager.h | 4 +- src/lib/utility/file/FileRegister.cpp | 2 +- src/lib/utility/file/FileSystem.cpp | 5 +- .../solution/SolutionParserVisualStudio.cpp | 6 + src/lib_gui/qt/element/QtLocationPicker.cpp | 1 + src/lib_gui/qt/element/QtLocationPicker.h | 3 + .../project_wizzard/QtProjectWizzard.cpp | 82 ++--- .../window/project_wizzard/QtProjectWizzard.h | 4 +- .../QtProjectWizzardContentBuildFile.cpp | 4 +- .../QtProjectWizzardContentCDBSource.cpp | 31 +- .../QtProjectWizzardContentData.cpp | 294 ++++++++++++------ .../QtProjectWizzardContentData.h | 29 +- .../QtProjectWizzardContentPaths.cpp | 26 +- .../QtProjectWizzardContentPaths.h | 1 - .../QtProjectWizzardContentSelect.cpp | 2 +- src/test/helper/TestFileManager.cpp | 7 +- src/test/helper/TestFileManager.h | 3 +- 20 files changed, 329 insertions(+), 204 deletions(-) diff --git a/bin/app/data/gui/window/window.css b/bin/app/data/gui/window/window.css index fa8eff5d..58fa237b 100644 --- a/bin/app/data/gui/window/window.css +++ b/bin/app/data/gui/window/window.css @@ -25,6 +25,10 @@ margin-left: 20px; } +#description { + font-size: 12pt; +} + #label { font-size: 12pt; font-weight: bold; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 7364b9d1..8d750633 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -250,15 +250,19 @@ void Project::updateFileManager() std::vector sourcePaths = projSettings->getAbsoluteSourcePaths(); std::vector headerPaths = sourcePaths; + std::vector sourceExtensions; + if (projSettings->getCompilationDatabasePath().exists()) { sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath()); } + else + { + sourceExtensions = projSettings->getSourceExtensions(); + } std::vector excludePaths = projSettings->getAbsoluteExcludePaths(); - std::vector sourceExtensions = projSettings->getSourceExtensions(); - m_fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); } diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index b79124e4..58b75a63 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -47,7 +47,7 @@ void FileManager::fetchFilePaths(const std::vector& oldFileInfos) for (std::map::iterator it = m_files.begin(); it != m_files.end(); it++) { const FilePath& filePath = it->first; - if (filePath.exists() && !hasSourceExtension(filePath)) + if (filePath.exists() && !hasSourceFilePath(filePath)) { FileInfo fileInfo = FileSystem::getFileInfoForPath(filePath); @@ -63,6 +63,8 @@ void FileManager::fetchFilePaths(const std::vector& oldFileInfos) } } + m_sourceFiles.clear(); + std::vector fileInfos = FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions); for (FileInfo fileInfo: fileInfos) { @@ -72,6 +74,8 @@ void FileManager::fetchFilePaths(const std::vector& oldFileInfos) continue; } + m_sourceFiles.insert(filePath); + std::map::iterator it = m_files.find(filePath); if (it != m_files.end()) { @@ -112,7 +116,7 @@ std::set FileManager::getRemovedFilePaths() const bool FileManager::hasFilePath(const FilePath& filePath) const { - if (m_files.find(filePath) != m_files.end()) + if (hasSourceFilePath(filePath)) { return true; } @@ -133,9 +137,14 @@ bool FileManager::hasFilePath(const FilePath& filePath) const return false; } -bool FileManager::hasSourceExtension(const FilePath& filePath) const +bool FileManager::hasSourceFilePath(const FilePath& filePath) const { - return filePath.hasExtension(m_sourceExtensions); + if (m_sourceFiles.find(filePath) != m_sourceFiles.end()) + { + return true; + } + + return false; } const FileInfo FileManager::getFileInfo(const FilePath& filePath) const diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index 7ac8117b..6247f872 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -29,7 +29,7 @@ public: std::set getRemovedFilePaths() const; virtual bool hasFilePath(const FilePath& filePath) const; - virtual bool hasSourceExtension(const FilePath& filePath) const; + virtual bool hasSourceFilePath(const FilePath& filePath) const; virtual const FileInfo getFileInfo(const FilePath& filePath) const; @@ -47,6 +47,8 @@ private: std::set m_addedFiles; std::set m_updatedFiles; std::set m_removedFiles; + + std::set m_sourceFiles; }; #endif // FILE_MANAGER_H diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index 0af1ef2a..cb2dafa2 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -19,7 +19,7 @@ void FileRegister::setFilePaths(const std::vector& filePaths) { FilePath path = p.exists() ? p.absolute() : p; - if (m_fileManager->hasSourceExtension(path)) + if (m_fileManager->hasSourceFilePath(path)) { m_sourceFilePaths.emplace(path, STATE_UNPARSED); } diff --git a/src/lib/utility/file/FileSystem.cpp b/src/lib/utility/file/FileSystem.cpp index 662193ee..bd3a5d79 100644 --- a/src/lib/utility/file/FileSystem.cpp +++ b/src/lib/utility/file/FileSystem.cpp @@ -81,7 +81,8 @@ std::vector FileSystem::getFileInfosFromPaths( it.pop(); continue; } - if (boost::filesystem::is_regular_file(*it) && hasExtension(it->path().string(), fileExtensions)) + if (boost::filesystem::is_regular_file(*it) && + (!fileExtensions.size() || hasExtension(it->path().string(), fileExtensions))) { std::time_t t = boost::filesystem::last_write_time(*it); boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t); @@ -89,7 +90,7 @@ std::vector FileSystem::getFileInfosFromPaths( } } } - else if (path.exists() && path.hasExtension(fileExtensions)) + else if (path.exists() && (!fileExtensions.size() || path.hasExtension(fileExtensions))) { std::time_t t = boost::filesystem::last_write_time(path.path()); boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t); diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.cpp b/src/lib/utility/solution/SolutionParserVisualStudio.cpp index c2a41b93..63d76ddd 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.cpp +++ b/src/lib/utility/solution/SolutionParserVisualStudio.cpp @@ -157,8 +157,10 @@ std::vector SolutionParserVisualStudio::getCompileFlags() std::vector validExtensions; validExtensions.push_back(".c"); + validExtensions.push_back(".cc"); validExtensions.push_back(".cpp"); validExtensions.push_back(".h"); + validExtensions.push_back(".hh"); validExtensions.push_back(".hpp"); for (unsigned int i = 0; i < projectFiles.size(); i++) @@ -301,8 +303,10 @@ std::vector SolutionParserVisualStudio::findProjectItems() std::vector validFileExtensions; validFileExtensions.push_back(".c"); + validFileExtensions.push_back(".cc"); validFileExtensions.push_back(".cpp"); validFileExtensions.push_back(".h"); + validFileExtensions.push_back(".hh"); validFileExtensions.push_back(".hpp"); for (unsigned int i = 0; i < projectFilesNames.size(); i++) @@ -460,8 +464,10 @@ std::vector SolutionParserVisualStudio::findIncludePaths() std::vector validExtensions; validExtensions.push_back(".c"); + validExtensions.push_back(".cc"); validExtensions.push_back(".cpp"); validExtensions.push_back(".h"); + validExtensions.push_back(".hh"); validExtensions.push_back(".hpp"); for (unsigned int i = 0; i < projectFiles.size(); i++) diff --git a/src/lib_gui/qt/element/QtLocationPicker.cpp b/src/lib_gui/qt/element/QtLocationPicker.cpp index 8c7162bb..7cd61c0a 100644 --- a/src/lib_gui/qt/element/QtLocationPicker.cpp +++ b/src/lib_gui/qt/element/QtLocationPicker.cpp @@ -81,5 +81,6 @@ void QtLocationPicker::handleButtonPress() if (!fileName.isEmpty()) { m_data->setText(fileName); + emit locationPicked(); } } diff --git a/src/lib_gui/qt/element/QtLocationPicker.h b/src/lib_gui/qt/element/QtLocationPicker.h index 001ebb9a..8b78cf9a 100644 --- a/src/lib_gui/qt/element/QtLocationPicker.h +++ b/src/lib_gui/qt/element/QtLocationPicker.h @@ -22,6 +22,9 @@ public: void setPickDirectory(bool pickDirectory); void setFileFilter(const QString& fileFilter); +signals: + void locationPicked(); + private slots: void handleButtonPress(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 8371be9c..ee1fcc6e 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -142,34 +142,6 @@ void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, cons } } -void QtProjectWizzard::newProjectFromCompilationDatabase(const std::string& compilationDatabasePath) -{ - m_settings = getSettingsForCompilationDatabase(compilationDatabasePath); - - headerPathsCDB(); -} - -void QtProjectWizzard::refreshProjectFromCompilationDatabase(const std::string& compilationDatabasePath) -{ - QtProjectWizzardWindow* window = dynamic_cast(m_windowStack.getTopWindow()); - if (window) - { - window->content()->save(); - } - - ProjectSettings settings = getSettingsForCompilationDatabase(compilationDatabasePath); - - m_settings.setSourcePaths(settings.getSourcePaths()); - m_settings.setHeaderSearchPaths(settings.getHeaderSearchPaths()); - m_settings.setFrameworkSearchPaths(settings.getFrameworkSearchPaths()); - m_settings.setCompilationDatabasePath(FilePath(compilationDatabasePath)); - - if (window) - { - window->content()->load(); - } -} - void QtProjectWizzard::editProject(const ProjectSettings& settings) { m_settings = settings; @@ -374,17 +346,7 @@ void QtProjectWizzard::selectedProjectType(QtProjectWizzardContentSelect::Projec } case QtProjectWizzardContentSelect::PROJECT_CDB: - { - QString fileName = QFileDialog::getOpenFileName( - this, tr("Open JSON Compilation Database"), "", "JSON Compilation Database (*.json)" - ); - - if (!fileName.isNull()) - { - newProjectFromCompilationDatabase(fileName.toStdString()); - } - break; - } + emptyProjectCDB(); break; } } @@ -462,6 +424,15 @@ void QtProjectWizzard::frameworkSearchPaths() connect(window, SIGNAL(next()), this, SLOT(showSummary())); } +void QtProjectWizzard::emptyProjectCDB() +{ + QtProjectWizzardWindow* window = createWindowWithContent(); + + window->updateTitle("NEW PROJECT FROM COMPILATION DATABASE"); + + connect(window, SIGNAL(next()), this, SLOT(headerPathsCDB())); +} + void QtProjectWizzard::headerPathsCDB() { QtProjectWizzardWindow* window = createWindowWithSummary( @@ -523,22 +494,21 @@ void QtProjectWizzard::showSummary() ProjectSettings* settings = &m_settings; - QtProjectWizzardContentData* data = new QtProjectWizzardContentData(settings, window); - summary->addContent(data, false, false); - QtProjectWizzardContentBuildFile* buildFile = new QtProjectWizzardContentBuildFile(settings, window); - if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_EMPTY) - { - summary->addContent(buildFile, false, true); - - connect(dynamic_cast(buildFile), - SIGNAL(refreshVisualStudioSolution(const std::string&, const std::string&)), - this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&))); - } - if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_CDB) { + summary->addContent(new QtProjectWizzardContentData(settings, window), false, false); + + if (buildFile->getType() == QtProjectWizzardContentSelect::PROJECT_MANAGED) + { + summary->addContent(buildFile, false, true); + + connect(dynamic_cast(buildFile), + SIGNAL(refreshVisualStudioSolution(const std::string&, const std::string&)), + this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&))); + } + QtProjectWizzardContentPathsSource* source = new QtProjectWizzardContentPathsSource(settings, window); summary->addContent(source, false, true); connectShowFiles(source); @@ -555,22 +525,22 @@ void QtProjectWizzard::showSummary() } else { + summary->addContent(new QtProjectWizzardContentDataCDB(settings, window), false, false); + QtProjectWizzardContent* headers = new QtProjectWizzardContentPathsCDBHeader(settings, window); summary->addContent(headers, false, true); - connectShowFiles(headers); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), true, false); summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, true); if (QSysInfo::macVersion() != QSysInfo::MV_None) { + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), true, false); summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); } - - data->hideLanguage(); } - summary->addContent(new QtProjectWizzardContentFlags(settings, window), true, false); - summary->addContent(new QtProjectWizzardContentExtensions(settings, window), true, true); + summary->addContent(new QtProjectWizzardContentFlags(settings, window), true, true); summary->addContent(new QtProjectWizzardContentPathsExclude(settings, window), true, true); window->setup(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index c7187467..e29757d1 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -34,11 +34,8 @@ public slots: void newProject(); void newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); - void refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); - void newProjectFromCompilationDatabase(const std::string& compilationDatabasePath); - void refreshProjectFromCompilationDatabase(const std::string& compilationDatabasePath); void editProject(const ProjectSettings& settings); void showPreferences(); @@ -82,6 +79,7 @@ private slots: void headerSearchPathsDone(); void frameworkSearchPaths(); + void emptyProjectCDB(); void headerPathsCDB(); void headerPathsCDBDone(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index 3660b422..f3c303f8 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -144,8 +144,8 @@ void QtProjectWizzardContentBuildFile::refreshClicked() QMessageBox::question( this, "Refresh Paths", - "Do you really want to refresh from the given file? All changes you have made to the project's analyzed " - "paths and header search paths will be lost.", + "Do you really want to refresh from the given file? All changes you have made to the project paths " + "and include paths will be lost.", QMessageBox::Yes | QMessageBox::No ); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp index d72ed493..4bcce2ab 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp @@ -33,16 +33,35 @@ void QtProjectWizzardContentCDBSource::populateWindow(QGridLayout* layout, int& void QtProjectWizzardContentCDBSource::load() { - std::vector filePaths = TaskParseCxx::getSourceFilesFromCDB(m_settings->getCompilationDatabasePath()); - std::vector extensions = m_settings->getSourceExtensions(); - m_fileNames.clear(); - for (const FilePath& path : filePaths) + + FilePath projectPath = m_settings->getProjectFileLocation(); + std::vector excludePaths = m_settings->getAbsoluteExcludePaths(); + + std::vector filePaths = TaskParseCxx::getSourceFilesFromCDB(m_settings->getCompilationDatabasePath()); + for (FilePath path : filePaths) { - if (path.hasExtension(extensions)) + bool excluded = false; + for (FilePath p : excludePaths) { - m_fileNames << QString::fromStdString(path.str()); + if (p == path || p.contains(path)) + { + excluded = true; + break; + } } + + if (excluded) + { + continue; + } + + if (projectPath.exists()) + { + path = path.relativeTo(projectPath); + } + + m_fileNames << QString::fromStdString(path.str()); } if (m_text) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp index bd6247a0..926b42fe 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp @@ -5,15 +5,15 @@ QtProjectWizzardContentData::QtProjectWizzardContentData(ProjectSettings* settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) - , m_showLanguage(true) + , m_projectName(nullptr) + , m_projectFileLocation(nullptr) + , m_language(nullptr) + , m_cppStandard(nullptr) + , m_cStandard(nullptr) + , m_buildFilePicker(nullptr) { } -void QtProjectWizzardContentData::hideLanguage() -{ - m_showLanguage = false; -} - void QtProjectWizzardContentData::populateWindow(QGridLayout* layout) { int row = 0; @@ -31,118 +31,71 @@ void QtProjectWizzardContentData::populateWindow(QGridLayout* layout) void QtProjectWizzardContentData::populateForm(QGridLayout* layout, int& row) { - QLabel* nameLabel = createFormLabel("Name"); - m_projectName = new QLineEdit(); - m_projectName->setObjectName("name"); - m_projectName->setAttribute(Qt::WA_MacShowFocusRect, 0); - - layout->addWidget(nameLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_projectName, row, QtProjectWizzardWindow::BACK_COL); - row++; - - QLabel* locationLabel = createFormLabel("Location"); - m_projectFileLocation = new QtLocationPicker(this); - m_projectFileLocation->setPickDirectory(true); - - layout->addWidget(locationLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_projectFileLocation, row, QtProjectWizzardWindow::BACK_COL); - row++; - - - QLabel* languageLabel = new QLabel("Language"); - languageLabel->setObjectName("label"); - m_language = new QComboBox(); - m_language->insertItem(0, "C++"); - m_language->insertItem(1, "C"); - connect(m_language, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); - - - QLabel* standardLabel = createFormLabel("Standard"); - - m_cppStandard = new QComboBox(); - m_cppStandard->insertItem(0, "1z"); - m_cppStandard->insertItem(1, "14"); - m_cppStandard->insertItem(2, "1y"); - m_cppStandard->insertItem(3, "11"); - m_cppStandard->insertItem(4, "0x"); - m_cppStandard->insertItem(5, "03"); - m_cppStandard->insertItem(6, "98"); - - m_cStandard = new QComboBox(); - m_cStandard->insertItem(0, "1x"); - m_cStandard->insertItem(1, "11"); - m_cStandard->insertItem(2, "9x"); - m_cStandard->insertItem(3, "99"); - m_cStandard->insertItem(4, "90"); - m_cStandard->insertItem(5, "89"); - - if (m_showLanguage) - { - layout->addWidget(languageLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_language, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - - row++; - - layout->addWidget(standardLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); - layout->addWidget(m_cppStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - layout->addWidget(m_cStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - } - else - { - languageLabel->hide(); - m_language->hide(); - - standardLabel->hide(); - m_cppStandard->hide(); - m_cStandard->hide(); - } - - row++; + addNameAndLocation(layout, row); + addLanguageAndStandard(layout, row); } void QtProjectWizzardContentData::load() { - m_projectName->setText(QString::fromStdString(m_settings->getProjectName())); - m_projectFileLocation->setText(QString::fromStdString(m_settings->getProjectFileLocation().str())); - - if (m_settings->getLanguage().length() > 0) + if (m_projectName) { - m_language->setCurrentText(QString::fromStdString(m_settings->getLanguage())); + m_projectName->setText(QString::fromStdString(m_settings->getProjectName())); + m_projectFileLocation->setText(QString::fromStdString(m_settings->getProjectFileLocation().str())); } - if (m_settings->getStandard().length() > 0) + if (m_language) { - if (m_language->currentIndex() == 0) // c++ + if (m_settings->getLanguage().length() > 0) { - m_cppStandard->setCurrentText(QString::fromStdString(m_settings->getStandard())); - } - else if (m_language->currentIndex() == 1) // c - { - m_cStandard->setCurrentText(QString::fromStdString(m_settings->getStandard())); + m_language->setCurrentText(QString::fromStdString(m_settings->getLanguage())); } - handleSelectionChanged(m_language->currentIndex()); + if (m_settings->getStandard().length() > 0) + { + if (m_language->currentIndex() == 0) // c++ + { + m_cppStandard->setCurrentText(QString::fromStdString(m_settings->getStandard())); + } + else if (m_language->currentIndex() == 1) // c + { + m_cStandard->setCurrentText(QString::fromStdString(m_settings->getStandard())); + } + + handleSelectionChanged(m_language->currentIndex()); + } } } void QtProjectWizzardContentData::save() { - m_settings->setProjectName(m_projectName->text().toStdString()); - m_settings->setProjectFileLocation(m_projectFileLocation->getText().toStdString()); - m_settings->setLanguage(m_language->currentText().toStdString()); - - if (m_cppStandard->isVisible()) + if (m_projectName) { - m_settings->setStandard(m_cppStandard->currentText().toStdString()); + m_settings->setProjectName(m_projectName->text().toStdString()); + m_settings->setProjectFileLocation(m_projectFileLocation->getText().toStdString()); } - else if (m_cStandard->isVisible()) + + if (m_language) { - m_settings->setStandard(m_cStandard->currentText().toStdString()); + m_settings->setLanguage(m_language->currentText().toStdString()); + + if (m_cppStandard->isVisible()) + { + m_settings->setStandard(m_cppStandard->currentText().toStdString()); + } + else if (m_cStandard->isVisible()) + { + m_settings->setStandard(m_cStandard->currentText().toStdString()); + } } } bool QtProjectWizzardContentData::check() { + if (!m_projectName) + { + return true; + } + if (m_projectName->text().isEmpty()) { QMessageBox msgBox; @@ -175,9 +128,99 @@ QSize QtProjectWizzardContentData::preferredWindowSize() const return QSize(580, 340); } +void QtProjectWizzardContentData::addNameAndLocation(QGridLayout* layout, int& row) +{ + QLabel* nameLabel = createFormLabel("Name"); + m_projectName = new QLineEdit(); + m_projectName->setObjectName("name"); + m_projectName->setAttribute(Qt::WA_MacShowFocusRect, 0); + + layout->addWidget(nameLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_projectName, row, QtProjectWizzardWindow::BACK_COL); + row++; + + + QLabel* locationLabel = createFormLabel("Location"); + m_projectFileLocation = new QtLocationPicker(this); + m_projectFileLocation->setPickDirectory(true); + + layout->addWidget(locationLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_projectFileLocation, row, QtProjectWizzardWindow::BACK_COL); + row++; +} + +void QtProjectWizzardContentData::addLanguageAndStandard(QGridLayout* layout, int& row) +{ + QLabel* languageLabel = new QLabel("Language"); + languageLabel->setObjectName("label"); + m_language = new QComboBox(); + m_language->insertItem(0, "C++"); + m_language->insertItem(1, "C"); + connect(m_language, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); + + layout->addWidget(languageLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_language, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + row++; + + + QLabel* standardLabel = createFormLabel("Standard"); + + m_cppStandard = new QComboBox(); + m_cppStandard->insertItem(0, "1z"); + m_cppStandard->insertItem(1, "14"); + m_cppStandard->insertItem(2, "1y"); + m_cppStandard->insertItem(3, "11"); + m_cppStandard->insertItem(4, "0x"); + m_cppStandard->insertItem(5, "03"); + m_cppStandard->insertItem(6, "98"); + + m_cStandard = new QComboBox(); + m_cStandard->insertItem(0, "1x"); + m_cStandard->insertItem(1, "11"); + m_cStandard->insertItem(2, "9x"); + m_cStandard->insertItem(3, "99"); + m_cStandard->insertItem(4, "90"); + m_cStandard->insertItem(5, "89"); + + layout->addWidget(standardLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_cppStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + layout->addWidget(m_cStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + row++; +} + +void QtProjectWizzardContentData::addBuildFilePicker( + QGridLayout* layout, int& row, const QString& name, const QString& filter) +{ + QLabel* label = createFormLabel(name); + layout->addWidget(label, row, QtProjectWizzardWindow::FRONT_COL); + + m_buildFilePicker = new QtLocationPicker(this); + m_buildFilePicker->setFileFilter(filter); + + // QPushButton* button = new QPushButton("", this); + // button->setObjectName("refreshButton"); + // button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + // button->setToolTip("refresh paths"); + // connect(button, SIGNAL(clicked()), this, SLOT(refreshClicked())); + + // m_buildFilePicker->layout()->addWidget(button); + + layout->addWidget(m_buildFilePicker, row, QtProjectWizzardWindow::BACK_COL); + + row++; + + QLabel* description = new QLabel( + "The project will stay up-to-date with changes in the compilation database on refresh.", this); + description->setObjectName("description"); + description->setWordWrap(true); + layout->addWidget(description, row, QtProjectWizzardWindow::BACK_COL); + + row++; +} + void QtProjectWizzardContentData::handleSelectionChanged(int index) { - if (!m_showLanguage) + if (!m_language) { return; } @@ -193,3 +236,64 @@ void QtProjectWizzardContentData::handleSelectionChanged(int index) m_cStandard->hide(); } } + + +QtProjectWizzardContentDataCDB::QtProjectWizzardContentDataCDB( + ProjectSettings* settings, QtProjectWizzardWindow* window) + : QtProjectWizzardContentData(settings, window) +{ +} + +void QtProjectWizzardContentDataCDB::populateForm(QGridLayout* layout, int& row) +{ + QString name = "Compilation Database"; + QString filter = "JSON Compilation Database (*.json)"; + + addNameAndLocation(layout, row); + + layout->setRowMinimumHeight(row++, 20); + + addBuildFilePicker(layout, row, name, filter); +} + +void QtProjectWizzardContentDataCDB::load() +{ + QtProjectWizzardContentData::load(); + + m_buildFilePicker->setText(QString::fromStdString(m_settings->getCompilationDatabasePath().str())); +} + +void QtProjectWizzardContentDataCDB::save() +{ + QtProjectWizzardContentData::save(); + + FilePath path = m_buildFilePicker->getText().toStdString(); + if (!path.exists() || path.extension() != ".json") + { + return; + } + m_settings->setCompilationDatabasePath(path); +} + +bool QtProjectWizzardContentDataCDB::check() +{ + if (!QtProjectWizzardContentData::check()) + { + return false; + } + + FilePath path = m_buildFilePicker->getText().toStdString(); + if (!path.exists() || path.extension() != ".json") + { + QMessageBox msgBox; + msgBox.setText("Please enter a valid compilation database file (*.json)."); + msgBox.exec(); + return false; + } + + return true; +} + +void QtProjectWizzardContentDataCDB::refreshClicked() +{ +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h index 10f33f2f..b47e06de 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h @@ -15,8 +15,6 @@ class QtProjectWizzardContentData public: QtProjectWizzardContentData(ProjectSettings* settings, QtProjectWizzardWindow* window); - void hideLanguage(); - // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; virtual void populateForm(QGridLayout* layout, int& row) override; @@ -27,7 +25,11 @@ public: virtual QSize preferredWindowSize() const override; -private: +protected: + virtual void addNameAndLocation(QGridLayout* layout, int& row); + virtual void addLanguageAndStandard(QGridLayout* layout, int& row); + virtual void addBuildFilePicker(QGridLayout* layout, int& row, const QString& name, const QString& filter); + QLineEdit* m_projectName; QtLocationPicker* m_projectFileLocation; @@ -35,10 +37,29 @@ private: QComboBox* m_cppStandard; QComboBox* m_cStandard; - bool m_showLanguage; + QtLocationPicker* m_buildFilePicker; private slots: void handleSelectionChanged(int index); }; + +class QtProjectWizzardContentDataCDB + : public QtProjectWizzardContentData +{ + Q_OBJECT + +public: + QtProjectWizzardContentDataCDB(ProjectSettings* settings, QtProjectWizzardWindow* window); + + virtual void populateForm(QGridLayout* layout, int& row) override; + + virtual void load() override; + virtual void save() override; + virtual bool check() override; + +private slots: + void refreshClicked(); +}; + #endif // QT_PROJECT_WIZZARD_CONTENT_DATA_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index ca1970a5..ea9eab6c 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -170,7 +170,10 @@ void QtProjectWizzardContentPaths::addDetection(QString name, QGridLayout* layou hlayout->addWidget(m_detectorBox); hlayout->addWidget(button); - layout->addLayout(hlayout, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop); + QWidget* detectionWidget = new QWidget(); + detectionWidget->setLayout(hlayout); + + layout->addWidget(detectionWidget, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop); } void QtProjectWizzardContentPaths::detectionClicked() @@ -208,7 +211,7 @@ QtProjectWizzardContentPathsSource::QtProjectWizzardContentPathsSource( "Project Paths", "Add all directories or files you want to analyse. Usually these are all source and header files of " "your project or a subset of them.", - "Project Paths define the source files and directories that will be analyzed by Coati. Usually these are the " + "Project Paths define the files and directories that will be analyzed by Coati. Usually these are the " "source and header files of your project or a subset of them." ); } @@ -228,19 +231,6 @@ void QtProjectWizzardContentPathsSource::save() m_settings->setSourcePaths(m_list->getList()); } -bool QtProjectWizzardContentPathsSource::check() -{ - if (m_list->getList().size() == 0) - { - QMessageBox msgBox; - msgBox.setText("Please add at least one path."); - msgBox.exec(); - return false; - } - - return QtProjectWizzardContentPaths::check(); -} - QStringList QtProjectWizzardContentPathsSource::getFileNames() const { std::vector sourcePaths = m_settings->getAbsoluteSourcePaths(); @@ -300,12 +290,12 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader( setTitleString("Header Paths"); setDescriptionString( - "Add the header files or directories containing the header files of the source files above. These header files " - "or files within these directories will be analyzed if included." + "Where are the header files of the source files? Add the directories or files that should be " + "analyzed if included by one of the source files." ); setHelpString( "The compilation database only contains source files. Add the header files or directories containing the header " - "files of these source files. The header files will be analyzed if included." + "files here. Header files will be analyzed if included." ); } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index e4101ec5..a422e0c1 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -64,7 +64,6 @@ public: virtual void load() override; virtual void save() override; - virtual bool check() override; virtual QStringList getFileNames() const override; virtual QString getFileNamesTitle() const override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index 16cbb5a3..b3295f32 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -70,7 +70,7 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) m_solutionDescription.push_back("Create a new Coati project by defining what files will be analyzed and header search paths."); m_solutionDescription.push_back("Create a project from an existing Compilation Database. Compilation Databases can be created from " - "cmake projects. Have a look at the " + "Make and CMake projects. Have a look at the " "" "documentation to find out more."); diff --git a/src/test/helper/TestFileManager.cpp b/src/test/helper/TestFileManager.cpp index b728574a..25c42f3b 100644 --- a/src/test/helper/TestFileManager.cpp +++ b/src/test/helper/TestFileManager.cpp @@ -9,12 +9,7 @@ bool TestFileManager::hasFilePath(const FilePath& filePath) const return true; } -bool TestFileManager::hasSourceExtension(const FilePath& filePath) const -{ - return true; -} - -bool TestFileManager::hasIncludeExtension(const FilePath& filePath) const +bool TestFileManager::hasSourceFilePath(const FilePath& filePath) const { return true; } diff --git a/src/test/helper/TestFileManager.h b/src/test/helper/TestFileManager.h index e9ebf561..071aec4f 100644 --- a/src/test/helper/TestFileManager.h +++ b/src/test/helper/TestFileManager.h @@ -10,8 +10,7 @@ public: TestFileManager(); virtual bool hasFilePath(const FilePath& filePath) const; - virtual bool hasSourceExtension(const FilePath& filePath) const; - virtual bool hasIncludeExtension(const FilePath& filePath) const; + virtual bool hasSourceFilePath(const FilePath& filePath) const; virtual const FileInfo getFileInfo(const FilePath& filePath) const; };