00001 /*************************************************************************** 00002 ** 00003 ** This file is part of QGpCoreTools. 00004 ** 00005 ** This library is free software; you can redistribute it and/or 00006 ** modify it under the terms of the GNU Lesser General Public 00007 ** License as published by the Free Software Foundation; either 00008 ** version 2.1 of the License, or (at your option) any later version. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00013 ** License for more details. 00014 ** 00015 ** You should have received a copy of the GNU Lesser General Public 00016 ** License along with this library; if not, write to the Free Software 00017 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ** 00019 ** See http://www.geopsy.org for more information. 00020 ** 00021 ** Created : 2007-11-25 00022 ** Authors : 00023 ** Marc Wathelet 00024 ** Marc Wathelet (LGIT, Grenoble, France) 00025 ** 00026 ***************************************************************************/ 00027 00028 #ifndef XMLGENERICITEM_H 00029 #define XMLGENERICITEM_H 00030 00031 #include "TreeContainer.h" 00032 #include "QGpCoreToolsDLLExport.h" 00033 00034 namespace QGpCoreTools { 00035 00036 class QGPCORETOOLS_EXPORT XMLGenericItem: public TreeContainer 00037 { 00038 public: 00039 XMLGenericItem(XMLGenericItem * parent=0); 00040 XMLGenericItem(const QString& tag, XMLGenericItem * parent=0); 00041 00042 inline XMLGenericItem * childAt(int index); 00043 inline const XMLGenericItem * childAt(int index) const; 00044 inline XMLGenericItem * parent(); 00045 inline const XMLGenericItem * parent() const; 00046 00047 void setEnabled(bool e) {_enabled=e;} 00048 bool isEnabled() const {return _enabled;} 00049 bool isParentEnabled() const; 00050 00051 const QVariant& value() const {return _value;} 00052 void setValue(const QVariant& v) {_value=v;} 00053 00054 void setTag(const QString& tag) {_tag=tag;} 00055 virtual const QString& xml_tagName() const {return _tag;} 00056 00057 const XMLSaveAttributes& attributes() const {return _attributes;} 00058 XMLSaveAttributes& attributes() {return _attributes;} 00059 virtual void xml_attributes(XML_ATTRIBUTES_ARGS) const; 00060 virtual bool xml_setAttributes(XML_SETATTRIBUTES_ARGS); 00061 void addAttribute(const QString& key, const QString& value=QString::null) {_attributes.add(key, value);} 00062 00063 QList<XMLGenericItem *> children(const QString& tag) const; 00064 void find(QList<XMLGenericItem *>& itemList, const XMLGenericItem * queryItem) const; 00065 protected: 00066 virtual TreeItem * createNewItem(TreeItem *) {return 0;} 00067 virtual XMLMember xml_member(XML_MEMBER_ARGS); 00068 virtual bool xml_setProperty(XML_SETPROPERTY_ARGS); 00069 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const; 00070 virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const; 00071 virtual bool xml_setBinaryData(XML_SETBINARYDATA_ARGS); 00072 private: 00073 bool _enabled; 00074 QString _tag; 00075 XMLSaveAttributes _attributes; 00076 QVariant _value; 00077 }; 00078 00079 inline const XMLGenericItem * XMLGenericItem::childAt(int index) const 00080 { 00081 TRACE; 00082 return static_cast<const XMLGenericItem *>(TreeContainer::childAt(index)); 00083 } 00084 00085 inline XMLGenericItem * XMLGenericItem::childAt(int index) 00086 { 00087 TRACE; 00088 return static_cast<XMLGenericItem *>(TreeContainer::childAt(index)); 00089 } 00090 00091 inline XMLGenericItem * XMLGenericItem::parent() 00092 { 00093 TRACE; 00094 return static_cast<XMLGenericItem *>(TreeContainer::parent()); 00095 } 00096 00097 inline const XMLGenericItem * XMLGenericItem::parent() const 00098 { 00099 TRACE; 00100 return static_cast<const XMLGenericItem *>(TreeContainer::parent()); 00101 } 00102 00103 } // namespace QGpCoreTools 00104 00105 #endif // XMLGENERICITEM_H