Changeset - b1d64d0822d2
[Not reviewed]
default
0 4 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-04-01 12:41:24
hy@ozderya.net
add windows style line endings option for recording
4 files changed with 92 insertions and 37 deletions:
0 comments (0 inline, 0 general)
src/datarecorder.cpp
Show inline comments
 
@@ -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";
 
}
src/datarecorder.h
Show inline comments
 
@@ -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
src/recordpanel.cpp
Show inline comments
 
@@ -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()
src/recordpanel.ui
Show inline comments
 
@@ -6,7 +6,7 @@
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>532</width>
 
    <width>627</width>
 
    <height>261</height>
 
   </rect>
 
  </property>
 
@@ -44,6 +44,54 @@
 
      </layout>
 
     </item>
 
     <item>
 
      <layout class="QGridLayout" name="gridLayout">
 
       <item row="1" column="1">
 
        <widget class="QCheckBox" name="cbHeader">
 
         <property name="toolTip">
 
          <string>Channel names are written to the first line of record file</string>
 
         </property>
 
         <property name="text">
 
          <string>Write header line</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="2" column="0">
 
        <widget class="QCheckBox" name="cbRecordPaused">
 
         <property name="toolTip">
 
          <string>Continue recording to file even when plotting is paused</string>
 
         </property>
 
         <property name="text">
 
          <string>Record while paused</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="3" column="0">
 
        <widget class="QCheckBox" name="cbDisableBuffering">
 
         <property name="toolTip">
 
          <string>Do not buffer when writing to file. Check this if you are using other software to open the file during recording.</string>
 
         </property>
 
         <property name="text">
 
          <string>Disable buffering</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="2" column="1">
 
        <widget class="QCheckBox" name="cbStopOnClose">
 
         <property name="text">
 
          <string>Stop recording when port closed</string>
 
         </property>
 
         <property name="checked">
 
          <bool>true</bool>
 
         </property>
 
        </widget>
 
       </item>
 
       <item row="1" column="0">
 
      <widget class="QCheckBox" name="cbAutoIncrement">
 
       <property name="toolTip">
 
        <string>Increments file name automatically everytime a new recording starts</string>
 
@@ -56,41 +104,33 @@
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QCheckBox" name="cbRecordPaused">
 
       <item row="3" column="1">
 
        <widget class="QCheckBox" name="cbWindowsLE">
 
       <property name="toolTip">
 
        <string>Continue recording to file even when plotting is paused</string>
 
          <string>Use CR+LF as line endings. Some windows software may not show lines correctly otherwise. Can't be changed during recording.</string>
 
       </property>
 
       <property name="text">
 
        <string>Record while paused</string>
 
          <string>Windows Style Line Endings</string>
 
       </property>
 
       <property name="checked">
 
        <bool>true</bool>
 
          <bool>false</bool>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QCheckBox" name="cbStopOnClose">
 
       <property name="text">
 
        <string>Stop recording when port closed</string>
 
       <item row="1" column="2">
 
        <spacer name="horizontalSpacer_2">
 
         <property name="orientation">
 
          <enum>Qt::Horizontal</enum>
 
       </property>
 
       <property name="checked">
 
        <bool>true</bool>
 
         <property name="sizeHint" stdset="0">
 
          <size>
 
           <width>1</width>
 
           <height>20</height>
 
          </size>
 
       </property>
 
      </widget>
 
        </spacer>
 
     </item>
 
     <item>
 
      <widget class="QCheckBox" name="cbHeader">
 
       <property name="toolTip">
 
        <string>Channel names are written to the first line of record file</string>
 
       </property>
 
       <property name="text">
 
        <string>Write header line</string>
 
       </property>
 
       <property name="checked">
 
        <bool>true</bool>
 
       </property>
 
      </widget>
 
      </layout>
 
     </item>
 
     <item>
 
      <layout class="QHBoxLayout" name="horizontalLayout_3">
 
@@ -133,16 +173,6 @@
 
      </layout>
 
     </item>
 
     <item>
 
      <widget class="QCheckBox" name="cbDisableBuffering">
 
       <property name="toolTip">
 
        <string>Do not buffer when writing to file. Check this if you are using other software to open the file during recording.</string>
 
       </property>
 
       <property name="text">
 
        <string>Disable buffering</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <spacer name="verticalSpacer">
 
       <property name="orientation">
 
        <enum>Qt::Vertical</enum>
0 comments (0 inline, 0 general)