Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDomUtils Namespace Reference

Namespaces

namespace  Private
 

Functions

QDomElement findElementByAttribute (QDomNode parent, const QString &tag, const QString &attribute, const QString &value)
 
bool findOnlyElement (const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)
 
template<template< class ... > class Container, typename T , typename E , typename F , typename ... Args>
std::enable_if< KritaUtils::is_appendable_container< Container< T, Args... > >::value, bool >::type loadValue (const QDomElement &e, Container< T, Args... > *array, const E &env1, const F &env2)
 
template<template< class ... > class Container, typename T , typename E , typename ... Args>
std::enable_if< KritaUtils::is_appendable_container< Container< T, Args... > >::value, bool >::type loadValue (const QDomElement &e, Container< T, Args... > *array, const E &env=std::tuple<>())
 
bool loadValue (const QDomElement &e, double *v)
 
bool loadValue (const QDomElement &e, float *v)
 
bool loadValue (const QDomElement &e, KisLazyFillTools::KeyStroke *stroke, const KoColorSpace *colorSpace, const QPoint &offset)
 
bool loadValue (const QDomElement &e, QColor *value)
 
bool loadValue (const QDomElement &e, QPoint *pt)
 
bool loadValue (const QDomElement &e, QPointF *pt)
 
bool loadValue (const QDomElement &e, QRect *rc)
 
bool loadValue (const QDomElement &e, QRectF *rc)
 
bool loadValue (const QDomElement &e, QSize *size)
 
bool loadValue (const QDomElement &e, QString *value)
 
bool loadValue (const QDomElement &e, QTransform *t)
 
bool loadValue (const QDomElement &e, QVector3D *pt)
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, bool >::type loadValue (const QDomElement &e, T *value)
 
bool loadValue (const QDomElement &parent, const QString &tag, KisTimeSpan *range)
 
template<typename T , typename E , typename F >
bool loadValue (const QDomElement &parent, const QString &tag, T *value, const E &env1, const F &env2)
 
template<typename T , typename E = std::tuple<>>
bool loadValue (const QDomElement &parent, const QString &tag, T *value, const E &env=E())
 
template<typename T , typename E >
std::enable_if< std::is_empty< E >::value, bool >::type loadValue (const QDomElement &parent, T *value, const E &)
 
QString qColorToQString (QColor color)
 
QColor qStringToQColor (QString colorString)
 
bool removeElements (QDomElement &parent, const QString &tag)
 
template<template< class... > class Container, typename T , typename ... Args>
std::enable_if< KritaUtils::is_container< Container< T, Args... > >::value, void >::type saveValue (QDomElement *parent, const QString &tag, const Container< T, Args... > &array)
 
void saveValue (QDomElement *parent, const QString &tag, const KisLazyFillTools::KeyStroke &stroke)
 
void saveValue (QDomElement *parent, const QString &tag, const KisTimeSpan &range)
 
void saveValue (QDomElement *parent, const QString &tag, const QColor &c)
 
void saveValue (QDomElement *parent, const QString &tag, const QPoint &pt)
 
void saveValue (QDomElement *parent, const QString &tag, const QPointF &pt)
 
void saveValue (QDomElement *parent, const QString &tag, const QRect &rc)
 
void saveValue (QDomElement *parent, const QString &tag, const QRectF &rc)
 
void saveValue (QDomElement *parent, const QString &tag, const QSize &size)
 
void saveValue (QDomElement *parent, const QString &tag, const QTransform &t)
 
void saveValue (QDomElement *parent, const QString &tag, const QVector3D &pt)
 
template<typename T >
void saveValue (QDomElement *parent, const QString &tag, T value)
 
double toDouble (const QString &str, bool *ok=nullptr)
 
int toInt (const QString &str, bool *ok=nullptr)
 
QString toString (const QString &value)
 
QString toString (double value)
 
QString toString (float value)
 
template<typename T >
QString toString (T value)
 

Function Documentation

◆ findElementByAttribute()

