Write data to csv-file @input: - filePath - string with absolute path to csv-file - data - not empty AbstractData object that contains information that should be written to csv-file - separator - string or character that would separate values in a row (line) in csv-file - textDelimiter - string or character that enclose each element in a row - mode - write mode of the file - header - strings that
| 193 | // @output: |
| 194 | // - bool - True if data was written to the file, otherwise False |
| 195 | bool Writer::write( |
| 196 | const QString& filePath, |
| 197 | const AbstractData& data, |
| 198 | const QString& separator, |
| 199 | const QString& textDelimiter, |
| 200 | const WriteMode mode, |
| 201 | const QList<QString>& header, |
| 202 | const QList<QString>& footer, |
| 203 | const QStringConverter::Encoding codec) |
| 204 | { |
| 205 | if (filePath.isEmpty()) { |
| 206 | qDebug() << __FUNCTION__ << "Error - empty path to file"; |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | if (data.isEmpty()) { |
| 211 | qDebug() << __FUNCTION__ << "Error - empty data"; |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | if (false == CheckFile(filePath)) { |
| 216 | qDebug() << __FUNCTION__ << "Error - wrong file path/name:" << filePath; |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | ContentIterator content(data, separator, textDelimiter, header, footer); |
| 221 | switch (mode) |
| 222 | { |
| 223 | case WriteMode::APPEND: |
| 224 | return WriterPrivate::appendToFile(filePath, content, codec); |
| 225 | break; |
| 226 | case WriteMode::REWRITE: |
| 227 | default: |
| 228 | return WriterPrivate::overwriteFile(filePath, content, codec); |
| 229 | } |
| 230 | |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | // Write data to IO Device |
| 235 | // @input: |