File indexing completed on 2025-01-05 05:23:44

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2010, 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "scriptvalueconverter.hpp"
0010 #include "scriptvalueconverter_p.hpp"
0011 #include "../script/scriptlogger.hpp"
0012 
0013 #include <QString>
0014 #include <QVector>
0015 #include <QScriptValue>
0016 #include <QScriptEngine>
0017 #include <QScriptValueIterator>
0018 
0019 namespace ScriptValueConverter {
0020 
0021 DataInformation* convert(const QScriptValue& value, const QString& name, ScriptLogger* logger,
0022                          DataInformation* parent)
0023 {
0024     // TODO Q_CHECK_PTR(parent)
0025     const ParserInfo info(name, logger, parent, value.engine());
0026     return toDataInformation(value, info); // could be NULL
0027 }
0028 
0029 QVector<DataInformation*> convertValues(const QScriptValue& value, ScriptLogger* logger,
0030                                         DataInformation* parent)
0031 {
0032     // TODO Q_CHECK_PTR(parent);
0033     QVector<DataInformation*> ret;
0034     QScriptValueIterator it(value);
0035     const bool isArray = value.isArray();
0036     while (it.hasNext()) {
0037         it.next();
0038         if (isArray && it.name() == QLatin1String("length")) {
0039             continue; // skip the length property of arrays
0040         }
0041         const ParserInfo info(it.name(), logger, parent, value.engine());
0042         DataInformation* inf = toDataInformation(it.value(), info);
0043 
0044         if (inf) {
0045             ret.append(inf);
0046         } else { // TODO remove the null check once parent must be nonnull
0047             logger->info(parent ? parent->fullObjectPath() : QString()).nospace()
0048                 << "Could not convert property '" << it.name() << "'.";
0049         }
0050     }
0051     return ret;
0052 }
0053 
0054 } // namespace ScriptValueConverter