KRITAGLOBAL_EXPORT QDomElement KisDomUtils::findElementByAttribute ( QDomNode parent,
const QString & tag,
const QString & attribute,
const QString & value )

Definition at line 283 of file kis_dom_utils.cpp.

287{
288 QDomElement e;
289 for (e = parent.firstChildElement(tag); !e.isNull(); e = e.nextSiblingElement(tag)) {
290 if (value == e.attribute(attribute, "<undefined>")) {
291 return e;
292 }
293 }
294
295 return QDomElement();
296}
float value(const T *src, size_t ch)

References value().

◆ findOnlyElement()

bool KRITAGLOBAL_EXPORT KisDomUtils::findOnlyElement ( const QDomElement & parent,
const QString & tag,
QDomElement * el,
QStringList * errorMessages = 0 )

Find an element with tag tag which is a child of parent. The element should be the only element with the provided tag in this parent.

Returns
true is the element with tag is found and it is unique

Definition at line 124 of file kis_dom_utils.cpp.

125{
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());
129 if (errorMessages) {
130 *errorMessages << msg;
131 } else {
132 warnKrita << msg;
133 }
134
135 return false;
136 }
137
138 *el = list.at(0).toElement();
139 return true;
140}
#define warnKrita
Definition kis_debug.h:87

References warnKrita.

◆ loadValue() [1/19]

template<template< class ... > class Container, typename T , typename E , typename F , typename ... Args>
std::enable_if< KritaUtils::is_appendable_container< Container< T, Args... > >::value, bool >::type KisDomUtils::loadValue ( const QDomElement & e,
Container< T, Args... > * array,
const E & env1,
const F & env2 )

Definition at line 285 of file kis_dom_utils.h.

286{
287 if (!Private::checkType(e, "array")) return false;
288
289 QDomElement child = e.firstChildElement();
290 while (!child.isNull()) {
291 T value;
292 if (!loadValue(child, &value, env1, env2)) return false;
293 array->push_back(value);
294 child = child.nextSiblingElement();
295 }
296 return true;
297}

References KisDomUtils::Private::checkType(), loadValue(), and value().

◆ loadValue() [2/19]

template<template< class ... > class Container, typename T , typename E , typename ... Args>
std::enable_if< KritaUtils::is_appendable_container< Container< T, Args... > >::value, bool >::type KisDomUtils::loadValue ( const QDomElement & e,
Container< T, Args... > * array,
const E & env = std::tuple<>() )

Load an array from an XML element, which is a child of parent and has a tag tag.

Returns
true if the object is successfully loaded and is unique
See also
saveValue()

Definition at line 269 of file kis_dom_utils.h.

270{
271 if (!Private::checkType(e, "array")) return false;
272
273 QDomElement child = e.firstChildElement();
274 while (!child.isNull()) {
275 T value;
276 if (!loadValue(child, &value, env)) return false;
277 array->push_back(value);
278 child = child.nextSiblingElement();
279 }
280 return true;
281}

References KisDomUtils::Private::checkType(), loadValue(), and value().

◆ loadValue() [3/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
double * v )

Definition at line 173 of file kis_dom_utils.cpp.

174{
175 if (!Private::checkType(e, "value")) return false;
176 *v = toDouble(e.attribute("value", "0"));
177 return true;
178}
qreal v
double toDouble(const quint8 *data, int channelpos)

References KisDomUtils::Private::checkType(), toDouble(), and v.

◆ loadValue() [4/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
float * v )

Load an object from an XML element, which is a child of parent and has a tag tag.

Returns
true if the object is successfully loaded and is unique
See also
saveValue()

Definition at line 166 of file kis_dom_utils.cpp.

167{
168 if (!Private::checkType(e, "value")) return false;
169 *v = toDouble(e.attribute("value", "0"));
170 return true;
171}

References KisDomUtils::Private::checkType(), toDouble(), and v.

◆ loadValue() [5/19]

