1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "cmakeoptionwidget.h"
6#include "kitsmanagerwidget.h"
7
8#include "services/option/optionutils.h"
9#include "services/option/optiondatastruct.h"
10#include "services/option/optionmanager.h"
11
12#include <QHBoxLayout>
13#include <QTabWidget>
14
15class CMakeOptionWidgetPrivate {
16 QTabWidget* tabWidget = nullptr;
17
18 friend class CMakeOptionWidget;
19};
20
21CMakeOptionWidget::CMakeOptionWidget(QWidget *parent)
22 : PageWidget(parent)
23 , d(new CMakeOptionWidgetPrivate())
24{
25 QHBoxLayout *layout = new QHBoxLayout();
26 d->tabWidget = new QTabWidget();
27 layout->addWidget(d->tabWidget);
28
29 d->tabWidget->addTab(new KitsManagerWidget(), "Kits");
30 QObject::connect(d->tabWidget, &QTabWidget::currentChanged, [this]() {
31 readConfig();
32 });
33
34 setLayout(layout);
35}
36
37CMakeOptionWidget::~CMakeOptionWidget()
38{
39 if (d)
40 delete d;
41}
42
43void CMakeOptionWidget::saveConfig()
44{
45 for (int index = 0; index < d->tabWidget->count(); index++)
46 {
47 PageWidget *pageWidget = qobject_cast<PageWidget*>(d->tabWidget->widget(index));
48 if (pageWidget) {
49 QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex());
50 QMap<QString, QVariant> map;
51 pageWidget->getUserConfig(map);
52 OptionUtils::writeJsonSection(OptionUtils::getJsonFilePath(),
53 option::CATEGORY_CMAKE, itemNode, map);
54
55 OptionManager::getInstance()->updateData();
56 }
57 }
58}
59
60void CMakeOptionWidget::readConfig()
61{
62 for (int index = 0; index < d->tabWidget->count(); index++)
63 {
64 PageWidget *pageWidget = qobject_cast<PageWidget*>(d->tabWidget->widget(index));
65 if (pageWidget) {
66 QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex());
67 QMap<QString, QVariant> map;
68 OptionUtils::readJsonSection(OptionUtils::getJsonFilePath(),
69 option::CATEGORY_CMAKE, itemNode, map);
70 pageWidget->setUserConfig(map);
71 }
72 }
73}
74
75