[qet] [4313] Forget file from previous comit |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4313
Author: blacksun
Date: 2016-01-08 18:44:55 +0100 (Fri, 08 Jan 2016)
Log Message:
-----------
Forget file from previous comit
Modified Paths:
--------------
trunk/sources/qetxml.cpp
trunk/sources/qetxml.h
Modified: trunk/sources/qetxml.cpp
===================================================================
--- trunk/sources/qetxml.cpp 2016-01-08 17:01:51 UTC (rev 4312)
+++ trunk/sources/qetxml.cpp 2016-01-08 17:44:55 UTC (rev 4313)
@@ -16,7 +16,9 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetxml.h"
+#include "nameslist.h"
#include <QPen>
+#include <QDir>
/**
* @brief QETXML::penToXml
@@ -75,3 +77,70 @@
pen.setWidthF(element.attribute("widthF", "1").toDouble());
return pen;
}
+
+/**
+ * @brief QETXML::fileSystemDirToXmlCollectionDir
+ * @param document : owner document of returned QDomElement, use to create the QDomElement.
+ * @param dir : file system direcory to convert to QDomElement directory
+ * @return A file system directory converted to a QDomElement directory ready to be inserted into a XmlElementCollection.
+ * If the QDomElement can't be created, return a null QDomElement.
+ */
+QDomElement QETXML::fileSystemDirToXmlCollectionDir(QDomDocument &document, const QDir &dir)
+{
+ if (!dir.exists()) return QDomElement();
+
+ QDomElement dir_element = document.createElement("category");
+ dir_element.setAttribute("name", dir.dirName());
+
+ //Get the traduction of this directory
+ QFile qet_dir(dir.filePath("qet_directory"));
+ if (qet_dir.exists() && qet_dir.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ //Get the content of the file
+ QDomDocument trad_document;
+ if (trad_document.setContent(&qet_dir))
+ {
+ QDomElement root = trad_document.documentElement();
+ if (root.tagName() == "qet-directory")
+ {
+ NamesList nl;
+ nl.fromXml(root);
+ dir_element.appendChild(nl.toXml(document));
+ }
+ }
+ qet_dir.close();
+ }
+
+ return dir_element;
+}
+
+/**
+ * @brief QETXML::fileSystemElementToXmlCollectionElement
+ * @param document : owner document of returned QDomElement, use to create the QDomElement.
+ * @param file : file system element file to convert to QDomElement;
+ * @return A file system element converted to a QDomElement ready to be inserted into a XmlElementCollection
+ * If the QDomElement can't be created, return a null QDomElement
+ */
+QDomElement QETXML::fileSystemElementToXmlCollectionElement(QDomDocument &document, QFile &file)
+{
+ if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ QDomDocument docu;
+ if (docu.setContent(&file))
+ {
+ QFileInfo fi(file);
+ QDomElement dom_element = document.createElement("element");
+ dom_element.setAttribute("name", fi.fileName());
+ dom_element.appendChild(docu.documentElement());
+ file.close();
+ return dom_element;
+ }
+ else
+ {
+ file.close();
+ return QDomElement();
+ }
+ }
+ else
+ return QDomElement();
+}
Modified: trunk/sources/qetxml.h
===================================================================
--- trunk/sources/qetxml.h 2016-01-08 17:01:51 UTC (rev 4312)
+++ trunk/sources/qetxml.h 2016-01-08 17:44:55 UTC (rev 4313)
@@ -18,9 +18,13 @@
#ifndef QETXML_H
#define QETXML_H
-#include <QDomDocument>
+#include <QDomElement>
#include <QPen>
+class QDomDocument;
+class QDir;
+class QFile;
+
/**
*This namespace contain some function to use xml with QET.
*/
@@ -29,6 +33,9 @@
QDomElement penToXml(QDomDocument &parent_document, QPen pen);
QPen penFromXml (const QDomElement &element);
+ QDomElement fileSystemDirToXmlCollectionDir (QDomDocument &document, const QDir &dir);
+ QDomElement fileSystemElementToXmlCollectionElement (QDomDocument &document, QFile &file);
+
}
#endif // QETXML_H