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
+2
View File
@@ -322,6 +322,8 @@ add_files(
settings/SourceGroupSettingsCppEmpty.h
settings/SourceGroupSettingsCxxCdb.cpp
settings/SourceGroupSettingsCxxCdb.h
settings/SourceGroupSettingsCxxCdbVs.cpp
settings/SourceGroupSettingsCxxCdbVs.h
settings/SourceGroupSettingsCxxCodeblocks.cpp
settings/SourceGroupSettingsCxxCodeblocks.h
settings/SourceGroupSettingsCxxSonargraph.cpp
+2
View File
@@ -21,6 +21,8 @@ public:
SourceGroupSettings(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings);
virtual ~SourceGroupSettings() = default;
virtual std::shared_ptr<SourceGroupSettings> createCopy() const = 0;
virtual void load(std::shared_ptr<const ConfigManager> config);
virtual void save(std::shared_ptr<ConfigManager> config);
@@ -5,6 +5,11 @@ SourceGroupSettingsCEmpty::SourceGroupSettingsCEmpty(const std::string& id, cons
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCEmpty::createCopy() const
{
return std::make_shared<SourceGroupSettingsCEmpty>(*this);
}
void SourceGroupSettingsCEmpty::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsCxx::load(config);
@@ -19,6 +19,8 @@ class SourceGroupSettingsCEmpty
public:
SourceGroupSettingsCEmpty(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -5,6 +5,11 @@ SourceGroupSettingsCppEmpty::SourceGroupSettingsCppEmpty(const std::string& id,
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCppEmpty::createCopy() const
{
return std::make_shared<SourceGroupSettingsCppEmpty>(*this);
}
void SourceGroupSettingsCppEmpty::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsCxx::load(config);
@@ -19,6 +19,8 @@ class SourceGroupSettingsCppEmpty
public:
SourceGroupSettingsCppEmpty(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -9,6 +9,11 @@ SourceGroupSettingsCxxCdb::SourceGroupSettingsCxxCdb(const std::string& id, cons
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCxxCdb::createCopy() const
{
return std::make_shared<SourceGroupSettingsCxxCdb>(*this);
}
void SourceGroupSettingsCxxCdb::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsCxx::load(config);
@@ -14,6 +14,8 @@ class SourceGroupSettingsCxxCdb
public:
SourceGroupSettingsCxxCdb(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -0,0 +1,11 @@
#include "settings/SourceGroupSettingsCxxCdbVs.h"
SourceGroupSettingsCxxCdbVs::SourceGroupSettingsCxxCdbVs(const std::string& id, const ProjectSettings* projectSettings)
: SourceGroupSettingsCxxCdb(id, projectSettings)
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCxxCdbVs::createCopy() const
{
return std::make_shared<SourceGroupSettingsCxxCdbVs>(*this);
}
@@ -0,0 +1,16 @@
#ifndef SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
#define SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
#include "settings/SourceGroupSettingsCxxCdb.h"
#include "utility/file/FilePath.h"
class SourceGroupSettingsCxxCdbVs
: public SourceGroupSettingsCxxCdb
{
public:
SourceGroupSettingsCxxCdbVs(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
};
#endif // SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
@@ -8,6 +8,11 @@ SourceGroupSettingsCxxCodeblocks::SourceGroupSettingsCxxCodeblocks(const std::st
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCxxCodeblocks::createCopy() const
{
return std::make_shared<SourceGroupSettingsCxxCodeblocks>(*this);
}
void SourceGroupSettingsCxxCodeblocks::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsCxx::load(config);
@@ -19,6 +19,8 @@ class SourceGroupSettingsCxxCodeblocks
public:
SourceGroupSettingsCxxCodeblocks(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -5,6 +5,11 @@ SourceGroupSettingsCxxSonargraph::SourceGroupSettingsCxxSonargraph(const std::st
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsCxxSonargraph::createCopy() const
{
return std::make_shared<SourceGroupSettingsCxxSonargraph>(*this);
}
void SourceGroupSettingsCxxSonargraph::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsCxx::load(config);
@@ -15,6 +15,8 @@ class SourceGroupSettingsCxxSonargraph
public:
SourceGroupSettingsCxxSonargraph(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -5,6 +5,11 @@ SourceGroupSettingsJavaEmpty::SourceGroupSettingsJavaEmpty(const std::string& id
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsJavaEmpty::createCopy() const
{
return std::make_shared<SourceGroupSettingsJavaEmpty>(*this);
}
void SourceGroupSettingsJavaEmpty::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettings::load(config);
@@ -13,6 +13,8 @@ class SourceGroupSettingsJavaEmpty
public:
SourceGroupSettingsJavaEmpty(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -11,6 +11,11 @@ SourceGroupSettingsJavaGradle::SourceGroupSettingsJavaGradle(const std::string&
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsJavaGradle::createCopy() const
{
return std::make_shared<SourceGroupSettingsJavaGradle>(*this);
}
void SourceGroupSettingsJavaGradle::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsJava::load(config);
@@ -10,6 +10,8 @@ class SourceGroupSettingsJavaGradle
public:
SourceGroupSettingsJavaGradle(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -11,6 +11,11 @@ SourceGroupSettingsJavaMaven::SourceGroupSettingsJavaMaven(const std::string& id
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsJavaMaven::createCopy() const
{
return std::make_shared<SourceGroupSettingsJavaMaven>(*this);
}
void SourceGroupSettingsJavaMaven::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettingsJava::load(config);
@@ -10,6 +10,8 @@ class SourceGroupSettingsJavaMaven
public:
SourceGroupSettingsJavaMaven(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -5,6 +5,11 @@ SourceGroupSettingsJavaSonargraph::SourceGroupSettingsJavaSonargraph(const std::
{
}
std::shared_ptr<SourceGroupSettings> SourceGroupSettingsJavaSonargraph::createCopy() const
{
return std::make_shared<SourceGroupSettingsJavaSonargraph>(*this);
}
void SourceGroupSettingsJavaSonargraph::load(std::shared_ptr<const ConfigManager> config)
{
SourceGroupSettings::load(config);
@@ -15,6 +15,8 @@ class SourceGroupSettingsJavaSonargraph
public:
SourceGroupSettingsJavaSonargraph(const std::string& id, const ProjectSettings* projectSettings);
std::shared_ptr<SourceGroupSettings> createCopy() const override;
void load(std::shared_ptr<const ConfigManager> config) override;
void save(std::shared_ptr<ConfigManager> config) override;
@@ -293,10 +293,10 @@ namespace Sonargraph
std::vector<std::shared_ptr<IndexerCommand>> XsdCmakeJsonModule::getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath> indexedHeaderPaths,
const std::set<FilePath>& indexedHeaderPaths,
const std::string& languageStandard,
const std::vector<FilePath> systemHeaderSearchPaths,
const std::vector<FilePath> frameworkSearchPaths) const
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
if (rootPath)
@@ -33,10 +33,10 @@ namespace Sonargraph
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath> indexedHeaderPaths,
const std::set<FilePath>& indexedHeaderPaths,
const std::string& languageStandard,
const std::vector<FilePath> systemHeaderSearchPaths,
const std::vector<FilePath> frameworkSearchPaths) const;
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const;
std::vector<std::shared_ptr<XsdRootPathWithFiles>> m_rootPathWithFiles;
};
+2
View File
@@ -219,6 +219,8 @@ add_files(
qt/window/project_wizzard/QtProjectWizzardContentVS.h
qt/window/project_wizzard/QtProjectWizzardWindow.cpp
qt/window/project_wizzard/QtProjectWizzardWindow.h
qt/window/project_wizzard/QtSourceGroupWizzard.h
qt/window/project_wizzard/QtSourceGroupWizzardPage.h
qt/window/QtAbout.cpp
qt/window/QtAbout.h
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
+5
View File
@@ -425,6 +425,11 @@ private:
: SourceGroupSettings("TEST_ID", SOURCE_GROUP_UNKNOWN, projectSettings)
{
}
std::shared_ptr<SourceGroupSettings> createCopy() const override
{
return std::shared_ptr<SourceGroupSettings>();
}
};
class SourceGroupTest : public SourceGroup