diff --git a/libs/global/kis_dom_utils.h b/libs/global/kis_dom_utils.h index 8b8d9d2c3e..a3a095b046 100644 --- a/libs/global/kis_dom_utils.h +++ b/libs/global/kis_dom_utils.h @@ -1,295 +1,295 @@ /* * Copyright (c) 2014 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __KIS_DOM_UTILS_H #define __KIS_DOM_UTILS_H #include #include #include #include #include #include #include #include #include "kritaglobal_export.h" #include "kis_debug.h" namespace KisDomUtils { inline QString toString(const QString &value) { return value; } template inline QString toString(T value) { return QString::number(value); } inline QString toString(float value) { QString str; QTextStream stream; stream.setString(&str, QIODevice::WriteOnly); stream.setRealNumberPrecision(FLT_DIG); stream << value; return str; } inline QString toString(double value) { QString str; QTextStream stream; stream.setString(&str, QIODevice::WriteOnly); - stream.setRealNumberPrecision(11); + stream.setRealNumberPrecision(15); stream << value; return str; } inline int toInt(const QString &str) { bool ok = false; int value = 0; QLocale c(QLocale::German); value = str.toInt(&ok); if (!ok) { value = c.toInt(str, &ok); } if (!ok) { warnKrita << "WARNING: KisDomUtils::toInt failed:" << ppVar(str); value = 0; } return value; } inline double toDouble(const QString &str) { bool ok = false; double value = 0; QLocale c(QLocale::German); /** * 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. */ value = str.toDouble(&ok); if (!ok) { value = c.toDouble(str, &ok); } if (!ok) { warnKrita << "WARNING: KisDomUtils::toDouble failed:" << ppVar(str); value = 0; } return value; } inline QString qColorToQString(QColor color) { // color channels will usually have 0-255 QString customColor = QString::number(color.red()).append(",") .append(QString::number(color.green())).append(",") .append(QString::number(color.blue())).append(",") .append(QString::number(color.alpha())); return customColor; } inline QColor qStringToQColor(QString colorString) { QStringList colorComponents = colorString.split(','); return QColor(colorComponents[0].toInt(), colorComponents[1].toInt(), colorComponents[2].toInt(), colorComponents[3].toInt()); } /** * Save a value of type QRect into an XML tree. A child for \p parent * is created and assigned a tag \p tag. The corresponding value can * be fetched from the XML using loadValue() later. * * \see loadValue() */ void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QRect &rc); void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QSize &size); void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QPoint &pt); void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QPointF &pt); void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QVector3D &pt); void KRITAGLOBAL_EXPORT saveValue(QDomElement *parent, const QString &tag, const QTransform &t); /** * Save a value of a scalar type into an XML tree. A child for \p parent * is created and assigned a tag \p tag. The corresponding value can * be fetched from the XML using loadValue() later. * * \see loadValue() */ template void saveValue(QDomElement *parent, const QString &tag, T value) { QDomDocument doc = parent->ownerDocument(); QDomElement e = doc.createElement(tag); parent->appendChild(e); e.setAttribute("type", "value"); e.setAttribute("value", toString(value)); } /** * Save a vector of values into an XML tree. A child for \p parent is * created and assigned a tag \p 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 loadValue() */ template