bool KRITALIBKRA_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
KisLazyFillTools::KeyStroke * stroke,
const KoColorSpace * colorSpace,
const QPoint & offset )

Definition at line 36 of file kis_colorize_dom_utils.cpp.

37 {
38 using namespace KRA;
39
40 if (!Private::checkType(e, COLORIZE_KEYSTROKE)) return false;
41
42 stroke->isTransparent = toInt(e.attribute(COLORIZE_KEYSTROKE_IS_TRANSPARENT, "0"));
43
44 QByteArray colorData = QByteArray::fromBase64(e.attribute(COLORBYTEDATA).toLatin1());
45 KoColor color((const quint8*)colorData.data(), colorSpace);
46 stroke->color = color;
47
48 stroke->dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
49 stroke->dev->moveTo(offset);
50
51 return true;
52 }
void moveTo(qint32 x, qint32 y)
int toInt(const QString &str, bool *ok=nullptr)
static KoColorSpaceRegistry * instance()

References KisDomUtils::Private::checkType(), KisLazyFillTools::KeyStroke::color, KisLazyFillTools::KeyStroke::dev, KoColorSpaceRegistry::instance(), KisLazyFillTools::KeyStroke::isTransparent, KisPaintDevice::moveTo(), and toInt().

◆ loadValue() [6/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QColor * value )

Definition at line 276 of file kis_dom_utils.cpp.

277{
278 if (!Private::checkType(e, "qcolor")) return false;
279 value->setNamedColor(e.attribute("value", "#FFFF0000"));
280 return true;
281}

References KisDomUtils::Private::checkType(), and value().

◆ loadValue() [7/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QPoint * pt )

Definition at line 214 of file kis_dom_utils.cpp.

215{
216 if (!Private::checkType(e, "point")) return false;
217
218 pt->setX(toInt(e.attribute("x", "0")));
219 pt->setY(toInt(e.attribute("y", "0")));
220
221 return true;
222}

References KisDomUtils::Private::checkType(), and toInt().

◆ loadValue() [8/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QPointF * pt )

Definition at line 224 of file kis_dom_utils.cpp.

225{
226 if (!Private::checkType(e, "pointf")) return false;
227
228 pt->setX(toDouble(e.attribute("x", "0")));
229 pt->setY(toDouble(e.attribute("y", "0")));
230
231 return true;
232}

References KisDomUtils::Private::checkType(), and toDouble().

◆ loadValue() [9/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QRect * rc )

Definition at line 190 of file kis_dom_utils.cpp.

191{
192 if (!Private::checkType(e, "rect")) return false;
193
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")));
198
199 return true;
200}

References KisDomUtils::Private::checkType(), and toInt().

◆ loadValue() [10/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QRectF * rc )

Definition at line 202 of file kis_dom_utils.cpp.

203{
204 if (!Private::checkType(e, "rectf")) return false;
205
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")));
210
211 return true;
212}

References KisDomUtils::Private::checkType(), and toInt().

◆ loadValue() [11/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QSize * size )

Definition at line 180 of file kis_dom_utils.cpp.

181{
182 if (!Private::checkType(e, "size")) return false;
183
184 size->setWidth(toInt(e.attribute("w", "0")));
185 size->setHeight(toInt(e.attribute("h", "0")));
186
187 return true;
188}

References KisDomUtils::Private::checkType(), and toInt().

◆ loadValue() [12/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QString * value )

Definition at line 269 of file kis_dom_utils.cpp.

270{
271 if (!Private::checkType(e, "value")) return false;
272 *value = e.attribute("value", "no-value");
273 return true;
274}

References KisDomUtils::Private::checkType(), and value().

◆ loadValue() [13/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QTransform * t )

Definition at line 245 of file kis_dom_utils.cpp.

246{
247 if (!Private::checkType(e, "transform")) return false;
248
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"));
252
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"));
256
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"));
260
261 t->setMatrix(
262 m11, m12, m13,
263 m21, m22, m23,
264 m31, m32, m33);
265
266 return true;
267}

