From: Frederik Gladhorn Date: Mon, 21 Apr 2008 14:01:31 +0000 (+0000) Subject: Create the xml from the document in memory using qbytearray instead of needing to... X-Git-Tag: v4.0.71^0 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=2b92a8bf8a4a948da1e2d91fa03f1ca30b23d80f;p=libqmvoc.git Create the xml from the document in memory using qbytearray instead of needing to read from disk which would fail when not using kvtml2 and also needed a saved document to work. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=799410 --- diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index 6bb747a..37621c4 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -413,6 +413,13 @@ int KEduVocDocument::saveAs( const KUrl & url, FileType ft, const QString & gene return 0; } +QByteArray KEduVocDocument::toByteArray(const QString &generator) +{ + // no file needed + KEduVocKvtml2Writer kvtmlWriter(0); + return kvtmlWriter.toByteArray( this, generator ); +} + void KEduVocDocument::merge( KEduVocDocument *docToMerge, bool matchIdentifiers ) { kDebug(1100) << "Merging of docs is not implemented"; /// @todo IMPLEMENT ME @@ -784,7 +791,6 @@ QString KEduVocDocument::license() const return d->m_license; } - QString KEduVocDocument::documentComment() const { return d->m_comment; diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index a206728..cffe1a2 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -117,6 +117,8 @@ public: */ int saveAs( const KUrl & url, FileType ft, const QString & generator ); + QByteArray toByteArray(const QString &generator); + /** * Merges data from another document * diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 64ee0c4..64dcdf9 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -33,8 +33,25 @@ KEduVocKvtml2Writer::KEduVocKvtml2Writer( QFile *file ) m_outputFile = file; } - bool KEduVocKvtml2Writer::writeDoc( KEduVocDocument *doc, const QString &generator ) +{ + if (createXmlDocument(doc, generator)) { + QTextStream ts( m_outputFile ); + m_domDoc.save( ts, 2 ); + return true; + } + return false; +} + +QByteArray KEduVocKvtml2Writer::toByteArray(KEduVocDocument * doc, const QString & generator) +{ + if (createXmlDocument(doc, generator)) { + return m_domDoc.toByteArray(); + } + return QByteArray(); +} + +bool KEduVocKvtml2Writer::createXmlDocument( KEduVocDocument *doc, const QString &generator ) { m_doc = doc; @@ -88,9 +105,6 @@ bool KEduVocKvtml2Writer::writeDoc( KEduVocDocument *doc, const QString &generat m_domDoc.appendChild( domElementKvtml ); - QTextStream ts( m_outputFile ); - m_domDoc.save( ts, 2 ); - return true; } @@ -605,3 +619,4 @@ void KEduVocKvtml2Writer::appendTextElement(QDomElement & parent, const QString element.appendChild( textNode ); } + diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index dab473d..45095cd 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -41,6 +41,8 @@ public: bool writeDoc( KEduVocDocument *doc, const QString &generator ); + QByteArray toByteArray( KEduVocDocument *doc, const QString &generator ); + /** * Helper function, appends a new element AND a text child to @p parent * Only appends if @p text is NOT empty. @@ -51,6 +53,9 @@ public: static void appendTextElement( QDomElement &parent, const QString &elementName, const QString &text ); private: + + bool createXmlDocument( KEduVocDocument *doc, const QString &generator ); + /** write information entries * @param informationElement QDomElement information to write to * @param generator text describing generator