36 #include <QJsonDocument>
38 #include <QJsonObject>
46 static const char LICENSE_HEADER[] =
47 R
"(/****************************************************************************
49 ** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
50 ** Contact: https://www.qt.io/licensing/
52 ** This file is part of the QtGui module of the Qt Toolkit.
54 ** $QT_BEGIN_LICENSE:LGPL$
55 ** Commercial License Usage
56 ** Licensees holding valid commercial Qt licenses may use this file in
57 ** accordance with the commercial license agreement provided with the
58 ** Software or, alternatively, in accordance with the terms contained in
59 ** a written agreement between you and The Qt Company. For licensing terms
60 ** and conditions see https://www.qt.io/terms-conditions. For further
61 ** information use the contact form at https://www.qt.io/contact-us.
63 ** GNU Lesser General Public License Usage
64 ** Alternatively, this file may be used under the terms of the GNU Lesser
65 ** General Public License version 3 as published by the Free Software
66 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
67 ** packaging of this file. Please review the following information to
68 ** ensure the GNU Lesser General Public License version 3 requirements
69 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
71 ** GNU General Public License Usage
72 ** Alternatively, this file may be used under the terms of the GNU
73 ** General Public License version 2.0 or (at your option) the GNU General
74 ** Public license version 3 or any later version approved by the KDE Free
75 ** Qt Foundation. The licenses are as published by the Free Software
76 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
77 ** included in the packaging of this file. Please review the following
78 ** information to ensure the GNU General Public License requirements will
79 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
80 ** https://www.gnu.org/licenses/gpl-3.0.html.
84 ****************************************************************************/)";
107 printLine(qPrintable(
str));
113 cout << m_indentString <<
str <<
'\n';
143 return s1.position <
s2.position;
149 const QString presetCaseString(
"case QGradient::%1:");
150 const QString presetStopColorString(
"QColor(%1, %2, %3, %4)");
151 const QString presetStopString(
"QGradientStop(%1, %2), ");
153 const auto presetStopToGradientStop = [](
const QJsonValue &presetStop)
161 for (
const QJsonValue &presetValue : presets) {
162 if (!presetValue.isObject())
169 p.printLine(presetCaseString.arg(presetName));
181 std::back_inserter(gradientStops),
182 presetStopToGradientStop);
185 std::sort(gradientStops.
begin(), gradientStops.
end(),
192 result.reserve(
result.size() + gradientStops.
size() * (presetStopString.size() + 20));
193 result +=
"return Q_ARRAY_LITERAL(QGradientStop, ";
195 for (
const GradientStop &stop : qAsConst(gradientStops)) {
199 const QString colorString = presetStopColorString
204 result += presetStopString.
arg(stop.position).
arg(colorString);
213 p.printLine(presetCaseString.arg(
"NumPresets"));
216 p.printLine(
"Q_UNREACHABLE();");
224 for (
const QJsonValue &presetValue : presets) {
225 if (!presetValue.isObject()) {
226 p.printLine(
"{ { 0, 0, 0, 0 } },");
246 cin.read(arr,
sizeof(arr));
247 json.
append(arr, cin.gcount());
252 if (jsonDocument.
isNull())
253 qFatal(
"Error: %s at offset %d", qPrintable(
error.errorString()),
error.offset);
256 qFatal(
"Error: expected a document with a JSON array");
262 p.printLine(LICENSE_HEADER);
264 p.printLine(
"// This file is auto-generated by gradientgen. DO NOT EDIT!");
267 p.printLine(
"static QList<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset)");
271 p.printLine(
"Q_ASSERT(preset < QGradient::NumPresets);");
272 p.printLine(
"switch (preset) {");
273 printGradientStops(
p, presets);
275 p.printLine(
"Q_UNREACHABLE();");
276 p.printLine(
"return {};");
281 p.printLine(
"static constexpr QGradient::QGradientData qt_preset_gradient_data[] = {");
284 printGradientData(
p, presets);
289 p.printLine(
"static void *qt_preset_gradient_dummy()");
293 p.printLine(
"union {void *p; uint i;};");
294 p.printLine(
"p = 0;");
295 p.printLine(
"i |= uint(QGradient::ObjectMode);");
296 p.printLine(
"return p;");
small capitals from c petite p scientific i
[1]
void printLine(const char *str=nullptr) const
void printLine(const QString &str) const
The QByteArray class provides an array of bytes.
QByteArray & append(char c)
The QJsonArray class encapsulates a JSON array.
const_iterator cend() const
const_iterator cbegin() const
The QJsonDocument class provides a way to read and write JSON documents.
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
The QJsonObject class encapsulates a JSON object.
The QJsonValue class encapsulates a value in JSON.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
qsizetype size() const noexcept
void reserve(qsizetype size)
The QString class provides a Unicode character string.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
char * formatString(const char *prefix, const char *suffix, size_t numArguments,...)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
#define Q_DISABLE_COPY_MOVE(Class)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLuint GLenum GLenum transform
GLsizei const GLchar *const * string
[0]
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
static bool sortByPosition(GradientStop s1, GradientStop s2)
The QJsonParseError class is used to report errors during JSON parsing.