示例#1
0
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));
}
示例#2
0
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;
}
void WorkspaceSerializerTests::VerifyActualDataAndPersistedFile(const QString& file, const DataMap& expectedDataMap, const QString& expectedDomain, const QColor& expectedBackground)
{
	SignalData actualSignalData;
	PlotInfo actualPlotInfo;
	QSignalSpy dataSpy(&actualSignalData, SIGNAL(DataAdded(const DataMap&)));
	QSignalSpy plotSpy(&actualPlotInfo, SIGNAL(BackgroundColorChanged(const QColor&)));

	WorkspaceSerializer::Read(file, actualSignalData, actualPlotInfo);

	QCOMPARE(1, dataSpy.count());
	QCOMPARE(1, plotSpy.count());

	auto actualdata = dataSpy.takeFirst().takeFirst().value<DataMap>();
	QCOMPARE(actualdata, expectedDataMap);
	QCOMPARE(actualSignalData.getDomain()->name, expectedDomain);

	auto actualColor = plotSpy.takeFirst().takeFirst().value<QColor>();
	QCOMPARE(actualColor, expectedBackground);
}