Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [project] debug/release switch issue #865

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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<QString>();
TargetsManager::instance()->readTargets(directory, param->workspace);
break;
}
}
param->tempSelType = param->defaultType;

if (d)
delete d;
}
Expand Down Expand Up @@ -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();
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 @@
d->projectInfo = projectInfo;
d->item = item;
setupUi();

connect(ConfigUtil::instance(), &ConfigUtil::configTypeSwitched, this, [=]() {
updateData();
});
}

RunPropertyPage::~RunPropertyPage()
Expand Down Expand Up @@ -103,17 +107,17 @@
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) {

Check warning on line 120 in src/plugins/cxx/cmake/project/properties/runCfgWidget/runpropertypage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
d->projectInfo.setRunEnvironment(it.env.toList());
break;
}
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 getActiveProjectItem
*/
DPF_INTERFACE(QStandardItem *, getActiveProjectItem);

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