summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-14 11:01:37 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-14 11:03:51 (GMT)
commitb770651f19741907cd415ea9ad6e087cb32cc948 (patch)
treeecc163e8b33af66454b84ca7f9159d11d6f0cd91 /src/gui/text
parent51ce8a80acebc67ef09d506d89a2ee1972377877 (diff)
downloadQt-b770651f19741907cd415ea9ad6e087cb32cc948.zip
Qt-b770651f19741907cd415ea9ad6e087cb32cc948.tar.gz
Qt-b770651f19741907cd415ea9ad6e087cb32cc948.tar.bz2
QVariant: added toFloat and toReal
Made better use of qreal all over the place. We were previously using QVariant::toDouble a lot. That is triggering unnecessary conversions between float and double on embedded. Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qcssparser.cpp13
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp4
-rw-r--r--src/gui/text/qtextformat.cpp7
3 files changed, 11 insertions, 13 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index e0af6d2..181ec7e 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -382,10 +382,7 @@ LengthData ValueExtractor::lengthValue(const Value& v)
if (data.unit != LengthData::None)
s.chop(2);
- bool ok;
- data.number = s.toDouble(&ok);
- if (!ok)
- data.number = 0;
+ data.number = s.toDouble();
return data;
}
@@ -711,7 +708,7 @@ static ColorData parseColorValue(Value v)
for (int i = 0; i < qMin(colorDigits.count(), 7); i += 2) {
if (colorDigits.at(i).type == Value::Percentage) {
- colorDigits[i].variant = colorDigits.at(i).variant.toDouble() * 255. / 100.;
+ colorDigits[i].variant = colorDigits.at(i).variant.toReal() * (255. / 100.);
colorDigits[i].type = Value::Number;
} else if (colorDigits.at(i).type != Value::Number) {
return ColorData();
@@ -788,7 +785,7 @@ static BrushData parseBrushValue(const Value &v, const QPalette &pal)
ColorData cd = parseColorValue(color);
if(cd.type == ColorData::Role)
dependsOnThePalette = true;
- stops.append(QGradientStop(stop.variant.toDouble(), colorFromData(cd, pal)));
+ stops.append(QGradientStop(stop.variant.toReal(), colorFromData(cd, pal)));
} else {
parser.next();
Value value;
@@ -1079,8 +1076,8 @@ static bool setFontSizeFromValue(Value value, QFont *font, int *fontSizeAdjustme
if (s.endsWith(QLatin1String("pt"), Qt::CaseInsensitive)) {
s.chop(2);
value.variant = s;
- if (value.variant.convert(QVariant::Double)) {
- font->setPointSizeF(value.variant.toDouble());
+ if (value.variant.convert((QVariant::Type)qMetaTypeId<qreal>())) {
+ font->setPointSizeF(value.variant.toReal());
valid = true;
}
} else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) {
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index cfec8e9..e26961f 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -198,8 +198,8 @@ public:
if (v.isNull()) {
return cellPadding;
} else {
- Q_ASSERT(v.type() == QVariant::Double);
- return QFixed::fromReal(v.toDouble() * deviceScale);
+ Q_ASSERT(v.userType() == QVariant::Double || v.userType() == QMetaType::Float);
+ return QFixed::fromReal(v.toReal() * deviceScale);
}
}
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 8e9b892..075f2ff 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -271,6 +271,7 @@ static uint variantHash(const QVariant &variant)
case QVariant::Invalid: return 0;
case QVariant::Bool: return variant.toBool();
case QVariant::Int: return variant.toInt();
+ case QMetaType::Float: return static_cast<int>(variant.toFloat());
case QVariant::Double: return static_cast<int>(variant.toDouble());
case QVariant::String: return qHash(variant.toString());
case QVariant::Color: return qHash(qvariant_cast<QColor>(variant).rgb());
@@ -325,7 +326,7 @@ void QTextFormatPrivate::recalcFont() const
f.setFamily(props.at(i).value.toString());
break;
case QTextFormat::FontPointSize:
- f.setPointSizeF(props.at(i).value.toDouble());
+ f.setPointSizeF(props.at(i).value.toReal());
break;
case QTextFormat::FontPixelSize:
f.setPixelSize(props.at(i).value.toInt());
@@ -352,10 +353,10 @@ void QTextFormatPrivate::recalcFont() const
f.setStrikeOut(props.at(i).value.toBool());
break;
case QTextFormat::FontLetterSpacing:
- f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toDouble());
+ f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
break;
case QTextFormat::FontWordSpacing:
- f.setWordSpacing(props.at(i).value.toDouble());
+ f.setWordSpacing(props.at(i).value.toReal());
break;
case QTextFormat::FontCapitalization:
f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));