| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | class QTextDocumentWriterPrivate | - |
| 7 | { | - |
| 8 | public: | - |
| 9 | QTextDocumentWriterPrivate(QTextDocumentWriter* qq); | - |
| 10 | | - |
| 11 | | - |
| 12 | QByteArray format; | - |
| 13 | QIODevice *device; | - |
| 14 | bool deleteDevice; | - |
| 15 | | - |
| 16 | QTextCodec *codec; | - |
| 17 | | - |
| 18 | | - |
| 19 | QTextDocumentWriter *q; | - |
| 20 | }; | - |
| 21 | QTextDocumentWriterPrivate::QTextDocumentWriterPrivate(QTextDocumentWriter *qq) | - |
| 22 | : device(0), | - |
| 23 | deleteDevice(false), | - |
| 24 | | - |
| 25 | codec(QTextCodec::codecForName("utf-8")), | - |
| 26 | | - |
| 27 | q(qq) | - |
| 28 | { | - |
| 29 | } executed: }Execution Count:3 | 3 |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | QTextDocumentWriter::QTextDocumentWriter() | - |
| 37 | : d(new QTextDocumentWriterPrivate(this)) | - |
| 38 | { | - |
| 39 | } | 0 |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | QTextDocumentWriter::QTextDocumentWriter(QIODevice *device, const QByteArray &format) | - |
| 46 | : d(new QTextDocumentWriterPrivate(this)) | - |
| 47 | { | - |
| 48 | d->device = device; | - |
| 49 | d->format = format; | - |
| 50 | } executed: }Execution Count:3 | 3 |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | QTextDocumentWriter::QTextDocumentWriter(const QString &fileName, const QByteArray &format) | - |
| 59 | : d(new QTextDocumentWriterPrivate(this)) | - |
| 60 | { | - |
| 61 | QFile *file = new QFile(fileName); | - |
| 62 | d->device = file; | - |
| 63 | d->deleteDevice = true; | - |
| 64 | d->format = format; | - |
| 65 | } | 0 |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | | - |
| 70 | QTextDocumentWriter::~QTextDocumentWriter() | - |
| 71 | { | - |
| 72 | if (d->deleteDevice) partially evaluated: d->deleteDevice| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 73 | delete d->device; never executed: delete d->device; | 0 |
| 74 | delete d; | - |
| 75 | } executed: }Execution Count:3 | 3 |
| 76 | void QTextDocumentWriter::setFormat (const QByteArray &format) | - |
| 77 | { | - |
| 78 | d->format = format; | - |
| 79 | } | 0 |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | QByteArray QTextDocumentWriter::format () const | - |
| 87 | { | - |
| 88 | return d->format; never executed: return d->format; | 0 |
| 89 | } | - |
| 90 | void QTextDocumentWriter::setDevice (QIODevice *device) | - |
| 91 | { | - |
| 92 | if (d->device && d->deleteDevice) never evaluated: d->device never evaluated: d->deleteDevice | 0 |
| 93 | delete d->device; never executed: delete d->device; | 0 |
| 94 | | - |
| 95 | d->device = device; | - |
| 96 | d->deleteDevice = false; | - |
| 97 | } | 0 |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | QIODevice *QTextDocumentWriter::device () const | - |
| 104 | { | - |
| 105 | return d->device; never executed: return d->device; | 0 |
| 106 | } | - |
| 107 | void QTextDocumentWriter::setFileName (const QString &fileName) | - |
| 108 | { | - |
| 109 | setDevice(new QFile(fileName)); | - |
| 110 | d->deleteDevice = true; | - |
| 111 | } | 0 |
| 112 | QString QTextDocumentWriter::fileName () const | - |
| 113 | { | - |
| 114 | QFile *file = qobject_cast<QFile *>(d->device); | - |
| 115 | return file ? file->fileName() : QString(); never executed: return file ? file->fileName() : QString(); | 0 |
| 116 | } | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | bool QTextDocumentWriter::write(const QTextDocument *document) | - |
| 123 | { | - |
| 124 | QByteArray suffix; | - |
| 125 | | - |
| 126 | if (d->device && d->format.isEmpty()) { partially evaluated: d->device| yes Evaluation Count:3 | no Evaluation Count:0 |
partially evaluated: d->format.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 127 | | - |
| 128 | | - |
| 129 | if (QFile *file = qobject_cast<QFile *>(d->device)) never evaluated: QFile *file = qobject_cast<QFile *>(d->device) | 0 |
| 130 | suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1(); never executed: suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1(); | 0 |
| 131 | } | 0 |
| 132 | | - |
| 133 | QByteArray format = !d->format.isEmpty() ? d->format.toLower() : suffix; partially evaluated: !d->format.isEmpty()| yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
| 134 | | - |
| 135 | | - |
| 136 | if (format == "odf" || format == "opendocumentformat" || format == "odt") { partially evaluated: format == "odf"| yes Evaluation Count:3 | no Evaluation Count:0 |
never evaluated: format == "opendocumentformat" never evaluated: format == "odt" | 0-3 |
| 137 | QTextOdfWriter writer(*document, d->device); | - |
| 138 | | - |
| 139 | writer.setCodec(d->codec); | - |
| 140 | | - |
| 141 | return writer.writeAll(); executed: return writer.writeAll();Execution Count:3 | 3 |
| 142 | } | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 146 | if (format == "html" || format == "htm") { never evaluated: format == "html" never evaluated: format == "htm" | 0 |
| 147 | if (!d->device->isWritable() && ! d->device->open(QIODevice::WriteOnly)) { never evaluated: !d->device->isWritable() never evaluated: ! d->device->open(QIODevice::WriteOnly) | 0 |
| 148 | QMessageLogger("text/qtextdocumentwriter.cpp", 274, __PRETTY_FUNCTION__).warning() << "QTextDocumentWriter::write: the device can not be opened for writing"; | - |
| 149 | return false; never executed: return false; | 0 |
| 150 | } | - |
| 151 | QTextStream ts(d->device); | - |
| 152 | | - |
| 153 | ts.setCodec(d->codec); | - |
| 154 | ts << document->toHtml(d->codec->name()); | - |
| 155 | | - |
| 156 | d->device->close(); | - |
| 157 | return true; never executed: return true; | 0 |
| 158 | } | - |
| 159 | | - |
| 160 | if (format == "txt" || format == "plaintext") { never evaluated: format == "txt" never evaluated: format == "plaintext" | 0 |
| 161 | if (!d->device->isWritable() && ! d->device->open(QIODevice::WriteOnly)) { never evaluated: !d->device->isWritable() never evaluated: ! d->device->open(QIODevice::WriteOnly) | 0 |
| 162 | QMessageLogger("text/qtextdocumentwriter.cpp", 288, __PRETTY_FUNCTION__).warning() << "QTextDocumentWriter::write: the device can not be opened for writing"; | - |
| 163 | return false; never executed: return false; | 0 |
| 164 | } | - |
| 165 | QTextStream ts(d->device); | - |
| 166 | | - |
| 167 | ts.setCodec(d->codec); | - |
| 168 | | - |
| 169 | ts << document->toPlainText(); | - |
| 170 | d->device->close(); | - |
| 171 | return true; never executed: return true; | 0 |
| 172 | } | - |
| 173 | | - |
| 174 | return false; never executed: return false; | 0 |
| 175 | } | - |
| 176 | | - |
| 177 | | - |
| 178 | | - |
| 179 | | - |
| 180 | | - |
| 181 | bool QTextDocumentWriter::write(const QTextDocumentFragment &fragment) | - |
| 182 | { | - |
| 183 | if (fragment.d == 0) partially evaluated: fragment.d == 0| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 184 | return false; never executed: return false; | 0 |
| 185 | QTextDocument *doc = fragment.d->doc; | - |
| 186 | if (doc) partially evaluated: doc| yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
| 187 | return write(doc); executed: return write(doc);Execution Count:3 | 3 |
| 188 | return false; never executed: return false; | 0 |
| 189 | } | - |
| 190 | void QTextDocumentWriter::setCodec(QTextCodec *codec) | - |
| 191 | { | - |
| 192 | if (codec == 0) never evaluated: codec == 0 | 0 |
| 193 | codec = QTextCodec::codecForName("UTF-8"); never executed: codec = QTextCodec::codecForName("UTF-8"); | 0 |
| 194 | qt_noop(); | - |
| 195 | d->codec = codec; | - |
| 196 | } | 0 |
| 197 | | - |
| 198 | | - |
| 199 | | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | QTextCodec *QTextDocumentWriter::codec() const | - |
| 204 | { | - |
| 205 | return d->codec; never executed: return d->codec; | 0 |
| 206 | } | - |
| 207 | QList<QByteArray> QTextDocumentWriter::supportedDocumentFormats() | - |
| 208 | { | - |
| 209 | QList<QByteArray> answer; | - |
| 210 | answer << "plaintext"; | - |
| 211 | | - |
| 212 | | - |
| 213 | answer << "HTML"; | - |
| 214 | | - |
| 215 | | - |
| 216 | answer << "ODF"; | - |
| 217 | | - |
| 218 | | - |
| 219 | qSort(answer); | - |
| 220 | return answer; never executed: return answer; | 0 |
| 221 | } | - |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| | |