References KisDomUtils::Private::checkType(), and toDouble().

◆ loadValue() [14/19]

bool KRITAGLOBAL_EXPORT KisDomUtils::loadValue ( const QDomElement & e,
QVector3D * pt )

Definition at line 234 of file kis_dom_utils.cpp.

235{
236 if (!Private::checkType(e, "vector3d")) return false;
237
238 pt->setX(toDouble(e.attribute("x", "0")));
239 pt->setY(toDouble(e.attribute("y", "0")));
240 pt->setZ(toDouble(e.attribute("z", "0")));
241
242 return true;
243}

References KisDomUtils::Private::checkType(), and toDouble().

◆ loadValue() [15/19]

template<typename T >
std::enable_if< std::is_arithmetic< T >::value, bool >::type KisDomUtils::loadValue ( const QDomElement & e,
T * value )

Load a scalar value from an XML element, which is a child of parent and has a tag tag.

Returns
true if the object is successfully loaded and is unique
See also
saveValue()

Definition at line 239 of file kis_dom_utils.h.

240{
241 if (!Private::checkType(e, "value")) return false;
242
243 QVariant v(e.attribute("value", "no-value"));
244 *value = v.value<T>();
245 return true;
246}

References KisDomUtils::Private::checkType(), v, and value().

◆ loadValue() [16/19]

bool KRITAIMAGE_EXPORT KisDomUtils::loadValue ( const QDomElement & parent,
const QString & tag,
KisTimeSpan * range )

Definition at line 115 of file kis_time_span.cpp.

116{
117 QDomElement e;
118 if (!findOnlyElement(parent, tag, &e)) return false;
119
120 if (!Private::checkType(e, "timerange")) return false;
121
122 int start = toInt(e.attribute("from", "-1"));
123 int end = toInt(e.attribute("to", "-1"));
124
125 if (start == -1) {
126 *range = KisTimeSpan();
127 } else if (end == -1) {
128 *range = KisTimeSpan::infinite(start);
129 } else {
130 *range = KisTimeSpan::fromTimeToTime(start, end);
131 }
132 return true;
133}
static KisTimeSpan infinite(int start)
static KisTimeSpan fromTimeToTime(int start, int end)
bool findOnlyElement(const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)

References KisDomUtils::Private::checkType(), findOnlyElement(), KisTimeSpan::fromTimeToTime(), KisTimeSpan::infinite(), and toInt().

◆ loadValue() [17/19]

template<typename T , typename E , typename F >
bool KisDomUtils::loadValue ( const QDomElement & parent,
const QString & tag,
T * value,
const E & env1,
const F & env2 )

Definition at line 309 of file kis_dom_utils.h.

310{
311 QDomElement e;
312 if (!findOnlyElement(parent, tag, &e)) return false;
313
314 return loadValue(e, value, env1, env2);
315}

References findOnlyElement(), loadValue(), and value().

◆ loadValue() [18/19]

template<typename T , typename E = std::tuple<>>
bool KisDomUtils::loadValue ( const QDomElement & parent,
const QString & tag,
T * value,
const E & env = E() )

Definition at line 300 of file kis_dom_utils.h.

301{
302 QDomElement e;
303 if (!findOnlyElement(parent, tag, &e)) return false;
304
305 return loadValue(e, value, env);
306}

References findOnlyElement(), loadValue(), and value().

◆ loadValue() [19/19]

template<typename T , typename E >
std::enable_if< std::is_empty< E >::value, bool >::type KisDomUtils::loadValue ( const QDomElement & parent,
T * value,
const E &  )

A special adapter method that makes vector- and tag-based methods work with environment parameter uniformly.

Definition at line 254 of file kis_dom_utils.h.

254 {
255 return loadValue(parent, value);
256}

References loadValue(), and value().

◆ qColorToQString()

QString KisDomUtils::qColorToQString ( QColor color)
inline

Definition at line 116 of file kis_dom_utils.h.

