Subversion Repositories Scribus

Rev

Rev 22607 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17223 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
 
8
#include "scclocale.h"
9
#include "scdomelement.h"
10
 
11
ScDomElement::ScDomElement(const QDomElement &elem) : QDomElement(elem)
12
{
13
 
14
}
15
 
16
int ScDomElement::valueAsInt (const QString& attrName, int def) const
17
{
18
        int retValue = def;
19
        QString attr = attribute(attrName);
20
        if (!attr.isEmpty())
21
        {
22
                bool success = false;
23
                int intVal = attr.toInt(&success);
24
                if (success)
25
                        retValue = intVal;
26
        }
27
        return retValue;
28
}
29
 
30
int ScDomElement::valueAsInt (const QString& attrName, int min, int max, int def) const
31
{
32
        int value = valueAsInt(attrName, def);
33
        return qMin(max, qMax(value, min));
34
}
35
 
36
uint ScDomElement::valueAsUInt (const QString& attrName, uint def) const
37
{
38
        uint retValue = def;
39
        QString attr = attribute(attrName);
40
        if (!attr.isEmpty())
41
        {
42
                bool success = false;
43
                uint intVal = attr.toUInt(&success);
44
                if (success)
45
                        retValue = intVal;
46
        }
47
        return retValue;
48
}
49
 
50
uint ScDomElement::valueAsUInt (const QString& attrName, uint min, uint max, uint def) const
51
{
52
        uint value = valueAsUInt(attrName, def);
53
        return qMin(max, qMax(value, min));
54
}
55
 
56
double ScDomElement::valueAsDouble (const QString& attrName, double def) const
57
{
58
        double retValue = def;
59
        QString attr = attribute(attrName);
60
        if (!attr.isEmpty())
61
                retValue = ScCLocale::toDoubleC(attr, def);
62
        return retValue;
63
}
64
 
65
double ScDomElement::valueAsDouble (const QString& attrName, double min, double max, double def) const
66
{
67
        double value = valueAsDouble(attrName, def);
68
        return qMin(max, qMax(value, min));
69
}