From: konrad Date: Sat, 24 Jan 2009 14:42:47 +0000 (+0000) Subject: added DOM query class X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d28c7bc3f21d35f290efd8ef323b068cc82edb66;p=konrad%2Fsmoke.git added DOM query class git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@246 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/domquery.cpp b/src/domquery.cpp new file mode 100644 index 0000000..04ed351 --- /dev/null +++ b/src/domquery.cpp @@ -0,0 +1,55 @@ +// +// C++ Implementation: domquery +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "domquery.h" + +MDomQuery::MDomQuery(const QDomElement&start,QString path) +{ + //split query + QStringList ql=path.split("/",QString::SkipEmptyParts); + //determine start mode and initialize list + MDomNodeList ndlst; + if(path.startsWith("//")){ + QDomDocument doc=start.ownerDocument(); + if(ql.size()<1){ + qDebug("MDomQuery: // query must not be empty!"); + return; + } + if(ql[0]=="*"){ + qDebug("MDomQuery: // query must not start with wildcard *."); + return; + } + ndlst=doc.elementsByTagName(ql[0]); + ql.removeFirst(); + }else + if(path.startsWith("/")){ + QDomElement root=start.ownerDocument().documentElement(); + if(ql.size()<1){ + //hmm, guess what the user really wanted (assume "/ *" ) + m_result<, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_DOMQUERY_H +#define MAGICSMOKE_DOMQUERY_H + + +#include +#include +#include + +/**Helper class: more flexible version of QDomNodeList*/ +class MDomNodeList:public QList +{ + public: + MDomNodeList(){} + MDomNodeList(const MDomNodeList&l):QList(l){} + MDomNodeList(const QList&l):QList(l){} + MDomNodeList(const QDomNodeList&l){for(int i=0;i +mousereturn all child elements of the current element that are called "mouse" +\@mousereturn all attribute nodes of the current element that are called "mouse" +*returns all child elements of the current element +\@*returns all attributes of the current element +/*returns the root element of the document irrespective of name +/mousereturns the root element of the document if it has the tag name "mouse" or an empty list +/*/mousereturns all elements directly below the root element that are called "mouse" +//mousereturns all elements in the document that are called "mouse" +mouse/\@trap/doorsyntax error, attributes cannot have children + +*/ +class MDomQuery +{ + public: + /**creates the query object and executes the query*/ + MDomQuery(const QDomElement&start,QString path); + + /**returns the search result as a single string, if there were multiple matches, they are separated by spaces*/ + QString toString()const; + /**returns the search result as a list of strings, one string element per match*/ + QStringList toStringList()const; + /**returns the result as a list of DOM nodes*/ + MDomNodeList toNodeList()const{return m_result;} + + /**cast to QString: see toString()*/ + operator QString()const{return toString();} + /**cast to QStringList: see toStringList()*/ + operator QStringList()const{return toStringList();} + /**cast to DOM node list: see toNodeList()*/ + operator MDomNodeList()const{return m_result;} + private: + MDomNodeList m_result; +}; + +#endif diff --git a/src/smoke.pro b/src/smoke.pro index 0e79167..b05c470 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -50,7 +50,8 @@ SOURCES = \ office.cpp \ centbox.cpp \ moneylog.cpp \ - autoupdate.cpp + autoupdate.cpp \ + domquery.cpp HEADERS = \ keygen.h \ @@ -79,7 +80,8 @@ HEADERS = \ office.h \ centbox.h \ moneylog.h \ - autoupdate.h + autoupdate.h \ + domquery.h #some PHP files are listed in this file to scan them for translatable items #use genphpscan.sh to regenerate it.