File indexing completed on 2024-05-05 04:03:26
0001 /*************************************************************************** 0002 cmapfilefilterxml.h 0003 ------------------- 0004 begin : Tue Nov 19 2002 0005 copyright : (C) 2002 by Kmud Developer Team 0006 email : kmud-devel@kmud.de 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #ifndef CMAPFILEFILTERXML_H 0019 #define CMAPFILEFILTERXML_H 0020 0021 #include "../cmapfilefilterbase.h" 0022 #include "../cmapelement.h" 0023 0024 #include <qfile.h> 0025 #include <qstring.h> 0026 0027 class CMapManager; 0028 0029 /** 0030 *@author Kmud Developer Team 0031 */ 0032 0033 class CMapFileFilterXML : public CMapFileFilterBase 0034 { 0035 public: 0036 CMapFileFilterXML(CMapManager *manager); 0037 ~CMapFileFilterXML() override; 0038 0039 /** This returns name of the import/export filter. This should be kept small 0040 * @return The Name of the filter */ 0041 QString getName(void) override; 0042 /** This returns a discription of the import/export filter 0043 * @return The discription */ 0044 QString getDescription(void) override; 0045 /** This returns the extension of the filename that will be loaded,created 0046 * @return The exstension */ 0047 QString getExtension(void) override; 0048 /** This returns the pattern extension of the filename that will be loaded,created 0049 * @return The exstension */ 0050 QString getPatternExtension(void) override; 0051 0052 0053 /** This method will return true or false depending on if it's a export filter 0054 * @return True if this is a export filter, otherwise false */ 0055 bool supportSave(void) override { return true; }; 0056 /** This method will return true or false depending on if it's a import filter 0057 * @return True if this is a import filter, otherwise false */ 0058 bool supportLoad(void) override { return true; }; 0059 /** Is this the native format? */ 0060 bool isNative() override { return true; }; 0061 0062 /** This method should be reimplemented if this is a to be a export filter. It 0063 * is called to save the map data 0064 * @param url The url of the file to be saved 0065 * @return 0, The file was saved succesfully 0066 * @return -1, The file could not be created 0067 */ 0068 int saveData(const QString &filename) override; 0069 /** This method should be reimplemeted if this is to be a import filter. It is 0070 * called to load the map data 0071 * @param filename The url of the file to be loaded 0072 * @return 0 , The file was loaded without problems 0073 * -1 , Could not open the file 0074 * -2 , If the file is corrupt 0075 */ 0076 int loadData(const QString &filename) override; 0077 0078 private: 0079 int loadXMLData(const QByteArray & buffer); 0080 0081 QString saveXMLFile(); 0082 0083 /** 0084 * This method is used to save element properties that are stored in plugins 0085 * @param element The element being saved 0086 * @param doc The XML document 0087 * @param elProperties The xml properties of the element 0088 */ 0089 void savePluginPropertiesForElement(CMapElement *element,QDomDocument *doc,QDomElement *elProperties); 0090 /** 0091 * This method is used to load element properties that are stored in plugins 0092 * @param element The Element being loaded 0093 * @param elProperties the xml properties of the element 0094 */ 0095 void loadPluginPropertiesForElement(CMapElement *element,QDomElement *elProperties); 0096 0097 0098 /** 0099 * This method is used to save the zone and all of it's sub elements 0100 * @param doc The document being the elemnts are saved too 0101 * @param rootNode The XML node to save the zone to 0102 * @param zone The zone to save 0103 */ 0104 void saveZone(QDomDocument *doc,QDomNode *rootNode,CMapZone *zone); 0105 0106 /** 0107 * This method is used to save all the paths in a zone 0108 * @param doc The document being the paths are saved too 0109 * @param rootNode The XML node to save the paths to 0110 * @param zone The zone to save 0111 */ 0112 void saveZoneLinks(QDomDocument *doc,QDomElement *pathsNode,QDomElement *linksNode,CMapZone *zone); 0113 0114 /** 0115 * This method is used to load the zone and all of it's sub elememnts 0116 * @param zoneNode The XML node to load the zone from 0117 * @param intoLevel The level to create the zone in 0118 * @return 0 , The file was loaded without problems 0119 * -2 , If the file is corrupt 0120 */ 0121 int loadZone(QDomElement *zoneNode); 0122 0123 /** This method is used to load all of the paths 0124 * @param pathsNode The XML node to load the paths from 0125 * @return 0 , The file was loaded without problems 0126 * -2 , If the file is corrupt 0127 */ 0128 int loadPaths(QDomElement *pathsNode); 0129 0130 /** This method is used to load all of the links 0131 * @param pathsNode The XML node to load the links from 0132 * @return 0 , The file was loaded without problems 0133 * -2 , If the file is corrupt 0134 */ 0135 int loadLinks(QDomElement *pathsNode); 0136 0137 /** 0138 * This method is used to read a child XML object of a XML object 0139 * @param parent The parent XML object 0140 * @param key The name of the child 0141 * @return The child node 0142 */ 0143 QDomElement readChildElement(QDomElement *parent,QString key); 0144 0145 }; 0146 0147 #endif