| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "runpropertywidget.h" |
| 6 | #include "environmentwidget.h" |
| 7 | #include "common/common.h" |
| 8 | #include "runconfigpane.h" |
| 9 | #include "configutil.h" |
| 10 | #include "targetsmanager.h" |
| 11 | |
| 12 | #include <QListWidget> |
| 13 | #include <QSplitter> |
| 14 | #include <QComboBox> |
| 15 | #include <QVBoxLayout> |
| 16 | #include <QGroupBox> |
| 17 | #include <QPushButton> |
| 18 | #include <QStyleFactory> |
| 19 | #include <QStackedWidget> |
| 20 | |
| 21 | using namespace config; |
| 22 | |
| 23 | class RunPropertyWidgetPrivate |
| 24 | { |
| 25 | friend class RunPropertyWidget; |
| 26 | |
| 27 | QComboBox *exeComboBox{nullptr}; |
| 28 | RunConfigPane *runConfigPane{nullptr}; |
| 29 | |
| 30 | QVector<RunParam> paramsShadow; |
| 31 | QStandardItem *item{nullptr}; |
| 32 | dpfservice::ProjectInfo projectInfo; |
| 33 | }; |
| 34 | |
| 35 | RunPropertyWidget::RunPropertyWidget(const dpfservice::ProjectInfo &projectInfo, QStandardItem *item, QWidget *parent) |
| 36 | : PageWidget(parent) |
| 37 | , d(new RunPropertyWidgetPrivate()) |
| 38 | { |
| 39 | d->projectInfo = projectInfo; |
| 40 | d->item = item; |
| 41 | setupUi(); |
| 42 | } |
| 43 | |
| 44 | RunPropertyWidget::~RunPropertyWidget() |
| 45 | { |
| 46 | if (d) |
| 47 | delete d; |
| 48 | } |
| 49 | |
| 50 | void RunPropertyWidget::setupUi() |
| 51 | { |
| 52 | ConfigureWidget *runCfgWidget = new ConfigureWidget(this); |
| 53 | |
| 54 | QWidget *titleWidget = new QWidget(runCfgWidget); |
| 55 | QHBoxLayout *runCfgLayout = new QHBoxLayout(titleWidget); |
| 56 | QLabel *runCfgLabel = new QLabel(tr("Run configuration:" )); |
| 57 | d->exeComboBox = new QComboBox(); |
| 58 | d->exeComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
| 59 | QObject::connect(d->exeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ |
| 60 | if (index >= 0 && index < d->paramsShadow.count()) { |
| 61 | d->runConfigPane->bindValues(&d->paramsShadow[index]); |
| 62 | } |
| 63 | }); |
| 64 | runCfgLayout->addWidget(runCfgLabel, 0, Qt::AlignLeft); |
| 65 | runCfgLayout->addWidget(d->exeComboBox, 0, Qt::AlignLeft); |
| 66 | runCfgLayout->addStretch(10); |
| 67 | runCfgLayout->setMargin(0); |
| 68 | |
| 69 | d->runConfigPane = new RunConfigPane(this); |
| 70 | runCfgWidget->addWidget(titleWidget); |
| 71 | runCfgWidget->addWidget(d->runConfigPane); |
| 72 | |
| 73 | QVBoxLayout *vLayout = new QVBoxLayout(this); |
| 74 | vLayout->addWidget(runCfgWidget); |
| 75 | } |
| 76 | |
| 77 | void RunPropertyWidget::updateData() |
| 78 | { |
| 79 | d->exeComboBox->clear(); |
| 80 | |
| 81 | ConfigureParam *param = ConfigUtil::instance()->getConfigureParamPointer(); |
| 82 | for (auto iter = param->buildConfigures.begin(); iter != param->buildConfigures.end(); ++iter) { |
| 83 | if (param->tempSelType == iter->type) { |
| 84 | d->paramsShadow = iter->runConfigure.params; |
| 85 | auto iterExe = d->paramsShadow.begin(); |
| 86 | int index = 0; |
| 87 | for (; iterExe != d->paramsShadow.end(); ++iterExe, index++) { |
| 88 | d->exeComboBox->insertItem(index, iterExe->targetName); |
| 89 | if (iter->runConfigure.defaultTargetName == iterExe->targetName) { |
| 90 | d->exeComboBox->setCurrentIndex(index); |
| 91 | d->runConfigPane->bindValues(iterExe); |
| 92 | } |
| 93 | } |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void RunPropertyWidget::readConfig() |
| 100 | { |
| 101 | updateData(); |
| 102 | } |
| 103 | |
| 104 | void RunPropertyWidget::saveConfig() |
| 105 | { |
| 106 | ConfigureParam *param = ConfigUtil::instance()->getConfigureParamPointer(); |
| 107 | auto iter = param->buildConfigures.begin(); |
| 108 | for (; iter != param->buildConfigures.end(); ++iter) { |
| 109 | if (param->defaultType == iter->type) { |
| 110 | iter->runConfigure.params = d->paramsShadow; |
| 111 | iter->runConfigure.defaultTargetName = d->exeComboBox->currentText(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | QString filePath = ConfigUtil::instance()->getConfigPath(param->workspace); |
| 116 | ConfigUtil::instance()->saveConfig(filePath, *param); |
| 117 | |
| 118 | ConfigUtil::instance()->updateProjectInfo(d->projectInfo, param); |
| 119 | dpfservice::ProjectInfo::set(d->item, d->projectInfo); |
| 120 | } |
| 121 | |