From: Pino Toscano Date: Mon, 4 Jul 2005 11:14:45 +0000 (+0000) Subject: Applied a patch from carsten to improve the loading of glossaries and slightly edited... X-Git-Tag: v3.4.90~19 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=e9a035c2c3a00d84cd261e0153cf34dc11e76e30;p=libqmvoc.git Applied a patch from carsten to improve the loading of glossaries and slightly edited by me to fix the compilation. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=431446 --- diff --git a/kdeeduui/kdeeduglossary.cpp b/kdeeduui/kdeeduglossary.cpp index cf86b6a..fad0048 100644 --- a/kdeeduui/kdeeduglossary.cpp +++ b/kdeeduui/kdeeduglossary.cpp @@ -29,12 +29,8 @@ #include #include -bool Glossary::loadLayout( QDomDocument &questionDocument, const QString& path, const QString& filename ) +bool Glossary::loadLayout( QDomDocument &questionDocument, const KURL& url ) { - KURL url; - url.setPath( path ); - url.setFileName( filename ); - QFile layoutFile( url.path() ); if (!layoutFile.exists()) @@ -56,6 +52,22 @@ bool Glossary::loadLayout( QDomDocument &questionDocument, const QString& path, return true; } +Glossary* Glossary::readFromXML( const KURL& url ) +{ + QDomDocument doc( "document" ); + + Glossary *glossary = new Glossary(); + + if ( glossary->loadLayout( doc, url ) ) + { + QValueList itemList; + itemList = glossary->readItems( doc ); + glossary->setItemlist( itemList ); + } + + return glossary; +} + QValueList Glossary::readItems( QDomDocument &itemDocument ) { QValueList list; diff --git a/kdeeduui/kdeeduglossary.h b/kdeeduui/kdeeduglossary.h index 7f5aeaa..63e9543 100644 --- a/kdeeduui/kdeeduglossary.h +++ b/kdeeduui/kdeeduglossary.h @@ -68,17 +68,26 @@ class Glossary QString name()const{ return m_name; } - + + void setItemlist( QValueList list ){ + m_itemlist = list; + } + /** - * @param path The path where to look for the file - * @param filename The file to be loaded - * @return true if the file was successfully loaded + * Read a glossary from an XML file. + * + * @param url The path of the file to load + * + * @return a pointer to the loaded glossary. Even in case of + * error, this won't return 0 but an empty Glossary. */ - bool loadLayout( QDomDocument&, const QString& path, const QString& filename ); + static Glossary* readFromXML( const KURL& url ); private: QValueList readItems( QDomDocument &itemDocument ); + bool loadLayout( QDomDocument&, const KURL& url ); + QValueList m_itemlist; QString m_name;