forked from qt-creator/qt-creator
Restore JsonWizard expander functionality
Task-number: QTCREATORBUG-13229 Change-Id: I91fd996cdbf5f3e71bdf817e9c5beebbb007681b Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -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<QByteArray, MacroExpander::StringFunction> m_map;
|
||||
QHash<QByteArray, MacroExpander::PrefixFunction> m_prefixMap;
|
||||
QVector<MacroExpander::ResolverFunction> m_extraResolvers;
|
||||
QMap<QByteArray, QString> m_descriptions;
|
||||
QString m_displayName;
|
||||
QVector<MacroExpanderProvider> 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.
|
||||
*
|
||||
|
@@ -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<QString(QString)> PrefixFunction;
|
||||
typedef std::function<bool(QString, QString *)> ResolverFunction;
|
||||
typedef std::function<QString()> StringFunction;
|
||||
typedef std::function<int()> IntFunction;
|
||||
|
||||
@@ -80,6 +81,8 @@ public:
|
||||
void registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading, const StringFunction &value);
|
||||
|
||||
void registerExtraResolver(const ResolverFunction &value);
|
||||
|
||||
QList<QByteArray> variables() const;
|
||||
QString variableDescription(const QByteArray &variable) const;
|
||||
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "jsonfieldpage.h"
|
||||
|
||||
#include "jsonwizard.h"
|
||||
#include "jsonwizardexpander.h"
|
||||
#include "jsonwizardfactory.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "jsonwizard.h"
|
||||
|
||||
#include "jsonwizardexpander.h"
|
||||
#include "jsonwizardgeneratorfactory.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -36,13 +36,10 @@
|
||||
#include <coreplugin/generatedfile.h>
|
||||
|
||||
#include <utils/wizard.h>
|
||||
|
||||
namespace Utils { class MacroExpander; }
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
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<JsonWizardGenerator *> m_generators;
|
||||
|
||||
GeneratorFiles m_files;
|
||||
Internal::JsonWizardExpander *m_expander;
|
||||
Utils::MacroExpander m_expander;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -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 \
|
||||
|
@@ -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 <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
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
|
@@ -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 <utils/macroexpander.h>
|
||||
|
||||
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
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user