diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2016-07-05 17:34:37 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2016-07-06 13:04:07 +0000 |
commit | bf1ccfc91061a76b60c3622804a2e1f685c20d71 (patch) | |
tree | f0b916928917f5bb8763bc216a63d6dae36d5abd | |
parent | c546093257353d8a3cd2fa8b22118a795de5e3b6 (diff) |
Extract toJSLiteral functions from scripttools.{h|cpp}
The toJSLiteral functions do not use QtScript and are needed by
libqtprofilesetup. This extraction is needed to remove the
QtScript-dependency from libqtprofilesetup in a subsequent commit.
Change-Id: Ide1737269d4b98f38eee93cdf9b6c33a6967c91c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/lib/corelib/api/projectdata.cpp | 2 | ||||
-rw-r--r-- | src/lib/corelib/api/projectfileupdater.cpp | 2 | ||||
-rw-r--r-- | src/lib/corelib/corelib.qbs | 2 | ||||
-rw-r--r-- | src/lib/corelib/language/propertymapinternal.cpp | 2 | ||||
-rw-r--r-- | src/lib/corelib/language/tst_language.cpp | 1 | ||||
-rw-r--r-- | src/lib/corelib/tools/jsliterals.cpp | 93 | ||||
-rw-r--r-- | src/lib/corelib/tools/jsliterals.h | 49 | ||||
-rw-r--r-- | src/lib/corelib/tools/scripttools.cpp | 59 | ||||
-rw-r--r-- | src/lib/corelib/tools/scripttools.h | 6 | ||||
-rw-r--r-- | src/lib/corelib/tools/settingsmodel.cpp | 4 | ||||
-rw-r--r-- | src/lib/corelib/tools/tools.pri | 2 | ||||
-rw-r--r-- | src/lib/qtprofilesetup/qtprofilesetup.cpp | 2 |
12 files changed, 154 insertions, 70 deletions
diff --git a/src/lib/corelib/api/projectdata.cpp b/src/lib/corelib/api/projectdata.cpp index 8ae109c33..55d7f7c9e 100644 --- a/src/lib/corelib/api/projectdata.cpp +++ b/src/lib/corelib/api/projectdata.cpp @@ -33,9 +33,9 @@ #include "propertymap_p.h" #include <language/propertymapinternal.h> #include <tools/fileinfo.h> +#include <tools/jsliterals.h> #include <tools/propertyfinder.h> #include <tools/qbsassert.h> -#include <tools/scripttools.h> #include <algorithm> diff --git a/src/lib/corelib/api/projectfileupdater.cpp b/src/lib/corelib/api/projectfileupdater.cpp index 5dafa4458..57eb58899 100644 --- a/src/lib/corelib/api/projectfileupdater.cpp +++ b/src/lib/corelib/api/projectfileupdater.cpp @@ -41,7 +41,7 @@ #include <parser/qmljslexer_p.h> #include <parser/qmljsparser_p.h> #include <tools/hostosinfo.h> -#include <tools/scripttools.h> +#include <tools/jsliterals.h> #include <tools/qbsassert.h> #include <QFile> diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs index 978adf7b0..723531d37 100644 --- a/src/lib/corelib/corelib.qbs +++ b/src/lib/corelib/corelib.qbs @@ -338,6 +338,8 @@ QbsLibrary { "hostosinfo.h", "id.cpp", "id.h", + "jsliterals.cpp", + "jsliterals.h", "installoptions.cpp", "msvcinfo.cpp", "msvcinfo.h", diff --git a/src/lib/corelib/language/propertymapinternal.cpp b/src/lib/corelib/language/propertymapinternal.cpp index fa5f5493e..084721dad 100644 --- a/src/lib/corelib/language/propertymapinternal.cpp +++ b/src/lib/corelib/language/propertymapinternal.cpp @@ -30,9 +30,9 @@ #include "propertymapinternal.h" +#include <tools/jsliterals.h> #include <tools/persistence.h> #include <tools/propertyfinder.h> -#include <tools/scripttools.h> namespace qbs { namespace Internal { diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp index c68147ecd..a3aa44279 100644 --- a/src/lib/corelib/language/tst_language.cpp +++ b/src/lib/corelib/language/tst_language.cpp @@ -49,6 +49,7 @@ #include <tools/error.h> #include <tools/fileinfo.h> #include <tools/hostosinfo.h> +#include <tools/jsliterals.h> #include <tools/profile.h> #include <tools/propertyfinder.h> #include <tools/settings.h> diff --git a/src/lib/corelib/tools/jsliterals.cpp b/src/lib/corelib/tools/jsliterals.cpp new file mode 100644 index 000000000..408bd6f2f --- /dev/null +++ b/src/lib/corelib/tools/jsliterals.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "jsliterals.h" + +namespace qbs { + +QString toJSLiteral(const bool b) +{ + return b ? QLatin1String("true") : QLatin1String("false"); +} + +QString toJSLiteral(const QString &str) +{ + QString js = str; + js.replace(QRegExp(QLatin1String("([\\\\\"])")), QLatin1String("\\\\1")); + js.prepend(QLatin1Char('"')); + js.append(QLatin1Char('"')); + return js; +} + +QString toJSLiteral(const QStringList &strs) +{ + QString js = QLatin1String("["); + for (int i = 0; i < strs.count(); ++i) { + if (i != 0) + js.append(QLatin1String(", ")); + js.append(toJSLiteral(strs.at(i))); + } + js.append(QLatin1Char(']')); + return js; +} + +QString toJSLiteral(const QVariant &val) +{ + if (!val.isValid()) + return QLatin1String("undefined"); + if (val.type() == QVariant::List || val.type() == QVariant::StringList) { + QString res; + foreach (const QVariant &child, val.toList()) { + if (res.length()) res.append(QLatin1String(", ")); + res.append(toJSLiteral(child)); + } + res.prepend(QLatin1Char('[')); + res.append(QLatin1Char(']')); + return res; + } + if (val.type() == QVariant::Map) { + const QVariantMap &vm = val.toMap(); + QString str = QLatin1String("{"); + for (QVariantMap::const_iterator it = vm.begin(); it != vm.end(); ++it) { + if (it != vm.begin()) + str += QLatin1Char(','); + str += toJSLiteral(it.key()) + QLatin1Char(':') + toJSLiteral(it.value()); + } + str += QLatin1Char('}'); + return str; + } + if (val.type() == QVariant::Bool) + return val.toBool() ? QLatin1String("true") : QLatin1String("false"); + if (val.canConvert(QVariant::String)) + return toJSLiteral(val.toString()); + return QString::fromLatin1("Unconvertible type %1").arg(QLatin1String(val.typeName())); +} + +} // namespace qbs diff --git a/src/lib/corelib/tools/jsliterals.h b/src/lib/corelib/tools/jsliterals.h new file mode 100644 index 000000000..371e51ec1 --- /dev/null +++ b/src/lib/corelib/tools/jsliterals.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** 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 The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. 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, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QBS_JSLITERALS_H +#define QBS_JSLITERALS_H + +#include "qbs_export.h" + +#include <QString> +#include <QStringList> +#include <QVariant> + +namespace qbs { + +QBS_EXPORT QString toJSLiteral(const bool b); +QBS_EXPORT QString toJSLiteral(const QString &str); +QBS_EXPORT QString toJSLiteral(const QStringList &strs); +QBS_EXPORT QString toJSLiteral(const QVariant &val); + +} // namespace qbs + +#endif // QBS_JSLITERALS_H diff --git a/src/lib/corelib/tools/scripttools.cpp b/src/lib/corelib/tools/scripttools.cpp index 11cd53100..b68ac2b4b 100644 --- a/src/lib/corelib/tools/scripttools.cpp +++ b/src/lib/corelib/tools/scripttools.cpp @@ -57,65 +57,6 @@ QDataStream &operator>> (QDataStream &s, QScriptProgram &script) QT_END_NAMESPACE namespace qbs { - -QString toJSLiteral(const bool b) -{ - return b ? QLatin1String("true") : QLatin1String("false"); -} - -QString toJSLiteral(const QString &str) -{ - QString js = str; - js.replace(QRegExp(QLatin1String("([\\\\\"])")), QLatin1String("\\\\1")); - js.prepend(QLatin1Char('"')); - js.append(QLatin1Char('"')); - return js; -} - -QString toJSLiteral(const QStringList &strs) -{ - QString js = QLatin1String("["); - for (int i = 0; i < strs.count(); ++i) { - if (i != 0) - js.append(QLatin1String(", ")); - js.append(toJSLiteral(strs.at(i))); - } - js.append(QLatin1Char(']')); - return js; -} - -QString toJSLiteral(const QVariant &val) -{ - if (!val.isValid()) - return QLatin1String("undefined"); - if (val.type() == QVariant::List || val.type() == QVariant::StringList) { - QString res; - foreach (const QVariant &child, val.toList()) { - if (res.length()) res.append(QLatin1String(", ")); - res.append(toJSLiteral(child)); - } - res.prepend(QLatin1Char('[')); - res.append(QLatin1Char(']')); - return res; - } - if (val.type() == QVariant::Map) { - const QVariantMap &vm = val.toMap(); - QString str = QLatin1String("{"); - for (QVariantMap::const_iterator it = vm.begin(); it != vm.end(); ++it) { - if (it != vm.begin()) - str += QLatin1Char(','); - str += toJSLiteral(it.key()) + QLatin1Char(':') + toJSLiteral(it.value()); - } - str += QLatin1Char('}'); - return str; - } - if (val.type() == QVariant::Bool) - return val.toBool() ? QLatin1String("true") : QLatin1String("false"); - if (val.canConvert(QVariant::String)) - return toJSLiteral(val.toString()); - return QString::fromLatin1("Unconvertible type %1").arg(QLatin1String(val.typeName())); -} - namespace Internal { void setConfigProperty(QVariantMap &cfg, const QStringList &name, const QVariant &value) diff --git a/src/lib/corelib/tools/scripttools.h b/src/lib/corelib/tools/scripttools.h index 774c4ac2e..20c531293 100644 --- a/src/lib/corelib/tools/scripttools.h +++ b/src/lib/corelib/tools/scripttools.h @@ -47,12 +47,6 @@ QDataStream &operator>> (QDataStream &s, QScriptProgram &script); QT_END_NAMESPACE namespace qbs { - -QBS_EXPORT QString toJSLiteral(const bool b); -QBS_EXPORT QString toJSLiteral(const QString &str); -QBS_EXPORT QString toJSLiteral(const QStringList &strs); -QBS_EXPORT QString toJSLiteral(const QVariant &val); - namespace Internal { template <typename C> diff --git a/src/lib/corelib/tools/settingsmodel.cpp b/src/lib/corelib/tools/settingsmodel.cpp index c14226012..2730bf455 100644 --- a/src/lib/corelib/tools/settingsmodel.cpp +++ b/src/lib/corelib/tools/settingsmodel.cpp @@ -29,7 +29,7 @@ ****************************************************************************/ #include "settingsmodel.h" -#include <tools/scripttools.h> +#include <tools/jsliterals.h> #include <tools/settings.h> #ifdef QT_GUI_LIB @@ -38,6 +38,8 @@ #include <QList> #include <QScopedPointer> +#include <QScriptEngine> +#include <QScriptValue> #include <QString> namespace qbs { diff --git a/src/lib/corelib/tools/tools.pri b/src/lib/corelib/tools/tools.pri index 3fe070575..48d545cc5 100644 --- a/src/lib/corelib/tools/tools.pri +++ b/src/lib/corelib/tools/tools.pri @@ -13,6 +13,7 @@ HEADERS += \ $$PWD/filetime.h \ $$PWD/generateoptions.h \ $$PWD/id.h \ + $$PWD/jsliterals.h \ $$PWD/msvcinfo.h \ $$PWD/persistence.h \ $$PWD/scannerpluginmanager.h \ @@ -54,6 +55,7 @@ SOURCES += \ $$PWD/fileinfo.cpp \ $$PWD/generateoptions.cpp \ $$PWD/id.cpp \ + $$PWD/jsliterals.cpp \ $$PWD/msvcinfo.cpp \ $$PWD/persistence.cpp \ $$PWD/scannerpluginmanager.cpp \ diff --git a/src/lib/qtprofilesetup/qtprofilesetup.cpp b/src/lib/qtprofilesetup/qtprofilesetup.cpp index e6cfec8c9..f74ae3498 100644 --- a/src/lib/qtprofilesetup/qtprofilesetup.cpp +++ b/src/lib/qtprofilesetup/qtprofilesetup.cpp @@ -35,8 +35,8 @@ #include <logging/translator.h> #include <tools/error.h> #include <tools/fileinfo.h> +#include <tools/jsliterals.h> #include <tools/profile.h> -#include <tools/scripttools.h> #include <tools/settings.h> #include <tools/version.h> |