diff --git a/src/datarecorder.h b/src/datarecorder.h --- a/src/datarecorder.h +++ b/src/datarecorder.h @@ -1,5 +1,5 @@ /* - Copyright © 2017 Hasan Yavuz Özderya + Copyright © 2018 Hasan Yavuz Özderya This file is part of serialplot. @@ -24,7 +24,15 @@ #include #include -class DataRecorder : public QObject +#include "sink.h" + +/** + * Implemented as a `Sink` that writes incoming data to a file. Before + * connecting a `Source` recording must be started with the `startRecording` + * method. Also before calling `stopRecording`, recorder should be disconnected + * from source. + */ +class DataRecorder : public QObject, public Sink { Q_OBJECT public: @@ -44,14 +52,17 @@ public: /** * @brief Starts recording data to a file in CSV format. * - * File is opened and header line (names of channels) is written. + * File is opened and header line (names of channels) is written. After + * calling this function recorder should be connected to a `Source`. * * @param fileName name of the recording file * @param separator column separator * @param channelNames names of the channels for header line, if empty no header line is written + * @param insertTime enable inserting timestamp * @return false if file operation fails (read only etc.) */ - bool startRecording(QString fileName, QString separator, QStringList channelNames); + bool startRecording(QString fileName, QString separator, + QStringList channelNames, bool insertTime); /** * @brief Adds data to a channel. @@ -75,11 +86,15 @@ public: /// Stops recording, closes file. void stopRecording(); +protected: + virtual void feedIn(const SamplePack& data); + private: unsigned lastNumChannels; ///< used for error message only QFile file; QTextStream fileStream; QString _sep; + bool timestampEn; /// Returns the selected line ending. const char* le() const;