diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index 3ef756d5..abc50cea 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -1,4 +1,4 @@ -ConfigManager.cpp WARNING: value source/header_search_paths/header_search_path is not present in config. +ConfigManager.cpp WARNING: value path/to/nowhere is not present in config. CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:20 CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:20 @@ -66,6 +66,7 @@ NetworkProtocolHelper.cpp ERROR: Failed to parse message, invalid type token NetworkProtocolHelper.cpp ERROR: Failed to parse setActiveToken message, invalid token count Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml +ConfigManager.cpp WARNING: value NewBool is not present in config. INFO: file: file.cpp < 0:0 0:0> TextAccess.cpp ERROR: Could not open file file.cpp INFO: typedef: type diff --git a/src/app/data/parser/cxx/TaskParseCxx.cpp b/src/app/data/parser/cxx/TaskParseCxx.cpp index 5059ed44..ad19536f 100644 --- a/src/app/data/parser/cxx/TaskParseCxx.cpp +++ b/src/app/data/parser/cxx/TaskParseCxx.cpp @@ -2,6 +2,8 @@ #include +#include "clang/Tooling/JSONCompilationDatabase.h" + #include "data/parser/cxx/CxxParser.h" #include "data/parser/ParserClient.h" #include "utility/file/FileRegister.h" @@ -19,18 +21,49 @@ TaskParseCxx::TaskParseCxx( , m_parser(std::make_shared(client, fileManager)) , m_arguments(arguments) , m_files(files) + , m_isCDB(false) { + if (arguments.compilationDatabasePath.exists()) + { + m_isCDB = true; + } +} + +std::vector TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath) +{ + std::string error; + std::shared_ptr cdb = std::shared_ptr + (clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error)); + + std::vector files = cdb->getAllFiles(); + std::vector filePaths; + for (const std::string& file : files) + { + filePaths.push_back(FilePath(file)); + } + return filePaths; } void TaskParseCxx::enter() { m_start = utility::durationStart(); - m_parser->setupParsing(m_files, m_arguments); + if (m_isCDB) + { + std::string error; + m_cdb = std::shared_ptr + (clang::tooling::JSONCompilationDatabase::loadFromFile(m_arguments.compilationDatabasePath.str(), error)); + + m_parser->setupParsingCDB(m_files, m_arguments); + } + else + { + m_parser->setupParsing(m_files, m_arguments); + } for (const FilePath& path : m_parser->getFileRegister()->getUnparsedSourceFilePaths()) { - m_sourcePaths.push(path.absolute()); + m_sourcePaths.push_back(path.absolute()); } m_client->startParsing(); @@ -46,10 +79,10 @@ Task::TaskState TaskParseCxx::update() if (m_sourcePaths.size()) { sourcePath = m_sourcePaths.front(); - m_sourcePaths.pop(); + m_sourcePaths.pop_front(); isSource = true; } - else + else if (!m_isCDB) { std::vector unparsedHeaders = fileRegister->getUnparsedIncludeFilePaths(); if (unparsedHeaders.size()) @@ -65,14 +98,26 @@ Task::TaskState TaskParseCxx::update() std::stringstream ss; ss << "analyzing files (ESC to quit): ["; - ss << fileRegister->getParsedFilesCount() << "/" << fileRegister->getFilesCount() << "] "; + ss << (m_isCDB ? fileRegister->getParsedSourceFilesCount() : fileRegister->getParsedFilesCount()) + 1 << "/"; + ss << (m_isCDB ? fileRegister->getSourceFilesCount() : fileRegister->getFilesCount()) << "] "; ss << sourcePath.str(); MessageStatus(ss.str(), false, true).dispatch(); m_client->startParsingFile(sourcePath); - m_parser->runTool(std::vector(1, sourcePath.str())); + if (m_isCDB) + { + std::vector commands = m_cdb->getCompileCommands(sourcePath.str()); + if (commands.size() > 0) + { + m_parser->runTool(commands[0], m_arguments); + } + } + else + { + m_parser->runTool(std::vector(1, sourcePath.str())); + } m_client->finishParsingFile(sourcePath); @@ -93,8 +138,8 @@ void TaskParseCxx::exit() FileRegister* fileRegister = m_parser->getFileRegister(); MessageFinishedParsing( - fileRegister->getParsedFilesCount(), - fileRegister->getFilesCount(), + (m_isCDB ? fileRegister->getParsedSourceFilesCount() : fileRegister->getParsedFilesCount()), + (m_isCDB ? fileRegister->getSourceFilesCount() : fileRegister->getFilesCount()), utility::duration(m_start) ).dispatch(); } diff --git a/src/app/main.cpp b/src/app/main.cpp index f7d4ef8a..8a6bdf28 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -19,7 +19,6 @@ #include "version.h" #include "settings/ProjectSettings.h" -#include "utility/solution/SolutionParserCompilationDatabase.h" void init() { diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 367e6b4a..975e160f 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -271,8 +271,6 @@ add_files( utility/solution/ISolutionParser.cpp utility/solution/ISolutionParser.h - utility/solution/SolutionParserCompilationDatabase.cpp - utility/solution/SolutionParserCompilationDatabase.h utility/solution/SolutionParserVisualStudio.cpp utility/solution/SolutionParserVisualStudio.h diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index e0d9e887..de414252 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -168,12 +168,19 @@ void Project::updateFileManager() { std::shared_ptr projSettings = ProjectSettings::getInstance(); - std::vector sourcePaths(projSettings->getSourcePaths()); + std::vector sourcePaths = projSettings->getSourcePaths(); + std::vector headerPaths; + + if (projSettings->getCompilationDatabasePath().exists()) + { + headerPaths = sourcePaths; + sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath()); + } std::vector sourceExtensions = projSettings->getSourceExtensions(); std::vector includeExtensions = projSettings->getHeaderExtensions(); - m_fileManager.setPaths(sourcePaths, sourceExtensions, includeExtensions); + m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions, includeExtensions); } Parser::Arguments Project::getParserArguments() const @@ -212,6 +219,7 @@ Parser::Arguments Project::getParserArguments() const args.language = projSettings->getLanguage(); args.languageStandard = projSettings->getStandard(); + args.compilationDatabasePath = projSettings->getCompilationDatabasePath(); return args; } diff --git a/src/lib/data/parser/Parser.h b/src/lib/data/parser/Parser.h index 73f67a3f..79b48e14 100644 --- a/src/lib/data/parser/Parser.h +++ b/src/lib/data/parser/Parser.h @@ -24,6 +24,8 @@ public: bool logErrors; std::string language; std::string languageStandard; + + FilePath compilationDatabasePath; }; Parser(ParserClient* client); diff --git a/src/lib/data/parser/cxx/TaskParseCxx.h b/src/lib/data/parser/cxx/TaskParseCxx.h index dc11651f..50333ff9 100644 --- a/src/lib/data/parser/cxx/TaskParseCxx.h +++ b/src/lib/data/parser/cxx/TaskParseCxx.h @@ -2,7 +2,7 @@ #define TASK_PARSE_CXX_H #include -#include +#include #include "data/parser/Parser.h" #include "utility/scheduling/Task.h" @@ -12,6 +12,14 @@ class ParserClient; class FileManager; class CxxParser; +namespace clang +{ + namespace tooling + { + class JSONCompilationDatabase; + } +} + class TaskParseCxx : public Task { @@ -23,6 +31,8 @@ public: const std::vector& files ); + static std::vector getSourceFilesFromCDB(const FilePath& compilationDatabasePath); + virtual void enter(); virtual TaskState update(); virtual void exit(); @@ -36,9 +46,12 @@ private: const Parser::Arguments m_arguments; const std::vector m_files; - std::queue m_sourcePaths; + std::deque m_sourcePaths; TimePoint m_start; + + bool m_isCDB; + std::shared_ptr m_cdb; }; #endif // TASK_PARSE_CXX_H diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index fb2e8b71..eb2f613d 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -22,10 +22,12 @@ const std::vector& FileManager::getSourcePaths() const void FileManager::setPaths( std::vector sourcePaths, + std::vector headerPaths, std::vector sourceExtensions, std::vector includeExtensions ){ m_sourcePaths = sourcePaths; + m_headerPaths = headerPaths; m_sourceExtensions = sourceExtensions; m_includeExtensions = includeExtensions; } @@ -123,6 +125,7 @@ std::vector FileManager::getFileInfosInProject() const std::vector, std::vector>> pathsExtensionsPairs; pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_includeExtensions)); pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_sourceExtensions)); + pathsExtensionsPairs.push_back(std::make_pair(m_headerPaths, m_includeExtensions)); for (size_t i = 0; i < pathsExtensionsPairs.size(); i++) { diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index 09dd6cf7..0f982563 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -17,6 +17,7 @@ public: void setPaths( std::vector sourcePaths, + std::vector headerPaths, std::vector sourceExtensions, std::vector includeExtensions ); @@ -40,6 +41,8 @@ private: std::map m_files; std::vector m_sourcePaths; + std::vector m_headerPaths; + std::vector m_sourceExtensions; std::vector m_includeExtensions; diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index 6b6944e6..aa6d592e 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -138,7 +138,17 @@ size_t FileRegister::getFilesCount() const return m_sourceFilePaths.size() + m_includeFilePaths.size(); } +size_t FileRegister::getSourceFilesCount() const +{ + return m_sourceFilePaths.size(); +} + size_t FileRegister::getParsedFilesCount() const { return getFilesCount() - getUnparsedSourceFilePaths().size() - getUnparsedIncludeFilePaths().size(); } + +size_t FileRegister::getParsedSourceFilesCount() const +{ + return getSourceFilesCount() - getUnparsedSourceFilePaths().size(); +} diff --git a/src/lib/utility/file/FileRegister.h b/src/lib/utility/file/FileRegister.h index d6d81dad..d27cc110 100644 --- a/src/lib/utility/file/FileRegister.h +++ b/src/lib/utility/file/FileRegister.h @@ -31,7 +31,9 @@ public: void markParsingIncludeFilesParsed(); size_t getFilesCount() const; + size_t getSourceFilesCount() const; size_t getParsedFilesCount() const; + size_t getParsedSourceFilesCount() const; private: enum ParseState diff --git a/src/lib/utility/solution/SolutionParserCompilationDatabase.cpp b/src/lib/utility/solution/SolutionParserCompilationDatabase.cpp deleted file mode 100644 index 846bfb0b..00000000 --- a/src/lib/utility/solution/SolutionParserCompilationDatabase.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* -#include "utility/solution/SolutionParserCompilationDatabase.h" - -#include - -#include "clang/Tooling/JSONCompilationDatabase.h" -#include "settings/ProjectSettings.h" -#include "utility/file/FilePath.h" -#include "utility/file/FileSystem.h" -#include "utility/logging/logging.h" -#include "utility/utility.h" - -SolutionParserCompilationDatabase::SolutionParserCompilationDatabase() -{ -} - -SolutionParserCompilationDatabase::~SolutionParserCompilationDatabase() -{ -} - -std::string SolutionParserCompilationDatabase::getSolutionName() -{ - return ""; -} - -std::vector SolutionParserCompilationDatabase::getProjects() -{ - return std::vector(); -} - -std::vector SolutionParserCompilationDatabase::getProjectItems() -{ - std::vector files = getDatabase()->getAllFiles(); - - std::vector extensions = ProjectSettings::getInstance()->getHeaderExtensions(); - std::vector fileInfos = FileSystem::getFileInfosFromPaths(m_headerPaths, extensions); - - for (const FileInfo& info : fileInfos) - { - files.push_back(info.path.str()); - } - - return files; -} - -std::vector SolutionParserCompilationDatabase::getIncludePaths() -{ - return m_searchPaths; -} - -std::vector SolutionParserCompilationDatabase::getFrameworkPaths() -{ - return m_frameworkPaths; -} - -void SolutionParserCompilationDatabase::parseDatabase() -{ - std::vector commands = getDatabase()->getAllCompileCommands(); - - std::set headerPaths; - std::set searchPaths; - std::set frameworkPaths; - bool insertNext = false; - bool insertFramework = false; - for(clang::tooling::CompileCommand command : commands) - { - std::string dir = command.Directory; - for(std::string argument : command.CommandLine) - { - if(insertNext) - { - searchPaths.insert(getIncludePath(argument, command.Directory)); - insertNext = false; - } - if(insertFramework) - { - frameworkPaths.insert(getIncludePath(argument,command.Directory)); - insertFramework = false; - } - if(argument.substr(0,2) == "-I") - { - std::string includePath = getIncludePath(argument.substr(2), command.Directory); - headerPaths.insert(includePath); - searchPaths.insert(includePath); - } - if(argument == "-isystem") - { - insertNext = true; - } - if (argument == "-iframework") - { - insertFramework = true; - } - } - } - - for(std::string p : headerPaths) - { - m_headerPaths.push_back(FilePath(p)); - } - - for(std::string p : searchPaths) - { - m_searchPaths.push_back(p); - } - - for(std::string p : frameworkPaths) - { - m_frameworkPaths.push_back(p); - } -} - - -std::vector SolutionParserCompilationDatabase::getProjectFiles() -{ - return std::vector(); -} - -std::string SolutionParserCompilationDatabase::getIncludePath(const std::string& path, const std::string& dir) -{ - if (FilePath(path).isAbsolute()) - { - return path; - } - return dir + "/" + path; -} - -clang::tooling::JSONCompilationDatabase* SolutionParserCompilationDatabase::getDatabase() -{ - if(m_database == nullptr) - { - if(m_solutionPath.empty()) - { - LOG_ERROR("No compilation database file"); - } - else - { - std::string error; - m_database = std::shared_ptr - ( clang::tooling::JSONCompilationDatabase::loadFromFile(m_solutionPath + m_solutionName,error) ); - } - if(m_database == nullptr) - { - LOG_ERROR("Could not load compilation database from file: " + m_solutionPath ); - } - } - return m_database.get(); -} -*/ diff --git a/src/lib/utility/solution/SolutionParserCompilationDatabase.h b/src/lib/utility/solution/SolutionParserCompilationDatabase.h deleted file mode 100644 index c1717a3b..00000000 --- a/src/lib/utility/solution/SolutionParserCompilationDatabase.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -#ifndef COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H -#define COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H - -#include "utility/solution/ISolutionParser.h" - -#include -#include - -class FilePath; -namespace clang -{ - namespace tooling - { - class JSONCompilationDatabase; - } -} - -class SolutionParserCompilationDatabase : public ISolutionParser -{ -public: - SolutionParserCompilationDatabase(); - ~SolutionParserCompilationDatabase(); - - virtual std::string getSolutionName(); - virtual std::vector getProjects(); - virtual std::vector getProjectFiles(); - virtual std::vector getProjectItems(); - virtual std::vector getIncludePaths(); - std::vector getFrameworkPaths(); - - void parseDatabase(); - -private: - clang::tooling::JSONCompilationDatabase* getDatabase(); - std::string getIncludePath(const std::string& argument, const std::string& dir); - - std::shared_ptr m_database; - - std::vector m_headerPaths; - std::vector m_searchPaths; - std::vector m_frameworkPaths; -}; - - -#endif //COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H -*/ \ No newline at end of file diff --git a/src/lib/utility/utility.h b/src/lib/utility/utility.h index e4758fc5..a1cfc7ee 100644 --- a/src/lib/utility/utility.h +++ b/src/lib/utility/utility.h @@ -43,7 +43,7 @@ namespace utility bool isPermutation(const std::vector& a, const std::vector& b) { return ( - a.size() == b.size() && + a.size() == b.size() && std::is_permutation(a.begin(), a.end(), b.begin()) ); } diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index f9fdd82e..199a10bb 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -107,14 +107,14 @@ add_files( qt/window/project_wizzard/QtProjectWizzardContent.h qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h + qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp + qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h qt/window/project_wizzard/QtProjectWizzardContentData.cpp qt/window/project_wizzard/QtProjectWizzardContentData.h qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp qt/window/project_wizzard/QtProjectWizzardContentFlags.h qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp qt/window/project_wizzard/QtProjectWizzardContentPaths.h - qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp - qt/window/project_wizzard/QtProjectWizzardContentPreferences.h qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp qt/window/project_wizzard/QtProjectWizzardContentSelect.h qt/window/project_wizzard/QtProjectWizzardContentSimple.cpp diff --git a/src/lib_gui/qt/window/QtWindowStack.cpp b/src/lib_gui/qt/window/QtWindowStack.cpp index acde28ca..aabb8d44 100644 --- a/src/lib_gui/qt/window/QtWindowStack.cpp +++ b/src/lib_gui/qt/window/QtWindowStack.cpp @@ -21,6 +21,11 @@ QtWindowStackElement* QtWindowStack::getTopWindow() return nullptr; } +size_t QtWindowStack::getWindowCount() +{ + return m_stack.size(); +} + void QtWindowStack::pushWindow(QtWindowStackElement* window) { if (m_stack.size()) diff --git a/src/lib_gui/qt/window/QtWindowStack.h b/src/lib_gui/qt/window/QtWindowStack.h index 8b813960..e92ba0b1 100644 --- a/src/lib_gui/qt/window/QtWindowStack.h +++ b/src/lib_gui/qt/window/QtWindowStack.h @@ -30,6 +30,7 @@ public: QtWindowStack(QObject* parent = nullptr); QtWindowStackElement* getTopWindow(); + size_t getWindowCount(); public slots: void pushWindow(QtWindowStackElement* window); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 41099baa..21c72dd3 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -5,15 +5,16 @@ #include #include "qt/window/project_wizzard/QtProjectWizzardContent.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h" #include "qt/window/project_wizzard/QtProjectWizzardContentData.h" +#include "qt/window/project_wizzard/QtProjectWizzardContentFlags.h" #include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h" #include "qt/window/project_wizzard/QtProjectWizzardContentSimple.h" #include "qt/window/project_wizzard/QtProjectWizzardContentSourceList.h" #include "qt/window/project_wizzard/QtProjectWizzardContentSummary.h" #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "utility/messaging/type/MessageLoadProject.h" -#include "utility/solution/SolutionParserCompilationDatabase.h" #include "utility/solution/SolutionParserVisualStudio.h" QtProjectWizzard::QtProjectWizzard(QWidget* parent) @@ -64,11 +65,15 @@ void QtProjectWizzard::newProjectFromVisualStudioSolution(const std::string& vis editProject(settings); - QWidget* window = m_windowStack.getTopWindow(); + QWidget* widget = m_windowStack.getTopWindow(); - if (window) + if (widget) { - dynamic_cast(window)->updateTitle("NEW PROJECT FROM VS SOLUTION"); + QtProjectWizzardWindow* window = dynamic_cast(widget); + + window->updateTitle("NEW PROJECT FROM VS SOLUTION"); + window->updateNextButton("Create"); + window->setPreviousVisible(m_windowStack.getWindowCount() > 0); } } @@ -94,16 +99,9 @@ void QtProjectWizzard::refreshProjectFromVisualStudioSolution(const std::string& void QtProjectWizzard::newProjectFromCompilationDatabase(const std::string& compilationDatabasePath) { - ProjectSettings settings = getSettingsForCompilationDatabase(compilationDatabasePath); + m_settings = getSettingsForCompilationDatabase(compilationDatabasePath); - editProject(settings); - - QWidget* window = m_windowStack.getTopWindow(); - - if (window) - { - dynamic_cast(window)->updateTitle("NEW PROJECT FROM COMPILATION DATABASE"); - } + headerPathsCDB(); } void QtProjectWizzard::refreshProjectFromCompilationDatabase(const std::string& compilationDatabasePath) @@ -141,14 +139,33 @@ void QtProjectWizzard::editProject(const ProjectSettings& settings) window->updateTitle("EDIT PROJECT"); window->updateNextButton("Save"); - window->setPreviousVisible(false); - connect(window, SIGNAL(next()), this, SLOT(createProject())); } void QtProjectWizzard::showPreferences() { - QtProjectWizzardWindow* window = createWindowWithContent(); + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + summary->setIsForm(true); + + ProjectSettings* settings = &m_settings; + + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + + if (QSysInfo::macVersion() != QSysInfo::MV_None) + { + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + } + + window->setup(); + + window->updateTitle("PREFERENCES"); + window->updateNextButton("Save"); + window->setPreviousVisible(false); + } + ); + connect(window, SIGNAL(next()), this, SLOT(cancelWizzard())); } @@ -157,12 +174,30 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent() { QtProjectWizzardWindow* window = new QtProjectWizzardWindow(parentWidget()); + connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow())); + connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard())); + window->setContent(new T(&m_settings, window)); window->setup(); + m_windowStack.pushWindow(window); + + return window; +} + +QtProjectWizzardWindow* QtProjectWizzard::createWindowWithSummary( + std::function func +){ + QtProjectWizzardWindow* window = new QtProjectWizzardWindow(parentWidget()); + connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow())); connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard())); + QtProjectWizzardContentSummary* summary = new QtProjectWizzardContentSummary(&m_settings, window); + + window->setContent(summary); + func(window, summary); + m_windowStack.pushWindow(window); return window; @@ -232,43 +267,17 @@ ProjectSettings QtProjectWizzard::getSettingsForVisualStudioSolution(const std:: ProjectSettings QtProjectWizzard::getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const { - // SolutionParserCompilationDatabase parser; - // parser.openSolutionFile(compilationDatabasePath); - // parser.parseDatabase(); - ProjectSettings settings; - // settings.setProjectName(parser.getSolutionName()); - // settings.setProjectFileLocation(parser.getSolutionPath()); - // settings.setCompilationDatabasePath(FilePath(compilationDatabasePath)); - - // std::vector sourceFiles = parser.getProjectItems(); - // std::vector sourcePaths; - // for (const std::string& p : sourceFiles) - // { - // sourcePaths.push_back(FilePath(p)); - // } - - // std::vector includePaths = parser.getIncludePaths(); - // std::vector headerPaths; - // for (const std::string& p : includePaths) - // { - // headerPaths.push_back(FilePath(p)); - // } - - // std::vector frameworkPaths = parser.getFrameworkPaths(); - // std::vector frameworkSearchPaths; - // for (const std::string& p : frameworkPaths) - // { - // frameworkSearchPaths.push_back(FilePath(p)); - // } - - // settings.setSourcePaths(sourcePaths); - // settings.setHeaderSearchPaths(headerPaths); - // settings.setFrameworkSearchPaths(frameworkSearchPaths); - + settings.setCompilationDatabasePath(FilePath(compilationDatabasePath)); return settings; } +void QtProjectWizzard::connectShowFiles(QtProjectWizzardContent* content) +{ + connect(content, SIGNAL(filesButtonClicked(QtProjectWizzardContent*)), + this, SLOT(showFiles(QtProjectWizzardContent*))); +} + void QtProjectWizzard::cancelWizzard() { m_windowStack.clearWindows(); @@ -360,14 +369,23 @@ void QtProjectWizzard::sourcePaths() { QtProjectWizzardWindow* window = createWindowWithContent(); connect(window, SIGNAL(next()), this, SLOT(headerSearchPaths())); - - connect(dynamic_cast(window->content()), - SIGNAL(showSourceFiles()), this, SLOT(showSourceFiles())); + connectShowFiles(window->content()); } void QtProjectWizzard::headerSearchPaths() { - QtProjectWizzardWindow* window = createWindowWithContent(); + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + ProjectSettings* settings = &m_settings; + + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + + window->setup(); + } + ); + connect(window, SIGNAL(next()), this, SLOT(headerSearchPathsDone())); } @@ -375,14 +393,23 @@ void QtProjectWizzard::simpleSourcePaths() { QtProjectWizzardWindow* window = createWindowWithContent(); connect(window, SIGNAL(next()), this, SLOT(simpleHeaderSearchPaths())); - - connect(dynamic_cast(window->content()), - SIGNAL(showSourceFiles()), this, SLOT(showSourceFiles())); + connectShowFiles(window->content()); } void QtProjectWizzard::simpleHeaderSearchPaths() { - QtProjectWizzardWindow* window = createWindowWithContent(); + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + ProjectSettings* settings = &m_settings; + + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchSimple(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + + window->setup(); + } + ); + connect(window, SIGNAL(next()), this, SLOT(headerSearchPathsDone())); } @@ -400,39 +427,125 @@ void QtProjectWizzard::headerSearchPathsDone() void QtProjectWizzard::frameworkSearchPaths() { - QtProjectWizzardWindow* window = createWindowWithContent(); + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + ProjectSettings* settings = &m_settings; + + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + + window->setup(); + } + ); + connect(window, SIGNAL(next()), this, SLOT(showSummary())); } -void QtProjectWizzard::showSourceFiles() +void QtProjectWizzard::headerPathsCDB() { - QWidget* topWindow = m_windowStack.getTopWindow(); - if (topWindow) - { - dynamic_cast(topWindow)->content()->save(); - } + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + ProjectSettings* settings = &m_settings; + QtProjectWizzardContent* source = new QtProjectWizzardContentCDBSource(settings, window); + summary->addContent(source, false, false); + connectShowFiles(source); + + QtProjectWizzardContent* header = new QtProjectWizzardContentPathsCDBHeader(settings, window); + summary->addContent(header, false, false); + connectShowFiles(header); + + window->setup(); + + window->updateTitle("NEW PROJECT FROM COMPILATION DATABASE"); + } + ); + + connect(window, SIGNAL(next()), this, SLOT(headerPathsCDBDone())); +} + +void QtProjectWizzard::headerPathsCDBDone() +{ + showSummary(); + + QWidget* widget = m_windowStack.getTopWindow(); + + if (widget) + { + QtProjectWizzardWindow* window = dynamic_cast(widget); + + window->updateTitle("NEW PROJECT FROM COMPILATION DATABASE - SUMMARY"); + window->updateNextButton("Create"); + window->setPreviousVisible(m_windowStack.getWindowCount() > 0); + } +} + +void QtProjectWizzard::showFiles(QtProjectWizzardContent* content) +{ QtProjectWizzardWindow* window = createPopupWithContent(); - dynamic_cast(window->content())->showFilesFromSourcePaths(); + dynamic_cast(window->content())->showFilesFromContent(content); } void QtProjectWizzard::showSummary() { - QtProjectWizzardWindow* window = createWindowWithContent(); + QtProjectWizzardWindow* window = createWindowWithSummary( + [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) + { + summary->setIsForm(true); + + 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&)), + this, SLOT(refreshProjectFromVisualStudioSolution(const std::string&))); + } + + if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_CDB) + { + QtProjectWizzardContentPathsSource* source = new QtProjectWizzardContentPathsSource(settings, window); + summary->addContent(source, false, true); + connectShowFiles(source); + + summary->addContent(new QtProjectWizzardContentSimple(settings, window), false, true); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + + if (QSysInfo::macVersion() != QSysInfo::MV_None) + { + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), false, true); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + } + } + else + { + QtProjectWizzardContent* headers = new QtProjectWizzardContentPathsCDBHeader(settings, window); + summary->addContent(headers, false, true); + connectShowFiles(headers); + + data->hideLanguage(); + } + + summary->addContent(new QtProjectWizzardContentFlags(settings, window), true, false); + + window->setup(); + + window->updateTitle("NEW PROJECT - SUMMARY"); + window->updateNextButton("Create"); + } + ); + connect(window, SIGNAL(next()), this, SLOT(createProject())); - - QtProjectWizzardContentSummary* summary = dynamic_cast(window->content()); - - connect(dynamic_cast(summary->contentBuildFile()), - SIGNAL(refreshVisualStudioSolution(const std::string&)), - this, SLOT(refreshProjectFromVisualStudioSolution(const std::string&))); - - connect(dynamic_cast(summary->contentBuildFile()), - SIGNAL(refreshCompilationDatabase(const std::string&)), - this, SLOT(refreshProjectFromCompilationDatabase(const std::string&))); - - connect(dynamic_cast(summary->contentPathsSource()), - SIGNAL(showSourceFiles()), this, SLOT(showSourceFiles())); } void QtProjectWizzard::createProject() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index 41f1bc5f..094bc5d0 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -7,6 +7,7 @@ #include "qt/window/QtWindowStack.h" class ProjectSettings; +class QtProjectWizzardContentSummary; class QtProjectWizzardWindow; class QtProjectWizzard @@ -37,12 +38,16 @@ public slots: private: template QtProjectWizzardWindow* createWindowWithContent(); + QtProjectWizzardWindow* createWindowWithSummary( + std::function func); template QtProjectWizzardWindow* createPopupWithContent(); ProjectSettings getSettingsForVisualStudioSolution(const std::string& visualStudioSolutionPath) const; ProjectSettings getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const; + void connectShowFiles(QtProjectWizzardContent* content); + QtWindowStack m_windowStack; std::shared_ptr m_popup; ProjectSettings m_settings; @@ -67,7 +72,11 @@ private slots: void headerSearchPathsDone(); void frameworkSearchPaths(); - void showSourceFiles(); + void headerPathsCDB(); + void headerPathsCDBDone(); + + void showFiles(QtProjectWizzardContent* content); + void showSummary(); void createProject(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp index df09b02e..d1d6aa06 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp @@ -39,6 +39,10 @@ void QtProjectWizzardContent::populateWindow(QGridLayout* layout) { } +void QtProjectWizzardContent::populateWindow(QGridLayout* layout, int& row) +{ +} + void QtProjectWizzardContent::populateForm(QGridLayout* layout, int& row) { } @@ -70,6 +74,21 @@ QSize QtProjectWizzardContent::preferredWindowSize() const return QSize(750, 620); } +QStringList QtProjectWizzardContent::getFileNames() const +{ + return QStringList(); +} + +QString QtProjectWizzardContent::getFileNamesTitle() const +{ + return "File List"; +} + +QString QtProjectWizzardContent::getFileNamesDescription() const +{ + return "files"; +} + QLabel* QtProjectWizzardContent::createFormLabel(QString name) const { QLabel* label = new QLabel(name); @@ -97,3 +116,20 @@ QtHelpButton* QtProjectWizzardContent::addHelpButton(QString helpString, QGridLa layout->addWidget(button, row, QtProjectWizzardWindow::HELP_COL, Qt::AlignTop); return button; } + +QPushButton* QtProjectWizzardContent::addFilesButton(QString name, QGridLayout* layout, int row) const +{ + QPushButton* button = new QPushButton(name); + button->setObjectName("windowButton"); + layout->addWidget(button, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight | Qt::AlignTop); + connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + + return button; +} + +void QtProjectWizzardContent::buttonClicked() +{ + save(); + + emit filesButtonClicked(this); +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h index 4122ac99..ec7a8f51 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h @@ -37,6 +37,7 @@ public: virtual void populateWindow(QWidget* widget); virtual void populateWindow(QGridLayout* layout); + virtual void populateWindow(QGridLayout* layout, int& row); virtual void populateForm(QGridLayout* layout, int& row); virtual void windowReady(); @@ -48,14 +49,25 @@ public: virtual QSize preferredWindowSize() const; + virtual QStringList getFileNames() const; + virtual QString getFileNamesTitle() const; + virtual QString getFileNamesDescription() const; + +signals: + void filesButtonClicked(QtProjectWizzardContent* content); + protected: QLabel* createFormLabel(QString name) const; QToolButton* createProjectButton(QString name, QString iconPath) const; QtHelpButton* addHelpButton(QString helpString, QGridLayout* layout, int row) const; + QPushButton* addFilesButton(QString name, QGridLayout* layout, int row) const; ProjectSettings* m_settings; QtProjectWizzardWindow* m_window; + +private slots: + void buttonClicked(); }; #endif // QT_PROJECT_WIZZARD_CONTENT_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index 404eec98..feb988a7 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -21,6 +21,11 @@ QtProjectWizzardContentBuildFile::QtProjectWizzardContentBuildFile( } } +QtProjectWizzardContentSelect::ProjectType QtProjectWizzardContentBuildFile::getType() const +{ + return m_type; +} + void QtProjectWizzardContentBuildFile::populateForm(QGridLayout* layout, int& row) { QString name; @@ -54,6 +59,11 @@ void QtProjectWizzardContentBuildFile::populateForm(QGridLayout* layout, int& ro button->setToolTip("refresh paths"); connect(button, SIGNAL(clicked()), this, SLOT(refreshClicked())); + if (m_type == QtProjectWizzardContentSelect::PROJECT_CDB) + { + button->hide(); + } + m_picker->layout()->addWidget(button); layout->addWidget(m_picker, row, QtProjectWizzardWindow::BACK_COL); @@ -76,6 +86,49 @@ void QtProjectWizzardContentBuildFile::load() } } +void QtProjectWizzardContentBuildFile::save() +{ + switch (m_type) + { + case QtProjectWizzardContentSelect::PROJECT_EMPTY: + case QtProjectWizzardContentSelect::PROJECT_VS: + break; + case QtProjectWizzardContentSelect::PROJECT_CDB: + { + FilePath path = m_picker->getText().toStdString(); + if (!path.exists() || path.extension() != ".json") + { + return; + } + m_settings->setCompilationDatabasePath(m_picker->getText().toStdString()); + break; + } + } +} + +bool QtProjectWizzardContentBuildFile::check() +{ + switch (m_type) + { + case QtProjectWizzardContentSelect::PROJECT_EMPTY: + case QtProjectWizzardContentSelect::PROJECT_VS: + break; + case QtProjectWizzardContentSelect::PROJECT_CDB: + { + FilePath path = m_picker->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 QtProjectWizzardContentBuildFile::refreshClicked() { FilePath path = FilePath(m_picker->getText().toStdString()); @@ -101,14 +154,10 @@ void QtProjectWizzardContentBuildFile::refreshClicked() switch (m_type) { case QtProjectWizzardContentSelect::PROJECT_EMPTY: + case QtProjectWizzardContentSelect::PROJECT_CDB: break; case QtProjectWizzardContentSelect::PROJECT_VS: - { emit refreshVisualStudioSolution(path.str()); break; - } - case QtProjectWizzardContentSelect::PROJECT_CDB: - emit refreshCompilationDatabase(path.str()); - break; } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h index 06d2b7e8..d2767727 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h @@ -14,15 +14,18 @@ class QtProjectWizzardContentBuildFile signals: void refreshVisualStudioSolution(const std::string&); - void refreshCompilationDatabase(const std::string&); public: QtProjectWizzardContentBuildFile(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentSelect::ProjectType getType() const; + // QtProjectWizzardContent implementation virtual void populateForm(QGridLayout* layout, int& row) override; virtual void load() override; + virtual void save() override; + virtual bool check() override; private slots: void refreshClicked(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp new file mode 100644 index 00000000..913fed13 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp @@ -0,0 +1,63 @@ +#include "qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h" + +#include "data/parser/cxx/TaskParseCxx.h" + +QtProjectWizzardContentCDBSource::QtProjectWizzardContentCDBSource( + ProjectSettings* settings, QtProjectWizzardWindow* window +) + : QtProjectWizzardContent(settings, window) + , m_text(nullptr) +{ +} + +void QtProjectWizzardContentCDBSource::populateWindow(QGridLayout* layout, int& row) +{ + layout->setRowMinimumHeight(row++, 10); + + QLabel* title = new QLabel("Source Files"); + title->setWordWrap(true); + title->setObjectName("section"); + layout->addWidget(title, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); + layout->setRowStretch(row, 0); + + m_text = new QLabel(""); + layout->addWidget(m_text, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignTop); + + addFilesButton("show source files", layout, row + 1); + + row += 2; + + layout->setColumnStretch(QtProjectWizzardWindow::FRONT_COL, 1); + layout->setColumnStretch(QtProjectWizzardWindow::BACK_COL, 2); +} + +void QtProjectWizzardContentCDBSource::load() +{ + std::vector filePaths = TaskParseCxx::getSourceFilesFromCDB(m_settings->getCompilationDatabasePath()); + + m_fileNames.clear(); + for (const FilePath& path : filePaths) + { + m_fileNames << QString::fromStdString(path.str()); + } + + if (m_text) + { + m_text->setText(QString::number(m_fileNames.size()) + " source files were found in the compilation database."); + } +} + +QStringList QtProjectWizzardContentCDBSource::getFileNames() const +{ + return m_fileNames; +} + +QString QtProjectWizzardContentCDBSource::getFileNamesTitle() const +{ + return "Source Files"; +} + +QString QtProjectWizzardContentCDBSource::getFileNamesDescription() const +{ + return "source files will be analyzed."; +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h new file mode 100644 index 00000000..52c2b4f5 --- /dev/null +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h @@ -0,0 +1,28 @@ +#ifndef QT_PROJECT_WIZZARD_CONTENT_CDB_SOURCE_H +#define QT_PROJECT_WIZZARD_CONTENT_CDB_SOURCE_H + +#include "qt/window/project_wizzard/QtProjectWizzardContent.h" + +class QtProjectWizzardContentCDBSource + : public QtProjectWizzardContent +{ + Q_OBJECT + +public: + QtProjectWizzardContentCDBSource(ProjectSettings* settings, QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual void populateWindow(QGridLayout* layout, int& row) override; + + virtual void load() override; + + virtual QStringList getFileNames() const override; + virtual QString getFileNamesTitle() const override; + virtual QString getFileNamesDescription() const override; + +private: + QLabel* m_text; + QStringList m_fileNames; +}; + +#endif // QT_PROJECT_WIZZARD_CONTENT_CDB_SOURCE_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp index be3eb7b6..d580422f 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp @@ -5,9 +5,15 @@ QtProjectWizzardContentData::QtProjectWizzardContentData(ProjectSettings* settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) + , m_showLanguage(true) { } +void QtProjectWizzardContentData::hideLanguage() +{ + m_showLanguage = false; +} + void QtProjectWizzardContentData::populateWindow(QGridLayout* layout) { int row = 0; @@ -42,6 +48,7 @@ void QtProjectWizzardContentData::populateForm(QGridLayout* layout, int& row) layout->addWidget(m_projectFileLocation, row, QtProjectWizzardWindow::BACK_COL); row++; + QLabel* languageLabel = new QLabel("Language"); languageLabel->setObjectName("label"); m_language = new QComboBox(); @@ -49,13 +56,8 @@ void QtProjectWizzardContentData::populateForm(QGridLayout* layout, int& row) 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"); - layout->addWidget(standardLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); m_cppStandard = new QComboBox(); m_cppStandard->insertItem(0, "1z"); @@ -66,8 +68,6 @@ void QtProjectWizzardContentData::populateForm(QGridLayout* layout, int& row) m_cppStandard->insertItem(5, "03"); m_cppStandard->insertItem(6, "98"); - layout->addWidget(m_cppStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); - m_cStandard = new QComboBox(); m_cStandard->insertItem(0, "1x"); m_cStandard->insertItem(1, "11"); @@ -76,7 +76,26 @@ void QtProjectWizzardContentData::populateForm(QGridLayout* layout, int& row) m_cStandard->insertItem(4, "90"); m_cStandard->insertItem(5, "89"); - layout->addWidget(m_cStandard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft); + 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++; } @@ -158,6 +177,11 @@ QSize QtProjectWizzardContentData::preferredWindowSize() const void QtProjectWizzardContentData::handleSelectionChanged(int index) { + if (!m_showLanguage) + { + return; + } + if (index != 0) { m_cStandard->show(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h index 9a29e214..10f33f2f 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h @@ -15,6 +15,8 @@ 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; @@ -33,6 +35,8 @@ private: QComboBox* m_cppStandard; QComboBox* m_cStandard; + bool m_showLanguage; + private slots: void handleSelectionChanged(int index); }; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 97d8c53a..3530b509 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -6,47 +6,24 @@ #include "qt/element/QtDirectoryListBox.h" #include "settings/ApplicationSettings.h" - +#include "utility/file/FileSystem.h" +#include "utility/utility.h" QtProjectWizzardContentPaths::QtProjectWizzardContentPaths(ProjectSettings* settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) - , m_subPaths(nullptr) - , m_addShowSourcesButton(false) { } void QtProjectWizzardContentPaths::populateWindow(QGridLayout* layout) { int row = 0; - - layout->setRowMinimumHeight(row, 10); - row++; - - populateLayout(layout, row); - - if (m_addShowSourcesButton) - { - layout->setRowStretch(row, 10); - addSourcesButton(layout, row); - } - - if (m_subPaths) - { - layout->setRowMinimumHeight(row, 30); - row++; - - m_subPaths->populateLayout(layout, row); - - layout->setRowMinimumHeight(row, 10); - row++; - } - - layout->setColumnStretch(QtProjectWizzardWindow::FRONT_COL, 1); - layout->setColumnStretch(QtProjectWizzardWindow::BACK_COL, 2); + populateWindow(layout, row); } -void QtProjectWizzardContentPaths::populateLayout(QGridLayout* layout, int& row) +void QtProjectWizzardContentPaths::populateWindow(QGridLayout* layout, int& row) { + layout->setRowMinimumHeight(row++, 10); + QLabel* title = new QLabel(m_titleString); title->setWordWrap(true); title->setObjectName("section"); @@ -63,6 +40,17 @@ void QtProjectWizzardContentPaths::populateLayout(QGridLayout* layout, int& row) layout->addWidget(m_list, row, QtProjectWizzardWindow::BACK_COL, 2, 1, Qt::AlignTop); row += 2; + + if (m_showFilesString.size() > 0) + { + layout->setRowStretch(row, 10); + addFilesButton(m_showFilesString, layout, row); + } + + row++; + + layout->setColumnStretch(QtProjectWizzardWindow::FRONT_COL, 1); + layout->setColumnStretch(QtProjectWizzardWindow::BACK_COL, 2); } void QtProjectWizzardContentPaths::populateForm(QGridLayout* layout, int& row) @@ -79,45 +67,11 @@ void QtProjectWizzardContentPaths::populateForm(QGridLayout* layout, int& row) layout->addWidget(m_list, row, QtProjectWizzardWindow::BACK_COL); row++; - if (m_addShowSourcesButton) + if (m_showFilesString.size() > 0) { - addSourcesButton(layout, row); + addFilesButton(m_showFilesString, layout, row); + row++; } - - if (m_subPaths) - { - m_subPaths->populateForm(layout, row); - } -} - -void QtProjectWizzardContentPaths::load() -{ - loadPaths(); - - if (m_subPaths) - { - return m_subPaths->loadPaths(); - } -} - -void QtProjectWizzardContentPaths::save() -{ - savePaths(); - - if (m_subPaths) - { - m_subPaths->savePaths(); - } -} - -bool QtProjectWizzardContentPaths::check() -{ - if (m_subPaths) - { - return checkPaths() && m_subPaths->checkPaths(); - } - - return checkPaths(); } QSize QtProjectWizzardContentPaths::preferredWindowSize() const @@ -125,19 +79,6 @@ QSize QtProjectWizzardContentPaths::preferredWindowSize() const return QSize(850, 500); } -void QtProjectWizzardContentPaths::loadPaths() -{ -} - -void QtProjectWizzardContentPaths::savePaths() -{ -} - -bool QtProjectWizzardContentPaths::checkPaths() -{ - return true; -} - void QtProjectWizzardContentPaths::setInfo(const QString& title, const QString& description, const QString& help) { m_titleString = title; @@ -160,31 +101,12 @@ void QtProjectWizzardContentPaths::setHelpString(const QString& help) m_helpString = help; } -void QtProjectWizzardContentPaths::showSourcesClicked() -{ - emit showSourceFiles(); -} - -void QtProjectWizzardContentPaths::addSourcesButton(QGridLayout* layout, int& row) -{ - if (!m_addShowSourcesButton) - { - return; - } - - QPushButton* button = new QPushButton("show files"); - button->setObjectName("windowButton"); - layout->addWidget(button, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight | Qt::AlignTop); - connect(button, SIGNAL(clicked()), this, SLOT(showSourcesClicked())); - row++; -} - QtProjectWizzardContentPathsSource::QtProjectWizzardContentPathsSource( ProjectSettings* settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { - m_addShowSourcesButton = true; + m_showFilesString = "show files"; setInfo( "Project Paths", @@ -200,17 +122,17 @@ QSize QtProjectWizzardContentPathsSource::preferredWindowSize() const return QSize(850, 370); } -void QtProjectWizzardContentPathsSource::loadPaths() +void QtProjectWizzardContentPathsSource::load() { m_list->setList(m_settings->getSourcePaths()); } -void QtProjectWizzardContentPathsSource::savePaths() +void QtProjectWizzardContentPathsSource::save() { m_settings->setSourcePaths(m_list->getList()); } -bool QtProjectWizzardContentPathsSource::checkPaths() +bool QtProjectWizzardContentPathsSource::check() { if (m_list->getList().size() == 0) { @@ -223,12 +145,58 @@ bool QtProjectWizzardContentPathsSource::checkPaths() return true; } +QStringList QtProjectWizzardContentPathsSource::getFileNames() const +{ + return getSourceFileNames(false); +} + +QString QtProjectWizzardContentPathsSource::getFileNamesTitle() const +{ + return "Analyzed Files"; +} + +QString QtProjectWizzardContentPathsSource::getFileNamesDescription() const +{ + return "files will be analyzed."; +} + +QStringList QtProjectWizzardContentPathsSource::getSourceFileNames(bool headersOnly) const +{ + std::vector sourcePaths = m_settings->getSourcePaths(); + + std::vector extensions; + if (!headersOnly) + { + utility::append(extensions, m_settings->getSourceExtensions()); + } + utility::append(extensions, m_settings->getHeaderExtensions()); + + std::vector fileInfos = FileSystem::getFileInfosFromPaths(sourcePaths, extensions); + + FilePath projectPath = FilePath(m_settings->getProjectFileLocation()); + + QStringList list; + for (const FileInfo& info : fileInfos) + { + FilePath path = info.path; + + if (projectPath.exists()) + { + path = path.relativeTo(projectPath); + } + + list << QString::fromStdString(path.str()); + } + + return list; +} + QtProjectWizzardContentPathsSourceSimple::QtProjectWizzardContentPathsSourceSimple( ProjectSettings* settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPathsSource(settings, window) { - m_addShowSourcesButton = true; + m_showFilesString = "show files"; setTitleString("Project Paths"); setDescriptionString( @@ -237,6 +205,43 @@ QtProjectWizzardContentPathsSourceSimple::QtProjectWizzardContentPathsSourceSimp ); } +QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader( + ProjectSettings* settings, QtProjectWizzardWindow* window +) + : QtProjectWizzardContentPathsSource(settings, window) +{ + m_showFilesString = "show header files"; + + setTitleString("Header Paths"); + setDescriptionString( + "Add the header files or directories containing the header files of the source files above. These header files " + "will be analyzed if included." + ); + 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." + ); +} + +bool QtProjectWizzardContentPathsCDBHeader::check() +{ + return true; +} + +QStringList QtProjectWizzardContentPathsCDBHeader::getFileNames() const +{ + return getSourceFileNames(true); +} + +QString QtProjectWizzardContentPathsCDBHeader::getFileNamesTitle() const +{ + return "Header Files"; +} + +QString QtProjectWizzardContentPathsCDBHeader::getFileNamesDescription() const +{ + return "header files found."; +} QtProjectWizzardContentPathsHeaderSearch::QtProjectWizzardContentPathsHeaderSearch( ProjectSettings* settings, QtProjectWizzardWindow* window @@ -250,16 +255,14 @@ QtProjectWizzardContentPathsHeaderSearch::QtProjectWizzardContentPathsHeaderSear "header files of frameworks or libraries that your project uses. These files won't be analyzed, but Coati needs " "them for correct analysis." ); - - m_subPaths = new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window); } -void QtProjectWizzardContentPathsHeaderSearch::loadPaths() +void QtProjectWizzardContentPathsHeaderSearch::load() { m_list->setList(m_settings->getHeaderSearchPaths()); } -void QtProjectWizzardContentPathsHeaderSearch::savePaths() +void QtProjectWizzardContentPathsHeaderSearch::save() { m_settings->setHeaderSearchPaths(m_list->getList()); } @@ -298,12 +301,12 @@ QtProjectWizzardContentPathsHeaderSearchGlobal::QtProjectWizzardContentPathsHead ); } -void QtProjectWizzardContentPathsHeaderSearchGlobal::loadPaths() +void QtProjectWizzardContentPathsHeaderSearchGlobal::load() { m_list->setList(ApplicationSettings::getInstance()->getHeaderSearchPaths()); } -void QtProjectWizzardContentPathsHeaderSearchGlobal::savePaths() +void QtProjectWizzardContentPathsHeaderSearchGlobal::save() { ApplicationSettings::getInstance()->setHeaderSearchPaths(m_list->getList()); ApplicationSettings::getInstance()->save(); @@ -321,16 +324,14 @@ QtProjectWizzardContentPathsFrameworkSearch::QtProjectWizzardContentPathsFramewo "Framework Search Paths define where MacOS framework containers (.framework), that your project depends on, are " "found." ); - - m_subPaths = new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window); } -void QtProjectWizzardContentPathsFrameworkSearch::loadPaths() +void QtProjectWizzardContentPathsFrameworkSearch::load() { m_list->setList(m_settings->getFrameworkSearchPaths()); } -void QtProjectWizzardContentPathsFrameworkSearch::savePaths() +void QtProjectWizzardContentPathsFrameworkSearch::save() { m_settings->setFrameworkSearchPaths(m_list->getList()); } @@ -356,12 +357,12 @@ QtProjectWizzardContentPathsFrameworkSearchGlobal::QtProjectWizzardContentPathsF ); } -void QtProjectWizzardContentPathsFrameworkSearchGlobal::loadPaths() +void QtProjectWizzardContentPathsFrameworkSearchGlobal::load() { m_list->setList(ApplicationSettings::getInstance()->getFrameworkSearchPaths()); } -void QtProjectWizzardContentPathsFrameworkSearchGlobal::savePaths() +void QtProjectWizzardContentPathsFrameworkSearchGlobal::save() { ApplicationSettings::getInstance()->setFrameworkSearchPaths(m_list->getList()); ApplicationSettings::getInstance()->save(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index 71b9892f..15d9f596 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -20,19 +20,11 @@ public: // QtSettingsWindow implementation virtual void populateWindow(QGridLayout* layout) override; - void populateLayout(QGridLayout* layout, int& row); + virtual void populateWindow(QGridLayout* layout, int& row) override; virtual void populateForm(QGridLayout* layout, int& row) override; - virtual void load() override; - virtual void save() override; - virtual bool check() override; - virtual QSize preferredWindowSize() const override; - virtual void loadPaths(); - virtual void savePaths(); - virtual bool checkPaths(); - protected: void setInfo(const QString& title, const QString& description, const QString& help); void setTitleString(const QString& title); @@ -40,16 +32,10 @@ protected: void setHelpString(const QString& help); QtDirectoryListBox* m_list; - QtProjectWizzardContentPaths* m_subPaths; - bool m_addShowSourcesButton; - -private slots: - void showSourcesClicked(); + QString m_showFilesString; private: - void addSourcesButton(QGridLayout* layout, int& row); - QString m_titleString; QString m_descriptionString; QString m_helpString; @@ -65,10 +51,16 @@ public: // QtProjectWizzardContent implementation virtual QSize preferredWindowSize() const override; - // QtProjectWizzardContentPaths implementation - virtual void loadPaths() override; - virtual void savePaths() override; - virtual bool checkPaths() override; + virtual void load() override; + virtual void save() override; + virtual bool check() override; + + virtual QStringList getFileNames() const override; + virtual QString getFileNamesTitle() const override; + virtual QString getFileNamesDescription() const override; + +protected: + QStringList getSourceFileNames(bool headersOnly) const; }; class QtProjectWizzardContentPathsSourceSimple @@ -78,6 +70,20 @@ public: QtProjectWizzardContentPathsSourceSimple(ProjectSettings* settings, QtProjectWizzardWindow* window); }; +class QtProjectWizzardContentPathsCDBHeader + : public QtProjectWizzardContentPathsSource +{ +public: + QtProjectWizzardContentPathsCDBHeader(ProjectSettings* settings, QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + virtual bool check() override; + + virtual QStringList getFileNames() const override; + virtual QString getFileNamesTitle() const override; + virtual QString getFileNamesDescription() const override; +}; + class QtProjectWizzardContentPathsHeaderSearch : public QtProjectWizzardContentPaths @@ -86,8 +92,8 @@ public: QtProjectWizzardContentPathsHeaderSearch(ProjectSettings* settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation - virtual void loadPaths() override; - virtual void savePaths() override; + virtual void load() override; + virtual void save() override; virtual bool isScrollAble() const override; }; @@ -106,8 +112,8 @@ public: QtProjectWizzardContentPathsHeaderSearchGlobal(ProjectSettings* settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation - virtual void loadPaths() override; - virtual void savePaths() override; + virtual void load() override; + virtual void save() override; }; @@ -118,8 +124,8 @@ public: QtProjectWizzardContentPathsFrameworkSearch(ProjectSettings* settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation - virtual void loadPaths() override; - virtual void savePaths() override; + virtual void load() override; + virtual void save() override; virtual bool isScrollAble() const override; }; @@ -131,8 +137,8 @@ public: QtProjectWizzardContentPathsFrameworkSearchGlobal(ProjectSettings* settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation - virtual void loadPaths() override; - virtual void savePaths() override; + virtual void load() override; + virtual void save() override; }; #endif // QT_PROJECT_WIZZARD_CONTENT_PATHS_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp deleted file mode 100644 index 83739693..00000000 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h" - -#include - -QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences(ProjectSettings* settings, QtProjectWizzardWindow* window) - : QtProjectWizzardContent(settings, window) - , m_headerSearch(nullptr) - , m_frameworkSearch(nullptr) -{ - m_headerSearch = new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window); - - if (QSysInfo::macVersion() != QSysInfo::MV_None) - { - m_frameworkSearch = new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window); - } -} - -void QtProjectWizzardContentPreferences::populateWindow(QGridLayout* layout) -{ - int row = 0; - - layout->setRowMinimumHeight(row, 10); - row++; - - m_headerSearch->populateForm(layout, row); - - if (m_frameworkSearch) - { - m_frameworkSearch->populateForm(layout, row); - } - - layout->setRowMinimumHeight(row, 10); - - layout->setRowStretch(row, 1); -} - -void QtProjectWizzardContentPreferences::windowReady() -{ - m_window->updateTitle("PREFERENCES"); - m_window->updateNextButton("Save"); - m_window->setPreviousVisible(false); -} - -void QtProjectWizzardContentPreferences::load() -{ - m_headerSearch->load(); - - if (m_frameworkSearch) - { - m_frameworkSearch->load(); - } -} - -void QtProjectWizzardContentPreferences::save() -{ - m_headerSearch->save(); - - if (m_frameworkSearch) - { - m_frameworkSearch->save(); - } -} - -bool QtProjectWizzardContentPreferences::isScrollAble() const -{ - return true; -} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h deleted file mode 100644 index 1eb49538..00000000 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H -#define QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H - -#include "qt/window/project_wizzard/QtProjectWizzardContent.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h" - -class QtProjectWizzardContentPreferences - : public QtProjectWizzardContent -{ -public: - QtProjectWizzardContentPreferences(ProjectSettings* settings, QtProjectWizzardWindow* window); - -protected: - // QtProjectContentWindow implementation - virtual void populateWindow(QGridLayout* layout) override; - virtual void windowReady() override; - - virtual void load() override; - virtual void save() override; - - virtual bool isScrollAble() const override; - -private: - QtProjectWizzardContentPathsHeaderSearchGlobal* m_headerSearch; - QtProjectWizzardContentPathsFrameworkSearchGlobal* m_frameworkSearch; -}; - -#endif // QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index 310cb0d3..9af057d6 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -67,8 +67,6 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) QToolButton* c = createProjectButton( "from Compilation\nDatabase", (ResourcePaths::getGuiPath() + "icon/project_cdb_256_256.png").c_str()); - c->hide(); - m_buttons = new QButtonGroup(this); m_buttons->addButton(a); m_buttons->addButton(b); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp index 2c82e7b3..8505a56d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp @@ -3,9 +3,6 @@ #include #include -#include "utility/file/FileSystem.h" -#include "utility/utility.h" - QtProjectWizzardContentSourceList::QtProjectWizzardContentSourceList( ProjectSettings* settings, QtProjectWizzardWindow* window ) @@ -32,7 +29,6 @@ void QtProjectWizzardContentSourceList::populateWindow(QWidget* widget) void QtProjectWizzardContentSourceList::windowReady() { - m_window->updateTitle("Analyzed Files"); } QSize QtProjectWizzardContentSourceList::preferredWindowSize() const @@ -40,34 +36,13 @@ QSize QtProjectWizzardContentSourceList::preferredWindowSize() const return QSize(500, 500); } -void QtProjectWizzardContentSourceList::showFilesFromSourcePaths() +void QtProjectWizzardContentSourceList::showFilesFromContent(QtProjectWizzardContent* content) { - std::vector sourcePaths = m_settings->getSourcePaths(); + QStringList list = content->getFileNames(); + m_text->setText(QString::number(list.size()) + " " + content->getFileNamesDescription()); + m_window->updateTitle(content->getFileNamesTitle()); - std::vector extensions; - utility::append(extensions, m_settings->getSourceExtensions()); - utility::append(extensions, m_settings->getHeaderExtensions()); - - std::vector fileInfos = FileSystem::getFileInfosFromPaths(sourcePaths, extensions); - - FilePath projectPath = FilePath(m_settings->getProjectFileLocation()); - - QStringList list; - for (const FileInfo& info : fileInfos) - { - FilePath path = info.path; - - if (projectPath.exists()) - { - path = path.relativeTo(projectPath); - } - - list << QString::fromStdString(path.str()); - } - - m_text->setText(QString::number(list.size()) + " files will be analyzed."); - - QStringListModel* model = new QStringListModel(this); - model->setStringList(list); - m_list->setModel(model); + QStringListModel* model = new QStringListModel(this); + model->setStringList(list); + m_list->setModel(model); } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h index b1ee0dba..b612b55a 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h @@ -18,7 +18,7 @@ public: virtual QSize preferredWindowSize() const override; - void showFilesFromSourcePaths(); + void showFilesFromContent(QtProjectWizzardContent* content); private: QLabel* m_text; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp index fd944fc5..e8940010 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp @@ -1,143 +1,134 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentSummary.h" -#include - -QtProjectWizzardContentSummary::QtProjectWizzardContentSummary(ProjectSettings* settings, QtProjectWizzardWindow* window) +QtProjectWizzardContentSummary::QtProjectWizzardContentSummary( + ProjectSettings* settings, QtProjectWizzardWindow* window +) : QtProjectWizzardContent(settings, window) - , m_data(nullptr) - , m_buildFile(nullptr) - , m_source(nullptr) - , m_simple(nullptr) - , m_headerSearch(nullptr) - , m_frameworkSearch(nullptr) + , m_isForm(false) { - m_data = new QtProjectWizzardContentData(settings, window); - m_buildFile = new QtProjectWizzardContentBuildFile(settings, window); - m_source = new QtProjectWizzardContentPathsSource(settings, window); - m_simple = new QtProjectWizzardContentSimple(settings, window); - m_headerSearch = new QtProjectWizzardContentPathsHeaderSearch(settings, window); - - if (QSysInfo::macVersion() != QSysInfo::MV_None) - { - m_frameworkSearch = new QtProjectWizzardContentPathsFrameworkSearch(settings, window); - } - - m_compilerFlags = new QtProjectWizzardContentFlags(settings, window); } -QtProjectWizzardContentBuildFile* QtProjectWizzardContentSummary::contentBuildFile() +void QtProjectWizzardContentSummary::addContent(QtProjectWizzardContent* content, bool advanced, bool gapBefore) { - return m_buildFile; + Element element; + element.content = content; + element.advanced = advanced; + element.gapBefore = gapBefore; + m_elements.push_back(element); } -QtProjectWizzardContentPathsSource* QtProjectWizzardContentSummary::contentPathsSource() +void QtProjectWizzardContentSummary::setIsForm(bool isForm) { - return m_source; + m_isForm = isForm; } void QtProjectWizzardContentSummary::populateWindow(QGridLayout* layout) { int row = 0; - layout->setRowMinimumHeight(row, 10); - row++; - - m_data->populateForm(layout, row); - layout->setRowMinimumHeight(row, 15); - row++; - - int row2 = row; - m_buildFile->populateForm(layout, row); - if (row != row2) + if (m_isForm) { - layout->setRowMinimumHeight(row, 15); - row++; + populateForm(layout, row); + return; } - m_source->populateForm(layout, row); - layout->setRowMinimumHeight(row, 15); - row++; + layout->setRowMinimumHeight(row++, 10); - m_simple->populateForm(layout, row); - m_headerSearch->populateForm(layout, row); - - if (m_frameworkSearch) + for (const Element& element : m_elements) { - layout->setRowMinimumHeight(row, 15); - row++; - m_frameworkSearch->populateForm(layout, row); + if (element.advanced) + { + continue; + } + + if (element.gapBefore) + { + layout->setRowMinimumHeight(row++, 20); + } + + element.content->populateWindow(layout, row); } - layout->setRowMinimumHeight(row, 15); - row++; - - QFrame* separator = new QFrame(); - separator->setFrameShape(QFrame::HLine); - - QPalette palette = separator->palette(); - palette.setColor(QPalette::WindowText, Qt::lightGray); - separator->setPalette(palette); - - layout->addWidget(separator, row, 0, 1, -1); - row++; - - QLabel* advancedLabel = createFormLabel("ADVANCED"); - layout->addWidget(advancedLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); - row++; - - m_compilerFlags->populateForm(layout, row); - layout->setRowMinimumHeight(row, 10); + layout->setRowStretch(row, 1); } -void QtProjectWizzardContentSummary::windowReady() +void QtProjectWizzardContentSummary::populateForm(QGridLayout* layout, int& row) { - m_window->updateTitle("NEW PROJECT - SUMMARY"); - m_window->updateNextButton("Create"); + layout->setRowMinimumHeight(row++, 10); + + bool hasAdvanced = false; + for (int i = 0; i < 2; i++) + { + bool advanced = i > 0; + + for (const Element& element : m_elements) + { + if (element.advanced != advanced) + { + hasAdvanced = true; + continue; + } + + if (element.gapBefore) + { + layout->setRowMinimumHeight(row++, 15); + } + + element.content->populateForm(layout, row); + } + + if (i > 0 || !hasAdvanced) + { + continue; + } + + QFrame* separator = new QFrame(); + separator->setFrameShape(QFrame::HLine); + + QPalette palette = separator->palette(); + palette.setColor(QPalette::WindowText, Qt::lightGray); + separator->setPalette(palette); + + layout->addWidget(separator, row++, 0, 1, -1); + + QLabel* advancedLabel = createFormLabel("ADVANCED"); + layout->addWidget(advancedLabel, row++, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); + + layout->setRowMinimumHeight(row++, 15); + } + + layout->setRowMinimumHeight(row, 10); + layout->setRowStretch(row, 1); } void QtProjectWizzardContentSummary::load() { - m_data->load(); - m_buildFile->load(); - m_source->load(); - m_simple->load(); - m_headerSearch->load(); - - if (m_frameworkSearch) + for (const Element& element : m_elements) { - m_frameworkSearch->load(); + element.content->load(); } - - m_compilerFlags->load(); } void QtProjectWizzardContentSummary::save() { - m_data->save(); - m_buildFile->save(); - m_source->save(); - m_simple->save(); - m_headerSearch->save(); - - if (m_frameworkSearch) + for (const Element& element : m_elements) { - m_frameworkSearch->save(); + element.content->save(); } - - m_compilerFlags->save(); } bool QtProjectWizzardContentSummary::check() { - return - m_data->check() && - m_buildFile->check() && - m_source->check() && - m_simple->check() && - m_headerSearch->check() && - (!m_frameworkSearch || m_frameworkSearch->check()) && - m_compilerFlags->check(); + for (const Element& element : m_elements) + { + if (!element.content->check()) + { + return false; + } + } + + return true; } bool QtProjectWizzardContentSummary::isScrollAble() const diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h index 8c09acb6..40ed3280 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h @@ -2,25 +2,28 @@ #define QT_PROJECT_WIZZARD_CONTENT_SUMMARY_H #include "qt/window/project_wizzard/QtProjectWizzardContent.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentData.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentFlags.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentSimple.h" -#include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h" class QtProjectWizzardContentSummary : public QtProjectWizzardContent { +private: + struct Element + { + QtProjectWizzardContent* content; + bool advanced; + bool gapBefore; + }; + public: QtProjectWizzardContentSummary(ProjectSettings* settings, QtProjectWizzardWindow* window); - QtProjectWizzardContentBuildFile* contentBuildFile(); - QtProjectWizzardContentPathsSource* contentPathsSource(); + void addContent(QtProjectWizzardContent* content, bool advanced, bool gapBefore); + void setIsForm(bool isForm); protected: - // QtProjectContentWindow implementation + // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; - virtual void windowReady() override; + virtual void populateForm(QGridLayout* layout, int& row) override; virtual void load() override; virtual void save() override; @@ -29,13 +32,9 @@ protected: virtual bool isScrollAble() const override; private: - QtProjectWizzardContentData* m_data; - QtProjectWizzardContentBuildFile* m_buildFile; - QtProjectWizzardContentPathsSource* m_source; - QtProjectWizzardContentSimple* m_simple; - QtProjectWizzardContentPathsHeaderSearch* m_headerSearch; - QtProjectWizzardContentPathsFrameworkSearch* m_frameworkSearch; - QtProjectWizzardContentFlags* m_compilerFlags; + std::vector m_elements; + + bool m_isForm; }; #endif // QT_PROJECT_WIZZARD_CONTENT_SUMMARY_H diff --git a/src/lib_parser/CMakeLists.txt b/src/lib_parser/CMakeLists.txt index d82a617b..bac6b90d 100644 --- a/src/lib_parser/CMakeLists.txt +++ b/src/lib_parser/CMakeLists.txt @@ -21,6 +21,8 @@ add_files( data/parser/cxx/ASTVisitor.h data/parser/cxx/CommentHandler.cpp data/parser/cxx/CommentHandler.h + data/parser/cxx/CxxCompilationDatabaseSingle.cpp + data/parser/cxx/CxxCompilationDatabaseSingle.h data/parser/cxx/CxxDiagnosticConsumer.cpp data/parser/cxx/CxxDiagnosticConsumer.h data/parser/cxx/CxxParser.cpp diff --git a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp index d3584a32..7af259c3 100644 --- a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp @@ -10,7 +10,6 @@ #include "data/parser/ParseLocation.h" #include "utility/file/FileManager.h" -#include "utility/file/FileSystem.h" #include "utility/ScopedSwitcher.h" @@ -1004,9 +1003,7 @@ ParseLocation ASTVisitor::getDeclRefRange(clang::NamedDecl *decl, clang::SourceL const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId); if (fileEntry != NULL) { - std::string fielName = fileEntry->getName(); - std::string filePath = FileSystem::absoluteFilePath(fielName); - parseLocation.filePath = FilePath(filePath); + parseLocation.filePath = FilePath(fileEntry->getName()).canonical(); } } @@ -1488,9 +1485,9 @@ bool ASTVisitor::isLocatedInUnparsedProjectFile(clang::SourceLocation loc) const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId); if (fileEntry != NULL) { - std::string fielName = fileEntry->getName(); - std::string filePath = FileSystem::absoluteFilePath(fielName); - ret = m_fileRegister->includeFileIsParsing(filePath); + std::string fileName = fileEntry->getName(); + FilePath filePath = FilePath(fileName).canonical(); + ret = m_fileRegister->includeFileIsParsing(filePath.str()); } } m_inUnparsedProjectFileMap[fileId] = ret; @@ -1522,9 +1519,9 @@ bool ASTVisitor::isLocatedInProjectFile(clang::SourceLocation loc) const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId); if (fileEntry != NULL) { - std::string fielName = fileEntry->getName(); - std::string filePath = FileSystem::absoluteFilePath(fielName); - bool ret = m_fileRegister->getFileManager()->hasFilePath(filePath); + std::string fileName = fileEntry->getName(); + FilePath filePath = FilePath(fileName).canonical(); + bool ret = m_fileRegister->getFileManager()->hasFilePath(filePath.str()); m_inProjectFileMap[fileId] = ret; return ret; } diff --git a/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.cpp b/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.cpp new file mode 100644 index 00000000..6ac05393 --- /dev/null +++ b/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.cpp @@ -0,0 +1,22 @@ +#include "data/parser/cxx/CxxCompilationDatabaseSingle.h" + +CxxCompilationDatabaseSingle::CxxCompilationDatabaseSingle(const clang::tooling::CompileCommand& command) + : m_command(command) +{ +} + +std::vector CxxCompilationDatabaseSingle::getCompileCommands( + llvm::StringRef FilePath +) const { + return getAllCompileCommands(); +} + +std::vector CxxCompilationDatabaseSingle::getAllFiles() const +{ + return std::vector(1, m_command.Filename); +} + +std::vector CxxCompilationDatabaseSingle::getAllCompileCommands() const +{ + return std::vector(1, m_command); +} diff --git a/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.h b/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.h new file mode 100644 index 00000000..a8a54a9b --- /dev/null +++ b/src/lib_parser/data/parser/cxx/CxxCompilationDatabaseSingle.h @@ -0,0 +1,20 @@ +#ifndef CXX_COMPILATION_DATABASE_SINGLE_H +#define CXX_COMPILATION_DATABASE_SINGLE_H + +#include "clang/Tooling/CompilationDatabase.h" + +class CxxCompilationDatabaseSingle + : public clang::tooling::CompilationDatabase +{ +public: + CxxCompilationDatabaseSingle(const clang::tooling::CompileCommand& command); + + virtual std::vector getCompileCommands(llvm::StringRef FilePath) const override; + virtual std::vector getAllFiles() const override; + virtual std::vector getAllCompileCommands() const override; + +private: + clang::tooling::CompileCommand m_command; +}; + +#endif // CXX_COMPILATION_DATABASE_SINGLE_H diff --git a/src/lib_parser/data/parser/cxx/CxxParser.cpp b/src/lib_parser/data/parser/cxx/CxxParser.cpp index d4657e9d..dfd08860 100644 --- a/src/lib_parser/data/parser/cxx/CxxParser.cpp +++ b/src/lib_parser/data/parser/cxx/CxxParser.cpp @@ -8,6 +8,7 @@ #include "utility/text/TextAccess.h" #include "data/parser/cxx/ASTActionFactory.h" +#include "data/parser/cxx/CxxCompilationDatabaseSingle.h" #include "data/parser/cxx/CxxDiagnosticConsumer.h" namespace @@ -51,6 +52,7 @@ namespace } } + CxxParser::CxxParser(ParserClient* client, const FileManager* fileManager) : Parser(client) , m_fileRegister(std::make_shared(fileManager)) @@ -94,7 +96,7 @@ void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr runToolOnCodeWithArgs(diagnostics.get(), actionFactory.create(), textAccess->getText(), args); } -std::vector CxxParser::getCommandlineArguments(const Arguments& arguments) const +std::vector CxxParser::getCommandlineArgumentsEssential(const Arguments& arguments) const { std::vector args; @@ -111,6 +113,32 @@ std::vector CxxParser::getCommandlineArguments(const Arguments& arg // The option -c signals that no executable is built. args.push_back("-c"); + args.insert(args.begin(), arguments.compilerFlags.begin(), arguments.compilerFlags.end()); + + for (const FilePath& path : arguments.headerSearchPaths) + { + args.push_back("-I" + path.str()); + } + + for (const FilePath& path : arguments.systemHeaderSearchPaths) + { + args.push_back("-isystem"); + args.push_back(path.str()); + } + + for (const FilePath& path : arguments.frameworkSearchPaths) + { + args.push_back("-iframework"); + args.push_back(path.str()); + } + + return args; +} + +std::vector CxxParser::getCommandlineArguments(const Arguments& arguments) const +{ + std::vector args = getCommandlineArgumentsEssential(arguments); + // The option '-x c++' treats subsequent input files as C++. args.push_back("-x"); std::string language = getLanguageArgument(arguments.language); @@ -122,23 +150,6 @@ std::vector CxxParser::getCommandlineArguments(const Arguments& arg standard += arguments.languageStandard; args.push_back(standard); - args.insert(args.begin(), arguments.compilerFlags.begin(), arguments.compilerFlags.end()); - - for (const FilePath& path : arguments.headerSearchPaths) - { - args.push_back("-I" + path.str()); - } - - for (const FilePath& path : arguments.systemHeaderSearchPaths) - { - args.push_back("-isystem" + path.str()); - } - - for (const FilePath& path : arguments.frameworkSearchPaths) - { - args.push_back("-iframework" + path.str()); - } - return args; } @@ -186,6 +197,12 @@ void CxxParser::setupParsing(const std::vector& filePaths, const Argum m_diagnostics = getDiagnostics(arguments); } +void CxxParser::setupParsingCDB(const std::vector& filePaths, const Arguments& arguments) +{ + m_fileRegister->setFilePaths(filePaths); + m_diagnostics = getDiagnostics(arguments); +} + void CxxParser::runTool(const std::vector& files) { clang::tooling::ClangTool tool(*m_compilationDatabase, files); @@ -195,6 +212,19 @@ void CxxParser::runTool(const std::vector& files) tool.run(&actionFactory); } +void CxxParser::runTool(clang::tooling::CompileCommand command, const Arguments& arguments) +{ + std::vector args = getCommandlineArgumentsEssential(arguments); + command.CommandLine.insert(command.CommandLine.end(), args.begin(), args.end()); + + CxxCompilationDatabaseSingle compilationDatabase(command); + clang::tooling::ClangTool tool(compilationDatabase, std::vector(1, command.Filename)); + tool.setDiagnosticConsumer(m_diagnostics.get()); + + ASTActionFactory actionFactory(m_client, m_fileRegister.get()); + tool.run(&actionFactory); +} + FileRegister* CxxParser::getFileRegister() { return m_fileRegister.get(); diff --git a/src/lib_parser/data/parser/cxx/CxxParser.h b/src/lib_parser/data/parser/cxx/CxxParser.h index 8c5fbc79..cf9a90c4 100644 --- a/src/lib_parser/data/parser/cxx/CxxParser.h +++ b/src/lib_parser/data/parser/cxx/CxxParser.h @@ -1,16 +1,9 @@ #ifndef CXX_PARSER_H #define CXX_PARSER_H +#include "data/parser/cxx/CxxCompilationDatabaseSingle.h" #include "data/parser/Parser.h" -namespace clang -{ - namespace tooling - { - class FixedCompilationDatabase; - } -} - class CxxDiagnosticConsumer; class FileManager; class FileRegister; @@ -27,6 +20,7 @@ public: virtual void parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments); private: + std::vector getCommandlineArgumentsEssential(const Arguments& arguments) const; std::vector getCommandlineArguments(const Arguments& arguments) const; std::shared_ptr getCompilationDatabase(const Arguments& arguments) const; @@ -34,7 +28,10 @@ private: // Accessed by TaskParseCxx void setupParsing(const std::vector& filePaths, const Arguments& arguments); + void setupParsingCDB(const std::vector& filePaths, const Arguments& arguments); + void runTool(const std::vector& files); + void runTool(clang::tooling::CompileCommand command, const Arguments& arguments); FileRegister* getFileRegister(); ParserClient* getParserClient(); @@ -45,7 +42,7 @@ private: std::shared_ptr m_fileRegister; - std::shared_ptr m_compilationDatabase; + std::shared_ptr m_compilationDatabase; std::shared_ptr m_diagnostics; }; diff --git a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp index 2db4e964..8d212556 100644 --- a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp @@ -36,6 +36,7 @@ void PreprocessorCallbacks::FileChanged( } FilePath filePath(fileEntry->getName()); + filePath = filePath.canonical(); if (m_fileRegister->getFileManager()->hasFilePath(filePath.str())) { diff --git a/src/test/FileManagerTestSuite.h b/src/test/FileManagerTestSuite.h index d138b1a8..e76714f7 100644 --- a/src/test/FileManagerTestSuite.h +++ b/src/test/FileManagerTestSuite.h @@ -19,6 +19,7 @@ public: std::vector sourcePaths; sourcePaths.push_back("./data/FileManagerTestSuite/src/"); sourcePaths.push_back("./data/FileManagerTestSuite/include/"); + std::vector headerPaths; std::vector sourceExtensions; sourceExtensions.push_back(".cpp"); sourceExtensions.push_back(".c"); @@ -27,7 +28,7 @@ public: includeExtensions.push_back(".h"); FileManager fm; - fm.setPaths(sourcePaths, sourceExtensions, includeExtensions); + fm.setPaths(sourcePaths, headerPaths, sourceExtensions, includeExtensions); fm.fetchFilePaths(std::vector()); TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 4); diff --git a/src/trial/data/parser/cxx/TaskParseCxx.cpp b/src/trial/data/parser/cxx/TaskParseCxx.cpp index 20368245..d1fc1c19 100644 --- a/src/trial/data/parser/cxx/TaskParseCxx.cpp +++ b/src/trial/data/parser/cxx/TaskParseCxx.cpp @@ -14,6 +14,11 @@ TaskParseCxx::TaskParseCxx( { } +std::vector TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath) +{ + return std::vector(); +} + void TaskParseCxx::enter() { m_client->startParsing();