6#include <QCoreApplication>
22 QSaveFile file(fileName);
24 if (!file.open(QIODevice::WriteOnly)) {
28 if (fileName.endsWith(
".dolphin")) {
29 qCDebug(zero) <<
"Saving dolphin file.";
30 QDataStream stream(&file);
34 qCDebug(zero) <<
"Saving CSV file.";
51 if (!file.open(QIODevice::ReadOnly)) {
52 qCDebug(zero) <<
"Could not open file in ReadOnly mode: " << file.errorString();
58 if (fileName.endsWith(
".dolphin")) {
59 qCDebug(zero) <<
"Dolphin file opened.";
60 QDataStream stream(&file);
63 }
else if (fileName.endsWith(
".csv")) {
64 qCDebug(zero) <<
"CSV file opened.";
67 qCDebug(zero) <<
"Format not supported. Could not open file: " << fileName;
79 QString str = in.readLine();
80 const auto wordList(str.split(
','));
82 if (wordList.size() < 2) {
86 int rows = wordList.at(0).toInt();
87 const int cols = wordList.at(1).toInt();
94 if (rows > maxInputPorts) {
105 data.
values.resize(rows * cols);
107 for (
int row = 0; row < rows; ++row) {
109 const auto wordList2(str.split(
','));
111 if (wordList2.size() < cols) {
112 throw PANDACEPTION_WITH_CONTEXT(
"BewavedDolphin",
"Row %1 has %2 value(s) but %3 are required.", QString::number(row), QString::number(wordList2.size()), QString::number(cols));
115 for (
int col = 0; col < cols; ++col) {
116 data.
values[row * cols + col] = wordList2.at(col).toInt();
Common logging utilities, the Pandaception error type, and helper macros.
#define PANDACEPTION_WITH_CONTEXT(context, msg,...)
#define qCDebug(category)
DolphinFile: reads/writes a SignalModel to .dolphin/.csv files on disk.
Circuit and waveform file serialization/deserialization utilities.
SignalModel for the beWavedDolphin waveform table.
static void readDolphinHeader(QDataStream &stream)
Reads and validates the BeWavedDolphin waveform file header.
static void writeDolphinHeader(QDataStream &stream)
Writes the BeWavedDolphin waveform file header to stream.
QStandardItemModel subclass that makes all cells non-editable.
static constexpr int kMaxColumns
Disk I/O for the beWavedDolphin formats: opens the file, dispatches by extension (....
DolphinSerializer::WaveformData parseTerminal(QTextStream &in, const int maxInputPorts)
DolphinSerializer::WaveformData load(const QString &fileName, const int maxInputPorts)
void save(const SignalModel &model, const QString &fileName, const int inputPorts)
Writes model to fileName atomically, choosing the format by extension.
void saveBinary(QDataStream &stream, const QStandardItemModel *model, const int inputPorts)
Serializes input rows to the binary .dolphin stream.
void saveCSV(QSaveFile &file, const QStandardItemModel *model)
Serializes all rows (inputs + outputs) to a .csv file.
WaveformData loadCSV(QFile &file, const int maxInputPorts)
Deserializes input rows from a .csv file.
WaveformData loadBinary(QDataStream &stream, const int maxInputPorts)
Deserializes input rows from a binary .dolphin stream.