117 {
118 // color channels will usually have 0-255
119 QString customColor = QString::number(color.red()).append(",")
120 .append(QString::number(color.green())).append(",")
121 .append(QString::number(color.blue())).append(",")
122 .append(QString::number(color.alpha()));
123
124 return customColor;
125 }

◆ qStringToQColor()

QColor KisDomUtils::qStringToQColor ( QString colorString)
inline

Definition at line 127 of file kis_dom_utils.h.

128 {
129 QStringList colorComponents = colorString.split(',');
130 return QColor(colorComponents[0].toInt(), colorComponents[1].toInt(), colorComponents[2].toInt(), colorComponents[3].toInt());
131 }

References toInt().

◆ removeElements()

KRITAGLOBAL_EXPORT bool KisDomUtils::removeElements ( QDomElement & parent,
const QString & tag )

Definition at line 142 of file kis_dom_utils.cpp.

142 {
143 QDomNodeList list = parent.elementsByTagName(tag);
144 KIS_SAFE_ASSERT_RECOVER_NOOP(list.size() <= 1);
145
146 for (int i = 0; i < list.size(); i++) {
147 parent.removeChild(list.at(i));
148 }
149
150 return list.size() > 0;
151}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP.

◆ saveValue() [1/12]

template<template< class... > class Container, typename T , typename ... Args>
std::enable_if< KritaUtils::is_container< Container< T, Args... > >::value, void >::type KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const Container< T, Args... > & array )

Save a vector of values into an XML tree. A child for parent is created and assigned a tag tag. The values in the array should have a type supported by saveValue() overrides. The corresponding vector can be fetched from the XML using loadValue() later.

See also
loadValue()

Definition at line 180 of file kis_dom_utils.h.

181{
182 QDomDocument doc = parent->ownerDocument();
183 QDomElement e = doc.createElement(tag);
184 parent->appendChild(e);
185
186 e.setAttribute("type", "array");
187
188 int i = 0;
189 Q_FOREACH (const T &v, array) {
190 saveValue(&e, QString("item_%1").arg(i++), v);
191 }
192}

References saveValue(), and v.

◆ saveValue() [2/12]

void KRITALIBKRA_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const KisLazyFillTools::KeyStroke & stroke )

Definition at line 16 of file kis_colorize_dom_utils.cpp.

17 {
18 using namespace KRA;
19
20 QDomDocument doc = parent->ownerDocument();
21 QDomElement e = doc.createElement(tag);
22 parent->appendChild(e);
23
24 e.setAttribute("type", COLORIZE_KEYSTROKE);
25
26 QString fileName = tag;
27 fileName.replace("item", COLORIZE_KEYSTROKE);
28
29 e.setAttribute(FILE_NAME, fileName);
30 e.setAttribute(COLORIZE_KEYSTROKE_IS_TRANSPARENT, stroke.isTransparent);
31
32 QByteArray colorData = QByteArray::fromRawData((const char*)stroke.color.data(), stroke.color.colorSpace()->pixelSize());
33 e.setAttribute(COLORBYTEDATA, QString(colorData.toBase64()));
34 }
virtual quint32 pixelSize() const =0
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82

References KisLazyFillTools::KeyStroke::color, KoColor::colorSpace(), KoColor::data(), KisLazyFillTools::KeyStroke::isTransparent, and KoColorSpace::pixelSize().

◆ saveValue() [3/12]

void KRITAIMAGE_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const KisTimeSpan & range )

Definition at line 97 of file kis_time_span.cpp.

98{
99 QDomDocument doc = parent->ownerDocument();
100 QDomElement e = doc.createElement(tag);
101 parent->appendChild(e);
102
103 e.setAttribute("type", "timerange");
104
105 if (range.isValid()) {
106 e.setAttribute("from", toString(range.start()));
107
108 if (!range.isInfinite()) {
109 e.setAttribute("to", toString(range.end()));
110 }
111 }
112}
int start() const
bool isInfinite() const
int end() const
bool isValid() const
QString toString(const QString &value)

