From kde-commits Thu Sep 22 19:44:01 2005 From: Sascha Cunz Date: Thu, 22 Sep 2005 19:44:01 +0000 To: kde-commits Subject: KDE/kdevelop/lib Message-Id: <1127418241.687874.11664.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=112741825931293 SVN commit 463043 by cunz: - Add QHash functions to DomUtil:: - Move FileTemplate:: from util into interfaces - Keep the project's substitution map available in the KDevProject M +3 -2 interfaces/Makefile.am M +28 -6 interfaces/domutil.cpp M +17 -7 interfaces/domutil.h A interfaces/filetemplate.cpp util/filetemplate.cpp#463035 A interfaces/filetemplate.h util/filetemplate.h#463035 M +22 -0 interfaces/kdevproject.cpp M +13 -0 interfaces/kdevproject.h M +2 -2 util/Makefile.am D util/filetemplate.cpp D util/filetemplate.h --- trunk/KDE/kdevelop/lib/interfaces/Makefile.am #463042:463043 @@ -12,7 +12,8 @@ KDevCoreIface.cpp kdevplugincontroller.cpp kdevprojectmodel.cpp \ kdevdifffrontend.cpp kdevplugin.cpp tag.cpp \ domutil.cpp kdevitemmodel.cpp urlutil.cpp \ - KDevPartControllerIface.skel KDevCoreIface.skel kdevprojectiface.skel + KDevPartControllerIface.skel KDevCoreIface.skel kdevprojectiface.skel \ + filetemplate.cpp libkdevinterfaces_la_LDFLAGS = \ $(DB3LDFLAGS) \ @@ -37,7 +38,7 @@ kdevlanguagesupport.h kdevprojectmodel.h \ kdevmainwindow.h tag.h \ kdevmakefrontend.h kdevitemmodel.h \ - urlutil.h + urlutil.h filetemplate.h servicetypedir = $(kde_servicetypesdir) servicetype_DATA = \ --- trunk/KDE/kdevelop/lib/interfaces/domutil.cpp #463042:463043 @@ -15,12 +15,10 @@ #include "domutil.h" #include -#include -#include -//Added by qt3to4: +#include +#include #include - void DomUtil::makeEmpty( QDomElement& e ) { while( !e.firstChild().isNull() ) @@ -133,6 +131,18 @@ return map; } +QHash DomUtil::readHashEntry(const QDomDocument &doc, const QString& path) +{ + QHash hash; + QDomElement el = elementByPath(doc, path); + QDomElement subEl = el.firstChild().toElement(); + while (!subEl.isNull()) { + hash[subEl.tagName()] = subEl.firstChild().toText().data(); + subEl = subEl.nextSibling().toElement(); + } + return hash; +} + QDomElement DomUtil::namedChildElement( QDomElement& el, const QString& name ) { QDomElement child = el.namedItem( name ).toElement(); @@ -173,12 +183,24 @@ QMap::ConstIterator it; for (it = map.begin(); it != map.end(); ++it) { - kdDebug( 9010 ) << "writing " << basePath << ";" << it.key() << ";" << it.data() << endl; + kdDebug( 9010 ) << "writing " << basePath << ";" << it.key() << ";" << it.value() << endl; if( ! it.key().isEmpty() ) - writeEntry(doc, basePath + it.key(), it.data() ); + writeEntry(doc, basePath + it.key(), it.value() ); } } +void DomUtil::writeHashEntry(QDomDocument &doc, const QString &path, const QHash &hash) +{ + QString basePath( path + "/" ); + QHash::ConstIterator it; + for (it = hash.begin(); it != hash.end(); ++it) + { + kdDebug( 9010 ) << "writing " << basePath << ";" << it.key() << ";" << it.value() << endl; + if( ! it.key().isEmpty() ) + writeEntry(doc, basePath + it.key(), it.value() ); + } +} + void DomUtil::writeIntEntry(QDomDocument &doc, const QString &path, int value) { writeEntry(doc, path, QString::number(value)); --- trunk/KDE/kdevelop/lib/interfaces/domutil.h #463042:463043 @@ -14,10 +14,11 @@ #define _DOMUTIL_H_ #include -#include -#include -#include -#include +#include +#include +#include +#include +#include /** @file domutil.h @@ -78,6 +79,10 @@ */ static QMap readMapEntry(const QDomDocument &doc, const QString &path); /** + * Reads a string to string hash. See writeHashEntry() + */ + static QHash readHashEntry(const QDomDocument &doc, const QString &path); + /** * Retrieves an element by path, return null if any item along * the path does not exist. */ @@ -151,9 +156,14 @@ const PairList &value); /** * Writes a string to string map. This map is stored in a way, that it can be read with - * readMapEntry() and readEntry() + * readMapEntry() readHashEntry() and readEntry() */ static void writeMapEntry(QDomDocument &doc, const QString& path, const QMap &map); + /** + * Writes a string to string hash. This hash is stored in a way, that it can be read with + * readMapEntry() readHashEntry() and readEntry() + */ + static void writeHashEntry(QDomDocument &doc, const QString& path, const QHash &hash); /** * Resolves an extended path @@ -195,12 +205,12 @@ static QDomElement elementByPathExt(QDomDocument &doc, const QString &pathstring); /** - * Open file - filename - and set setContents of doc + * Open file @a filename and set setContents of @a doc */ static bool openDOMFile(QDomDocument &doc, QString filename); /** - * Store contents of doc in file - filename. Existing file will be truncated! + * Store contents of @a doc in file @a filename. Existing file will be truncated! */ static bool saveDOMFile(QDomDocument &doc, QString filename); --- trunk/KDE/kdevelop/lib/interfaces/kdevproject.cpp #463042:463043 @@ -29,12 +29,15 @@ #include #include #include "kdevprojectiface.h" +#include "filetemplate.h" struct KDevProject::Private { QMap m_absToRel; QStringList m_symlinkList; QTimer *m_timer; KDevProjectIface *m_iface; + QHash m_templExpandMap; + QHash m_templExpandMapXML; }; KDevProject::KDevProject(const KDevPluginInfo *info, QObject *parent) @@ -114,6 +117,7 @@ void KDevProject::openProject( const QString & /*dirName*/, const QString & /*projectName*/ ) { buildFileMap(); + readSubstitutionMap(); } QStringList KDevProject::symlinkProjectFiles( ) @@ -152,4 +156,22 @@ } } +void KDevProject::readSubstitutionMap() +{ + d->m_templExpandMap = DomUtil::readHashEntry(*projectDom(), "substmap"); + d->m_templExpandMapXML = FileTemplate::normalSubstMapToXML(d->m_templExpandMap); +} + +const QHash& KDevProject::substMap( SubstitutionMapTypes type ) +{ + switch( type ) + { + default: + case NormalFile: + return d->m_templExpandMap; + case XMLFile: + return d->m_templExpandMapXML; + } +} + #include "kdevproject.moc" --- trunk/KDE/kdevelop/lib/interfaces/kdevproject.h #463042:463043 @@ -38,6 +38,13 @@ class QTimer; +/** Types of substitution maps */ +enum SubstitutionMapTypes +{ + NormalFile, //!< For a normal file + XMLFile //!< For a xml file +}; + /** KDevelop project interface. Plugins implementing the KDevProject interfaces are used to manage projects. @@ -160,6 +167,12 @@ /**@return The list of files known to the project through symlinks.*/ virtual QStringList symlinkProjectFiles(); + /** Reread template substitution map from dom */ + virtual void readSubstitutionMap(); + + /**@return The template substitution map. */ + virtual const QHash& substMap( SubstitutionMapTypes type = NormalFile ); + private slots: void buildFileMap(); void slotBuildFileMap(); --- trunk/KDE/kdevelop/lib/util/Makefile.am #463042:463043 @@ -3,14 +3,14 @@ noinst_LTLIBRARIES = libkdevutil.la libkdevutil_la_SOURCES = \ - execcommand.cpp filetemplate.cpp kfiltermodel.cpp kdevtreeview.cpp \ + execcommand.cpp kfiltermodel.cpp kdevtreeview.cpp \ configwidgetproxy.cpp rurl.cpp kscriptactionmanager.cpp settings.cpp METASOURCES = AUTO kdevelopincludedir = $(includedir)/kdevelop/util kdevelopinclude_HEADERS = \ - execcommand.h filetemplate.h configwidgetproxy.h rurl.h \ + execcommand.h configwidgetproxy.h rurl.h \ kscriptactionmanager.h kfiltermodel.h kdevtreeview.h DOXYGEN_REFERENCES = dcop interfaces kdecore kdefx kdeui khtml kmdi kio kjs kparts kutils kdevextensions kdevinterfaces