logic: refactored QtProjectWizzard to remove duplicate definition of contents shown for setup and summary

* also added current page count (e.g. 1/3) to project setup
* moved the code for copying a source group to the settings classes so that the wizzard doesn't need to know which source groups may be there anymore.
This commit is contained in:
mlangkabel
2018-06-25 16:00:20 +02:00
parent e287c86315
commit 08ab75f262
37 changed files with 901 additions and 599 deletions
File diff suppressed because it is too large Load Diff
@@ -6,8 +6,8 @@
#include <QWidget>
#include "qt/window/project_wizzard/QtProjectWizzardWindow.h"
#include "qt/window/project_wizzard/QtSourceGroupWizzard.h"
#include "qt/window/QtWindow.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
@@ -41,6 +41,9 @@ protected:
virtual void handlePrevious() override;
private:
template <typename SettingsType>
void executeSoureGroupSetup(std::shared_ptr<SettingsType> settings);
QtProjectWizzardWindow* createWindowWithContent(
std::function<QtProjectWizzardContent*(QtProjectWizzardWindow*)> func);
@@ -54,7 +57,7 @@ private:
std::shared_ptr<ProjectSettings> m_projectSettings;
std::vector<std::shared_ptr<SourceGroupSettings>> m_allSourceGroupSettings;
std::shared_ptr<SourceGroupSettings> m_newSourceGroupSettings;
std::shared_ptr<QtSourceGroupWizzardBase> m_sourceGroupWizzard;
ApplicationSettings m_appSettings;
bool m_editing;
@@ -83,28 +86,7 @@ private slots:
void newSourceGroup();
void selectedProjectType(SourceGroupType sourceGroupType);
void emptySourceGroup();
void emptySourceGroupCDBVS();
void emptySourceGroupCDB();
void emptySourceGroupCxxCodeblocks();
void emptySourceGroupCxxSonargraph();
void emptySourceGroupJavaSonargraph();
void sourcePaths();
void headerSearchPaths();
void headerSearchPathsDone();
void frameworkSearchPaths();
void sourcePathsJava();
void dependenciesJava();
void sourcePathsJavaMaven();
void sourcePathsJavaGradle();
void advancedSettingsCxx();
void advancedSettingsJava();
void createSourceGroup();
void createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
void createProject();
};
@@ -17,22 +17,10 @@ QtProjectWizzardContentCStandard::QtProjectWizzardContentCStandard(
void QtProjectWizzardContentCStandard::populate(QGridLayout* layout, int& row)
{
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
row++;
}
m_standard = new QComboBox();
layout->addWidget(createFormLabel("C Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft);
row++;
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
layout->setRowStretch(row, 1);
}
}
void QtProjectWizzardContentCStandard::load()
@@ -17,22 +17,10 @@ QtProjectWizzardContentCppStandard::QtProjectWizzardContentCppStandard(
void QtProjectWizzardContentCppStandard::populate(QGridLayout* layout, int& row)
{
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
row++;
}
m_standard = new QComboBox();
layout->addWidget(createFormLabel("C++ Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft);
row++;
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
layout->setRowStretch(row, 1);
}
}
void QtProjectWizzardContentCppStandard::load()
@@ -28,6 +28,19 @@ void QtProjectWizzardContentGroup::setIsForm(bool isForm)
m_isForm = isForm;
}
bool QtProjectWizzardContentGroup::hasContents() const
{
for (QtProjectWizzardContent* content : m_contents)
{
if (content)
{
return true;
}
}
return false;
}
void QtProjectWizzardContentGroup::populate(QGridLayout* layout, int& row)
{
if (m_isForm)
@@ -17,6 +17,7 @@ public:
void addSpace();
void setIsForm(bool isForm);
bool hasContents() const;
protected:
// QtProjectWizzardContent implementation
@@ -17,22 +17,10 @@ QtProjectWizzardContentJavaStandard::QtProjectWizzardContentJavaStandard(
void QtProjectWizzardContentJavaStandard::populate(QGridLayout* layout, int& row)
{
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
row++;
}
m_standard = new QComboBox();
layout->addWidget(createFormLabel("Java Standard"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_standard, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft);
row++;
if (!isInForm())
{
layout->setRowMinimumHeight(row, 15);
layout->setRowStretch(row, 1);
}
}
void QtProjectWizzardContentJavaStandard::load()
@@ -386,7 +386,7 @@ std::vector<FilePath> QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths
}
QtProjectWizzardContentIndexedHeaderPaths::QtProjectWizzardContentIndexedHeaderPaths(
const std::string& projectKindName, std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window
std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window, std::string projectKindName
)
: QtProjectWizzardContentPaths(settings, window, QtPathListBox::SELECTION_POLICY_FILES_AND_DIRECTORIES)
, m_projectKindName(projectKindName)
@@ -93,7 +93,7 @@ public:
static std::vector<FilePath> getIndexedPathsDerivedFromCDB(std::shared_ptr<const SourceGroupSettingsCxxCdb> settings);
QtProjectWizzardContentIndexedHeaderPaths(
const std::string& projectKindName, std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window);
std::shared_ptr<SourceGroupSettings> settings, QtProjectWizzardWindow* window, std::string projectKindName);
virtual void populate(QGridLayout* layout, int& row) override;
@@ -0,0 +1,154 @@
#ifndef QT_SOURCE_GROUP_WIZZARD_H
#define QT_SOURCE_GROUP_WIZZARD_H
#include <functional>
#include <memory>
#include <vector>
#include "qt/window/project_wizzard/QtProjectWizzardContentGroup.h"
#include "qt/window/project_wizzard/QtProjectWizzardWindow.h"
#include "qt/window/project_wizzard/QtSourceGroupWizzardPage.h"
#include "utility/logging/logging.h"
class SourceGroupSettings;
class QtSourceGroupWizzardBase
{
public:
virtual ~QtSourceGroupWizzardBase() = default;
virtual void execute(QtWindowStack& windowStack) = 0;
virtual bool canProcessSettings(std::shared_ptr<const SourceGroupSettings> settings) = 0;
};
template <typename SettingsType>
class QtSourceGroupWizzard: public QtSourceGroupWizzardBase
{
public:
QtSourceGroupWizzard(
std::shared_ptr<SettingsType> settings,
std::function<void()> onCancelClicked,
std::function<void(std::shared_ptr<SourceGroupSettings>)> onFinishedWizzard
);
void addPage(const QtSourceGroupWizzardPage<SettingsType>& page);
void execute(QtWindowStack& windowStack) override;
bool canProcessSettings(std::shared_ptr<const SourceGroupSettings> settings) override;
private:
void createWindowForPage(const size_t pageId, QtWindowStack& windowStack);
int mapToPageIdWithContentForContext(size_t pageId, WizzardContentContextType contextType) const;
std::shared_ptr<SettingsType> m_settings;
std::function<void()> m_onCancelClicked;
std::function<void(std::shared_ptr<SourceGroupSettings>)> m_onFinishedWizzard;
std::vector<QtSourceGroupWizzardPage<SettingsType>> m_pages;
};
template <typename SettingsType>
QtSourceGroupWizzard<SettingsType>::QtSourceGroupWizzard(
std::shared_ptr<SettingsType> settings,
std::function<void()> onCancelClicked,
std::function<void(std::shared_ptr<SourceGroupSettings>)> onFinishedWizzard
)
: m_settings(settings)
, m_onCancelClicked(onCancelClicked)
, m_onFinishedWizzard(onFinishedWizzard)
{
}
template <typename SettingsType>
void QtSourceGroupWizzard<SettingsType>::addPage(const QtSourceGroupWizzardPage<SettingsType>& page)
{
m_pages.push_back(page);
}
template <typename SettingsType>
void QtSourceGroupWizzard<SettingsType>::execute(QtWindowStack& windowStack)
{
if (!m_pages.empty())
{
createWindowForPage(mapToPageIdWithContentForContext(0, WIZZARD_CONTENT_CONTEXT_SETUP), windowStack);
}
}
template <typename SettingsType>
bool QtSourceGroupWizzard<SettingsType>::canProcessSettings(std::shared_ptr<const SourceGroupSettings> settings)
{
if (std::dynamic_pointer_cast<const SettingsType>(settings))
{
return true;
}
return false;
}
template <typename SettingsType>
void QtSourceGroupWizzard<SettingsType>::createWindowForPage(const size_t pageId, QtWindowStack& windowStack)
{
if (pageId >= m_pages.size())
{
LOG_ERROR("Project Setup does not contain page " + std::to_string(pageId));
return;
}
const QtSourceGroupWizzardPage<SettingsType>& page = m_pages.at(pageId);
const int nextPageId = mapToPageIdWithContentForContext(pageId + 1, WIZZARD_CONTENT_CONTEXT_SETUP);
QtProjectWizzardWindow* window = new QtProjectWizzardWindow(nullptr);
window->connect(window, &QtProjectWizzardWindow::previous, &windowStack, &QtWindowStack::popWindow);
window->connect(window, &QtProjectWizzardWindow::canceled, m_onCancelClicked);
if (nextPageId > 0)
{
window->connect(
window, &QtProjectWizzardWindow::next,
[this, nextPageId, &windowStack]() { this->createWindowForPage(nextPageId, windowStack); }
);
}
else
{
window->connect(window, &QtProjectWizzardWindow::next, [&]() { m_onFinishedWizzard(m_settings); });
}
QtProjectWizzardContentGroup* contentGroup = page.createContentGroup(WIZZARD_CONTENT_CONTEXT_SETUP, m_settings, window);
window->setPreferredSize(QSize(page.getPreferredWidth(), page.getPreferredHeight()));
window->setContent(contentGroup);
window->setScrollAble(window->content()->isScrollAble());
window->setup();
size_t currentPage = 0;
size_t totalPages = 0;
for (size_t i = 0; i < m_pages.size(); i++)
{
if (m_pages[i].hasContentForContext(WIZZARD_CONTENT_CONTEXT_SETUP))
{
if (i <= pageId)
{
currentPage++;
}
totalPages++;
}
}
window->updateSubTitle(QString::fromStdString(page.getTitle() + " - " + std::to_string(currentPage) + "/" + std::to_string(totalPages)));
windowStack.pushWindow(window);
}
template <typename SettingsType>
int QtSourceGroupWizzard<SettingsType>::mapToPageIdWithContentForContext(size_t pageId, WizzardContentContextType contextType) const
{
while (pageId < m_pages.size())
{
const QtSourceGroupWizzardPage<SettingsType>& page = m_pages.at(pageId);
if (page.hasContentForContext(contextType))
{
return pageId;
}
pageId++;
}
return -1;
}
#endif // QT_SOURCE_GROUP_WIZZARD_H
@@ -0,0 +1,163 @@
#ifndef QT_SOURCE_GROUP_WIZZARD_PAGE_H
#define QT_SOURCE_GROUP_WIZZARD_PAGE_H
#include <functional>
#include <memory>
#include <vector>
class QtProjectWizzardWindow;
enum WizzardContentContextType
{
WIZZARD_CONTENT_CONTEXT_SETUP = 1,
WIZZARD_CONTENT_CONTEXT_SUMMARY = 2,
WIZZARD_CONTENT_CONTEXT_ALL = 3
};
template <typename SettingsType>
class QtSourceGroupWizzardPage
{
public:
typedef std::function<QtProjectWizzardContent* (std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window)> ContentCreator;
QtSourceGroupWizzardPage(const std::string& title, int preferredWidth = 750, int preferredHeight = 600);
void addContentCreator(
WizzardContentContextType contextType,
ContentCreator contentCreator
);
template <typename ContentType>
void addContentCreatorSimple(WizzardContentContextType contextType);
template <typename ContentType>
void addContentCreatorWithSettings(WizzardContentContextType contextType);
template <typename ContentType, typename ... ParamTypes>
void addContentCreatorWithSettings(WizzardContentContextType contextType, ParamTypes ... params);
bool hasContentForContext(WizzardContentContextType contextType) const;
std::string getTitle() const;
int getPreferredWidth() const;
int getPreferredHeight() const;
QtProjectWizzardContentGroup* createContentGroup(WizzardContentContextType contextType, std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window) const;
private:
const std::string m_title;
const int m_preferredWidth;
const int m_preferredHeight;
std::vector<std::pair<WizzardContentContextType, ContentCreator>> m_contentCreators;
};
template <typename SettingsType>
QtSourceGroupWizzardPage<SettingsType>::QtSourceGroupWizzardPage(const std::string& title, int preferredWidth, int preferredHeight)
: m_title(title)
, m_preferredWidth(preferredWidth)
, m_preferredHeight(preferredHeight)
{
}
template <typename SettingsType>
void QtSourceGroupWizzardPage<SettingsType>::addContentCreator(
WizzardContentContextType contextType,
ContentCreator contentCreator
)
{
m_contentCreators.push_back(std::make_pair(contextType, contentCreator));
}
template <typename SettingsType>
template <typename ContentType>
void QtSourceGroupWizzardPage<SettingsType>::addContentCreatorSimple(WizzardContentContextType contextType)
{
addContentCreator(
contextType,
[](std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window)
{
return new ContentType(window);
}
);
}
template <typename SettingsType>
template <typename ContentType>
void QtSourceGroupWizzardPage<SettingsType>::addContentCreatorWithSettings(WizzardContentContextType contextType)
{
addContentCreator(
contextType,
[](std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window)
{
return new ContentType(settings, window);
}
);
}
template <typename SettingsType>
template <typename ContentType, typename ... ParamTypes>
void QtSourceGroupWizzardPage<SettingsType>::addContentCreatorWithSettings(WizzardContentContextType contextType, ParamTypes ... params)
{
addContentCreator(
contextType,
[=](std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window)
{
return new ContentType(settings, window, params...);
}
);
}
template <typename SettingsType>
std::string QtSourceGroupWizzardPage<SettingsType>::getTitle() const
{
return m_title;
}
template <typename SettingsType>
int QtSourceGroupWizzardPage<SettingsType>::getPreferredWidth() const
{
return m_preferredWidth;
}
template <typename SettingsType>
int QtSourceGroupWizzardPage<SettingsType>::getPreferredHeight() const
{
return m_preferredHeight;
}
template <typename SettingsType>
bool QtSourceGroupWizzardPage<SettingsType>::hasContentForContext(WizzardContentContextType contextType) const
{
for (const std::pair<WizzardContentContextType, ContentCreator>& contentCreator : m_contentCreators)
{
if (contentCreator.first & contextType)
{
return true;
}
}
return false;
}
template <typename SettingsType>
QtProjectWizzardContentGroup* QtSourceGroupWizzardPage<SettingsType>::createContentGroup(WizzardContentContextType contextType, std::shared_ptr<SettingsType> settings, QtProjectWizzardWindow* window) const
{
QtProjectWizzardContentGroup* contentGroup = new QtProjectWizzardContentGroup(window);
bool firstContentAdded = false;
for (const std::pair<WizzardContentContextType, ContentCreator>& contentCreator : m_contentCreators)
{
if (contentCreator.first & contextType)
{
if (firstContentAdded)
{
contentGroup->addSpace();
}
contentGroup->addContent(contentCreator.second(settings, window));
firstContentAdded = true;
}
}
return contentGroup;
}
#endif // QT_SOURCE_GROUP_WIZZARD_PAGE_H