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