2023-08-29 17:10:48 +00:00
|
|
|
// Copyright (C) 2018 Intel Corporation.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
|
|
|
|
#include "debugtextdumper.h"
|
2023-09-04 13:14:41 +00:00
|
|
|
#include "variantorderedmap.h"
|
2023-08-29 17:10:48 +00:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
|
|
|
// Static instance is declared in datastreamconverter.cpp, since it uses it.
|
|
|
|
|
|
|
|
static QString dumpVariant(const QVariant &v, const QString &indent = "\n"_L1)
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
QString indented = indent + " "_L1;
|
|
|
|
|
|
|
|
int type = v.userType();
|
|
|
|
if (type == qMetaTypeId<VariantOrderedMap>() || type == QMetaType::QVariantMap) {
|
|
|
|
const auto map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap())
|
|
|
|
: qvariant_cast<VariantOrderedMap>(v);
|
|
|
|
|
|
|
|
result = "Map {"_L1;
|
|
|
|
for (const auto &pair : map) {
|
|
|
|
result += indented + dumpVariant(pair.first, indented);
|
|
|
|
result.chop(1); // remove comma
|
|
|
|
result += " => "_L1 + dumpVariant(pair.second, indented);
|
|
|
|
}
|
|
|
|
result.chop(1); // remove comma
|
|
|
|
result += indent + "},"_L1;
|
|
|
|
} else if (type == QMetaType::QVariantList) {
|
|
|
|
const QVariantList list = v.toList();
|
|
|
|
|
|
|
|
result = "List ["_L1;
|
|
|
|
for (const auto &item : list)
|
|
|
|
result += indented + dumpVariant(item, indented);
|
|
|
|
result.chop(1); // remove comma
|
|
|
|
result += indent + "],"_L1;
|
|
|
|
} else {
|
|
|
|
QDebug debug(&result);
|
|
|
|
debug.nospace() << v << ',';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
QString DebugTextDumper::name() const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
|
|
|
return "debugtext-dump"_L1;
|
|
|
|
}
|
|
|
|
|
2023-09-04 12:37:25 +00:00
|
|
|
Converter::Directions DebugTextDumper::directions() const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
2023-09-05 13:37:20 +00:00
|
|
|
return Direction::Out;
|
2023-08-29 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
Converter::Options DebugTextDumper::outputOptions() const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
|
|
|
return SupportsArbitraryMapKeys;
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
const char *DebugTextDumper::optionsHelp() const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
bool DebugTextDumper::probeFile(QIODevice *f) const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
QVariant DebugTextDumper::loadFile(QIODevice *f, const Converter *&outputConverter) const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
Q_UNUSED(f);
|
|
|
|
Q_UNUSED(outputConverter);
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:34:26 +00:00
|
|
|
void DebugTextDumper::saveFile(QIODevice *f, const QVariant &contents,
|
|
|
|
const QStringList &options) const
|
2023-08-29 17:10:48 +00:00
|
|
|
{
|
2023-10-19 13:57:11 +00:00
|
|
|
if (!options.isEmpty()) {
|
|
|
|
qFatal("Unknown option '%s' to debug text output. This format has no options.",
|
|
|
|
qPrintable(options.first()));
|
|
|
|
}
|
2023-08-29 17:10:48 +00:00
|
|
|
QString s = dumpVariant(contents);
|
|
|
|
s[s.size() - 1] = u'\n'; // replace the comma with newline
|
|
|
|
|
|
|
|
QTextStream out(f);
|
|
|
|
out << s;
|
|
|
|
}
|