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
| 141 | // @output: |
| 142 | // - bool - True if data could be written to the IO Device |
| 143 | bool WriterPrivate::writeToIODevice( |
| 144 | QIODevice& ioDevice, |
| 145 | ContentIterator& content, |
| 146 | QTextCodec* codec) |
| 147 | { |
| 148 | if (content.isEmpty()) |
| 149 | { |
| 150 | qDebug() << __FUNCTION__ << "Error - invalid arguments"; |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | // Open IO Device if it was not opened |
| 155 | if (false == ioDevice.isOpen() && |
| 156 | false == ioDevice.open(QIODevice::Append | QIODevice::Text)) |
| 157 | { |
| 158 | qDebug() << __FUNCTION__ << "Error - failed to open IO Device"; |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | QTextStream stream(&ioDevice); |
| 163 | stream.setCodec(codec); |
| 164 | while(content.hasNext()) |
| 165 | { |
| 166 | stream << content.getNext(); |
| 167 | } |
| 168 | |
| 169 | stream.flush(); |
| 170 | |
| 171 | return stream.status() == QTextStream::Ok; |
| 172 | } |
| 173 | |
| 174 | // Create unique name for the temporary file |
| 175 | // @output: |