25 #if QT_VERSION >= 0x040000 26 # include <QDomElement> 28 # include <QStringList> 31 # include <qapplication.h> 34 # include <qstringlist.h> 46 static void warning(
const QString& message)
48 #if QT_VERSION >= 0x040000 49 qWarning(
"%s", message.toLatin1().constData());
51 qWarning(
"%s", message.latin1());
56 static float floatFromDom(
const QDomElement& e,
const QString& attribute,
float defValue)
58 float value = defValue;
59 if (e.hasAttribute(attribute)) {
60 const QString s = e.attribute(attribute);
62 value = s.toFloat(&ok);
64 warning(
"Bad float syntax for attribute \""+attribute+
"\" in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
68 warning(
"\""+attribute+
"\" attribute missing in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
74 warning(
"Warning, attribute \""+attribute+
"\" initialized to Not a Number in \""+e.tagName()+
"\"");
80 static double doubleFromDom(
const QDomElement& e,
const QString& attribute,
double defValue)
82 double value = defValue;
83 if (e.hasAttribute(attribute)) {
84 const QString s = e.attribute(attribute);
86 value = s.toDouble(&ok);
88 warning(
"Bad double syntax for attribute \""+attribute+
"\" in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
92 warning(
"\""+attribute+
"\" attribute missing in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
98 warning(
"Warning, attribute \""+attribute+
"\" initialized to Not a Number in \""+e.tagName()+
"\"");
104 static int intFromDom(
const QDomElement& e,
const QString& attribute,
int defValue)
106 int value = defValue;
107 if (e.hasAttribute(attribute))
109 const QString s = e.attribute(attribute);
115 warning(
"Bad integer syntax for attribute \""+attribute+
"\" in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
118 warning(
"\""+attribute+
"\" attribute missing in initialization of \""+e.tagName()+
"\". Setting value to "+QString::number(value)+
".");
122 static bool boolFromDom(
const QDomElement& e,
const QString& attribute,
bool defValue)
124 bool value = defValue;
125 if (e.hasAttribute(attribute))
127 const QString s = e.attribute(attribute);
128 #if QT_VERSION >= 0x040000 129 if (s.toLower() == QString(
"true"))
131 if (s.lower() == QString(
"true"))
134 #if QT_VERSION >= 0x040000 135 else if (s.toLower() == QString(
"false"))
137 else if (s.lower() == QString(
"false"))
142 warning(
"Bad boolean syntax for attribute \""+attribute+
"\" in initialization of \""+e.tagName()+
"\" (should be \"true\" or \"false\").");
143 warning(
"Setting value to "+(value?QString(
"true."):QString(
"false.")));
147 warning(
"\""+attribute+
"\" attribute missing in initialization of \""+e.tagName()+
"\". Setting value to "+(value?QString(
"true."):QString(
"false.")));
151 static QDomElement
QColorDomElement(
const QColor& color,
const QString& name, QDomDocument& doc)
153 QDomElement de = doc.createElement(name);
154 de.setAttribute(
"red", QString::number(color.red()));
155 de.setAttribute(
"green", QString::number(color.green()));
156 de.setAttribute(
"blue", QString::number(color.blue()));
163 QStringList attribute;
164 attribute <<
"red" <<
"green" <<
"blue";
165 #if QT_VERSION >= 0x040000 166 for (
int i=0; i<attribute.count(); ++i)
168 for (
unsigned int i=0; i<attribute.count(); ++i)
171 return QColor(color[0], color[1], color[2]);
static QDomElement QColorDomElement(const QColor &color, const QString &name, QDomDocument &doc)
static void warning(const QString &message)
static QColor QColorFromDom(const QDomElement &e)
static bool boolFromDom(const QDomElement &e, const QString &attribute, bool defValue)
static double doubleFromDom(const QDomElement &e, const QString &attribute, double defValue)
static int intFromDom(const QDomElement &e, const QString &attribute, int defValue)
static float floatFromDom(const QDomElement &e, const QString &attribute, float defValue)