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
| 212 | // @output: |
| 213 | // - bool - True if data was written to the file, otherwise False |
| 214 | bool Writer::write( |
| 215 | const QString& filePath, |
| 216 | const AbstractData& data, |
| 217 | const QString& separator, |
| 218 | const QString& textDelimiter, |
| 219 | const WriteMode& mode, |
| 220 | const QStringList& header, |
| 221 | const QStringList& footer, |
| 222 | QTextCodec* codec) |
| 223 | { |
| 224 | if (filePath.isEmpty()) |
| 225 | { |
| 226 | qDebug() << __FUNCTION__ << "Error - empty path to file"; |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | if (data.isEmpty()) |
| 231 | { |
| 232 | qDebug() << __FUNCTION__ << "Error - empty data"; |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | if (false == CheckFile(filePath)) |
| 237 | { |
| 238 | qDebug() << __FUNCTION__ << "Error - wrong file path/name:" << filePath; |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | ContentIterator content(data, separator, textDelimiter, header, footer); |
| 243 | bool result = false; |
| 244 | switch (mode) |
| 245 | { |
| 246 | case APPEND: |
| 247 | result = WriterPrivate::appendToFile(filePath, content, codec); |
| 248 | break; |
| 249 | case REWRITE: |
| 250 | default: |
| 251 | result = WriterPrivate::overwriteFile(filePath, content, codec); |
| 252 | } |
| 253 | |
| 254 | return result; |
| 255 | } |
| 256 | |
| 257 | // Write data to IO Device |
| 258 | // @input: |