16void saveValue(QDomElement *parent,
const QString &tag,
const QSize &size)
18 QDomDocument doc = parent->ownerDocument();
19 QDomElement e = doc.createElement(tag);
20 parent->appendChild(e);
22 e.setAttribute(
"type",
"size");
24 e.setAttribute(
"w",
toString(size.width()));
25 e.setAttribute(
"h",
toString(size.height()));
28void saveValue(QDomElement *parent,
const QString &tag,
const QRect &rc)
30 QDomDocument doc = parent->ownerDocument();
31 QDomElement e = doc.createElement(tag);
32 parent->appendChild(e);
34 e.setAttribute(
"type",
"rect");
36 e.setAttribute(
"x",
toString(rc.x()));
37 e.setAttribute(
"y",
toString(rc.y()));
38 e.setAttribute(
"w",
toString(rc.width()));
39 e.setAttribute(
"h",
toString(rc.height()));
42void saveValue(QDomElement *parent,
const QString &tag,
const QRectF &rc)
44 QDomDocument doc = parent->ownerDocument();
45 QDomElement e = doc.createElement(tag);
46 parent->appendChild(e);
48 e.setAttribute(
"type",
"rectf");
50 e.setAttribute(
"x",
toString(rc.x()));
51 e.setAttribute(
"y",
toString(rc.y()));
52 e.setAttribute(
"w",
toString(rc.width()));
53 e.setAttribute(
"h",
toString(rc.height()));
56void saveValue(QDomElement *parent,
const QString &tag,
const QPoint &pt)
58 QDomDocument doc = parent->ownerDocument();
59 QDomElement e = doc.createElement(tag);
60 parent->appendChild(e);
62 e.setAttribute(
"type",
"point");
64 e.setAttribute(
"x",
toString(pt.x()));
65 e.setAttribute(
"y",
toString(pt.y()));
68void saveValue(QDomElement *parent,
const QString &tag,
const QPointF &pt)
70 QDomDocument doc = parent->ownerDocument();
71 QDomElement e = doc.createElement(tag);
72 parent->appendChild(e);
74 e.setAttribute(
"type",
"pointf");
76 e.setAttribute(
"x",
toString(pt.x()));
77 e.setAttribute(
"y",
toString(pt.y()));
80void saveValue(QDomElement *parent,
const QString &tag,
const QVector3D &pt)
82 QDomDocument doc = parent->ownerDocument();
83 QDomElement e = doc.createElement(tag);
84 parent->appendChild(e);
86 e.setAttribute(
"type",
"vector3d");
88 e.setAttribute(
"x",
toString(pt.x()));
89 e.setAttribute(
"y",
toString(pt.y()));
90 e.setAttribute(
"z",
toString(pt.z()));
93void saveValue(QDomElement *parent,
const QString &tag,
const QTransform &t)
95 QDomDocument doc = parent->ownerDocument();
96 QDomElement e = doc.createElement(tag);
97 parent->appendChild(e);
99 e.setAttribute(
"type",
"transform");
101 e.setAttribute(
"m11",
toString(t.m11()));
102 e.setAttribute(
"m12",
toString(t.m12()));
103 e.setAttribute(
"m13",
toString(t.m13()));
105 e.setAttribute(
"m21",
toString(t.m21()));
106 e.setAttribute(
"m22",
toString(t.m22()));
107 e.setAttribute(
"m23",
toString(t.m23()));
109 e.setAttribute(
"m31",
toString(t.m31()));
110 e.setAttribute(
"m32",
toString(t.m32()));
111 e.setAttribute(
"m33",
toString(t.m33()));
114void saveValue(QDomElement *parent,
const QString &tag,
const QColor &c)
116 QDomDocument doc = parent->ownerDocument();
117 QDomElement e = doc.createElement(tag);
118 parent->appendChild(e);
120 e.setAttribute(
"type",
"qcolor");
121 e.setAttribute(
"value", c.name(QColor::HexArgb));
126 QDomNodeList list = parent.elementsByTagName(tag);
127 if (list.size() != 1 || !list.at(0).isElement()) {
128 QString msg = i18n(
"Could not find \"%1\" XML tag in \"%2\"", tag, parent.tagName());
130 *errorMessages << msg;
138 *el = list.at(0).toElement();
143 QDomNodeList list = parent.elementsByTagName(tag);
146 for (
int i = 0; i < list.size(); i++) {
147 parent.removeChild(list.at(i));
150 return list.size() > 0;
154 bool checkType(
const QDomElement &e,
const QString &expectedType)
156 QString type = e.attribute(
"type",
"unknown-type");
157 if (type != expectedType) {
158 warnKrita << i18n(
"Error: incorrect type (%2) for value %1. Expected %3", e.tagName(), type, expectedType);
169 *
v =
toDouble(e.attribute(
"value",
"0"));
176 *
v =
toDouble(e.attribute(
"value",
"0"));
184 size->setWidth(
toInt(e.attribute(
"w",
"0")));
185 size->setHeight(
toInt(e.attribute(
"h",
"0")));
194 rc->setX(
toInt(e.attribute(
"x",
"0")));
195 rc->setY(
toInt(e.attribute(
"y",
"0")));
196 rc->setWidth(
toInt(e.attribute(
"w",
"0")));
197 rc->setHeight(
toInt(e.attribute(
"h",
"0")));
206 rc->setX(
toInt(e.attribute(
"x",
"0")));
207 rc->setY(
toInt(e.attribute(
"y",
"0")));
208 rc->setWidth(
toInt(e.attribute(
"w",
"0")));
209 rc->setHeight(
toInt(e.attribute(
"h",
"0")));
218 pt->setX(
toInt(e.attribute(
"x",
"0")));
219 pt->setY(
toInt(e.attribute(
"y",
"0")));
228 pt->setX(
toDouble(e.attribute(
"x",
"0")));
229 pt->setY(
toDouble(e.attribute(
"y",
"0")));
238 pt->setX(
toDouble(e.attribute(
"x",
"0")));
239 pt->setY(
toDouble(e.attribute(
"y",
"0")));
240 pt->setZ(
toDouble(e.attribute(
"z",
"0")));
249 qreal m11 =
toDouble(e.attribute(
"m11",
"1.0"));
250 qreal m12 =
toDouble(e.attribute(
"m12",
"0.0"));
251 qreal m13 =
toDouble(e.attribute(
"m13",
"0.0"));
253 qreal m21 =
toDouble(e.attribute(
"m21",
"0.0"));
254 qreal m22 =
toDouble(e.attribute(
"m22",
"1.0"));
255 qreal m23 =
toDouble(e.attribute(
"m23",
"0.0"));
257 qreal m31 =
toDouble(e.attribute(
"m31",
"0.0"));
258 qreal m32 =
toDouble(e.attribute(
"m32",
"0.0"));
259 qreal m33 =
toDouble(e.attribute(
"m33",
"1.0"));
272 *
value = e.attribute(
"value",
"no-value");
279 value->setNamedColor(e.attribute(
"value",
"#FFFF0000"));
285 const QString &attribute,
286 const QString &
value)
289 for (e = parent.firstChildElement(tag); !e.isNull(); e = e.nextSiblingElement(tag)) {
290 if (
value == e.attribute(attribute,
"<undefined>")) {
295 return QDomElement();
float value(const T *src, size_t ch)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
bool checkType(const QDomElement &e, const QString &expectedType)
void saveValue(QDomElement *parent, const QString &tag, const QSize &size)
bool removeElements(QDomElement &parent, const QString &tag)
bool findOnlyElement(const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)
double toDouble(const QString &str, bool *ok=nullptr)
int toInt(const QString &str, bool *ok=nullptr)
QDomElement findElementByAttribute(QDomNode parent, const QString &tag, const QString &attribute, const QString &value)
bool loadValue(const QDomElement &e, float *v)
QString toString(const QString &value)