void WorkspaceSerializer::Write(const QString& fileName, const SignalData& data, const PlotInfo& plotInfo, bool writeValues /*= true*/) { QJsonObject json; json["background"] = plotInfo.getBackgroundColor().name(); if (writeValues) { if (auto domain = data.getDomain()) json["domain"] = domain->name; } QJsonArray signArray; data.onSignals([&](const Signal& signal){ QJsonObject signObj; signObj["name"] = signal.name; signObj["color"] = signal.graphic.color.name(); signObj["visible"] = signal.graphic.visible; signObj["range"] = ToJsonArray(QVector < qreal > {signal.graphic.rangeLower, signal.graphic.rangeUpper}); if (writeValues) signObj["values"] = ToJsonArray(signal.y); signObj["ticks"] = ToJsonArray(signal.graphic.ticks); signObj["tickLabels"] = ToJsonArray(signal.graphic.tickLabels); signArray.push_back(std::move(signObj)); }); json["signals"] = signArray; QJsonDocument saveDoc(json); QFile outF(fileName); outF.open(QIODevice::WriteOnly); outF.write(saveDoc.toJson(QJsonDocument::Indented)); }
DataToReplay PrepareReplay(const QString& file, SignalData& signalData) { SignalData data; PlotInfo info; WorkspaceSerializer::Read(file, data, info); DataMap toSet; vector < pair<QString, QVector<qreal>>> toSend; data.onSignals([&](const Signal& signal){ toSet.emplace(signal.name, Signal{ signal.name, {}, signal.graphic }); toSend.emplace_back(make_pair(signal.name, std::move(signal.y))); }); for (auto& signal : toSet) { signalData.addIfNotExists(std::move(signal.second)); } signalData.setAsDomain(data.getDomain()->name); return toSend; }