Skip to content

Commit

Permalink
fix: [project] debug/release switch issue
Browse files Browse the repository at this point in the history
Log: Support automatic switching of the application after toggling between debug/release compilation modes, and fix related bugs.
  • Loading branch information
LiHua000 committed Aug 6, 2024
1 parent 1e4f48d commit 5aaec82
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ 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<QString>();
TargetsManager::instance()->readTargets(directory, param->workspace);
break;
}
}

if (d)
delete d;
}
Expand Down Expand Up @@ -215,6 +228,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();
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/cxx/cmake/project/properties/configutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/plugins/cxx/cmake/project/properties/configutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ class ConfigUtil final : public QObject
void saveConfig(const QString &filePath, const ProjectConfigure &param);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -103,14 +107,14 @@ 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) {
iter->runConfigure.targetsRunConfigure = d->targetsRunConfigure;
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) {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/debugger/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ void Runner::running()
return;
}


LanguageService *service = dpfGetService(LanguageService);
if (service) {
auto generator = service->create<LanguageGenerator>(getActiveProjectInfo().kitName());
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/project/mainframe/projecttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/project/mainframe/projecttree.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProjectTree : public DTreeView
QList<dpfservice::ProjectInfo> 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;

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/project/projectcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/plugins/project/transceiver/projectcorereceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/services/project/projectservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class SERVICE_EXPORT ProjectService final : public dpf::PluginService,
*/
DPF_INTERFACE(dpfservice::ProjectInfo, getActiveProjectInfo);

/**
* @brief getActiveProjectInfo
*/
DPF_INTERFACE(QStandardItem *, getActiveProjectItem);

/**
* @brief DPF_INTERFACE
* @param projectInfo
Expand Down

0 comments on commit 5aaec82

Please sign in to comment.