diff --git a/core/config.cpp b/core/config.cpp index 37d662f..af96462 100644 --- a/core/config.cpp +++ b/core/config.cpp @@ -1,169 +1,187 @@ /* This file is part of KDevelop Copyright 2017 Anton Anikin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" #include "debug.h" #include #include namespace Valgrind { class Config::CmdItem { public: CmdItem(ItemInt* item, const QString& cmdName) : CmdItem(static_cast(item), cmdName) { m_type = Int; } CmdItem(ItemBool* item, const QString& cmdName) : CmdItem(static_cast(item), cmdName) { m_type = Bool; } + CmdItem(ItemDouble* item, const QString& cmdName) + : CmdItem(static_cast(item), cmdName) + { + m_type = Double; + } + CmdItem(ItemString* item, const QString& cmdName) : CmdItem(static_cast(item), cmdName) { m_type = String; } ~CmdItem() = default; QString cmdArg() { QString value; switch (m_type) { case Int: value = QString::number(m_item->property().toInt()); break; case Bool: value = m_item->property().toBool() ? QStringLiteral("yes") : QStringLiteral("no"); break; + case Double: + value = QString::number(m_item->property().toDouble(), 'f', 1); + break; + case String: value = m_item->property().toString(); break; } return QStringLiteral("--%1=%2").arg(m_cmdName, value); } private: CmdItem(KConfigSkeletonItem* item, const QString& cmdName) : m_item(item) , m_cmdName(cmdName) { Q_ASSERT(item); Q_ASSERT(!cmdName.isEmpty()); } enum Type { Int, Bool, + Double, String }; KConfigSkeletonItem* m_item; QString m_cmdName; Type m_type; }; Config::Config(const QString& group) : m_group(group) { setCurrentGroup(group); addItemString(QStringLiteral("extraArgs"), m_extraArgs); } Config::~Config() { qDeleteAll(m_cmdItems); } inline void addParent(QString& fullName, const KConfigGroup& parent) { fullName = parent.name() + QLatin1Char('\x1d') + fullName; } // TODO create patch for KCoreConfigSkeleton::setCurrentGroup(const KConfigGroup& group) overload ? void Config::setConfigGroup(const KConfigGroup& group) { setSharedConfig(KSharedConfig::openConfig(group.config()->name(), group.config()->openFlags())); QString fullName(m_group); addParent(fullName, group); KConfigGroup parentGroup = group.parent(); while (parentGroup.isValid() && parentGroup.name() != QStringLiteral("")) { addParent(fullName, parentGroup); parentGroup = parentGroup.parent(); } setCurrentGroup(fullName); const auto allItems = items(); for (auto item : allItems) { item->setGroup(fullName); } } QStringList Config::cmdArgs() { QStringList args; for (auto cmdItem : qAsConst(m_cmdItems)) { args += cmdItem->cmdArg(); } args += KShell::splitArgs(m_extraArgs); args.removeAll(QStringLiteral("")); return args; } Config::ItemInt* Config::addCmdItemInt(const QString& name, int& reference, int defaultValue, const QString& cmdName) { auto item = addItemInt(name, reference, defaultValue); m_cmdItems += new CmdItem(item, cmdName); return item; } Config::ItemBool* Config::addCmdItemBool(const QString& name, bool& reference, bool defaultValue, const QString& cmdName) { auto item = addItemBool(name, reference, defaultValue); m_cmdItems += new CmdItem(item, cmdName); return item; } +Config::ItemDouble* Config::addCmdItemDouble(const QString& name, double& reference, double defaultValue, const QString& cmdName) +{ + auto item = addItemDouble(name, reference, defaultValue); + m_cmdItems += new CmdItem(item, cmdName); + return item; +} + Config::ItemString* Config::addCmdItemString(const QString& name, QString& reference, const QString& defaultValue, const QString& cmdName) { auto item = addItemString(name, reference, defaultValue); m_cmdItems += new CmdItem(item, cmdName); return item; } } diff --git a/core/config.h b/core/config.h index 4fb86db..742f778 100644 --- a/core/config.h +++ b/core/config.h @@ -1,53 +1,54 @@ /* This file is part of KDevelop Copyright 2017 Anton Anikin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once #include namespace Valgrind { class Config : public KConfigSkeleton { Q_OBJECT public: ~Config() override; void setConfigGroup(const KConfigGroup& group); ItemInt* addCmdItemInt(const QString& name, int& reference, int defaultValue, const QString& cmdName); ItemBool* addCmdItemBool(const QString& name, bool& reference, bool defaultValue, const QString& cmdName); + ItemDouble* addCmdItemDouble(const QString& name, double& reference, double defaultValue, const QString& cmdName); ItemString* addCmdItemString(const QString& name, QString& reference, const QString& defaultValue, const QString& cmdName); QStringList cmdArgs(); protected: explicit Config(const QString& group); private: QString m_group; QString m_extraArgs; class CmdItem; QList m_cmdItems; }; }