diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp index fb365242ab9..8b65275b2df 100644 --- a/src/libs/utils/macroexpander.cpp +++ b/src/libs/utils/macroexpander.cpp @@ -63,6 +63,13 @@ public: return expander && expander->resolveMacro(name, ret); }); + if (found) + return true; + + found = Utils::anyOf(m_extraResolvers, [name, ret] (const MacroExpander::ResolverFunction &resolver) { + return resolver(name, ret); + }); + if (found) return true; @@ -94,6 +101,7 @@ public: QHash m_map; QHash m_prefixMap; + QVector m_extraResolvers; QMap m_descriptions; QString m_displayName; QVector m_subProviders; @@ -343,6 +351,11 @@ void MacroExpander::registerFileVariables(const QByteArray &prefix, [base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).baseName(); }); } +void MacroExpander::registerExtraResolver(const MacroExpander::ResolverFunction &value) +{ + d->m_extraResolvers.append(value); +} + /*! * Returns all registered variable names. * diff --git a/src/libs/utils/macroexpander.h b/src/libs/utils/macroexpander.h index 5e8dec9e01b..6c6007f4ffb 100644 --- a/src/libs/utils/macroexpander.h +++ b/src/libs/utils/macroexpander.h @@ -57,7 +57,7 @@ public: virtual bool resolveMacro(const QString &name, QString *ret) const; - QString value(const QByteArray &variable, bool *found = 0) const; + virtual QString value(const QByteArray &variable, bool *found = 0) const; QString expand(const QString &stringWithVariables) const; QByteArray expand(const QByteArray &stringWithVariables) const; @@ -65,6 +65,7 @@ public: QString expandProcessArgs(const QString &argsWithVariables) const; typedef std::function PrefixFunction; + typedef std::function ResolverFunction; typedef std::function StringFunction; typedef std::function IntFunction; @@ -80,6 +81,8 @@ public: void registerFileVariables(const QByteArray &prefix, const QString &heading, const StringFunction &value); + void registerExtraResolver(const ResolverFunction &value); + QList variables() const; QString variableDescription(const QByteArray &variable) const; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index 82ca0f8d3d6..23a899ba7d8 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -31,7 +31,6 @@ #include "jsonfieldpage.h" #include "jsonwizard.h" -#include "jsonwizardexpander.h" #include "jsonwizardfactory.h" #include diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index 32d7ff32b49..cfd78667900 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -30,7 +30,6 @@ #include "jsonwizard.h" -#include "jsonwizardexpander.h" #include "jsonwizardgeneratorfactory.h" #include @@ -43,14 +42,19 @@ namespace ProjectExplorer { JsonWizard::JsonWizard(QWidget *parent) : - Utils::Wizard(parent), - m_expander(new Internal::JsonWizardExpander(this)) -{ } + Utils::Wizard(parent) +{ + m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool { + QVariant v = value(name); + if (v.isValid()) + *ret = v.toString(); + return v.isValid(); + }); +} JsonWizard::~JsonWizard() { qDeleteAll(m_generators); - delete m_expander; } void JsonWizard::addGenerator(JsonWizardGenerator *gen) @@ -61,9 +65,9 @@ void JsonWizard::addGenerator(JsonWizardGenerator *gen) m_generators.append(gen); } -Utils::MacroExpander *JsonWizard::expander() const +Utils::MacroExpander *JsonWizard::expander() { - return m_expander; + return &m_expander; } void JsonWizard::resetFileList() @@ -85,7 +89,7 @@ JsonWizard::GeneratorFiles JsonWizard::fileList() if (m_files.isEmpty()) { emit preGenerateFiles(); foreach (JsonWizardGenerator *gen, m_generators) { - Core::GeneratedFiles tmp = gen->fileList(m_expander, value(QStringLiteral("WizardDir")).toString(), + Core::GeneratedFiles tmp = gen->fileList(&m_expander, value(QStringLiteral("WizardDir")).toString(), targetPath, &errorMessage); if (!errorMessage.isEmpty()) break; @@ -114,7 +118,7 @@ QVariant JsonWizard::value(const QString &n) const QVariant v = property(n.toUtf8()); if (v.isValid()) { if (v.type() == QVariant::String) - return m_expander->expand(v.toString()); + return m_expander.expand(v.toString()); else return v; } diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h index 2b30d9182af..210c9b4a722 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h @@ -36,13 +36,10 @@ #include #include - -namespace Utils { class MacroExpander; } +#include namespace ProjectExplorer { -namespace Internal { class JsonWizardExpander; } - class JsonWizardGenerator; // Documentation inside. @@ -71,7 +68,7 @@ public: void addGenerator(JsonWizardGenerator *gen); - Utils::MacroExpander *expander() const; + Utils::MacroExpander *expander(); void resetFileList(); GeneratorFiles fileList(); @@ -100,7 +97,7 @@ private: QList m_generators; GeneratorFiles m_files; - Internal::JsonWizardExpander *m_expander; + Utils::MacroExpander m_expander; }; } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri index 40d0f6a2a6d..8e8346e54ff 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri @@ -2,7 +2,6 @@ HEADERS += $$PWD/jsonfieldpage.h \ $$PWD/jsonfilepage.h \ $$PWD/jsonsummarypage.h \ $$PWD/jsonwizard.h \ - $$PWD/jsonwizardexpander.h \ $$PWD/jsonwizardfactory.h \ $$PWD/jsonwizardfilegenerator.h \ $$PWD/jsonwizardgeneratorfactory.h \ @@ -13,7 +12,6 @@ SOURCES += $$PWD/jsonfieldpage.cpp \ $$PWD/jsonfilepage.cpp \ $$PWD/jsonsummarypage.cpp \ $$PWD/jsonwizard.cpp \ - $$PWD/jsonwizardexpander.cpp \ $$PWD/jsonwizardfactory.cpp \ $$PWD/jsonwizardfilegenerator.cpp \ $$PWD/jsonwizardgeneratorfactory.cpp \ diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp deleted file mode 100644 index fcbe68b2a43..00000000000 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "jsonwizardexpander.h" - -#include "jsonwizard.h" - -#include -#include - -#include - -namespace ProjectExplorer { -namespace Internal { - -// -------------------------------------------------------------------- -// JsonWizardExpander: -// -------------------------------------------------------------------- - -JsonWizardExpander::JsonWizardExpander(JsonWizard *wizard) : - m_wizard(wizard) -{ - QTC_CHECK(m_wizard); -} - -bool JsonWizardExpander::resolveMacro(const QString &name, QString *ret) const -{ - QVariant v = m_wizard->value(name); - if (v.isValid()) { - *ret = v.toString(); - return true; - } - - return Utils::globalMacroExpander()->resolveMacro(name, ret); -} - -} // namespace Internal -} // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.h deleted file mode 100644 index 1a84643354d..00000000000 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://www.qt.io/licensing. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef JSONWIZARDEXPANDER_H -#define JSONWIZARDEXPANDER_H - -#include - -namespace ProjectExplorer { - -class JsonWizard; - -namespace Internal { - -// Documentation inside. -class JsonWizardExpander : public Utils::MacroExpander -{ -public: - explicit JsonWizardExpander(JsonWizard *wizard); - - bool resolveMacro(const QString &name, QString *ret) const; - -public: - JsonWizard *m_wizard; -}; - -} // namespace Internal -} // namespace ProjectExplorer - -#endif // JSONWIZARDEXPANDER_H diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index a9547898430..9115e7e5d4f 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -174,7 +174,6 @@ QtcPlugin { "jsonfilepage.cpp", "jsonfilepage.h", "jsonsummarypage.cpp", "jsonsummarypage.h", "jsonwizard.cpp", "jsonwizard.h", - "jsonwizardexpander.cpp", "jsonwizardexpander.h", "jsonwizardfactory.cpp", "jsonwizardfactory.h", "jsonwizardfilegenerator.cpp", "jsonwizardfilegenerator.h", "jsonwizardgeneratorfactory.cpp", "jsonwizardgeneratorfactory.h",