32 QDomElement element = parent_document.createElement(
"pen");
37 case Qt::SolidLine : style =
"SolidLine";
break;
38 case Qt::DashLine : style =
"DashLine";
break;
39 case Qt::DotLine : style =
"DotLine";
break;
40 case Qt::DashDotLine : style =
"DashDotLine";
break;
41 case Qt::DashDotDotLine : style =
"DashDotDotLine";
break;
42 case Qt::CustomDashLine : style =
"CustomDashLine";
break;
43 default : style =
"Unknown";
break;
46 element.setAttribute(
"style", style);
47 element.setAttribute(
"color", pen.color().name());
48 element.setAttribute(
"widthF", QString::number(pen.widthF()));
63 if (!(!element.isNull() && element.tagName() ==
"pen"))
65 pen.setStyle(Qt::DashLine);
69 QString style = element.attribute(
"style",
"DashLine");
70 if (style ==
"SolidLine") pen.setStyle(Qt::SolidLine);
71 else if (style ==
"DashLine") pen.setStyle(Qt::DashLine);
72 else if (style ==
"DotLine") pen.setStyle(Qt::DotLine);
73 else if (style ==
"DashDotLine") pen.setStyle(Qt::DashDotLine);
74 else if (style ==
"DashDotDotLine") pen.setStyle(Qt::DashDotDotLine);
75 else if (style ==
"CustomDashLine") pen.setStyle(Qt::CustomDashLine),
76 pen.setDashPattern( QVector<qreal>() << 10 << 10 );
77 else pen.setStyle(Qt::DashLine);
79 pen.setColor(QColor(element.attribute(
"color",
"#000000")));
80 pen.setWidthF(element.attribute(
"widthF",
"1").toDouble());
93 QDomElement element = parent_document.createElement(
"brush");
96 switch (brush.style())
98 case Qt::NoBrush : style =
"NoBrush";
break;
99 case Qt::SolidPattern : style =
"SolidPattern";
break;
100 case Qt::Dense1Pattern : style =
"Dense1Pattern";
break;
101 case Qt::Dense2Pattern : style =
"Dense2Pattern";
break;
102 case Qt::Dense3Pattern : style =
"Dense3Pattern";
break;
103 case Qt::Dense4Pattern : style =
"Dense4Pattern";
break;
104 case Qt::Dense5Pattern : style =
"Dense5Pattern";
break;
105 case Qt::Dense6Pattern : style =
"Dense6Pattern";
break;
106 case Qt::Dense7Pattern : style =
"Dense7Pattern";
break;
107 case Qt::HorPattern : style =
"HorPattern";
break;
108 case Qt::VerPattern : style =
"VerPattern";
break;
109 case Qt::CrossPattern : style =
"CrossPattern";
break;
110 case Qt::BDiagPattern : style =
"BDiagPattern";
break;
111 case Qt::FDiagPattern : style =
"FDiagPattern";
break;
112 case Qt::DiagCrossPattern : style =
"DiagCrossPattern";
break;
113 default : style =
"Unknown";
break;
116 element.setAttribute(
"style", style);
117 element.setAttribute(
"color", brush.color().name());
132 if (!(!element.isNull() && element.tagName() ==
"brush"))
return brush;
134 QString style = element.attribute(
"style",
"NoBrush");
135 if (style ==
"NoBrush") brush.setStyle(Qt::NoBrush);
136 else if (style ==
"SolidPattern") brush.setStyle(Qt::SolidPattern);
137 else if (style ==
"Dense1Pattern") brush.setStyle(Qt::Dense1Pattern);
138 else if (style ==
"Dense2Pattern") brush.setStyle(Qt::Dense2Pattern);
139 else if (style ==
"Dense3Pattern") brush.setStyle(Qt::Dense3Pattern);
140 else if (style ==
"Dense4Pattern") brush.setStyle(Qt::Dense4Pattern);
141 else if (style ==
"Dense5Pattern") brush.setStyle(Qt::Dense5Pattern);
142 else if (style ==
"Dense6Pattern") brush.setStyle(Qt::Dense6Pattern);
143 else if (style ==
"Dense7Pattern") brush.setStyle(Qt::Dense7Pattern);
144 else if (style ==
"HorPattern") brush.setStyle(Qt::HorPattern);
145 else if (style ==
"VerPattern") brush.setStyle(Qt::VerPattern);
146 else if (style ==
"CrossPattern") brush.setStyle(Qt::CrossPattern);
147 else if (style ==
"BDiagPattern") brush.setStyle(Qt::BDiagPattern);
148 else if (style ==
"FDiagPattern") brush.setStyle(Qt::FDiagPattern);
149 else if (style ==
"DiagCrossPattern") brush.setStyle(Qt::DiagCrossPattern);
150 else if (style ==
"Unknown") brush.setStyle(Qt::NoBrush);
152 brush.setColor(QColor(element.attribute(
"color",
"#000000")));
167 if (!dir.exists())
return QDomElement();
169 QDomElement dir_element = document.createElement(
"category");
170 dir_element.setAttribute(
"name", rename.isNull()? dir.dirName() : rename);
173 QFile qet_dir(dir.filePath(
"qet_directory"));
174 if (qet_dir.exists() && qet_dir.open(QIODevice::ReadOnly | QIODevice::Text))
177 QDomDocument trad_document;
178 if (trad_document.setContent(&qet_dir))
180 QDomElement root = trad_document.documentElement();
181 if (root.tagName() ==
"qet-directory")
185 dir_element.appendChild(
nl.toXml(document));
205 if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text))
208 if (docu.setContent(&file))
211 QDomElement dom_element = document.createElement(
"element");
212 dom_element.setAttribute(
"name", rename.isEmpty()? fi.fileName() : rename);
213 dom_element.appendChild(docu.documentElement());
220 return QDomElement();
224 return QDomElement();
237 QFile file(file_path);
240 bool file_opening = file.open(QIODevice::WriteOnly);
245 *error_message = QString(
QObject::tr(
"Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.",
246 "error message when attempting to write an XML file")
247 ).arg(file_path).arg(file.error());
252 QTextStream out(&file);
253 out.setCodec(
"UTF-8");
254 out.setGenerateByteOrderMark(
false);
255 out << xml_document.toString(4);
271 QDomElement element = document.createElement(tag_name);
272 QDomText text = document.createTextNode(value);
274 element.appendChild(text);
QDomElement penToXml(QDomDocument &parent_document, const QPen &pen)
QETXML::penToXml Write attribute of a QPen in xml element.
bool writeXmlFile(const QDomDocument &xml_document, const QString &file_path, QString *error_message=nullptr)
QETXML::writeXmlFile Export an XML document to an UTF-8 text file indented with 4 spaces...
QDomElement brushToXml(QDomDocument &parent_document, const QBrush &brush)
QETXML::brushToXml Write attribute of a QBrush in xml element.
QPen penFromXml(const QDomElement &element)
QETXML::penFromXml Build a QPen from a xml description.
QDomElement fileSystemDirToXmlCollectionDir(QDomDocument &document, const QDir &dir, const QString &rename=QString())
QDomElement fileSystemElementToXmlCollectionElement(QDomDocument &document, QFile &file, const QString &rename=QString())
QDomElement textToDomElement(QDomDocument &document, const QString &tag_name, const QString &value)
QETXML::textToDomElement Return a QDomElement, created from , with tag name and text ...
QBrush brushFromXml(const QDomElement &element)
QETXML::brushFromXml Build a QBrush from a xml description.