diff --git a/src/plugins/cxx/CMakeLists.txt b/src/plugins/cxx/CMakeLists.txt index 3f583010d..c21cf6f5a 100644 --- a/src/plugins/cxx/CMakeLists.txt +++ b/src/plugins/cxx/CMakeLists.txt @@ -33,7 +33,7 @@ add_library(${PROJECT_NAME} ${CXX_FILES} ${QT_THEME} ${CXX_QRC} - ) +) target_link_libraries(${PROJECT_NAME} framework diff --git a/src/plugins/cxx/cmake/model/kitlistmodel.cpp b/src/plugins/cxx/cmake/model/kitlistmodel.cpp new file mode 100644 index 000000000..9e58e5703 --- /dev/null +++ b/src/plugins/cxx/cmake/model/kitlistmodel.cpp @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "kitlistmodel.h" + +#include + +KitListModel::KitListModel(QObject *parent) + : QAbstractItemModel(parent) +{ +} + +int KitListModel::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QVariant KitListModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= kitItemList.size()) + return {}; + + switch (role) { + case Qt::ToolTipRole: + case Qt::DisplayRole: + return kitItemList.value(index.row()).kitName(); + default: + break; + } + + return {}; +} + +QModelIndex KitListModel::index(int row, int column, const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + if (column == 0 && row < kitItemList.size()) { + const auto &item = kitItemList.at(row); + return createIndex(row, 0, const_cast(&item)); + } + + return {}; +} + +QModelIndex KitListModel::parent(const QModelIndex &child) const +{ + return {}; +} + +int KitListModel::rowCount(const QModelIndex &parent) const +{ + return kitItemList.size(); +} + +Kit *KitListModel::itemForIndex(const QModelIndex &index) +{ + return static_cast(index.internalPointer()); +} + +void KitListModel::setItemList(const QList &itemList) +{ + beginResetModel(); + kitItemList = itemList; + endResetModel(); +} + +QModelIndex KitListModel::addItem() +{ + Kit item; + item.setKitName(tr("Unnamed")); + + int pos = kitItemList.size(); + beginInsertRows(QModelIndex(), pos, pos); + kitItemList.append(item); + endInsertRows(); + + return index(pos, 0); +} + +void KitListModel::removeItem(const QModelIndex &index) +{ + auto item = itemForIndex(index); + if (!item) + return; + + int pos = kitItemList.indexOf(*item); + beginRemoveRows(QModelIndex(), pos, pos); + kitItemList.removeAt(pos); + endRemoveRows(); +} diff --git a/src/plugins/cxx/cmake/model/kitlistmodel.h b/src/plugins/cxx/cmake/model/kitlistmodel.h new file mode 100644 index 000000000..1e528cb07 --- /dev/null +++ b/src/plugins/cxx/cmake/model/kitlistmodel.h @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef KITLISTMODEL_H +#define KITLISTMODEL_H + +#include "global_define.h" +#include "cmake/option/kit.h" + +#include + +class KitListModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit KitListModel(QObject *parent = nullptr); + + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &child) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + Kit *itemForIndex(const QModelIndex &index); + void setItemList(const QList &itemList); + QList itemList() const { return kitItemList; } + QModelIndex addItem(); + void removeItem(const QModelIndex &index); + +private: + QList kitItemList; +}; + +#endif // KITLISTMODEL_H diff --git a/src/plugins/cxx/cmake/option/cmakeoptionwidget.cpp b/src/plugins/cxx/cmake/option/cmakeoptionwidget.cpp deleted file mode 100644 index 9794a09ab..000000000 --- a/src/plugins/cxx/cmake/option/cmakeoptionwidget.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "cmakeoptionwidget.h" -#include "kitsmanagerwidget.h" - -#include "services/option/optionutils.h" -#include "services/option/optiondatastruct.h" -#include "services/option/optionmanager.h" - -#include -#include - -class CMakeOptionWidgetPrivate { - DTabWidget* tabWidget = nullptr; - - friend class CMakeOptionWidget; -}; - -CMakeOptionWidget::CMakeOptionWidget(QWidget *parent) - : PageWidget(parent) - , d(new CMakeOptionWidgetPrivate()) -{ - QHBoxLayout *layout = new QHBoxLayout(); - d->tabWidget = new DTabWidget(); - d->tabWidget->tabBar()->setAutoHide(true); - layout->addWidget(d->tabWidget); - - d->tabWidget->addTab(new KitsManagerWidget(), "Kits"); - //去除tabwidget的边框 - d->tabWidget->setDocumentMode(true); - QObject::connect(d->tabWidget, &DTabWidget::currentChanged, [this]() { - readConfig(); - }); - - setLayout(layout); -} - -CMakeOptionWidget::~CMakeOptionWidget() -{ - if (d) - delete d; -} - -void CMakeOptionWidget::saveConfig() -{ - for (int index = 0; index < d->tabWidget->count(); index++) - { - PageWidget *pageWidget = qobject_cast(d->tabWidget->widget(index)); - if (pageWidget) { - QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex()); - QMap map; - pageWidget->getUserConfig(map); - OptionUtils::writeJsonSection(OptionUtils::getJsonFilePath(), - option::CATEGORY_CMAKE, itemNode, map); - - OptionManager::getInstance()->updateData(); - } - } -} - -void CMakeOptionWidget::readConfig() -{ - for (int index = 0; index < d->tabWidget->count(); index++) - { - PageWidget *pageWidget = qobject_cast(d->tabWidget->widget(index)); - if (pageWidget) { - QString itemNode = d->tabWidget->tabText(d->tabWidget->currentIndex()); - QMap map; - OptionUtils::readJsonSection(OptionUtils::getJsonFilePath(), - option::CATEGORY_CMAKE, itemNode, map); - pageWidget->setUserConfig(map); - } - } -} - diff --git a/src/plugins/cxx/cmake/option/cmakeoptionwidget.h b/src/plugins/cxx/cmake/option/cmakeoptionwidget.h deleted file mode 100644 index e943db3aa..000000000 --- a/src/plugins/cxx/cmake/option/cmakeoptionwidget.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef CMAKEOPTIONWIDGET_H -#define CMAKEOPTIONWIDGET_H - -#include "common/common.h" - -class CMakeOptionWidgetPrivate; -class CMakeOptionWidget : public PageWidget -{ - Q_OBJECT -public: - explicit CMakeOptionWidget(QWidget *parent = nullptr); - ~CMakeOptionWidget() override; - - void saveConfig() override; - void readConfig() override; - -signals: - -public slots: -private: - CMakeOptionWidgetPrivate *const d; -}; - -#endif // CMAKEOPTIONWIDGET_H diff --git a/src/plugins/cxx/cmake/option/kit.cpp b/src/plugins/cxx/cmake/option/kit.cpp index 3a383a00b..ef4dfe0b1 100644 --- a/src/plugins/cxx/cmake/option/kit.cpp +++ b/src/plugins/cxx/cmake/option/kit.cpp @@ -6,10 +6,6 @@ #include -const char ID_KEY[] = "PE.Profile.Id"; -const char DISPLAYNAME_KEY[] = "PE.Profile.Name"; -const char DATA_KEY[] = "PE.Profile.Data"; - class KitPrivate { public: @@ -20,133 +16,169 @@ class KitPrivate id = QUuid::createUuid().toString(); } +public: QString id; - QString unexpandedDisplayName; - - QHash data; - - QString defaultOutput; + QString kitName; + Option ccompiler; + Option cxxcompiler; + Option debugger; + Option cmakeTool; + QString cmakeGenerator; }; -Kit::Kit(QString id, QObject *parent) : QObject(parent) - , d(std::make_unique(id)) +Kit::Kit(QString id, QObject *parent) + : QObject(parent), + d(new KitPrivate(id)) { } -QString fromSetting(const QVariant &variant) +Kit::Kit(const Kit &other) + : d(new KitPrivate("")) { - const QByteArray ba = variant.toString().toUtf8(); - if (ba.isEmpty()) - return {}; - return ba; + copyFrom(other); } -QString fromString(const QString &name) +Kit::~Kit() { - if (name.isEmpty()) - return {}; - return name.toUtf8(); + delete d; } -Kit::Kit(const QVariantMap &data) - : d(std::make_unique("")) +QString Kit::id() const { - d->id = fromSetting(data.value(QLatin1String(ID_KEY))); + return d->id; +} - d->unexpandedDisplayName = data.value(QLatin1String(DISPLAYNAME_KEY), - d->unexpandedDisplayName).toString(); +void Kit::setId(const QString &id) +{ + d->id = id; +} - QVariantMap extra = data.value(QLatin1String(DATA_KEY)).toMap(); - d->data.clear(); // remove default values - const QVariantMap::ConstIterator cend = extra.constEnd(); - for (QVariantMap::ConstIterator it = extra.constBegin(); it != cend; ++it) - d->data.insert(fromString(it.key()), it.value()); +QString Kit::kitName() const +{ + return d->kitName; } -QString Kit::displayName() const +void Kit::setKitName(const QString &name) { - return d->unexpandedDisplayName; + d->kitName = name; } -void Kit::setUnexpandedDisplayName(const QString &name) +Option Kit::ccompiler() const { - if (d->unexpandedDisplayName == name) - return; + return d->ccompiler; +} - d->unexpandedDisplayName = name; +void Kit::setCCompiler(const Option &opt) +{ + d->ccompiler = opt; } -QString Kit::id() const +Option Kit::cxxcompiler() const { - return d->id; + return d->cxxcompiler; } -QList Kit::allKeys() const +void Kit::setCXXCompiler(const Option &opt) { - return d->data.keys(); + d->cxxcompiler = opt; } -QVariant Kit::value(QString key, const QVariant &unset) const +Option Kit::debugger() const { - return d->data.value(key, unset); + return d->debugger; } -bool Kit::hasValue(QString key) const +void Kit::setDebugger(const Option &opt) { - return d->data.contains(key); + d->debugger = opt; } -void Kit::setValue(QString key, const QVariant &value) +Option Kit::cmakeTool() const { - if (d->data.value(key) == value) - return; - d->data.insert(key, value); + return d->cmakeTool; } -void Kit::setDefaultOutput(QString &defaultOutput) +void Kit::setCMakeTool(const Option &opt) { - d->defaultOutput = defaultOutput; + d->cmakeTool = opt; } -const QString &Kit::getDefaultOutput() const +QString Kit::cmakeGenerator() const { - return d->defaultOutput; + return d->cmakeGenerator; } -void Kit::copyFrom(const Kit &k) +void Kit::setCMakeGenerator(const QString &cg) { - d->data = k.d->data; - d->unexpandedDisplayName = k.d->unexpandedDisplayName; - d->defaultOutput = k.d->defaultOutput; + d->cmakeGenerator = cg; } -Kit::Kit(const Kit &other) +void Kit::copyFrom(const Kit &other) { - copyFrom(other); + d->id = other.d->id; + d->kitName = other.d->kitName; + d->ccompiler = other.d->ccompiler; + d->cxxcompiler = other.d->cxxcompiler; + d->debugger = other.d->debugger; + d->cmakeTool = other.d->cmakeTool; + d->cmakeGenerator = other.d->cmakeGenerator; } -Kit &Kit::operator=(const Kit &other) +QVariantMap Kit::toVariantMap() { - copyFrom(other); - return *this; + return toVariantMap(*this); +} + +QVariantMap Kit::toVariantMap(const Kit &kit) +{ + QMap map; + auto optionToMap = [&map](const QString key, const Option &opt) { + QVariantMap optMap; + optMap.insert(Name, opt.name); + optMap.insert(Path, opt.path); + map.insert(key, optMap); + }; + + optionToMap(kCCompiler, kit.d->ccompiler); + optionToMap(kCXXCompiler, kit.d->cxxcompiler); + optionToMap(kDebugger, kit.d->debugger); + optionToMap(kCMakeTool, kit.d->cmakeTool); + + map.insert(kCMakeGenerator, kit.d->cmakeGenerator); + map.insert(kID, kit.d->id); + return map; } -QVariantMap Kit::toMap() const +Kit Kit::fromVariantMap(const QVariantMap &map) { - using IdVariantConstIt = QHash::ConstIterator; + auto updateKit = [map](const QString key, Option &opt) { + const auto &item = map.value(key).toMap(); + opt.name = item.value(Name).toString(); + opt.path = item.value(Path).toString(); + }; - QVariantMap data; - data.insert(QLatin1String(ID_KEY), d->id); - data.insert(QLatin1String(DISPLAYNAME_KEY), d->unexpandedDisplayName); + Kit kit; + updateKit(kCCompiler, kit.d->ccompiler); + updateKit(kCXXCompiler, kit.d->cxxcompiler); + updateKit(kDebugger, kit.d->debugger); + updateKit(kCMakeTool, kit.d->cmakeTool); - QVariantMap extra; + kit.d->kitName = map.value(Name).toString(); + kit.d->cmakeGenerator = map.value(kCMakeGenerator).toString(); + kit.d->id = map.value(kID).toString(); + if (kit.d->id.isEmpty()) + kit.d->id = QUuid::createUuid().toString(); - const IdVariantConstIt cend = d->data.constEnd(); - for (IdVariantConstIt it = d->data.constBegin(); it != cend; ++it) - extra.insert(it.key(), it.value()); - data.insert(QLatin1String(DATA_KEY), extra); + return kit; +} - return data; +Kit &Kit::operator=(const Kit &other) +{ + copyFrom(other); + return *this; } -Kit::~Kit() = default; +bool Kit::operator==(const Kit &other) +{ + return d->id == other.d->id; +} diff --git a/src/plugins/cxx/cmake/option/kit.h b/src/plugins/cxx/cmake/option/kit.h index 9abca5f53..0ae3925d5 100644 --- a/src/plugins/cxx/cmake/option/kit.h +++ b/src/plugins/cxx/cmake/option/kit.h @@ -5,10 +5,7 @@ #ifndef KIT_H #define KIT_H -#include -#include - -#include +#include "global_define.h" class KitPrivate; class Kit : public QObject @@ -16,32 +13,34 @@ class Kit : public QObject Q_OBJECT public: explicit Kit(QString id = "", QObject *parent = nullptr); - explicit Kit(const QVariantMap &data); + Kit(const Kit &other); ~Kit(); - QString displayName() const; - void setUnexpandedDisplayName(const QString &name); QString id() const; - QList allKeys() const; - QVariant value(QString key, const QVariant &unset = QVariant()) const; - bool hasValue(QString key) const; - void setValue(QString key, const QVariant &value); - - void setDefaultOutput(QString &defaultOutput); - const QString &getDefaultOutput() const; - - void copyFrom(const Kit &k); + void setId(const QString &id); + QString kitName() const; + void setKitName(const QString &name); + Option ccompiler() const; + void setCCompiler(const Option &opt); + Option cxxcompiler() const; + void setCXXCompiler(const Option &opt); + Option debugger() const; + void setDebugger(const Option &opt); + Option cmakeTool() const; + void setCMakeTool(const Option &opt); + QString cmakeGenerator() const; + void setCMakeGenerator(const QString &cg); + + void copyFrom(const Kit &other); + QVariantMap toVariantMap(); + static QVariantMap toVariantMap(const Kit &kit); + static Kit fromVariantMap(const QVariantMap &map); - Kit(const Kit &other); Kit &operator=(const Kit &other); -signals: - -public slots: + bool operator==(const Kit &other); private: - QVariantMap toMap() const; - - const std::unique_ptr d; + KitPrivate *const d; }; -#endif // KIT_H +#endif // KIT_H diff --git a/src/plugins/cxx/cmake/option/kitmanager.cpp b/src/plugins/cxx/cmake/option/kitmanager.cpp index f7fe03aca..8defbc396 100644 --- a/src/plugins/cxx/cmake/option/kitmanager.cpp +++ b/src/plugins/cxx/cmake/option/kitmanager.cpp @@ -3,92 +3,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "kitmanager.h" -#include "common/util/custompaths.h" -#include "common/util/qtcassert.h" -#include "persistentsettings.h" - -#include - -const char KIT_DATA_KEY[] = "Profile."; -const char KIT_COUNT_KEY[] = "Profile.Count"; -const char KIT_DEFAULT_KEY[] = "Profile.Default"; -const char KIT_FILENAME[] = "/profiles.xml"; - -class KitManagerPrivate -{ -public: - Kit *defaultKit = nullptr; - bool initialized = false; - std::vector> kitList; - Kit selectedKit; - std::unique_ptr writer; -}; - -static KitManagerPrivate *d = nullptr; KitManager::KitManager(QObject *parent) : QObject(parent) { - d = new KitManagerPrivate; -} - -////////////////// -// find helpers -////////////////// -template -decltype(auto) equal(R (S::*function)() const, T value) -{ - // This should use std::equal_to<> instead of std::equal_to, - // but that's not supported everywhere yet, since it is C++14 - return std::bind(std::equal_to(), value, std::bind(function, std::placeholders::_1)); -} - -void KitManager::restoreKits() -{ - // TODO(Mozart) -} - -KitManager::KitList KitManager::restoreKits(const QString &fileName) -{ - KitList result; - - QFileInfo info(fileName); - if (!info.exists()) - return result; - - PersistentSettingsReader reader; - if (!reader.load(fileName)) { - qWarning("Warning: Failed to read \"%s\", cannot restore kits!", - qPrintable(fileName)); - return result; - } - QVariantMap data = reader.restoreValues(); - - const int count = data.value(QLatin1String(KIT_COUNT_KEY), 0).toInt(); - for (int i = 0; i < count; ++i) { - const QString key = QString::fromLatin1(KIT_DATA_KEY) + QString::number(i); - if (!data.contains(key)) - break; - - const QVariantMap stMap = data.value(key).toMap(); - - auto k = std::make_unique(stMap); - - result.kits.emplace_back(std::move(k)); - } - const QString id = data.value(QLatin1String(KIT_DEFAULT_KEY)).toString(); - if (id.isEmpty()) - return result; - - std::vector>::iterator it; - for (; it != result.kits.end(); ++it) { - if (it->get()->id() == id) { - result.defaultKit = id; - break; - } - } - - return result; } KitManager *KitManager::instance() @@ -97,21 +15,27 @@ KitManager *KitManager::instance() return &ins; } -KitManager::~KitManager() +void KitManager::setKitList(const QList &list) { + allKit = list; } -void KitManager::setSelectedKit(Kit &kit) +void KitManager::removeKit(const Kit &kit) { - d->selectedKit = kit; + allKit.removeOne(kit); } -const Kit &KitManager::getSelectedKit() +QList KitManager::kitList() const { - return d->selectedKit; + return allKit; } -QString KitManager::getDefaultOutputPath() const +Kit KitManager::findKit(const QString &id) { - return d->selectedKit.getDefaultOutput(); + auto iter = std::find_if(allKit.cbegin(), allKit.cbegin(), + [&id](const Kit &kit) { + return kit.id() == id; + }); + + return iter != allKit.cend() ? *iter : Kit(); } diff --git a/src/plugins/cxx/cmake/option/kitmanager.h b/src/plugins/cxx/cmake/option/kitmanager.h index 46b000cde..0e43f5c8a 100644 --- a/src/plugins/cxx/cmake/option/kitmanager.h +++ b/src/plugins/cxx/cmake/option/kitmanager.h @@ -14,32 +14,16 @@ class KitManager : public QObject Q_OBJECT public: static KitManager *instance(); - ~KitManager() override; - void save(); + void setKitList(const QList &list); + void removeKit(const Kit &kit); + QList kitList() const; + Kit findKit(const QString &id); - void setSelectedKit(Kit &kit); - const Kit &getSelectedKit(); - - QString getDefaultOutputPath() const; - -signals: - -public slots: private: explicit KitManager(QObject *parent = nullptr); - void restoreKits(); - - class KitList - { - public: - KitList() {} - QString defaultKit; - std::vector> kits; - }; - - KitList restoreKits(const QString &fileName); + QList allKit; }; -#endif // KITMANAGER_H +#endif // KITMANAGER_H diff --git a/src/plugins/cxx/cmake/option/kitsmanagerwidget.cpp b/src/plugins/cxx/cmake/option/kitsmanagerwidget.cpp deleted file mode 100644 index 2afec76d7..000000000 --- a/src/plugins/cxx/cmake/option/kitsmanagerwidget.cpp +++ /dev/null @@ -1,286 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "kitsmanagerwidget.h" -#include "services/option/toolchaindata.h" -#include "common/util/custompaths.h" -#include "common/toolchain/toolchain.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -DWIDGET_USE_NAMESPACE - -class KitsManagerWidgetPrivate -{ - friend class KitsManagerWidget; - DListView *listView = nullptr; - DLineEdit *nameEidt = nullptr; - DComboBox *cbCXXComplier = nullptr; - DComboBox *cbCMake = nullptr; - DComboBox *cbCComplier = nullptr; - DComboBox *cbDebugger = nullptr; - DComboBox *cbGenerator = nullptr; - DLabel *labelGeneratorExpression = nullptr; - QStringListModel *listModel = nullptr; - - QSharedPointer toolChainData; -}; - -KitsManagerWidget::KitsManagerWidget(QWidget *parent) - : PageWidget(parent) - , d(new KitsManagerWidgetPrivate) -{ - d->toolChainData.reset(new ToolChainData()); - QString retMsg; - bool ret = d->toolChainData->readToolChainData(retMsg); - if (ret) { - qInfo() << retMsg; - } - - setupUi(); - updateUi(); -} - -KitsManagerWidget::~KitsManagerWidget() -{ - if (d) { - delete d; - } -} - -void KitsManagerWidget::setupUi() -{ - auto centerLayout = new QHBoxLayout(this); - centerLayout->setSpacing(6); - - // leftSide - auto listFrame = new DFrame(this); - auto listlayout = new QVBoxLayout(listFrame); - - d->listView = new DListView(this); - d->listView->setAlternatingRowColors(true); - d->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); - - DFrame* separator = new DFrame(this); - separator->setFrameShape(DFrame::HLine); - separator->setFrameShadow(DFrame::Plain); - - DIconButton *iconBtnI = new DIconButton(DStyle::SP_IncreaseElement, this); - iconBtnI->setFixedSize(QSize(20,20)); - iconBtnI->setFlat(true); - DIconButton *iconBtnD = new DIconButton(DStyle::SP_DecreaseElement, this); - iconBtnD->setFixedSize(QSize(20,20)); - iconBtnD->setFlat(true); - - listlayout->addWidget(d->listView); - listlayout->addWidget(separator); - - auto btnlayout = new QHBoxLayout; - btnlayout->addWidget(iconBtnI); - btnlayout->addWidget(iconBtnD); - btnlayout->setAlignment(Qt::AlignLeft); - - listlayout->addLayout(btnlayout); - - d->listModel = new QStringListModel(this); - d->listView->setModel(d->listModel); - d->listModel->setStringList(QStringList() << tr("Desktop")); - - //rightSide - d->cbCXXComplier = new DComboBox(this); - - d->nameEidt = new DLineEdit(this); - d->nameEidt->setText(tr("Desktop")); - d->nameEidt->setEnabled(false); - - d->cbCMake = new DComboBox(this); - - auto labelCMake = new DLabel(this); - labelCMake->setText(tr("CMake Tool:")); - - d->cbCComplier = new DComboBox(this); - - d->cbDebugger = new DComboBox(this); - - auto labelGenerator = new DLabel(this); - labelGenerator->setText(tr("CMake generator:")); - d->cbGenerator = new DComboBox(this); - d->cbGenerator->insertItem(0, "CodeBlocks - Unix Makefiles"); - d->cbGenerator->setEnabled(false); - - auto labelDebugger = new DLabel(this); - labelDebugger->setText(tr("Debugger:")); - - d->labelGeneratorExpression = new DLabel(this); - d->labelGeneratorExpression->setText(QString()); - - auto Name = new DLabel(this); - Name->setText(tr("Name:")); - - auto labelCCompiler = new DLabel(this); - labelCCompiler->setText(tr("C Compiler:")); - - auto labelCXXCompiler = new DLabel(this); - labelCXXCompiler->setText(tr("C++ Compiler:")); - - auto formlayout = new QFormLayout; - formlayout->addRow(Name, d->nameEidt); - formlayout->addRow(labelCCompiler, d->cbCComplier); - formlayout->addRow(labelCXXCompiler, d->cbCXXComplier); - formlayout->addRow(labelDebugger, d->cbDebugger); - formlayout->addRow(labelCMake, d->cbCMake); - formlayout->addRow(labelGenerator, d->cbGenerator); - //formlayout->setContentsMargins(0, 0, 10, 0); - - centerLayout->addWidget(listFrame); - centerLayout->addSpacing(10); - centerLayout->addLayout(formlayout); - - setLayout(centerLayout); -} - -void KitsManagerWidget::updateUi() -{ - const ToolChainData::ToolChains &data = d->toolChainData->getToolChanins(); - - // Update compiler combox. - auto updateComplier = [](DComboBox *cb, ToolChainData::Params ¶ms) { - int i = 0; - for (auto p : params) { - QString text = p.name + "(" + p.path + ")"; - cb->insertItem(i, text); - cb->setItemData(i, QVariant::fromValue(p), Qt::UserRole + 1); - i++; - } - }; - - ToolChainData::Params cParams = data.value(kCCompilers); - updateComplier(d->cbCComplier, cParams); - - ToolChainData::Params cxxParams = data.value(kCXXCompilers); - updateComplier(d->cbCXXComplier, cxxParams); - - // Update Debugger combox. - ToolChainData::Params debugger = data.value(kCCXXDebuggers); - updateComplier(d->cbDebugger, debugger); - - // Update CMake combox. - ToolChainData::Params cmake = data.value(kCCXXBuildSystems); - updateComplier(d->cbCMake, cmake); -} - -bool KitsManagerWidget::getControlValue(QMap &map) -{ - KitConfig config; - config.name = d->nameEidt->text(); - - auto comboBoxValue = [](DComboBox *cb) { - int index = cb->currentIndex(); - if (index > -1) { - return qvariant_cast(cb->itemData(index, Qt::UserRole + 1)); - } else { - return ToolChainData::ToolChainParam(); - } - }; - - config.ccompiler = comboBoxValue(d->cbCComplier); - config.cppcompiler = comboBoxValue(d->cbCXXComplier); - config.debugger = comboBoxValue(d->cbDebugger); - config.cmake = comboBoxValue(d->cbCMake); - config.cmakeGenerator = d->labelGeneratorExpression->text(); - - dataToMap(config, map); - - return true; -} - -void KitsManagerWidget::setControlValue(const QMap &map) -{ - KitConfig config; - mapToData(map, config); - - auto updateComplier = [](DComboBox *cb, ToolChainData::ToolChainParam ¶ms) { - for (int i = 0; i < cb->count(); i++) { - ToolChainData::ToolChainParam data = qvariant_cast(cb->itemData(i, Qt::UserRole + 1)); - if (data.name == params.name && data.path == params.path) { - cb->setCurrentIndex(i); - return; - } - } - }; - - updateComplier(d->cbCComplier, config.ccompiler); - updateComplier(d->cbCXXComplier, config.cppcompiler); - updateComplier(d->cbDebugger, config.debugger); - updateComplier(d->cbCMake, config.cmake); - - //d->labelGeneratorExpression->setText(config.cmakeGenerator); -} - -bool KitsManagerWidget::dataToMap(const KitConfig &config, QMap &map) -{ - auto updateComplier = [](QMap &map, const QString key, const ToolChainData::ToolChainParam ¶ms) { - QMap version; - version.insert("name", params.name); - version.insert("path", params.path); - map.insert(key, version); - }; - - updateComplier(map, "ccompiler", config.ccompiler); - updateComplier(map, "cppcompiler", config.cppcompiler); - updateComplier(map, "debugger", config.debugger); - updateComplier(map, "cmake", config.cmake); - - map.insert("name", config.name); - map.insert("cmakeGenerator", config.cmakeGenerator); - - return true; -} - -bool KitsManagerWidget::mapToData(const QMap &map, KitConfig &config) -{ - auto updateComplier = [](const QMap &map, const QString key, ToolChainData::ToolChainParam ¶ms) { - QMap version = map.value(key).toMap(); - params.name = version.value("name").toString(); - params.path = version.value("path").toString(); - }; - - updateComplier(map, "ccompiler", config.ccompiler); - updateComplier(map, "cppcompiler", config.cppcompiler); - updateComplier(map, "debugger", config.debugger); - updateComplier(map, "cmake", config.cmake); - - config.name = map.value("name").toString(); - config.cmakeGenerator = map.value("cmakeGenerator").toString(); - - return true; -} - -void KitsManagerWidget::setUserConfig(const QMap &map) -{ - setControlValue(map); -} - -void KitsManagerWidget::getUserConfig(QMap &map) -{ - getControlValue(map); -} diff --git a/src/plugins/cxx/cmake/option/kitsmanagerwidget.h b/src/plugins/cxx/cmake/option/kitsmanagerwidget.h deleted file mode 100644 index 4b762cd8e..000000000 --- a/src/plugins/cxx/cmake/option/kitsmanagerwidget.h +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef KITSMANAGERWIDGET_H -#define KITSMANAGERWIDGET_H - -#include "services/option/toolchaindata.h" -#include "common/widget/pagewidget.h" - -struct KitConfig{ - QString name; - ToolChainData::ToolChainParam ccompiler; - ToolChainData::ToolChainParam cppcompiler; - ToolChainData::ToolChainParam debugger; - ToolChainData::ToolChainParam cmake; - QString cmakeGenerator; -}; - -class KitsManagerWidgetPrivate; -class KitsManagerWidget : public PageWidget -{ - Q_OBJECT -public: - explicit KitsManagerWidget(QWidget *parent = nullptr); - ~KitsManagerWidget() override; - - void setUserConfig(const QMap &map) override; - void getUserConfig(QMap &map) override; - -signals: - -public slots: - -private: - void setupUi(); - void updateUi(); - - bool dataToMap(const KitConfig &config, QMap &map); - bool mapToData(const QMap &map, KitConfig &config); - - bool getControlValue(QMap &map); - void setControlValue(const QMap &map); - - KitsManagerWidgetPrivate *const d; -}; - -#endif // KITSMANAGERWIDGET_H diff --git a/src/plugins/cxx/cmake/option/optioncmakegenerator.cpp b/src/plugins/cxx/cmake/option/optioncmakegenerator.cpp deleted file mode 100644 index 442f5a9ae..000000000 --- a/src/plugins/cxx/cmake/option/optioncmakegenerator.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "optioncmakegenerator.h" -#include "cmakeoptionwidget.h" - -class OptionCmakeGeneratorPrivate -{ - friend class OptionCmakeGenerator; - - CMakeOptionWidget *widget = nullptr; -}; - -OptionCmakeGenerator::OptionCmakeGenerator() - : d(new OptionCmakeGeneratorPrivate()) -{ - d->widget = new CMakeOptionWidget(); -} - -OptionCmakeGenerator::~OptionCmakeGenerator() -{ - delete d; -} - -QWidget *OptionCmakeGenerator::optionWidget() -{ - return d->widget; -} diff --git a/src/plugins/cxx/cmake/option/optioncmakegenerator.h b/src/plugins/cxx/cmake/option/optioncmakegenerator.h deleted file mode 100644 index bf0485702..000000000 --- a/src/plugins/cxx/cmake/option/optioncmakegenerator.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef OPTIONCMAKEGENERATOR_H -#define OPTIONCMAKEGENERATOR_H - -#include "services/option/optiongenerator.h" - -class OptionCmakeGeneratorPrivate; -class OptionCmakeGenerator : public dpfservice::OptionGenerator -{ -public: - explicit OptionCmakeGenerator(); - ~OptionCmakeGenerator() override; - - inline static QString kitName() {return "CMake";} - virtual QWidget *optionWidget() override; - -private: - OptionCmakeGeneratorPrivate *const d; -}; - -#endif // OPTIONCMAKEGENERATOR_H diff --git a/src/plugins/cxx/cmake/option/optioncmaketabwidget.cpp b/src/plugins/cxx/cmake/option/optioncmaketabwidget.cpp deleted file mode 100644 index 61b17e1c8..000000000 --- a/src/plugins/cxx/cmake/option/optioncmaketabwidget.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "optioncmaketabwidget.h" - - -OptionCmakeTabWidget::OptionCmakeTabWidget(QWidget *parent) - : QTabWidget (parent) -{ - -} diff --git a/src/plugins/cxx/cmake/option/optioncmaketabwidget.h b/src/plugins/cxx/cmake/option/optioncmaketabwidget.h deleted file mode 100644 index 8e5632f81..000000000 --- a/src/plugins/cxx/cmake/option/optioncmaketabwidget.h +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef OPTIONCMAKETABWIDGET_H -#define OPTIONCMAKETABWIDGET_H - -#include - -class OptionCmakeTabWidget : public QTabWidget -{ - Q_OBJECT -public: - explicit OptionCmakeTabWidget(QWidget *parent = nullptr); -}; - -#endif // OPTIONCMAKETABWIDGET_H diff --git a/src/plugins/cxx/cmake/option/persistentsettings.cpp b/src/plugins/cxx/cmake/option/persistentsettings.cpp deleted file mode 100644 index f712f0e0f..000000000 --- a/src/plugins/cxx/cmake/option/persistentsettings.cpp +++ /dev/null @@ -1,387 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "persistentsettings.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef QT_GUI_LIB -#include -#endif - -#include "common/util/qtcassert.h" - - -struct Context // Basic context containing element name string constants. -{ - Context() {} - const QString qtCreatorElement = QString("qtcreator"); - const QString dataElement = QString("data"); - const QString variableElement = QString("variable"); - const QString typeAttribute = QString("type"); - const QString valueElement = QString("value"); - const QString valueListElement = QString("valuelist"); - const QString valueMapElement = QString("valuemap"); - const QString keyAttribute = QString("key"); -}; - -struct ParseValueStackEntry -{ - explicit ParseValueStackEntry(QVariant::Type t = QVariant::Invalid, const QString &k = QString()) : type(t), key(k) {} - explicit ParseValueStackEntry(const QVariant &aSimpleValue, const QString &k); - - QVariant value() const; - void addChild(const QString &key, const QVariant &v); - - QVariant::Type type; - QString key; - QVariant simpleValue; - QVariantList listValue; - QVariantMap mapValue; -}; - -ParseValueStackEntry::ParseValueStackEntry(const QVariant &aSimpleValue, const QString &k) : - type(aSimpleValue.type()), key(k), simpleValue(aSimpleValue) -{ - QTC_ASSERT(simpleValue.isValid(), return); -} - -QVariant ParseValueStackEntry::value() const -{ - switch (type) { - case QVariant::Invalid: - return QVariant(); - case QVariant::Map: - return QVariant(mapValue); - case QVariant::List: - return QVariant(listValue); - default: - break; - } - return simpleValue; -} - -void ParseValueStackEntry::addChild(const QString &key, const QVariant &v) -{ - switch (type) { - case QVariant::Map: - mapValue.insert(key, v); - break; - case QVariant::List: - listValue.push_back(v); - break; - default: - qWarning() << "ParseValueStackEntry::Internal error adding " << key << v << " to " - << QVariant::typeToName(type) << value(); - break; - } -} - -class ParseContext : public Context -{ -public: - QVariantMap parse(QFile &file); - -private: - enum Element { QtCreatorElement, DataElement, VariableElement, - SimpleValueElement, ListValueElement, MapValueElement, UnknownElement }; - - Element element(const QStringRef &r) const; - static inline bool isValueElement(Element e) - { return e == SimpleValueElement || e == ListValueElement || e == MapValueElement; } - QVariant readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const; - - bool handleStartElement(QXmlStreamReader &r); - bool handleEndElement(const QStringRef &name); - - static QString formatWarning(const QXmlStreamReader &r, const QString &message); - - QStack m_valueStack; - QVariantMap m_result; - QString m_currentVariableName; -}; - -QVariantMap ParseContext::parse(QFile &file) -{ - QXmlStreamReader r(&file); - - m_result.clear(); - m_currentVariableName.clear(); - - while (!r.atEnd()) { - switch (r.readNext()) { - case QXmlStreamReader::StartElement: - if (handleStartElement(r)) - return m_result; - break; - case QXmlStreamReader::EndElement: - if (handleEndElement(r.name())) - return m_result; - break; - case QXmlStreamReader::Invalid: - qWarning("Error reading %s:%d: %s", qPrintable(file.fileName()), - int(r.lineNumber()), qPrintable(r.errorString())); - return QVariantMap(); - default: - break; - } // switch token - } // while (!r.atEnd()) - return m_result; -} - -bool ParseContext::handleStartElement(QXmlStreamReader &r) -{ - const QStringRef name = r.name(); - const Element e = element(name); - if (e == VariableElement) { - m_currentVariableName = r.readElementText(); - return false; - } - if (!ParseContext::isValueElement(e)) - return false; - - const QXmlStreamAttributes attributes = r.attributes(); - const QString key = attributes.hasAttribute(keyAttribute) ? - attributes.value(keyAttribute).toString() : QString(); - switch (e) { - case SimpleValueElement: { - // This reads away the end element, so, handle end element right here. - const QVariant v = readSimpleValue(r, attributes); - if (!v.isValid()) { - qWarning() << ParseContext::formatWarning(r, QString::fromLatin1("Failed to read element \"%1\".").arg(name.toString())); - return false; - } - m_valueStack.push_back(ParseValueStackEntry(v, key)); - return handleEndElement(name); - } - case ListValueElement: - m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key)); - break; - case MapValueElement: - m_valueStack.push_back(ParseValueStackEntry(QVariant::Map, key)); - break; - default: - break; - } - return false; -} - -bool ParseContext::handleEndElement(const QStringRef &name) -{ - const Element e = element(name); - if (ParseContext::isValueElement(e)) { - QTC_ASSERT(!m_valueStack.isEmpty(), return true); - const ParseValueStackEntry top = m_valueStack.pop(); - if (m_valueStack.isEmpty()) { - QTC_ASSERT(!m_currentVariableName.isEmpty(), return true); - m_result.insert(m_currentVariableName, top.value()); - m_currentVariableName.clear(); - return false; - } - m_valueStack.top().addChild(top.key, top.value()); - } - return e == QtCreatorElement; -} - -QString ParseContext::formatWarning(const QXmlStreamReader &r, const QString &message) -{ - QString result = QLatin1String("Warning reading "); - if (const QIODevice *device = r.device()) - if (const auto file = qobject_cast(device)) - result += QDir::toNativeSeparators(file->fileName()) + QLatin1Char(':'); - result += QString::number(r.lineNumber()); - result += QLatin1String(": "); - result += message; - return result; -} - -ParseContext::Element ParseContext::element(const QStringRef &r) const -{ - if (r == valueElement) - return SimpleValueElement; - if (r == valueListElement) - return ListValueElement; - if (r == valueMapElement) - return MapValueElement; - if (r == qtCreatorElement) - return QtCreatorElement; - if (r == dataElement) - return DataElement; - if (r == variableElement) - return VariableElement; - return UnknownElement; -} - -QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const -{ - // Simple value - const QStringRef type = attributes.value(typeAttribute); - const QString text = r.readElementText(); - if (type == QLatin1String("QChar")) { - QTC_ASSERT(text.size() == 1, return QVariant()); - return QVariant(QChar(text.at(0))); - } - QVariant value; - value.setValue(text); - value.convert(QMetaType::type(type.toLatin1().data())); - return value; -} - -// =================================== PersistentSettingsReader - -PersistentSettingsReader::PersistentSettingsReader() = default; - -QVariant PersistentSettingsReader::restoreValue(const QString &variable, const QVariant &defaultValue) const -{ - if (valueMap.contains(variable)) - return valueMap.value(variable); - return defaultValue; -} - -QVariantMap PersistentSettingsReader::restoreValues() const -{ - return valueMap; -} - -bool PersistentSettingsReader::load(const QString &fileName) -{ - valueMap.clear(); - - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) - return false; - ParseContext ctx; - valueMap = ctx.parse(file); - file.close(); - return true; -} - -static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx, - const QVariant &variant, const QString &key = QString()) -{ - switch (static_cast(variant.type())) { - case static_cast(QVariant::StringList): - case static_cast(QVariant::List): - w.writeStartElement(ctx.valueListElement); - w.writeAttribute(ctx.typeAttribute, QLatin1String(QVariant::typeToName(QVariant::List))); - if (!key.isEmpty()) - w.writeAttribute(ctx.keyAttribute, key); - foreach (const QVariant &var, variant.toList()) - writeVariantValue(w, ctx, var); - w.writeEndElement(); - break; - case static_cast(QVariant::Map): { - w.writeStartElement(ctx.valueMapElement); - w.writeAttribute(ctx.typeAttribute, QLatin1String(QVariant::typeToName(QVariant::Map))); - if (!key.isEmpty()) - w.writeAttribute(ctx.keyAttribute, key); - const QVariantMap varMap = variant.toMap(); - const QVariantMap::const_iterator cend = varMap.constEnd(); - for (QVariantMap::const_iterator i = varMap.constBegin(); i != cend; ++i) - writeVariantValue(w, ctx, i.value(), i.key()); - w.writeEndElement(); - } - break; - case static_cast(QMetaType::QObjectStar): // ignore QObjects! - case static_cast(QMetaType::VoidStar): // ignore void pointers! - break; - default: - w.writeStartElement(ctx.valueElement); - w.writeAttribute(ctx.typeAttribute, QLatin1String(variant.typeName())); - if (!key.isEmpty()) { - w.writeAttribute(ctx.keyAttribute, key); - w.writeCharacters(variant.toString()); - } - w.writeEndElement(); - break; - } -} - -PersistentSettingsWriter::PersistentSettingsWriter(const QString &_fileName, const QString &_docType) : - fileName(_fileName), docType(_docType) -{ } - -PersistentSettingsWriter::~PersistentSettingsWriter() -{ - write(savedData, nullptr); -} - -bool PersistentSettingsWriter::save(const QVariantMap &data, QString *errorString) const -{ - if (data == savedData) - return true; - return write(data, errorString); -} - -#ifdef QT_GUI_LIB -bool PersistentSettingsWriter::save(const QVariantMap &data, QWidget *parent) const -{ - QString errorString; - const bool success = save(data, &errorString); - if (!success) - QMessageBox::critical(parent, - QCoreApplication::translate("Utils::FileSaverBase", "File Error"), - errorString); - return success; -} -#endif // QT_GUI_LIB - -QString PersistentSettingsWriter::getFileName() const -{ return fileName; } - -void PersistentSettingsWriter::setContents(const QVariantMap &data) -{ - savedData = data; -} - -bool PersistentSettingsWriter::write(const QVariantMap &data, QString *errorString) const -{ - QDir tmp; - tmp.mkpath(fileName); -// FileSaver saver(m_fileName, QIODevice::Text); - QFile file(fileName); - if (/*!saver.hasError()*/ file.open(QIODevice::WriteOnly | QIODevice::Text)) { - const Context ctx; - QXmlStreamWriter w(&file); - w.setAutoFormatting(true); - w.setAutoFormattingIndent(1); // Historical, used to be QDom. - w.writeStartDocument(); - w.writeDTD(QLatin1String("')); - w.writeComment(QString::fromLatin1(" Written by %1 %2, %3. "). - arg(QCoreApplication::applicationName(), - QCoreApplication::applicationVersion(), - QDateTime::currentDateTime().toString(Qt::ISODate))); - w.writeStartElement(ctx.qtCreatorElement); - const QVariantMap::const_iterator cend = data.constEnd(); - for (QVariantMap::const_iterator it = data.constBegin(); it != cend; ++it) { - w.writeStartElement(ctx.dataElement); - w.writeTextElement(ctx.variableElement, it.key()); - writeVariantValue(w, ctx, it.value()); - w.writeEndElement(); - } - w.writeEndDocument(); - -// saver.setResult(&w); - } - - bool ok = /*saver.finalize();*/file.flush(); - if (ok) { - savedData = data; - } else if (errorString) { - savedData.clear(); -// *errorString = saver.errorString(); - } - - return ok; -} diff --git a/src/plugins/cxx/cmake/option/persistentsettings.h b/src/plugins/cxx/cmake/option/persistentsettings.h deleted file mode 100644 index 017f5797c..000000000 --- a/src/plugins/cxx/cmake/option/persistentsettings.h +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef PERSISTENTSETTINGS_H -#define PERSISTENTSETTINGS_H - -#include -#include - -class PersistentSettingsReader -{ -public: - PersistentSettingsReader(); - QVariant restoreValue(const QString &variable, const QVariant &defaultValue = QVariant()) const; - QVariantMap restoreValues() const; - bool load(const QString &QString); - -private: - QMap valueMap; -}; - -class PersistentSettingsWriter -{ -public: - PersistentSettingsWriter(const QString &_fileName, const QString &_docType); - ~PersistentSettingsWriter(); - - bool save(const QVariantMap &data, QString *errorString) const; -#ifdef QT_GUI_LIB - bool save(const QVariantMap &data, QWidget *parent) const; -#endif - - QString getFileName() const; - - void setContents(const QVariantMap &data); - -private: - bool write(const QVariantMap &data, QString *errorString) const; - - const QString fileName; - const QString docType; - mutable QMap savedData; -}; - -#endif // PERSISTENTSETTINGS_H diff --git a/src/plugins/cxx/cmake/project/properties/configWidget/configureprojpane.cpp b/src/plugins/cxx/cmake/project/properties/configWidget/configureprojpane.cpp index c8edc98ca..799fadc85 100644 --- a/src/plugins/cxx/cmake/project/properties/configWidget/configureprojpane.cpp +++ b/src/plugins/cxx/cmake/project/properties/configWidget/configureprojpane.cpp @@ -7,7 +7,7 @@ #include "cmakeasynparse.h" #include "cmakeprojectgenerator.h" -#include "services/option/optionmanager.h" +#include "cmake/option/kitmanager.h" #include #include @@ -39,26 +39,25 @@ class ConfigureProjPanePrivate { friend class ConfigureProjPane; - DComboBox *kitComboBox{nullptr}; + DComboBox *kitComboBox { nullptr }; - DRadioButton *radioDebug{nullptr}; - DRadioButton *radioRelease{nullptr}; + DRadioButton *radioDebug { nullptr }; + DRadioButton *radioRelease { nullptr }; - DLineEdit *lineEditDebug{nullptr}; - DLineEdit *lineEditRelease{nullptr}; + DLineEdit *lineEditDebug { nullptr }; + DLineEdit *lineEditRelease { nullptr }; - DPushButton *btnRWithDInfo{nullptr}; + DPushButton *btnRWithDInfo { nullptr }; - QButtonGroup *group{nullptr}; + QButtonGroup *group { nullptr }; - ProjectConfigure *cfgItem{nullptr}; + ProjectConfigure *cfgItem { nullptr }; }; ConfigureProjPane::ConfigureProjPane(const QString &language, const QString &workspace, QWidget *parent) - : DWidget(parent) - , d(new ConfigureProjPanePrivate) + : DWidget(parent), d(new ConfigureProjPanePrivate) { d->cfgItem = ConfigUtil::instance()->getConfigureParamPointer(); d->cfgItem->clear(); @@ -70,12 +69,12 @@ ConfigureProjPane::ConfigureProjPane(const QString &language, connect(ConfigUtil::instance(), QOverload::of(&ConfigUtil::configureDone), [this](const dpfservice::ProjectInfo &info) { - QString propertyPath = ConfigUtil::instance()->getConfigPath(d->cfgItem->workspace); - config::ConfigUtil::instance()->saveConfig(propertyPath, *d->cfgItem); - dpfservice::ProjectInfo projectInfo = info; - config::ConfigUtil::instance()->updateProjectInfo(projectInfo, d->cfgItem); - emit configureDone(projectInfo); - }); + QString propertyPath = ConfigUtil::instance()->getConfigPath(d->cfgItem->workspace); + config::ConfigUtil::instance()->saveConfig(propertyPath, *d->cfgItem); + dpfservice::ProjectInfo projectInfo = info; + config::ConfigUtil::instance()->updateProjectInfo(projectInfo, d->cfgItem); + emit configureDone(projectInfo); + }); } ConfigureProjPane::~ConfigureProjPane() @@ -86,8 +85,8 @@ ConfigureProjPane::~ConfigureProjPane() void ConfigureProjPane::setupUI() { - auto btnSignalConnect = [this](DPushButton *btn, DLineEdit *lineEdit){ - connect(btn, &DPushButton::clicked, [=](){ + auto btnSignalConnect = [this](DPushButton *btn, DLineEdit *lineEdit) { + connect(btn, &DPushButton::clicked, [=]() { QString outputDirectory = DFileDialog::getExistingDirectory(this, "Output directory"); if (!outputDirectory.isEmpty()) { lineEdit->setText(outputDirectory); @@ -150,7 +149,10 @@ void ConfigureProjPane::updateUI() { resetUI(); - d->kitComboBox->addItem(kDefaultKitName); + const auto &kitList = KitManager::instance()->kitList(); + for (const auto &kit : kitList) { + d->kitComboBox->addItem(kit.kitName(), kit.id()); + } if (d->cfgItem->workspace.isEmpty()) return; @@ -170,7 +172,7 @@ void ConfigureProjPane::updateUI() void ConfigureProjPane::slotConfigure() { - QList initType = {Debug, Release}; + QList initType = { Debug, Release }; foreach (auto type, initType) { BuildTypeConfigure buildTypeConfigure; buildTypeConfigure.type = type; @@ -203,6 +205,7 @@ void ConfigureProjPane::slotConfigure() d->cfgItem->defaultType = ConfigUtil::instance()->getTypeFromName(d->group->checkedButton()->text()); d->cfgItem->tempSelType = d->cfgItem->defaultType; d->cfgItem->kit = d->kitComboBox->currentText(); + d->cfgItem->kitId = d->kitComboBox->currentData().toString(); ConfigUtil::instance()->configProject(d->cfgItem); } diff --git a/src/plugins/cxx/cmake/project/properties/configutil.cpp b/src/plugins/cxx/cmake/project/properties/configutil.cpp index d7e3856d7..1171405fe 100644 --- a/src/plugins/cxx/cmake/project/properties/configutil.cpp +++ b/src/plugins/cxx/cmake/project/properties/configutil.cpp @@ -6,8 +6,7 @@ #include "cmakeasynparse.h" #include "cmakeprojectgenerator.h" #include "targetsmanager.h" - -#include "services/option/optionmanager.h" +#include "cmake/option/kitmanager.h" #include #include @@ -83,12 +82,14 @@ dpfservice::ProjectInfo ConfigUtil::createProjectInfo(const ProjectConfigure *pa dpfservice::ProjectInfo info; for (auto iter = param->buildTypeConfigures.begin(); iter != param->buildTypeConfigures.end(); ++iter) { if (d->configureParam.tempSelType == iter->type) { + Kit kit = KitManager::instance()->findKit(param->kitId); + info.setLanguage(param->language); info.setKitName(CmakeProjectGenerator::toolKitName()); info.setWorkspaceFolder(param->workspace); info.setBuildType(ConfigUtil::instance()->getNameFromType(iter->type)); info.setBuildFolder(iter->directory); - info.setBuildProgram(OptionManager::getInstance()->getCMakeToolPath()); + info.setBuildProgram(kit.cmakeTool().path); QStringList configArguments; configArguments << "-S"; @@ -139,7 +140,7 @@ void ConfigUtil::checkConfigInfo(const QString &buildType, const QString &direct QString cfgFile = iter->directory + QDir::separator() + TargetsManager::instance()->getCMakeConfigFile(); if (!QFileInfo(cfgFile).isFile()) { // not config -// configProject(&d->configureParam); + // configProject(&d->configureParam); } } } @@ -178,12 +179,14 @@ bool ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ProjectC for (auto iter = param->buildTypeConfigures.begin(); iter != param->buildTypeConfigures.end(); ++iter) { if (d->configureParam.defaultType == iter->type) { + Kit kit = KitManager::instance()->findKit(param->kitId); + info.setLanguage(param->language); info.setKitName(CmakeProjectGenerator::toolKitName()); info.setWorkspaceFolder(param->workspace); info.setBuildType(ConfigUtil::instance()->getNameFromType(iter->type)); info.setBuildFolder(iter->directory); - info.setBuildProgram(OptionManager::getInstance()->getCMakeToolPath()); + info.setBuildProgram(kit.cmakeTool().path); QStringList arguments; arguments << "-S"; diff --git a/src/plugins/cxx/cmake/project/properties/configutil.h b/src/plugins/cxx/cmake/project/properties/configutil.h index 6786c3b55..283a6cd6a 100644 --- a/src/plugins/cxx/cmake/project/properties/configutil.h +++ b/src/plugins/cxx/cmake/project/properties/configutil.h @@ -25,7 +25,8 @@ enum StepType { StepCount }; -struct StepItem { +struct StepItem +{ StepType type = Build; QString activeTargetName; QStringList allTargetNames; @@ -54,18 +55,20 @@ struct StepItem { } }; -struct EnvironmentItem { +struct EnvironmentItem +{ bool enable = true; QMap environments; - EnvironmentItem() { + EnvironmentItem() + { initEnvironments(); } QStringList toList() const { QStringList envList; - for (auto it = environments.begin() ; it != environments.end() ; it++) { + for (auto it = environments.begin(); it != environments.end(); it++) { envList.append(it.key() + "=" + it.value()); } return envList; @@ -98,7 +101,8 @@ struct EnvironmentItem { } }; -struct TargetRunConfigure { +struct TargetRunConfigure +{ QString targetName; QString targetPath; QString arguments; @@ -131,7 +135,8 @@ struct TargetRunConfigure { } }; -struct RunConfigure { +struct RunConfigure +{ QString defaultTargetName; QVector targetsRunConfigure; @@ -152,7 +157,8 @@ struct RunConfigure { } }; -struct BuildConfigue { +struct BuildConfigue +{ EnvironmentItem env; QVector steps; @@ -173,7 +179,8 @@ struct BuildConfigue { } }; -struct BuildTypeConfigure { +struct BuildTypeConfigure +{ ConfigType type = Unknown; QString directory; BuildConfigue buildConfigure; @@ -203,17 +210,20 @@ struct BuildTypeConfigure { }; using BuildTypeConfigures = QVector; -struct ProjectConfigure { +struct ProjectConfigure +{ QString kit; + QString kitId; QString language; QString workspace; ConfigType defaultType = Unknown; ConfigType tempSelType = Unknown; - BuildTypeConfigures buildTypeConfigures; // debug、release e.g + BuildTypeConfigures buildTypeConfigures; // debug、release e.g friend QDataStream &operator<<(QDataStream &stream, const ProjectConfigure &data) { stream << data.kit; + stream << data.kitId; stream << data.language; stream << data.workspace; int type = data.defaultType; @@ -228,6 +238,7 @@ struct ProjectConfigure { friend QDataStream &operator>>(QDataStream &stream, ProjectConfigure &data) { stream >> data.kit; + stream >> data.kitId; stream >> data.language; stream >> data.workspace; int type = 0; @@ -252,7 +263,7 @@ struct ProjectConfigure { }; class ConfigUtilPrivate; -class ConfigUtil final: public QObject +class ConfigUtil final : public QObject { Q_OBJECT public: @@ -287,6 +298,6 @@ class ConfigUtil final: public QObject ConfigUtilPrivate *const d; }; -} //namespace config +} //namespace config -#endif // CONFIGUTIL_H +#endif // CONFIGUTIL_H diff --git a/src/plugins/cxx/cmake/settings/baseoption.h b/src/plugins/cxx/cmake/settings/baseoption.h new file mode 100644 index 000000000..8b116fee0 --- /dev/null +++ b/src/plugins/cxx/cmake/settings/baseoption.h @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef BASEOPTION_H +#define BASEOPTION_H + +#include + +class BaseOption +{ +public: + virtual QString titleName() const = 0; + virtual QString configName() const = 0; + virtual void setConfig(const QVariantMap &config) = 0; + virtual QVariantMap getConfig() const = 0; +}; + +#endif // BASEOPTION_H diff --git a/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.cpp b/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.cpp new file mode 100644 index 000000000..7f37a44de --- /dev/null +++ b/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.cpp @@ -0,0 +1,278 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "baseoptionwidgethelper.h" + +#include "base/baseitemdelegate.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +class BaseOptionWidgetHelperPrivate : public QObject +{ +public: + explicit BaseOptionWidgetHelperPrivate(BaseOptionWidgetHelper *qq); + + void initUI(); + void initConnection(); + + QWidget *createOptionInfoWidget(); + void updateItem(const QModelIndex &index); + void showInfoForItem(const QModelIndex &index); + void handleCurrentChanged(const QModelIndex &now, const QModelIndex &previous); + void handleRemoveItem(); + +public: + BaseOptionWidgetHelper *q; + + QStandardItemModel optionModel; + QTreeView *optionView { nullptr }; + DToolButton *addOptionBtn { nullptr }; + DToolButton *delOptionBtn { nullptr }; + + DLineEdit *optionNameEdit { nullptr }; + DLineEdit *optionBrowseEdit { nullptr }; + DSuggestButton *browseBtn { nullptr }; +}; + +BaseOptionWidgetHelperPrivate::BaseOptionWidgetHelperPrivate(BaseOptionWidgetHelper *qq) + : q(qq) +{ +} + +void BaseOptionWidgetHelperPrivate::initUI() +{ + QVBoxLayout *mainLayout = new QVBoxLayout(q); + mainLayout->setContentsMargins(0, 0, 0, 0); + + optionView = new QTreeView(q); + optionView->setAlternatingRowColors(true); + optionView->setEditTriggers(QTreeView::NoEditTriggers); + optionView->setFrameShape(QFrame::NoFrame); + optionView->setHeaderHidden(true); + optionView->setModel(&optionModel); + optionView->setItemDelegate(new BaseItemDelegate(optionView)); + + addOptionBtn = new DToolButton(q); + addOptionBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::SP_IncreaseElement)); + addOptionBtn->setIconSize({ 16, 16 }); + + delOptionBtn = new DToolButton(q); + delOptionBtn->setIconSize({ 16, 16 }); + delOptionBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::DStyle::SP_DecreaseElement)); + delOptionBtn->setEnabled(false); + + QHBoxLayout *btnLayout = new QHBoxLayout; + btnLayout->setContentsMargins(10, 0, 10, 0); + btnLayout->addWidget(addOptionBtn); + btnLayout->addWidget(delOptionBtn); + btnLayout->addStretch(1); + + DFrame *viewFrame = new DFrame(q); + QVBoxLayout *viewLayout = new QVBoxLayout(viewFrame); + viewLayout->setContentsMargins(0, 8, 0, 0); + viewLayout->setSpacing(0); + viewLayout->addWidget(optionView); + viewLayout->addWidget(new DHorizontalLine(q)); + viewLayout->addLayout(btnLayout); + + mainLayout->addWidget(viewFrame); + mainLayout->addWidget(createOptionInfoWidget()); +} + +void BaseOptionWidgetHelperPrivate::initConnection() +{ + connect(optionView->selectionModel(), &QItemSelectionModel::currentChanged, + this, &BaseOptionWidgetHelperPrivate::handleCurrentChanged); + connect(browseBtn, &DSuggestButton::clicked, this, [this] { + const auto &fileName = QFileDialog::getOpenFileName(q, BaseOptionWidgetHelper::tr("Choose Executable"), + QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + if (!fileName.isEmpty()) + optionBrowseEdit->setText(fileName); + }); + connect(addOptionBtn, &DToolButton::clicked, q, &BaseOptionWidgetHelper::requestAddOption); + connect(delOptionBtn, &DToolButton::clicked, this, &BaseOptionWidgetHelperPrivate::handleRemoveItem); +} + +QWidget *BaseOptionWidgetHelperPrivate::createOptionInfoWidget() +{ + QWidget *widget = new QWidget(q); + QFormLayout *formLayout = new QFormLayout(widget); + + optionNameEdit = new DLineEdit(q); + optionBrowseEdit = new DLineEdit(q); + browseBtn = new DSuggestButton(q); + browseBtn->setIconSize({ 16, 16 }); + browseBtn->setIcon(DStyle::standardIcon(q->style(), DStyle::SP_SelectElement)); + + QHBoxLayout *layout = new QHBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(optionBrowseEdit, 1); + layout->addWidget(browseBtn); + + formLayout->addRow(BaseOptionWidgetHelper::tr("Name:"), optionNameEdit); + formLayout->addRow(BaseOptionWidgetHelper::tr("Path:"), layout); + + return widget; +} + +void BaseOptionWidgetHelperPrivate::updateItem(const QModelIndex &index) +{ + auto item = optionModel.itemFromIndex(index); + if (!item || item->hasChildren() || !item->data(OptionTypeRole).isValid()) + return; + + if (item->data(OptionTypeRole).toInt() == Detected) + return; + + const auto &name = optionNameEdit->text(); + const auto &path = optionBrowseEdit->text(); + + QString displayText; + if (path.isEmpty()) + displayText = name; + else + displayText = QString("%1 (%2)").arg(name, path); + + item->setText(displayText); + item->setData(name, OptionNameRole); + item->setData(path, OptionPathRole); + q->checkAndSetItemValid(item); +} + +void BaseOptionWidgetHelperPrivate::showInfoForItem(const QModelIndex &index) +{ + auto item = optionModel.itemFromIndex(index); + if (!item || item->hasChildren() || !item->data(OptionTypeRole).isValid()) { + q->setState(false, true); + delOptionBtn->setEnabled(false); + return; + } + + bool isManualItem = item->data(OptionTypeRole).toInt() == Manual; + q->setState(isManualItem, false); + delOptionBtn->setEnabled(isManualItem); + q->checkAndSetItemValid(item); + + optionNameEdit->setText(item->data(OptionNameRole).toString()); + optionBrowseEdit->setText(item->data(OptionPathRole).toString()); +} + +void BaseOptionWidgetHelperPrivate::handleCurrentChanged(const QModelIndex &now, const QModelIndex &previous) +{ + updateItem(previous); + showInfoForItem(now); +} + +void BaseOptionWidgetHelperPrivate::handleRemoveItem() +{ + auto index = optionView->currentIndex(); + auto item = optionModel.itemFromIndex(index); + if (!item || !item->data(OptionTypeRole).isValid() + || item->data(OptionTypeRole).toInt() == Detected) + return; + + optionModel.removeRow(index.row(), index.parent()); +} + +BaseOptionWidgetHelper::BaseOptionWidgetHelper(QWidget *parent) + : QWidget(parent), + d(new BaseOptionWidgetHelperPrivate(this)) +{ + d->initUI(); + d->initConnection(); +} + +BaseOptionWidgetHelper::~BaseOptionWidgetHelper() +{ + delete d; +} + +void BaseOptionWidgetHelper::addItem(QStandardItem *item) +{ + d->optionModel.appendRow(item); +} + +void BaseOptionWidgetHelper::setAddButtonMenu(QMenu *menu) +{ + d->addOptionBtn->setMenu(menu); + d->addOptionBtn->setPopupMode(QToolButton::InstantPopup); +} + +void BaseOptionWidgetHelper::setState(bool enabled, bool clear) +{ + d->optionNameEdit->setEnabled(enabled); + d->optionBrowseEdit->setEnabled(enabled); + d->browseBtn->setEnabled(enabled); + + if (clear) { + d->optionNameEdit->clear(); + d->optionBrowseEdit->clear(); + } +} + +void BaseOptionWidgetHelper::checkAndSetItemValid(QStandardItem *item) +{ + const auto &path = item->data(OptionPathRole).toString(); + if (path.isEmpty()) { + item->setData(false, OptionValidRole); + item->setIcon(QIcon::fromTheme("error")); + item->setToolTip(BaseOptionWidgetHelper::tr("This toolchain is invalid")); + } else if (!item->data(OptionValidRole).toBool()) { + item->setData(true, OptionValidRole); + item->setIcon({}); + item->setToolTip(""); + } +} + +void BaseOptionWidgetHelper::applyCurrentOption() const +{ + auto index = d->optionView->currentIndex(); + d->updateItem(index); +} + +void BaseOptionWidgetHelper::clearItem(QStandardItem *item) +{ + while (item->hasChildren()) { + item->removeRow(0); + } +} + +void BaseOptionWidgetHelper::expandAll() +{ + d->optionView->expandAll(); +} + +void BaseOptionWidgetHelper::sort(Qt::SortOrder order) +{ + d->optionView->sortByColumn(0, order); +} + +QModelIndex BaseOptionWidgetHelper::indexFromItem(const QStandardItem *item) +{ + return d->optionModel.indexFromItem(item); +} + +void BaseOptionWidgetHelper::setCurrentIndex(const QModelIndex &index) +{ + d->optionView->setCurrentIndex(index); +} + +void BaseOptionWidgetHelper::hideEvent(QHideEvent *event) +{ + applyCurrentOption(); + QWidget::hideEvent(event); +} diff --git a/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.h b/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.h new file mode 100644 index 000000000..c6cda3dce --- /dev/null +++ b/src/plugins/cxx/cmake/settings/baseoptionwidgethelper.h @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef BASEOPTIONWIDGETHELPER_H +#define BASEOPTIONWIDGETHELPER_H + +#include "global_define.h" + +#include +#include +#include + +enum OptionRole { + OptionNameRole = Qt::UserRole + 1, + OptionPathRole, + OptionTypeRole, + OptionValidRole +}; + +enum OptionType { + Detected = 0, + Manual +}; + +class BaseOptionWidgetHelperPrivate; +class BaseOptionWidgetHelper : public QWidget +{ + Q_OBJECT +public: + explicit BaseOptionWidgetHelper(QWidget *parent = nullptr); + ~BaseOptionWidgetHelper(); + + virtual QPair> getOptions() const = 0; + + void addItem(QStandardItem *item); + void setAddButtonMenu(QMenu *menu); + void setState(bool enabled, bool clear); + void checkAndSetItemValid(QStandardItem *item); + void applyCurrentOption() const; + void clearItem(QStandardItem *item); + void expandAll(); + void sort(Qt::SortOrder order = Qt::AscendingOrder); + + QModelIndex indexFromItem(const QStandardItem *item); + void setCurrentIndex(const QModelIndex &index); + +Q_SIGNALS: + void requestAddOption(); + +protected: + void hideEvent(QHideEvent *event) override; + +private: + BaseOptionWidgetHelperPrivate *const d; +}; + +#endif // BASEOPTIONWIDGETHELPER_H diff --git a/src/plugins/cxx/cmake/settings/cmakesettingswidget.cpp b/src/plugins/cxx/cmake/settings/cmakesettingswidget.cpp new file mode 100644 index 000000000..f3132c5fd --- /dev/null +++ b/src/plugins/cxx/cmake/settings/cmakesettingswidget.cpp @@ -0,0 +1,160 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "cmakesettingswidget.h" +#include "kitoptionwidget.h" +#include "compileroptionwidget.h" +#include "debuggeroptionwidget.h" +#include "tooloptionwidget.h" + +#include "services/option/optionutils.h" +#include "services/option/optiondatastruct.h" +#include "services/option/optionmanager.h" + +#include + +#include +#include + +DWIDGET_USE_NAMESPACE + +QWidget *CMakeSettingsWidgetGenerator::optionWidget() +{ + return new CMakeSettingsWidget; +} + +class CMakeSettingsWidgetPrivate : public QObject +{ +public: + explicit CMakeSettingsWidgetPrivate(CMakeSettingsWidget *qq); + + void initUI(); + void initConnection(); + void initOptions(); + + void setButtonList(); + void handleSwitchWidget(QAbstractButton *btn); + +public: + CMakeSettingsWidget *q; + + DButtonBox *buttonBox { nullptr }; + QStackedWidget *stackedWidget { nullptr }; + + KitOptionWidget *kitOptWidget { nullptr }; + CompilerOptionWidget *compilerOptWidget { nullptr }; + DebuggerOptionWidget *debuggerOptWidget { nullptr }; + ToolOptionWidget *toolOptWidget { nullptr }; +}; + +CMakeSettingsWidgetPrivate::CMakeSettingsWidgetPrivate(CMakeSettingsWidget *qq) + : q(qq) +{ +} + +void CMakeSettingsWidgetPrivate::initUI() +{ + QVBoxLayout *mainLayout = new QVBoxLayout(q); + mainLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->setSpacing(15); + + buttonBox = new DButtonBox(q); + stackedWidget = new QStackedWidget(q); + + mainLayout->addWidget(buttonBox, 0, Qt::AlignTop | Qt::AlignHCenter); + mainLayout->addWidget(stackedWidget, 1); + + initOptions(); +} + +void CMakeSettingsWidgetPrivate::initConnection() +{ + connect(buttonBox, &DButtonBox::buttonClicked, this, &CMakeSettingsWidgetPrivate::handleSwitchWidget); +} + +void CMakeSettingsWidgetPrivate::initOptions() +{ + // add option widget + kitOptWidget = new KitOptionWidget(q); + compilerOptWidget = new CompilerOptionWidget(q); + debuggerOptWidget = new DebuggerOptionWidget(q); + toolOptWidget = new ToolOptionWidget(q); + + stackedWidget->addWidget(kitOptWidget); + stackedWidget->addWidget(compilerOptWidget); + stackedWidget->addWidget(debuggerOptWidget); + stackedWidget->addWidget(toolOptWidget); + + // add option button + setButtonList(); +} + +void CMakeSettingsWidgetPrivate::setButtonList() +{ + QList btnList; + for (int i = 0; i < stackedWidget->count(); ++i) { + auto option = dynamic_cast(stackedWidget->widget(i)); + Q_ASSERT(option); + + DButtonBoxButton *btn = new DButtonBoxButton(option->titleName(), q); + btn->setProperty(OptionID, i); + btnList << btn; + } + + if (!btnList.isEmpty()) { + buttonBox->setButtonList(btnList, true); + btnList.first()->setChecked(true); + } +} + +void CMakeSettingsWidgetPrivate::handleSwitchWidget(QAbstractButton *btn) +{ + auto id = btn->property(OptionID).toInt(); + stackedWidget->setCurrentIndex(id); +} + +CMakeSettingsWidget::CMakeSettingsWidget(QWidget *parent) + : PageWidget(parent), + d(new CMakeSettingsWidgetPrivate(this)) +{ + d->initUI(); + d->initConnection(); +} + +CMakeSettingsWidget::~CMakeSettingsWidget() +{ + delete d; +} + +void CMakeSettingsWidget::saveConfig() +{ + for (int i = 0; i < d->stackedWidget->count(); ++i) { + auto option = dynamic_cast(d->stackedWidget->widget(i)); + Q_ASSERT(option); + + const auto &map = option->getConfig(); + OptionUtils::writeJsonSection(OptionUtils::getJsonFilePath(), + option::CATEGORY_CMAKE, option->configName(), map); + OptionManager::getInstance()->updateData(); + } +} + +void CMakeSettingsWidget::readConfig() +{ + // Finally set kit configuration, make sure + // that all other configuration has been configured + for (int i = d->stackedWidget->count() - 1; i >= 0; --i) { + auto widget = d->stackedWidget->widget(i); + auto option = dynamic_cast(widget); + Q_ASSERT(option); + + QMap map; + OptionUtils::readJsonSection(OptionUtils::getJsonFilePath(), + option::CATEGORY_CMAKE, option->configName(), map); + option->setConfig(map); + auto optWidget = dynamic_cast(widget); + if (optWidget) + d->kitOptWidget->setOptions(optWidget->getOptions()); + } +} diff --git a/src/plugins/cxx/cmake/settings/cmakesettingswidget.h b/src/plugins/cxx/cmake/settings/cmakesettingswidget.h new file mode 100644 index 000000000..31cb342c7 --- /dev/null +++ b/src/plugins/cxx/cmake/settings/cmakesettingswidget.h @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef CMAKESETTINGSWIDGET_H +#define CMAKESETTINGSWIDGET_H + +#include "global_define.h" + +#include "common/widget/pagewidget.h" +#include "services/option/optiongenerator.h" + +class CMakeSettingsWidgetGenerator : public dpfservice::OptionGenerator +{ + Q_OBJECT +public: + explicit CMakeSettingsWidgetGenerator() = default; + + inline static QString kitName() { return CMakeKitName; } + virtual QWidget *optionWidget() override; +}; + +class CMakeSettingsWidgetPrivate; +class CMakeSettingsWidget : public PageWidget +{ + Q_OBJECT +public: + explicit CMakeSettingsWidget(QWidget *parent = nullptr); + ~CMakeSettingsWidget() override; + + virtual void saveConfig() override; + virtual void readConfig() override; + +private: + CMakeSettingsWidgetPrivate *const d; +}; + +#endif // CMAKESETTINGSWIDGET_H diff --git a/src/plugins/cxx/cmake/settings/compileroptionwidget.cpp b/src/plugins/cxx/cmake/settings/compileroptionwidget.cpp new file mode 100644 index 000000000..6f234e9e7 --- /dev/null +++ b/src/plugins/cxx/cmake/settings/compileroptionwidget.cpp @@ -0,0 +1,256 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "global_define.h" +#include "compileroptionwidget.h" + +#include "services/option/toolchaindata.h" + +#include +#include + +inline constexpr char Type[] { "type" }; + +class CompilerOptionWidgetPrivate : public QObject +{ +public: + enum CompilerType { + DetectedCCompiler = 0, + DetectedCXXCompiler, + ManualCCompiler, + ManualCXXCompiler + }; + + explicit CompilerOptionWidgetPrivate(CompilerOptionWidget *qq); + + void initCompilers(); + + QStandardItem *appendCompiler(const QString &name, const QString &path, CompilerType type); + void handleAddCompiler(CompilerType type); + +public: + CompilerOptionWidget *q; + + QStandardItem *detectedCItem { nullptr }; + QStandardItem *detectedCXXItem { nullptr }; + QStandardItem *manualCItem { nullptr }; + QStandardItem *manualCXXItem { nullptr }; +}; + +CompilerOptionWidgetPrivate::CompilerOptionWidgetPrivate(CompilerOptionWidget *qq) + : q(qq) +{ + QMenu *menu = new QMenu(q); + menu->addAction("C", this, std::bind(&CompilerOptionWidgetPrivate::handleAddCompiler, this, ManualCCompiler)); + menu->addAction("C++", this, std::bind(&CompilerOptionWidgetPrivate::handleAddCompiler, this, ManualCXXCompiler)); + q->setAddButtonMenu(menu); +} + +void CompilerOptionWidgetPrivate::initCompilers() +{ + QStandardItem *detectedItem = new QStandardItem(CompilerOptionWidget::tr("Auto-detected")); + detectedItem->appendRow(detectedCItem = new QStandardItem("C")); + detectedItem->appendRow(detectedCXXItem = new QStandardItem("C++")); + + QStandardItem *manualItem = new QStandardItem(CompilerOptionWidget::tr("Manual")); + manualItem->appendRow(manualCItem = new QStandardItem("C")); + manualItem->appendRow(manualCXXItem = new QStandardItem("C++")); + q->addItem(detectedItem); + q->addItem(manualItem); + + ToolChainData toolCD; + QString retMsg; + bool ret = toolCD.readToolChainData(retMsg); + if (!ret) { + qWarning() << retMsg; + return; + } + + const auto &data = toolCD.getToolChanins(); + ToolChainData::Params cParams = data.value(kCCompilers); + for (const auto ¶m : cParams) { + appendCompiler(param.name, param.path, DetectedCCompiler); + } + + ToolChainData::Params cxxParams = data.value(kCXXCompilers); + for (const auto ¶m : cxxParams) { + appendCompiler(param.name, param.path, DetectedCXXCompiler); + } +} + +QStandardItem *CompilerOptionWidgetPrivate::appendCompiler(const QString &name, const QString &path, CompilerType type) +{ + QString tmpName = name; + if (name.isEmpty()) + tmpName = type % 2 + ? CompilerOptionWidget::tr("New C++ Compiler") + : CompilerOptionWidget::tr("New C Compiler"); + + QStandardItem *item = new QStandardItem(Option::displayName(tmpName, path)); + item->setData(tmpName, OptionNameRole); + item->setData(path, OptionPathRole); + q->checkAndSetItemValid(item); + + switch (type) { + case DetectedCCompiler: + item->setData(Detected, OptionTypeRole); + detectedCItem->appendRow(item); + break; + case DetectedCXXCompiler: + item->setData(Detected, OptionTypeRole); + detectedCXXItem->appendRow(item); + break; + case ManualCCompiler: + item->setData(Manual, OptionTypeRole); + manualCItem->appendRow(item); + break; + case ManualCXXCompiler: + item->setData(Manual, OptionTypeRole); + manualCXXItem->appendRow(item); + break; + } + + return item; +} + +void CompilerOptionWidgetPrivate::handleAddCompiler(CompilerType type) +{ + QStandardItem *item { nullptr }; + switch (type) { + case ManualCCompiler: + item = appendCompiler(CompilerOptionWidget::tr("New C Compiler"), "", type); + break; + case ManualCXXCompiler: + item = appendCompiler(CompilerOptionWidget::tr("New C++ Compiler"), "", type); + break; + default: + break; + } + + if (item) { + auto index = q->indexFromItem(item); + q->setCurrentIndex(index); + } +} + +CompilerOptionWidget::CompilerOptionWidget(QWidget *parent) + : BaseOptionWidgetHelper(parent), + d(new CompilerOptionWidgetPrivate(this)) +{ + d->initCompilers(); +} + +CompilerOptionWidget::~CompilerOptionWidget() +{ + delete d; +} + +QPair > CompilerOptionWidget::getOptions() const +{ + QList