2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
2021-03-09 15:32:02 +00:00
|
|
|
|
|
|
|
#include "propertyprinter.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2023-07-07 14:47:08 +00:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
|
|
|
|
2021-03-09 15:32:02 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
void qmakePropertyPrinter(const QList<QPair<QString, QString>> &values)
|
|
|
|
{
|
|
|
|
// Assume single property request
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
if (values.size() == 1) {
|
2021-03-09 15:32:02 +00:00
|
|
|
std::cout << qPrintable(values.at(0).second) << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &val : values) {
|
|
|
|
std::cout << qPrintable(val.first) << ":" << qPrintable(val.second) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void jsonPropertyPrinter(const QList<QPair<QString, QString>> &values)
|
|
|
|
{
|
2023-07-07 14:47:08 +00:00
|
|
|
QJsonObject object;
|
|
|
|
for (const auto &val : values)
|
|
|
|
object.insert(val.first, val.second);
|
|
|
|
|
|
|
|
QJsonDocument document(object);
|
|
|
|
std::cout << document.toJson().constData();
|
2021-03-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|