diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-08-24 13:58:22 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-09-05 10:05:22 +0200 |
commit | 79d5c78a4584f2ec503dce2b63c707794cd4618a (patch) | |
tree | 1b7b8f61a2bd8ee921373b64e018c3c5aa419225 | |
parent | bed2c39bbef95f549f69e28c3471d21f5b143a86 (diff) | |
download | qt-creator-79d5c78a4584f2ec503dce2b63c707794cd4618a.tar.gz |
SdkTool: Fix "get" for complex types
Change-Id: I8dd8101e33da4a2bdb0bf36f4217f1c466583b47
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
-rw-r--r-- | src/tools/sdktool/getoperation.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/tools/sdktool/getoperation.cpp b/src/tools/sdktool/getoperation.cpp index 2beb77f9e5..d9ca1cde36 100644 --- a/src/tools/sdktool/getoperation.cpp +++ b/src/tools/sdktool/getoperation.cpp @@ -62,6 +62,41 @@ bool GetOperation::setArguments(const QStringList &args) return !m_file.isEmpty() && !m_keys.isEmpty(); } +static QString toString(const QVariant &variant, int indentation = 0) +{ + const QString indent(indentation, QLatin1Char(' ')); + switch (variant.type()) { + case QVariant::Map: { + QVariantMap map = variant.toMap(); + QString res; + for (auto item = map.begin(); item != map.end(); ++item) { + res += indent + item.key() + QLatin1String(": "); + QVariant value = item.value(); + switch (value.type()) { + case QVariant::Map: + case QVariant::List: + res += QLatin1Char('\n') + toString(value, indentation + 1); + break; + default: + res += value.toString(); + break; + } + res += QLatin1Char('\n'); + } + return res; + } + case QVariant::List: { + QVariantList list = variant.toList(); + QString res; + int counter = 0; + foreach (const QVariant &item, list) + res += indent + QString::number(counter++) + QLatin1String(":\n") + toString(item, indentation + 1); + return res; + } + } + return indent + variant.toString(); +} + int GetOperation::execute() const { Q_ASSERT(!m_keys.isEmpty()); @@ -72,7 +107,7 @@ int GetOperation::execute() const if (!result.isValid()) std::cout << "<invalid>" << std::endl; else - std::cout << qPrintable(result.toString()) << std::endl; + std::cout << qPrintable(toString(result)) << std::endl; } return 0; |