| 151 | } |
| 152 | |
| 153 | QString Model::parse(const QByteArray &data) |
| 154 | { |
| 155 | QJsonParseError error; |
| 156 | const auto doc = QJsonDocument::fromJson(data, &error); |
| 157 | if (doc.isNull()) { |
| 158 | return tr("Failed to parse: %1 at %2") |
| 159 | .arg(error.errorString()) |
| 160 | .arg(error.offset); |
| 161 | } |
| 162 | |
| 163 | const auto json = doc.object(); |
| 164 | const auto version = json[versionKey].toInt(); |
| 165 | if (version != 1) { |
| 166 | return tr("Wrong updates version: %1").arg(version); |
| 167 | } |
| 168 | |
| 169 | beginResetModel(); |
| 170 | |
| 171 | root_ = parse(json); |
| 172 | if (root_) |
| 173 | updateStates(); |
| 174 | |
| 175 | endResetModel(); |
| 176 | |
| 177 | if (!root_) |
| 178 | return tr("No data parsed"); |
| 179 | return {}; |
| 180 | } |
| 181 | |
| 182 | std::unique_ptr<Model::Component> Model::parse(const QJsonObject &json) const |
| 183 | { |