diff --git a/src/datarecorder.cpp b/src/datarecorder.cpp --- a/src/datarecorder.cpp +++ b/src/datarecorder.cpp @@ -27,6 +27,7 @@ DataRecorder::DataRecorder(QObject *pare { lastNumChannels = 0; disableBuffering = false; + windowsLE = false; } bool DataRecorder::startRecording(QString fileName, QString separator, QStringList channelNames) @@ -47,7 +48,7 @@ bool DataRecorder::startRecording(QStrin if (!channelNames.isEmpty()) { fileStream << channelNames.join(_sep); - fileStream << "\n"; + fileStream << le(); lastNumChannels = channelNames.length(); } return true; @@ -74,7 +75,7 @@ void DataRecorder::addData(double* data, fileStream << data[ci * numOfSamples + i]; if (ci != numOfChannels-1) fileStream << _sep; } - fileStream << '\n'; + fileStream << le(); } if (disableBuffering) fileStream.flush(); @@ -87,3 +88,8 @@ void DataRecorder::stopRecording() file.close(); lastNumChannels = 0; } + +const char* DataRecorder::le() const +{ + return windowsLE ? "\r\n" : "\n"; +} diff --git a/src/datarecorder.h b/src/datarecorder.h --- a/src/datarecorder.h +++ b/src/datarecorder.h @@ -34,6 +34,14 @@ public: bool disableBuffering; /** + * Use CR+LF as line ending. `false` by default. + * + * @note Toggling this variable during a recording will result in + * a corrupted file. Care must be taken at higher (UI) levels. + */ + bool windowsLE; + + /** * @brief Starts recording data to a file in CSV format. * * File is opened and header line (names of channels) is written. @@ -72,6 +80,9 @@ private: QFile file; QTextStream fileStream; QString _sep; + + /// Returns the selected line ending. + const char* le() const; }; #endif // DATARECORDER_H diff --git a/src/recordpanel.cpp b/src/recordpanel.cpp --- a/src/recordpanel.cpp +++ b/src/recordpanel.cpp @@ -60,6 +60,14 @@ RecordPanel::RecordPanel(DataRecorder* r { _recorder->disableBuffering = enabled; }); + + connect(ui->cbWindowsLE, &QCheckBox::toggled, + [this](bool enabled) + { + _recorder->windowsLE = enabled; + }); + + connect(&recordAction, &QAction::toggled, ui->cbWindowsLE, &QWidget::setDisabled); } RecordPanel::~RecordPanel() diff --git a/src/recordpanel.ui b/src/recordpanel.ui --- a/src/recordpanel.ui +++ b/src/recordpanel.ui @@ -6,7 +6,7 @@ 0 0 - 532 + 627 261 @@ -44,53 +44,93 @@ - - - Increments file name automatically everytime a new recording starts - - - Auto increment file name - - - true - - - - - - - Continue recording to file even when plotting is paused - - - Record while paused - - - true - - - - - - - Stop recording when port closed - - - true - - - - - - - Channel names are written to the first line of record file - - - Write header line - - - true - - + + + + + Channel names are written to the first line of record file + + + Write header line + + + true + + + + + + + Continue recording to file even when plotting is paused + + + Record while paused + + + true + + + + + + + Do not buffer when writing to file. Check this if you are using other software to open the file during recording. + + + Disable buffering + + + + + + + Stop recording when port closed + + + true + + + + + + + Increments file name automatically everytime a new recording starts + + + Auto increment file name + + + true + + + + + + + Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording. + + + Windows Style Line Endings + + + false + + + + + + + Qt::Horizontal + + + + 1 + 20 + + + + + @@ -133,16 +173,6 @@ - - - Do not buffer when writing to file. Check this if you are using other software to open the file during recording. - - - Disable buffering - - - - Qt::Vertical