References KisTimeSpan::end(), KisTimeSpan::isInfinite(), KisTimeSpan::isValid(), KisTimeSpan::start(), and toString().

◆ saveValue() [4/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QColor & c )

Definition at line 114 of file kis_dom_utils.cpp.

115{
116 QDomDocument doc = parent->ownerDocument();
117 QDomElement e = doc.createElement(tag);
118 parent->appendChild(e);
119
120 e.setAttribute("type", "qcolor");
121 e.setAttribute("value", c.name(QColor::HexArgb));
122}

◆ saveValue() [5/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QPoint & pt )

Definition at line 56 of file kis_dom_utils.cpp.

57{
58 QDomDocument doc = parent->ownerDocument();
59 QDomElement e = doc.createElement(tag);
60 parent->appendChild(e);
61
62 e.setAttribute("type", "point");
63
64 e.setAttribute("x", toString(pt.x()));
65 e.setAttribute("y", toString(pt.y()));
66}

References toString().

◆ saveValue() [6/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QPointF & pt )

Definition at line 68 of file kis_dom_utils.cpp.

69{
70 QDomDocument doc = parent->ownerDocument();
71 QDomElement e = doc.createElement(tag);
72 parent->appendChild(e);
73
74 e.setAttribute("type", "pointf");
75
76 e.setAttribute("x", toString(pt.x()));
77 e.setAttribute("y", toString(pt.y()));
78}

References toString().

◆ saveValue() [7/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QRect & rc )

Save a value of type QRect into an XML tree. A child for parent is created and assigned a tag tag. The corresponding value can be fetched from the XML using loadValue() later.

See also
loadValue()

Definition at line 28 of file kis_dom_utils.cpp.

29{
30 QDomDocument doc = parent->ownerDocument();
31 QDomElement e = doc.createElement(tag);
32 parent->appendChild(e);
33
34 e.setAttribute("type", "rect");
35
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()));
40}

References toString().

◆ saveValue() [8/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QRectF & rc )

Definition at line 42 of file kis_dom_utils.cpp.

43{
44 QDomDocument doc = parent->ownerDocument();
45 QDomElement e = doc.createElement(tag);
46 parent->appendChild(e);
47
48 e.setAttribute("type", "rectf");
49
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()));
54}

References toString().

◆ saveValue() [9/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QSize & size )

Definition at line 16 of file kis_dom_utils.cpp.

17{
18 QDomDocument doc = parent->ownerDocument();
19 QDomElement e = doc.createElement(tag);
20 parent->appendChild(e);
21
22 e.setAttribute("type", "size");
23
24 e.setAttribute("w", toString(size.width()));
25 e.setAttribute("h", toString(size.height()));
26}

References toString().

◆ saveValue() [10/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QTransform & t )

Definition at line 93 of file kis_dom_utils.cpp.

94{
95 QDomDocument doc = parent->ownerDocument();
96 QDomElement e = doc.createElement(tag);
97 parent->appendChild(e);
98
99 e.setAttribute("type", "transform");
100
101 e.setAttribute("m11", toString(t.m11()));
102 e.setAttribute("m12", toString(t.m12()));
103 e.setAttribute("m13", toString(t.m13()));
104
105 e.setAttribute("m21", toString(t.m21()));
106 e.setAttribute("m22", toString(t.m22()));
107 e.setAttribute("m23", toString(t.m23()));
108
109 e.setAttribute("m31", toString(t.m31()));
110 e.setAttribute("m32", toString(t.m32()));
111 e.setAttribute("m33", toString(t.m33()));
112}

References toString().

◆ saveValue() [11/12]

void KRITAGLOBAL_EXPORT KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
const QVector3D & pt )

Definition at line 80 of file kis_dom_utils.cpp.

