From d58f7da31ee0d7d62d9401fb937d6cfc00e435eb Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Mon, 5 Aug 2024 16:25:22 +0800 Subject: [PATCH] fix: [project] debug/release switch issue Log: Support automatic switching of the application after toggling between debug/release compilation modes, and fix related bugs. --- .../cxx/cmake/project/cmakeprojectgenerator.cpp | 10 ++++++---- .../bulidCfgWidget/buildpropertypage.cpp | 16 ++++++++++++++++ .../cxx/cmake/project/properties/configutil.cpp | 5 +++++ .../cxx/cmake/project/properties/configutil.h | 2 ++ .../properties/runCfgWidget/runpropertypage.cpp | 6 +++++- src/plugins/debugger/runner/runner.cpp | 1 - src/plugins/project/mainframe/projecttree.cpp | 5 +++++ src/plugins/project/mainframe/projecttree.h | 1 + src/plugins/project/projectcore.cpp | 3 +++ .../project/transceiver/projectcorereceiver.cpp | 1 - src/services/project/projectservice.h | 5 +++++ 11 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp b/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp index 2b3e0e65f..a65870f19 100644 --- a/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp +++ b/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp @@ -66,8 +66,9 @@ CmakeProjectGenerator::CmakeProjectGenerator() QObject::connect(ProjectCmakeProxy::instance(), &ProjectCmakeProxy::openProjectPropertys, this, [this](const ProjectInfo &prjInfo){ + auto prjService = dpfGetService(ProjectService); if (prjInfo.kitName() == toolKitName()) - actionProperties(prjInfo, this->rootItem); + actionProperties(prjInfo, prjService->getActiveProjectItem()); }); QObject::connect(ProjectCmakeProxy::instance(), @@ -593,13 +594,14 @@ void CmakeProjectGenerator::recursionRemoveItem(QStandardItem *item) void CmakeProjectGenerator::targetInitialized(const QString& workspace) { ProjectConfigure *projectConfigure = ConfigUtil::instance()->getConfigureParamPointer(); + auto tempType = projectConfigure->tempSelType; ConfigUtil::instance()->readConfig(ConfigUtil::instance()->getConfigPath(workspace), *projectConfigure); - + projectConfigure->tempSelType = tempType; dpfservice::Target activeExecTarget = TargetsManager::instance()->getActivedTargetByTargetType(dpfservice::TargetType::kActiveExecTarget); for (auto &buildTypeConfigure : projectConfigure->buildTypeConfigures) { - createTargetsRunConfigure(buildTypeConfigure.directory, buildTypeConfigure.runConfigure); - if (buildTypeConfigure.type != projectConfigure->defaultType) + if (buildTypeConfigure.type != projectConfigure->tempSelType) continue; + createTargetsRunConfigure(buildTypeConfigure.directory, buildTypeConfigure.runConfigure); // update environment. for (auto targetRunConfigure : buildTypeConfigure.runConfigure.targetsRunConfigure) { diff --git a/src/plugins/cxx/cmake/project/properties/bulidCfgWidget/buildpropertypage.cpp b/src/plugins/cxx/cmake/project/properties/bulidCfgWidget/buildpropertypage.cpp index a2cc076ff..4dbace47f 100644 --- a/src/plugins/cxx/cmake/project/properties/bulidCfgWidget/buildpropertypage.cpp +++ b/src/plugins/cxx/cmake/project/properties/bulidCfgWidget/buildpropertypage.cpp @@ -173,6 +173,20 @@ BuildPropertyPage::BuildPropertyPage(const dpfservice::ProjectInfo &projectInfo, BuildPropertyPage::~BuildPropertyPage() { + // restore Targets data when dialog rejected + ProjectConfigure *param = ConfigUtil::instance()->getConfigureParamPointer(); + if (param->tempSelType != param->defaultType) { + for (int index = 0; index < d->configureComboBox->maxVisibleItems(); index ++) { + auto type = ConfigUtil::instance()->getTypeFromName(d->configureComboBox->itemText(index)); + if (type != param->defaultType) + continue; + auto directory = d->configureComboBox->itemData(index, Qt::UserRole + 1).value(); + TargetsManager::instance()->readTargets(directory, param->workspace); + break; + } + } + param->tempSelType = param->defaultType; + if (d) delete d; } @@ -215,6 +229,8 @@ void BuildPropertyPage::setupOverviewUI() ProjectConfigure *param = ConfigUtil::instance()->getConfigureParamPointer(); param->tempSelType = ConfigUtil::instance()->getTypeFromName(d->configureComboBox->currentText()); ConfigUtil::instance()->checkConfigInfo(d->configureComboBox->currentText(), d->outputDirEdit->text()); + TargetsManager::instance()->readTargets(d->outputDirEdit->text(), param->workspace); + ConfigUtil::instance()->switchConfigType(param->tempSelType); }); QHBoxLayout *hLayout = new QHBoxLayout(); diff --git a/src/plugins/cxx/cmake/project/properties/configutil.cpp b/src/plugins/cxx/cmake/project/properties/configutil.cpp index f402c29f1..ad6cf83c2 100644 --- a/src/plugins/cxx/cmake/project/properties/configutil.cpp +++ b/src/plugins/cxx/cmake/project/properties/configutil.cpp @@ -264,4 +264,9 @@ bool ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ProjectC return false; } +void ConfigUtil::switchConfigType(const ConfigType &type) +{ + emit configTypeSwitched(type); +} + } //namespace config diff --git a/src/plugins/cxx/cmake/project/properties/configutil.h b/src/plugins/cxx/cmake/project/properties/configutil.h index 283a6cd6a..54ce4304f 100644 --- a/src/plugins/cxx/cmake/project/properties/configutil.h +++ b/src/plugins/cxx/cmake/project/properties/configutil.h @@ -288,8 +288,10 @@ class ConfigUtil final : public QObject void saveConfig(const QString &filePath, const ProjectConfigure ¶m); bool updateProjectInfo(dpfservice::ProjectInfo &info, const ProjectConfigure *param); + void switchConfigType(const ConfigType &type); signals: void configureDone(const dpfservice::ProjectInfo &info); + void configTypeSwitched(const ConfigType &type); private: explicit ConfigUtil(QObject *parent = nullptr); diff --git a/src/plugins/cxx/cmake/project/properties/runCfgWidget/runpropertypage.cpp b/src/plugins/cxx/cmake/project/properties/runCfgWidget/runpropertypage.cpp index b1754f4c5..e48952e3a 100644 --- a/src/plugins/cxx/cmake/project/properties/runCfgWidget/runpropertypage.cpp +++ b/src/plugins/cxx/cmake/project/properties/runCfgWidget/runpropertypage.cpp @@ -42,6 +42,10 @@ RunPropertyPage::RunPropertyPage(const dpfservice::ProjectInfo &projectInfo, QSt d->projectInfo = projectInfo; d->item = item; setupUi(); + + connect(ConfigUtil::instance(), &ConfigUtil::configTypeSwitched, this, [=]() { + updateData(); + }); } RunPropertyPage::~RunPropertyPage() @@ -103,6 +107,7 @@ void RunPropertyPage::readConfig() void RunPropertyPage::saveConfig() { ProjectConfigure *param = ConfigUtil::instance()->getConfigureParamPointer(); + auto iter = param->buildTypeConfigures.begin(); for (; iter != param->buildTypeConfigures.end(); ++iter) { if (param->defaultType == iter->type) { @@ -110,7 +115,6 @@ void RunPropertyPage::saveConfig() iter->runConfigure.defaultTargetName = d->projectInfo.currentProgram(); } if (param->tempSelType == iter->type) { - d->projectInfo = dpfGetService(ProjectService)->getActiveProjectInfo(); auto activeTarget = TargetsManager::instance()->getActivedTargetByTargetType(kActiveExecTarget); for (auto it : iter->runConfigure.targetsRunConfigure) { if (it.targetName == activeTarget.name) { diff --git a/src/plugins/debugger/runner/runner.cpp b/src/plugins/debugger/runner/runner.cpp index 3e52c1e48..7787f6c9e 100644 --- a/src/plugins/debugger/runner/runner.cpp +++ b/src/plugins/debugger/runner/runner.cpp @@ -150,7 +150,6 @@ void Runner::running() return; } - LanguageService *service = dpfGetService(LanguageService); if (service) { auto generator = service->create(getActiveProjectInfo().kitName()); diff --git a/src/plugins/project/mainframe/projecttree.cpp b/src/plugins/project/mainframe/projecttree.cpp index 6aa693b1c..b35d5ecbc 100644 --- a/src/plugins/project/mainframe/projecttree.cpp +++ b/src/plugins/project/mainframe/projecttree.cpp @@ -367,6 +367,11 @@ ProjectInfo ProjectTree::getProjectInfo(const QString &kitName, const QString &w return projectInfo; } +QStandardItem *ProjectTree::getActiveProjectItem() const +{ + return d->itemModel->itemFromIndex(d->delegate->getActiveProject()); +} + ProjectInfo ProjectTree::getActiveProjectInfo() const { ProjectInfo projectInfo; diff --git a/src/plugins/project/mainframe/projecttree.h b/src/plugins/project/mainframe/projecttree.h index f120e814f..a8c29d3bf 100644 --- a/src/plugins/project/mainframe/projecttree.h +++ b/src/plugins/project/mainframe/projecttree.h @@ -37,6 +37,7 @@ class ProjectTree : public DTreeView QList getAllProjectInfo(); dpfservice::ProjectInfo getProjectInfo(const QString &kitName, const QString &workspace) const; dpfservice::ProjectInfo getActiveProjectInfo() const; + QStandardItem *getActiveProjectItem() const; bool updateProjectInfo(dpfservice::ProjectInfo &projectInfo); bool hasProjectInfo(const dpfservice::ProjectInfo &info) const; diff --git a/src/plugins/project/projectcore.cpp b/src/plugins/project/projectcore.cpp index f06d52155..138b2c120 100644 --- a/src/plugins/project/projectcore.cpp +++ b/src/plugins/project/projectcore.cpp @@ -212,6 +212,9 @@ void ProjectCore::initProject(dpf::PluginServiceContext &ctx) if (!projectService->openProject) { projectService->openProject = std::bind(&ProjectCore::openProject, this); } + if (!projectService->getActiveProjectItem) { + projectService->getActiveProjectItem = std::bind(&ProjectTree::getActiveProjectItem, treeView); + } } } diff --git a/src/plugins/project/transceiver/projectcorereceiver.cpp b/src/plugins/project/transceiver/projectcorereceiver.cpp index 59ac95d75..0c6fd1691 100644 --- a/src/plugins/project/transceiver/projectcorereceiver.cpp +++ b/src/plugins/project/transceiver/projectcorereceiver.cpp @@ -28,7 +28,6 @@ void ProjectCoreReceiver::eventProcess(const dpf::Event &event) { using namespace dpfservice; if (event.data() == project.activeProject.name) { - auto infos = ProjectKeeper::instance()->treeView()->getAllProjectInfo(); QString kitName = event.property("kitName").toString(); QString language = event.property("language").toString(); QString workspace = event.property("workspace").toString(); diff --git a/src/services/project/projectservice.h b/src/services/project/projectservice.h index 56cdc97fb..2a9361037 100644 --- a/src/services/project/projectservice.h +++ b/src/services/project/projectservice.h @@ -172,6 +172,11 @@ class SERVICE_EXPORT ProjectService final : public dpf::PluginService, */ DPF_INTERFACE(dpfservice::ProjectInfo, getActiveProjectInfo); + /** + * @brief getActiveProjectItem + */ + DPF_INTERFACE(QStandardItem *, getActiveProjectItem); + /** * @brief DPF_INTERFACE * @param projectInfo