Write csv data to IO Device @input: - iodevice - IO Device to write data to - content - not empty handler of content for csv-file - codec - pointer to codec object that would be used for file writing @output: - bool - True if data could be written to the IO Device
| 130 | // @output: |
| 131 | // - bool - True if data could be written to the IO Device |
| 132 | bool WriterPrivate::writeToIODevice( |
| 133 | QIODevice& ioDevice, |
| 134 | ContentIterator& content, |
| 135 | const QStringConverter::Encoding codec) |
| 136 | { |
| 137 | if (content.isEmpty()) { |
| 138 | qDebug() << __FUNCTION__ << "Error - invalid arguments"; |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | // Open IO Device if it was not opened |
| 143 | if (!ioDevice.isOpen() && |
| 144 | !ioDevice.open(QIODevice::Append | QIODevice::Text)) |
| 145 | { |
| 146 | qDebug() << __FUNCTION__ << "Error - failed to open IO Device"; |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | QTextStream stream(&ioDevice); |
| 151 | stream.setEncoding(codec); |
| 152 | while (content.hasNext()) { stream << content.getNext(); } |
| 153 | |
| 154 | stream.flush(); |
| 155 | return stream.status() == QTextStream::Ok; |
| 156 | } |
| 157 | |
| 158 | // Create unique name for the temporary file |
| 159 | // @output: |