logic: solution parsing refactor

Refactored solution parser handling to make it more generic
Also includes new parser (wip)
This commit is contained in:
Manuel Dobusch
2016-03-23 17:06:40 +01:00
parent bac394381c
commit 82db193c78
26 changed files with 1236 additions and 442 deletions
+2
View File
@@ -5,6 +5,8 @@
#include <QGraphicsView>
#include <memory>
class QTimer;
class QtGraphicsView
+2 -2
View File
@@ -566,9 +566,9 @@ void QtMainWindow::doCreateNewProject(MessageProjectNew message)
{
QtProjectWizzard* wizzard = createWindow<QtProjectWizzard>();
if (message.fromVisualStudioSolution())
if (message.fromSolution())
{
wizzard->newProjectFromVisualStudioSolution(message.visualStudioSolutionPath);
wizzard->newProjectFromSolution(message.ideId ,message.solutionPath);
}
else
{
@@ -1,5 +1,7 @@
#include "qt/window/project_wizzard/QtProjectWizzard.h"
#include <boost/algorithm/string.hpp>
#include <QFileDialog>
#include <QMessageBox>
#include <QSysInfo>
@@ -16,7 +18,14 @@
#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"
#include "utility/solution/SolutionParserCodeBlocks.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/logging/logging.h"
QtProjectWizzard::QtProjectWizzard(QWidget* parent)
: QtWindowStackElement(parent)
@@ -24,6 +33,12 @@ QtProjectWizzard::QtProjectWizzard(QWidget* parent)
{
connect(&m_windowStack, SIGNAL(push()), this, SLOT(windowStackChanged()));
connect(&m_windowStack, SIGNAL(pop()), this, SLOT(windowStackChanged()));
m_parserManager = std::make_shared<SolutionParserManager>();
// wip
/*m_parserManager->pushSolutionParser(std::make_shared<SolutionParserVisualStudio>());
m_parserManager->pushSolutionParser(std::make_shared<SolutionParserCodeBlocks>());*/
}
void QtProjectWizzard::showWindow()
@@ -60,41 +75,63 @@ void QtProjectWizzard::newProject()
window->setPreviousEnabled(false);
}
void QtProjectWizzard::newProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath)
void QtProjectWizzard::newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath)
{
ProjectSettings settings = getSettingsForVisualStudioSolution(visualStudioSolutionPath);
editProject(settings);
QWidget* widget = m_windowStack.getTopWindow();
if (widget)
if (m_parserManager->canParseSolution(ideId))
{
QtProjectWizzardWindow* window = dynamic_cast<QtProjectWizzardWindow*>(widget);
ProjectSettings settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath);
window->updateTitle("NEW PROJECT FROM VS SOLUTION");
window->updateNextButton("Create");
window->setPreviousVisible(m_windowStack.getWindowCount() > 0);
editProject(settings);
QWidget* widget = m_windowStack.getTopWindow();
if (widget)
{
QtProjectWizzardWindow* window = dynamic_cast<QtProjectWizzardWindow*>(widget);
std::string title = "NEW PROJECT FROM ";
title += ideId;
title += " SOLUTION";
boost::algorithm::to_upper(title);
window->updateTitle(QString(title.c_str()));
window->updateNextButton("Create");
window->setPreviousVisible(m_windowStack.getWindowCount() > 0);
}
}
else
{
LOG_ERROR_STREAM(<< "Unknown solution type");
MessageStatus("Unable to parse given solution", true).dispatch();
}
}
void QtProjectWizzard::refreshProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath)
void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath)
{
QtProjectWizzardWindow* window = dynamic_cast<QtProjectWizzardWindow*>(m_windowStack.getTopWindow());
if (window)
if (m_parserManager->canParseSolution(ideId))
{
window->content()->save();
QtProjectWizzardWindow* window = dynamic_cast<QtProjectWizzardWindow*>(m_windowStack.getTopWindow());
if (window)
{
window->content()->save();
}
ProjectSettings settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath);
m_settings.setSourcePaths(settings.getSourcePaths());
m_settings.setHeaderSearchPaths(settings.getHeaderSearchPaths());
m_settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath));
if (window)
{
window->content()->load();
}
}
ProjectSettings settings = getSettingsForVisualStudioSolution(visualStudioSolutionPath);
m_settings.setSourcePaths(settings.getSourcePaths());
m_settings.setHeaderSearchPaths(settings.getHeaderSearchPaths());
m_settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath));
if (window)
else
{
window->content()->load();
LOG_ERROR_STREAM(<< "Unknown solution type");
MessageStatus("Unable to parse given solution", true).dispatch();
}
}
@@ -186,6 +223,26 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent()
return window;
}
template<>
QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent<QtProjectWizzardContentSelect>()
{
QtProjectWizzardWindow* window = new QtProjectWizzardWindow(parentWidget());
connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow()));
connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard()));
QtProjectWizzardContentSelect* content = new QtProjectWizzardContentSelect(&m_settings, window, m_parserManager);
window->setContent(content);
window->setup();
m_windowStack.pushWindow(window);
return window;
}
QtProjectWizzardWindow* QtProjectWizzard::createWindowWithSummary(
std::function<void(QtProjectWizzardWindow*, QtProjectWizzardContentSummary*)> func
){
@@ -228,44 +285,6 @@ QtProjectWizzardWindow* QtProjectWizzard::createPopupWithContent()
return window;
}
ProjectSettings QtProjectWizzard::getSettingsForVisualStudioSolution(const std::string& visualStudioSolutionPath) const
{
SolutionParserVisualStudio parser;
parser.openSolutionFile(visualStudioSolutionPath);
ProjectSettings settings;
settings.setProjectName(parser.getSolutionName());
settings.setProjectFileLocation(parser.getSolutionPath());
settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath));
std::vector<std::string> sourceFiles = parser.getProjectItems();
std::vector<FilePath> sourcePaths;
for (const std::string& p : sourceFiles)
{
sourcePaths.push_back(FilePath(p));
}
std::vector<std::string> includePaths = parser.getIncludePaths();
std::vector<FilePath> headerPaths;
for (const std::string& p : includePaths)
{
headerPaths.push_back(FilePath(p));
}
settings.setSourcePaths(sourcePaths);
settings.setHeaderSearchPaths(headerPaths);
// For testing
// ProjectSettings settings;
// settings.setProjectName("hallo");
// settings.setProjectFileLocation("~/Desktop");
// settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath));
// settings.setSourcePaths(std::vector<FilePath>(1, visualStudioSolutionPath));
return settings;
}
ProjectSettings QtProjectWizzard::getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const
{
ProjectSettings settings;
@@ -315,13 +334,26 @@ void QtProjectWizzard::selectedProjectType(QtProjectWizzardContentSelect::Projec
case QtProjectWizzardContentSelect::PROJECT_VS:
{
std::string fileEndings = "(";
for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++)
{
fileEndings += " *" + m_parserManager->getParserFileEnding(i);
}
fileEndings += ")";
QString fileName = QFileDialog::getOpenFileName(
this, tr("Open Visual Studio Solution"), "", "Visual Studio Solution (*.sln)"
this, tr("Open Solution"), "", fileEndings.c_str()
);
if (!fileName.isNull())
{
newProjectFromVisualStudioSolution(fileName.toStdString());
for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++)
{
if (fileName.contains(m_parserManager->getParserFileEnding(i).c_str()))
{
newProjectFromSolution(m_parserManager->getParserIdeId(i), fileName.toStdString());
}
}
}
break;
}
@@ -508,8 +540,8 @@ void QtProjectWizzard::showSummary()
summary->addContent(buildFile, false, true);
connect(dynamic_cast<QtProjectWizzardContentBuildFile*>(buildFile),
SIGNAL(refreshVisualStudioSolution(const std::string&)),
this, SLOT(refreshProjectFromVisualStudioSolution(const std::string&)));
SIGNAL(refreshVisualStudioSolution(const std::string&, const std::string&)),
this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&)));
}
if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_CDB)
@@ -6,6 +6,8 @@
#include "qt/window/project_wizzard/QtProjectWizzardContentSelect.h"
#include "qt/window/QtWindowStack.h"
#include "utility/solution/SolutionParserManager.h"
class ProjectSettings;
class QtProjectWizzardContentSummary;
class QtProjectWizzardWindow;
@@ -28,8 +30,11 @@ public:
public slots:
void newProject();
void newProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath);
void refreshProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath);
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);
@@ -38,12 +43,15 @@ public slots:
private:
template<typename T>
QtProjectWizzardWindow* createWindowWithContent();
template<>
QtProjectWizzardWindow* createWindowWithContent<QtProjectWizzardContentSelect>();
QtProjectWizzardWindow* createWindowWithSummary(
std::function<void(QtProjectWizzardWindow*, QtProjectWizzardContentSummary*)> func);
template<typename T>
QtProjectWizzardWindow* createPopupWithContent();
ProjectSettings getSettingsForVisualStudioSolution(const std::string& visualStudioSolutionPath) const;
ProjectSettings getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const;
void connectShowFiles(QtProjectWizzardContent* content);
@@ -52,6 +60,8 @@ private:
std::shared_ptr<QtProjectWizzardWindow> m_popup;
ProjectSettings m_settings;
std::shared_ptr<SolutionParserManager> m_parserManager;
private slots:
void cancelWizzard();
void windowStackChanged();
@@ -160,7 +160,7 @@ void QtProjectWizzardContentBuildFile::refreshClicked()
case QtProjectWizzardContentSelect::PROJECT_CDB:
break;
case QtProjectWizzardContentSelect::PROJECT_VS:
emit refreshVisualStudioSolution(path.str());
emit refreshVisualStudioSolution("vs", path.str());
break;
}
}
@@ -13,7 +13,7 @@ class QtProjectWizzardContentBuildFile
Q_OBJECT
signals:
void refreshVisualStudioSolution(const std::string&);
void refreshVisualStudioSolution(const std::string& ideId, const std::string& solutionPath);
public:
QtProjectWizzardContentBuildFile(ProjectSettings* settings, QtProjectWizzardWindow* window);
@@ -8,8 +8,11 @@
#include "qt/window/project_wizzard/QtProjectWizzardWindow.h"
#include "utility/ResourcePaths.h"
QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window)
#include "utility/solution/SolutionParserManager.h"
QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr<SolutionParserManager> solutionParserManager)
: QtProjectWizzardContent(settings, window)
, m_solutionParserManager(solutionParserManager)
{
}
@@ -67,6 +70,14 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout)
QToolButton* c = createProjectButton(
"from Compilation\nDatabase", (ResourcePaths::getGuiPath() + "icon/project_cdb_256_256.png").c_str());
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 new project from an existing Visual Studio Solution file.");
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 "
"<a href=\"https://staging.coati.io/documentation/#CreateAProjectFromCompilationDatabase\">"
"documentation</a> to find out more.");
m_buttons = new QButtonGroup(this);
m_buttons->addButton(a);
m_buttons->addButton(b);
@@ -76,10 +87,39 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout)
m_buttons->setId(b, PROJECT_VS);
m_buttons->setId(c, PROJECT_CDB);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->addWidget(a);
hlayout->addWidget(b);
hlayout->addWidget(c);
unsigned int runningId = 3;
std::shared_ptr<SolutionParserManager> manager = m_solutionParserManager.lock();
if (manager != NULL)
{
for (unsigned int i = 0; i < manager->getParserCount(); i++)
{
std::string name = manager->getParserName(i);
QToolButton* button = createProjectButton(name.c_str(),
(ResourcePaths::getGuiPath() + "icon/project_vs_256_256.png").c_str());
m_buttons->addButton(button);
m_solutionDescription.push_back(manager->getParserDescription(i));
hlayout->addWidget(button);
m_buttons->setId(button, runningId);
runningId++;
}
}
connect(m_buttons, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
[this](int id)
{
switch (id)
/*switch (id)
{
case 0: m_description->setText(
"Create a new Coati project by defining what files will be analyzed and header search paths."
@@ -93,17 +133,15 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout)
"<a href=\"https://staging.coati.io/documentation/#CreateAProjectFromCompilationDatabase\">"
"documentation</a> to find out more."
); break;
}
}*/
m_description->setText(m_solutionDescription[id].c_str());
m_window->setNextEnabled(true);
}
);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->addWidget(a);
hlayout->addWidget(b);
hlayout->addWidget(c);
QFrame* container = new QFrame();
container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
@@ -141,9 +179,12 @@ void QtProjectWizzardContentSelect::save()
case 0: type = PROJECT_EMPTY; break;
case 1: type = PROJECT_VS; break;
case 2: type = PROJECT_CDB; break;
default: type = PROJECT_VS; break; // use vs for "standard" solutions TODO: change name of enum to reflect this is the default type
}
emit selected(type);
// emit selected(m_buttons->checkedId());
}
bool QtProjectWizzardContentSelect::check()
@@ -4,6 +4,7 @@
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
class QButtonGroup;
class SolutionParserManager;
class QtProjectWizzardContentSelect
: public QtProjectWizzardContent
@@ -18,7 +19,7 @@ public:
PROJECT_CDB = 2
};
QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window);
QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr<SolutionParserManager> solutionParserManager);
// QtProjectWizzardContent implementation
virtual void populateWindow(QGridLayout* layout) override;
@@ -31,12 +32,21 @@ public:
signals:
void selected(QtProjectWizzardContentSelect::ProjectType);
// void selected(unsigned int type);
private:
QButtonGroup* m_languages;
QButtonGroup* m_buttons;
QLabel* m_title;
QLabel* m_description;
std::vector<std::string> m_projectTypeNames;
std::vector<std::string> m_projectTypeDescriptions;
std::vector<std::string> m_projectTypeIconPaths;
std::weak_ptr<SolutionParserManager> m_solutionParserManager;
std::vector<std::string> m_solutionDescription;
};
#endif // QT_PROJECT_WIZZARD_CONTENT_SELECT_H