#include "figmaio.h" #include #include #include #include #include QMap FigmaIO::read(const QString &file) { QFile f(file); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning() << "FigmaIO::read - failed to open file:" << file; return {}; } QJsonParseError error; auto jsonDoc = QJsonDocument::fromJson(f.readAll(), &error); if (error.error != QJsonParseError::NoError) { qWarning() << "FigmaIO::read - error parsing json file:" << file << "->" << error.errorString(); return {}; } QMap mapping; if (jsonDoc.isObject()) { auto rootObject = jsonDoc.object(); auto i = rootObject.constBegin(); while (i != rootObject.constEnd()) { QJsonValue val = i.value(); QJsonArray links = val.toArray(); QStringList linksList; linksList.reserve(links.size()); for (const QJsonValue &link : qAsConst(links)) if (link.isString()) linksList << link.toString(); mapping.insert(i.key(), linksList); ++i; } } return mapping; }