#include "QtProjectWizard.h" #include #include #include #include #include #include #include "QtProjectWizardContent.h" #include "QtProjectWizardContentCppStandard.h" #include "QtProjectWizardContentCrossCompilationOptions.h" #include "QtProjectWizardContentCStandard.h" #include "QtProjectWizardContentCustomCommand.h" #include "QtProjectWizardContentCxxPchFlags.h" #include "QtProjectWizardContentExtensions.h" #include "QtProjectWizardContentFlags.h" #include "QtProjectWizardContentGroup.h" #include "QtProjectWizardContentJavaStandard.h" #include "QtProjectWizardContentPath.h" #include "QtProjectWizardContentPathCDB.h" #include "QtProjectWizardContentPathCodeblocksProject.h" #include "QtProjectWizardContentPathCxxPch.h" #include "QtProjectWizardContentPathPythonEnvironment.h" #include "QtProjectWizardContentPathSonargraphProject.h" #include "QtProjectWizardContentPathSourceGradle.h" #include "QtProjectWizardContentPathSourceMaven.h" #include "QtProjectWizardContentPaths.h" #include "QtProjectWizardContentPathsClassJava.h" #include "QtProjectWizardContentPathsExclude.h" #include "QtProjectWizardContentPathsFrameworkSearch.h" #include "QtProjectWizardContentPathsFrameworkSearchGlobal.h" #include "QtProjectWizardContentPathsHeaderSearch.h" #include "QtProjectWizardContentPathsHeaderSearchGlobal.h" #include "QtProjectWizardContentPathsIndexedHeaders.h" #include "QtProjectWizardContentPathsSource.h" #include "QtProjectWizardContentProjectData.h" #include "QtProjectWizardContentSelect.h" #include "QtProjectWizardContentSourceGroupData.h" #include "QtProjectWizardContentSourceGroupInfoText.h" #include "QtProjectWizardContentVS.h" #include "QtSourceGroupWizardPage.h" #include "SourceGroupSettingsCEmpty.h" #include "SourceGroupSettingsCppEmpty.h" #include "SourceGroupSettingsCustomCommand.h" #include "SourceGroupSettingsCxxCdb.h" #include "SourceGroupSettingsCxxCdbVs.h" #include "SourceGroupSettingsCxxCodeblocks.h" #include "SourceGroupSettingsCxxSonargraph.h" #include "SourceGroupSettingsJavaEmpty.h" #include "SourceGroupSettingsJavaGradle.h" #include "SourceGroupSettingsJavaMaven.h" #include "SourceGroupSettingsJavaSonargraph.h" #include "SourceGroupSettingsPythonEmpty.h" #include "MessageLoadProject.h" #include "MessageStatus.h" #include "ResourcePaths.h" #include "utility.h" #include "utilityApp.h" #include "utilityPathDetection.h" #include "utilityString.h" #include "utilityUuid.h" #include "Application.h" namespace { bool applicationSettingsContainVisualStudioHeaderSearchPaths() { std::vector expandedPaths; const std::shared_ptr headerPathDetector = utility::getCxxVsHeaderPathDetector(); for (const std::string& detectorName : headerPathDetector->getWorkingDetectorNames()) { for (const FilePath& path : headerPathDetector->getPaths(detectorName)) { utility::append(expandedPaths, path.expandEnvironmentVariables()); } } std::vector usedExpandedGlobalHeaderSearchPaths = ApplicationSettings::getInstance()->getHeaderSearchPathsExpanded(); for (const FilePath& usedExpandedPath : usedExpandedGlobalHeaderSearchPaths) { for (const FilePath& expandedPath : expandedPaths) { if (expandedPath == usedExpandedPath) { return true; } } } return false; } void addMsvcCompatibilityFlagsOnDemand(std::shared_ptr settings) { if (applicationSettingsContainVisualStudioHeaderSearchPaths()) { std::vector flags = settings->getCompilerFlags(); flags.push_back(L"-fms-extensions"); flags.push_back(L"-fms-compatibility"); flags.push_back(L"-fms-compatibility-version=19"); settings->setCompilerFlags(flags); } } template std::vector> getSourceGroupWizardPages(); template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Language Standard", 470, 460); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreator( WIZARD_CONTENT_CONTEXT_ALL, [](std::shared_ptr settings, QtProjectWizardWindow* window) { return new QtProjectWizardContentPathCxxPch(settings, settings, window); } ); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, false); pages.push_back(page); } return pages; } template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Language Standard", 470, 460); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreator( WIZARD_CONTENT_CONTEXT_ALL, [](std::shared_ptr settings, QtProjectWizardWindow* window) { return new QtProjectWizardContentPathCxxPch(settings, settings, window); } ); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, false); pages.push_back(page); } return pages; } template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Compilation Database Path"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, "Compilation Database"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreator( WIZARD_CONTENT_CONTEXT_ALL, [](std::shared_ptr settings, QtProjectWizardWindow* window) { return new QtProjectWizardContentPathCxxPch(settings, settings, window); } ); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, true); pages.push_back(page); } return pages; } template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Code::Blocks Project Path"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, std::string("Code::Blocks Project")); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); pages.push_back(page); } return pages; } template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Sonargraph Project Path"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreator( WIZARD_CONTENT_CONTEXT_ALL, [](std::shared_ptr settings, QtProjectWizardWindow* window) { return new QtProjectWizardContentPathSonargraphProject(settings, settings, settings, window); } ); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, std::string("Sonargraph project")); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); pages.push_back(page); } return pages; } template <> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("VS Solution"); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SETUP); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL, std::string("Compilation Database")); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Include Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } if (utility::getOsType() == OS_MAC) { QtSourceGroupWizardPage page("Framework Search Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); page.addContentCreatorSimple(WIZARD_CONTENT_CONTEXT_SUMMARY); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_SUMMARY, true); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Language Standard", 470, 230); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Indexed Paths", 750, 600); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Dependencies", 750, 600); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Sonargraph Project Path"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreator( WIZARD_CONTENT_CONTEXT_ALL, [](std::shared_ptr settings, QtProjectWizardWindow* window) { return new QtProjectWizardContentPathSonargraphProject(settings, std::shared_ptr(), settings, window); } ); pages.push_back(page); } { QtSourceGroupWizardPage page("Dependencies"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Indexed Paths", 750, 600); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template<> std::vector> getSourceGroupWizardPages() { std::vector> pages; { QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } return pages; } template void fillSummary(QtProjectWizardContentGroup* summary, std::shared_ptr settings, QtProjectWizardWindow* window) { const std::vector> pages = getSourceGroupWizardPages(); for (const QtSourceGroupWizardPage& page : pages) { QtProjectWizardContentGroup* contentGroup = page.createContentGroup(WIZARD_CONTENT_CONTEXT_SUMMARY, settings, window); if (contentGroup && contentGroup->hasContents()) { summary->addContent(contentGroup); summary->addSpace(); } } } } QtProjectWizard::QtProjectWizard(QWidget* parent) : QtProjectWizardWindow(parent, false) , m_windowStack(this) , m_editing(false) , m_previouslySelectedIndex(-1) , m_contentWidget(nullptr) { setScrollAble(true); connect(&m_windowStack, &QtWindowStack::push, this, &QtProjectWizard::windowStackChanged); connect(&m_windowStack, &QtWindowStack::pop, this, &QtProjectWizard::windowStackChanged); connect(&m_windowStack, &QtWindowStack::empty, this, &QtProjectWizard::windowStackChanged); // save old application settings so they can be compared later ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); m_appSettings.setHeaderSearchPaths(appSettings->getHeaderSearchPaths()); m_appSettings.setFrameworkSearchPaths(appSettings->getFrameworkSearchPaths()); } QSize QtProjectWizard::sizeHint() const { return QSize(900, 600); } void QtProjectWizard::newProject() { m_projectSettings = std::make_shared(); setup(); } void QtProjectWizard::newProjectFromCDB(const FilePath& filePath) { if (!m_projectSettings) { m_projectSettings = std::make_shared(); } if (m_projectSettings->getProjectFilePath().empty()) { m_projectSettings->setProjectFilePath(filePath.withoutExtension().fileName(), filePath.getParentDirectory()); } if (!m_contentWidget) { setup(); } else { loadContent(); } cancelSourceGroup(); std::shared_ptr sourceGroupSettings = std::make_shared(utility::getUuidString(), m_projectSettings.get()); sourceGroupSettings->setCompilationDatabasePath(filePath); executeSourceGroupSetup(sourceGroupSettings); } void QtProjectWizard::editProject(const FilePath& settingsPath) { std::shared_ptr settings = std::make_shared(settingsPath); settings->reload(); editProject(settings); } void QtProjectWizard::editProject(std::shared_ptr settings) { m_projectSettings = settings; m_allSourceGroupSettings = settings->getAllSourceGroupSettings(); m_editing = true; setup(); } void QtProjectWizard::populateWindow(QWidget* widget) { QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); { QWidget* menu = new QWidget(); menu->setObjectName("project_menu"); menu->setFixedWidth(200); layout->addWidget(menu); QVBoxLayout* menuLayout = new QVBoxLayout(menu); menuLayout->setContentsMargins(0, 0, 0, 0); menuLayout->setSpacing(0); m_generalButton = new QPushButton("General"); m_generalButton->setObjectName("general_button"); m_generalButton->setCheckable(true); connect(m_generalButton, &QPushButton::clicked, this, &QtProjectWizard::generalButtonClicked); menuLayout->addWidget(m_generalButton); QLabel* sourceGroupLabel = new QLabel("Source Groups:"); menuLayout->addWidget(sourceGroupLabel); m_sourceGroupList = new QListWidget(); m_sourceGroupList->setAttribute(Qt::WA_MacShowFocusRect, 0); connect(m_sourceGroupList, &QListWidget::currentRowChanged, this, &QtProjectWizard::selectedSourceGroupChanged); menuLayout->addWidget(m_sourceGroupList); QHBoxLayout* buttonsLayout = new QHBoxLayout(); buttonsLayout->setContentsMargins(0, 0, 0, 0); buttonsLayout->setSpacing(0); QPushButton* addButton = new QtIconButton( ResourcePaths::getGuiPath().concatenate(L"window/source_group_add.png"), ResourcePaths::getGuiPath().concatenate(L"window/source_group_add_hover.png") ); m_removeButton = new QtIconButton( ResourcePaths::getGuiPath().concatenate(L"window/source_group_delete.png"), ResourcePaths::getGuiPath().concatenate(L"window/source_group_delete_hover.png") ); m_duplicateButton = new QtIconButton( ResourcePaths::getGuiPath().concatenate(L"window/source_group_copy.png"), ResourcePaths::getGuiPath().concatenate(L"window/source_group_copy_hover.png") ); addButton->setIconSize(QSize(20, 20)); m_removeButton->setIconSize(QSize(20, 20)); m_duplicateButton->setIconSize(QSize(20, 20)); addButton->setToolTip("Add Source Group"); m_removeButton->setToolTip("Remove Source Group"); m_duplicateButton->setToolTip("Copy Source Group"); addButton->setObjectName("action_button"); m_removeButton->setObjectName("action_button"); m_duplicateButton->setObjectName("action_button"); m_removeButton->setEnabled(false); m_duplicateButton->setEnabled(false); connect(addButton, &QPushButton::clicked, this, &QtProjectWizard::newSourceGroup); connect(m_removeButton, &QPushButton::clicked, this, &QtProjectWizard::removeSelectedSourceGroup); connect(m_duplicateButton, &QPushButton::clicked, this, &QtProjectWizard::duplicateSelectedSourceGroup); buttonsLayout->addWidget(addButton); buttonsLayout->addWidget(m_removeButton); buttonsLayout->addWidget(m_duplicateButton); buttonsLayout->addStretch(); menuLayout->addLayout(buttonsLayout); } QFrame* separator = new QFrame(); separator->setFrameShape(QFrame::VLine); QPalette palette = separator->palette(); palette.setColor(QPalette::WindowText, Qt::lightGray); separator->setPalette(palette); layout->addWidget(separator); layout->addSpacing(10); m_contentWidget = new QWidget(); m_contentWidget->setObjectName("form"); QScrollArea* scrollArea = new QScrollArea(); scrollArea->setFrameShadow(QFrame::Plain); scrollArea->setObjectName("formArea"); scrollArea->setWidgetResizable(true); scrollArea->setWidget(m_contentWidget); layout->addWidget(scrollArea); widget->setLayout(layout); } void QtProjectWizard::windowReady() { if (m_editing) { updateTitle("Edit Project"); updateNextButton("Save"); } else { updateTitle("New Project"); updateNextButton("Create"); setNextEnabled(false); } updateSubTitle("Overview"); updatePreviousButton("Add Source Group"); connect(this, &QtProjectWizard::previous, this, &QtProjectWizard::newSourceGroup); connect(this, &QtProjectWizard::next, this, &QtProjectWizard::createProject); updateSourceGroupList(); if (!m_allSourceGroupSettings.empty()) { m_sourceGroupList->setCurrentRow(0); } else { generalButtonClicked(); } } void QtProjectWizard::handlePrevious() { QtWindow::handlePrevious(); } template void QtProjectWizard::executeSourceGroupSetup(std::shared_ptr settings) { std::shared_ptr> wizard = std::make_shared>( settings, std::bind(&QtProjectWizard::cancelSourceGroup, this), std::bind(&QtProjectWizard::createSourceGroup, this, std::placeholders::_1) ); for (const QtSourceGroupWizardPage& page : getSourceGroupWizardPages()) { wizard->addPage(page); } m_sourceGroupWizard = wizard; m_sourceGroupWizard->execute(m_windowStack); } QtProjectWizardWindow* QtProjectWizard::createWindowWithContent( std::function func ){ QtProjectWizardWindow* window = new QtProjectWizardWindow(parentWidget()); connect(window, &QtProjectWizardWindow::previous, &m_windowStack, &QtWindowStack::popWindow); connect(window, &QtProjectWizardWindow::canceled, this, &QtProjectWizard::cancelSourceGroup); window->setPreferredSize(QSize(580, 340)); window->setContent(func(window)); window->setScrollAble(window->content()->isScrollAble()); window->setup(); m_windowStack.pushWindow(window); return window; } QtProjectWizardWindow* QtProjectWizard::createWindowWithContentGroup( std::function func ){ QtProjectWizardWindow* window = new QtProjectWizardWindow(parentWidget()); connect(window, &QtProjectWizardWindow::previous, &m_windowStack, &QtWindowStack::popWindow); connect(window, &QtProjectWizardWindow::canceled, this, &QtProjectWizard::cancelSourceGroup); QtProjectWizardContentGroup* contentGroup = new QtProjectWizardContentGroup(window); window->setPreferredSize(QSize(750, 600)); window->setContent(contentGroup); window->setScrollAble(window->content()->isScrollAble()); func(window, contentGroup); window->setup(); m_windowStack.pushWindow(window); return window; } void QtProjectWizard::updateSourceGroupList() { m_sourceGroupList->clear(); for (const std::shared_ptr& group : m_allSourceGroupSettings) { QString name = QString::fromStdString(group->getName()); if (group->getStatus() == SOURCE_GROUP_STATUS_DISABLED) { name = "(" + name + ")"; } QListWidgetItem *item = new QListWidgetItem(name); m_sourceGroupList->addItem(item); } } bool QtProjectWizard::canExitContent() { if (content()) { if (!content()->check()) { return false; } saveContent(); } return true; } void QtProjectWizard::generalButtonClicked() { if (!canExitContent()) { m_generalButton->setChecked(false); return; } QtProjectWizardContentGroup* contentGroup = new QtProjectWizardContentGroup(this); contentGroup->addContent(new QtProjectWizardContentProjectData(m_projectSettings, this, m_editing)); if (m_allSourceGroupSettings.empty()) { contentGroup->addSpace(); contentGroup->addContent(new QtProjectWizardContentSourceGroupInfoText(this)); } setContent(contentGroup); qDeleteAll(m_contentWidget->children()); QtProjectWizardWindow::populateWindow(m_contentWidget); loadContent(); m_previouslySelectedIndex = -1; m_generalButton->setChecked(true); m_sourceGroupList->setCurrentRow(-1); } void QtProjectWizard::selectedSourceGroupChanged(int index) { if (index < 0 || index >= int(m_allSourceGroupSettings.size())) { m_removeButton->setEnabled(false); m_duplicateButton->setEnabled(false); return; } if (index == m_previouslySelectedIndex) { return; } if (!canExitContent()) { QTimer::singleShot(1, [&]() { m_sourceGroupList->setCurrentRow(m_previouslySelectedIndex); }); return; } m_generalButton->setChecked(false); m_removeButton->setEnabled(true); m_duplicateButton->setEnabled(true); std::shared_ptr group = m_allSourceGroupSettings[index]; QtProjectWizardContentGroup* summary = new QtProjectWizardContentGroup(this); summary->setIsForm(true); QtProjectWizardContentSourceGroupData* content = new QtProjectWizardContentSourceGroupData(group, this); connect(content, &QtProjectWizardContentSourceGroupData::nameUpdated, this, &QtProjectWizard::selectedSourceGroupNameChanged); summary->addContent(content); summary->addSpace(); if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(group)) { fillSummary(summary, settings, this); } setContent(summary); qDeleteAll(m_contentWidget->children()); QtProjectWizardWindow::populateWindow(m_contentWidget); loadContent(); m_previouslySelectedIndex = index; } void QtProjectWizard::selectedSourceGroupNameChanged(QString name) { m_sourceGroupList->item(m_sourceGroupList->currentRow())->setText(name); } void QtProjectWizard::removeSelectedSourceGroup() { if (!m_allSourceGroupSettings.size() || m_sourceGroupList->currentRow() < 0) { return; } QMessageBox msgBox; msgBox.setText("Remove Source Group"); msgBox.setInformativeText("Do you really want to remove this source group from the project?"); msgBox.addButton("Yes", QMessageBox::ButtonRole::YesRole); msgBox.addButton("No", QMessageBox::ButtonRole::NoRole); msgBox.setIcon(QMessageBox::Icon::Question); int ret = msgBox.exec(); if (ret == 0) // QMessageBox::Yes { int currentRow = m_sourceGroupList->currentRow(); m_allSourceGroupSettings.erase(m_allSourceGroupSettings.begin() + currentRow); updateSourceGroupList(); if (m_allSourceGroupSettings.empty()) { setNextEnabled(false); generalButtonClicked(); return; } if (currentRow >= int(m_allSourceGroupSettings.size())) { currentRow--; } m_previouslySelectedIndex = -1; m_sourceGroupList->setCurrentRow(currentRow); } } void QtProjectWizard::duplicateSelectedSourceGroup() { if (!m_allSourceGroupSettings.size() || m_sourceGroupList->currentRow() < 0 || !canExitContent()) { return; } std::shared_ptr oldSourceGroup = m_allSourceGroupSettings[m_sourceGroupList->currentRow()]; std::shared_ptr newSourceGroup = oldSourceGroup->createCopy(); newSourceGroup->setId(utility::getUuidString()); { const std::string newNameBase = oldSourceGroup->getName() + " - Copy"; int id = 0; std::string newName; while (true) { newName = newNameBase + (id > 0 ? " (" + std::to_string(id) + ")" : ""); bool nameAlreadyExists = false; for (std::shared_ptr sourceGroupSettings : m_allSourceGroupSettings) { if (sourceGroupSettings && sourceGroupSettings->getName() == newName) { nameAlreadyExists = true; break; } } if (!nameAlreadyExists) { break; } id++; } newSourceGroup->setName(newName); } const int newRow = m_sourceGroupList->currentRow() + 1; m_allSourceGroupSettings.insert(m_allSourceGroupSettings.begin() + newRow, newSourceGroup); updateSourceGroupList(); m_previouslySelectedIndex = -1; m_sourceGroupList->setCurrentRow(newRow); } void QtProjectWizard::cancelSourceGroup() { m_windowStack.clearWindows(); } void QtProjectWizard::cancelWizard() { m_windowStack.clearWindows(); emit canceled(); } void QtProjectWizard::finishWizard() { m_windowStack.clearWindows(); emit finished(); } void QtProjectWizard::windowStackChanged() { QWidget* window = m_windowStack.getTopWindow(); if (window) { dynamic_cast(window)->content()->load(); setEnabled(false); } else { setEnabled(true); raise(); } } void QtProjectWizard::newSourceGroup() { if (!canExitContent()) { return; } QtProjectWizardWindow* window = createWindowWithContent( [](QtProjectWizardWindow* window) { window->setPreferredSize(QSize(560, 520)); return new QtProjectWizardContentSelect(window); } ); window->resize(QSize(560, 520)); connect(dynamic_cast(window->content()), &QtProjectWizardContentSelect::selected, this, &QtProjectWizard::selectedProjectType); window->show(); window->setNextEnabled(false); window->setPreviousEnabled(false); window->updateSubTitle("Type Selection"); } void QtProjectWizard::selectedProjectType(SourceGroupType sourceGroupType) { const std::string sourceGroupId = utility::getUuidString(); switch (sourceGroupType) { case SOURCE_GROUP_C_EMPTY: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); addMsvcCompatibilityFlagsOnDemand(settings); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CPP_EMPTY: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); addMsvcCompatibilityFlagsOnDemand(settings); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CXX_CDB: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CXX_CODEBLOCKS: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); addMsvcCompatibilityFlagsOnDemand(settings); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CXX_SONARGRAPH: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); addMsvcCompatibilityFlagsOnDemand(settings); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CXX_VS: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_JAVA_EMPTY: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_JAVA_MAVEN: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_JAVA_GRADLE: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_JAVA_SONARGRAPH: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_PYTHON_EMPTY: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_CUSTOM_COMMAND: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_UNKNOWN: break; } } void QtProjectWizard::createSourceGroup(std::shared_ptr settings) { m_allSourceGroupSettings.push_back(settings); updateSourceGroupList(); cancelSourceGroup(); setNextEnabled(true); m_previouslySelectedIndex = -1; m_sourceGroupList->setCurrentRow(m_allSourceGroupSettings.size() - 1); } void QtProjectWizard::createProject() { FilePath path = m_projectSettings->getFilePath(); m_projectSettings->setVersion(ProjectSettings::VERSION); m_projectSettings->setAllSourceGroupSettings(m_allSourceGroupSettings); m_projectSettings->save(path); bool settingsChanged = false; if (m_editing) { std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); if (currentProject) { settingsChanged = !(currentProject->settingsEqualExceptNameAndLocation(*(m_projectSettings.get()))); } settingsChanged |= !(m_appSettings == *ApplicationSettings::getInstance().get()); } else { MessageStatus(L"Created project: " + path.wstr()).dispatch(); } MessageLoadProject(path, settingsChanged).dispatch(); finishWizard(); }