81{
82 QDomDocument doc = parent->ownerDocument();
83 QDomElement e = doc.createElement(tag);
84 parent->appendChild(e);
85
86 e.setAttribute("type", "vector3d");
87
88 e.setAttribute("x", toString(pt.x()));
89 e.setAttribute("y", toString(pt.y()));
90 e.setAttribute("z", toString(pt.z()));
91}

References toString().

◆ saveValue() [12/12]

template<typename T >
void KisDomUtils::saveValue ( QDomElement * parent,
const QString & tag,
T value )

Save a value of a scalar type into an XML tree. A child for parent is created and assigned a tag tag. The corresponding value can be fetched from the XML using loadValue() later.

See also
loadValue()

Definition at line 160 of file kis_dom_utils.h.

161{
162 QDomDocument doc = parent->ownerDocument();
163 QDomElement e = doc.createElement(tag);
164 parent->appendChild(e);
165
166 e.setAttribute("type", "value");
167 e.setAttribute("value", toString(value));
168}

References toString(), and value().

◆ toDouble()

double KisDomUtils::toDouble ( const QString & str,
bool * ok = nullptr )
inline

A special workaround to handle ','/'.' decimal point in different locales. Added for backward compatibility, because we used to save qreals directly using

e.setAttribute("w", (qreal)value),

which did local-aware conversion.

Definition at line 82 of file kis_dom_utils.h.

82 {
83 bool ok_locale = false;
84 double value = 0;
85
86 QLocale c(QLocale::German);
87
98 value = str.toDouble(&ok_locale);
99 if (!ok_locale) {
100 value = c.toDouble(str, &ok_locale);
101 }
102
103 if (!ok_locale && ok == nullptr) {
104 warnKrita << "WARNING: KisDomUtils::toDouble failed:" << ppVar(str);
105 value = 0.0;
106 }
107
108 if (ok != nullptr) {
109 *ok = ok_locale;
110 }
111
112 return value;
113 }
#define ppVar(var)
Definition kis_debug.h:155

References ppVar, value(), and warnKrita.

◆ toInt()

int KisDomUtils::toInt ( const QString & str,
bool * ok = nullptr )
inline

Definition at line 59 of file kis_dom_utils.h.

59 {
60 bool ok_locale = false;
61 int value = 0;
62
63 QLocale c(QLocale::German);
64
65 value = str.toInt(&ok_locale);
66 if (!ok_locale) {
67 value = c.toInt(str, &ok_locale);
68 }
69
70 if (!ok_locale && ok == nullptr) {
71 warnKrita << "WARNING: KisDomUtils::toInt failed:" << ppVar(str);
72 value = 0;
73 }
74
75 if (ok != nullptr) {
76 *ok = ok_locale;
77 }
78
79 return value;
80 }

References ppVar, value(), and warnKrita.

◆ toString() [1/4]

QString KisDomUtils::toString ( const QString & value)
inline

Definition at line 30 of file kis_dom_utils.h.

30 {
31 return value;
32 }

References value().

◆ toString() [2/4]

QString KisDomUtils::toString ( double value)
inline

Definition at line 49 of file kis_dom_utils.h.

49 {
50 QString str;
51 QTextStream stream;
53 stream.setString(&str, QIODevice::WriteOnly);
54 stream.setRealNumberPrecision(15);
55 stream << value;
56 return str;
57 }
void setUtf8OnStream(QTextStream &stream)

References KisPortingUtils::setUtf8OnStream(), and value().

◆ toString() [3/4]

QString KisDomUtils::toString ( float value)
inline

Definition at line 39 of file kis_dom_utils.h.

39 {
40 QString str;
41 QTextStream stream;
43 stream.setString(&str, QIODevice::WriteOnly);
44 stream.setRealNumberPrecision(FLT_DIG);
45 stream << value;
46 return str;
47 }

References KisPortingUtils::setUtf8OnStream(), and value().

◆ toString() [4/4]

template<typename T >
QString KisDomUtils::toString ( T value)
inline

Definition at line 35 of file kis_dom_utils.h.

35 {
36 return QString::number(value);
37 }

References value().