From 3c8f4512df30dee4a867a498fff6d2b27b881e4b Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Fri, 14 Aug 2009 17:04:42 +0200 Subject: QVariant: more work on avoinding conversion between float and doubles we call QVariant::toReal instead of toDouble when needed --- src/3rdparty/phonon/ds9/effect.cpp | 3 +-- src/3rdparty/phonon/phonon/effectwidget.cpp | 13 +++++++------ src/gui/text/qtexthtmlparser.cpp | 5 ++--- src/svg/qsvghandler.cpp | 7 +++---- src/xmlpatterns/data/qatomicvalue.cpp | 4 +++- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/3rdparty/phonon/ds9/effect.cpp b/src/3rdparty/phonon/ds9/effect.cpp index dc4ac3d..104a3c1 100644 --- a/src/3rdparty/phonon/ds9/effect.cpp +++ b/src/3rdparty/phonon/ds9/effect.cpp @@ -138,8 +138,7 @@ namespace Phonon ComPointer params(filter, IID_IMediaParams); Q_ASSERT(params); - MP_DATA data = float(v.toDouble()); - params->SetParam(p.id(), data); + params->SetParam(p.id(), v.toFloat()); } } diff --git a/src/3rdparty/phonon/phonon/effectwidget.cpp b/src/3rdparty/phonon/phonon/effectwidget.cpp index 99478f7..8f105f2 100644 --- a/src/3rdparty/phonon/phonon/effectwidget.cpp +++ b/src/3rdparty/phonon/phonon/effectwidget.cpp @@ -111,7 +111,7 @@ void EffectWidgetPrivate::autogenerateUi() #endif QWidget *control = 0; - switch (para.type()) { + switch (para.userType()) { case QVariant::String: { QComboBox *cb = new QComboBox(q); @@ -157,19 +157,20 @@ void EffectWidgetPrivate::autogenerateUi() QObject::connect(sb, SIGNAL(valueChanged(int)), q, SLOT(_k_setIntParameter(int))); } break; + case QMetaType::Float: case QVariant::Double: { - const double minValue = (para.minimumValue().type() == QVariant::Double ? - para.minimumValue().toDouble() : DEFAULT_MIN); - const double maxValue = (para.maximumValue().type() == QVariant::Double ? - para.maximumValue().toDouble() : DEFAULT_MAX); + const qreal minValue = para.minimumValue().canConvert(QVariant::Double) ? + para.minimumValue().toReal(&ok) : DEFAULT_MIN; + const qreal maxValue = para.maximumValue().canConvert(QVariant::Double) ? + para.maximumValue().toReal(&ok) : DEFAULT_MAX; if (minValue == -1. && maxValue == 1.) { //Special case values between -1 and 1.0 to use a slider for improved usability QSlider *slider = new QSlider(Qt::Horizontal, q); control = slider; slider->setRange(-SLIDER_RANGE, +SLIDER_RANGE); - slider->setValue(int(SLIDER_RANGE * value.toDouble())); + slider->setValue(int(SLIDER_RANGE * value.toReal())); slider->setTickPosition(QSlider::TicksBelow); slider->setTickInterval(TICKINTERVAL); QObject::connect(slider, SIGNAL(valueChanged(int)), q, SLOT(_k_setSliderParameter(int))); diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 8910394..92b2d4e 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1443,14 +1443,13 @@ static bool setFloatAttribute(qreal *destination, const QString &value) static void setWidthAttribute(QTextLength *width, QString value) { - qreal realVal; bool ok = false; - realVal = value.toDouble(&ok); + qreal realVal = value.toDouble(&ok); if (ok) { *width = QTextLength(QTextLength::FixedLength, realVal); } else { value = value.trimmed(); - if (!value.isEmpty() && value.at(value.length() - 1) == QLatin1Char('%')) { + if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) { value.chop(1); realVal = value.toDouble(&ok); if (ok) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 3b5bd0d..5e07181 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -1740,14 +1740,13 @@ static void parseOpacity(QSvgNode *node, const QSvgAttributes &attributes, QSvgHandler *) { - QString value = attributes.value(QLatin1String("opacity")).toString(); - value = value.trimmed(); + const QString value = attributes.value(QLatin1String("opacity")).toString().trimmed(); bool ok = false; - qreal op = value.toDouble(&ok); + qreal op = value.toReal(&ok); if (ok) { - QSvgOpacityStyle *opacity = new QSvgOpacityStyle(qMin(qreal(1.0), qMax(qreal(0.0), op))); + QSvgOpacityStyle *opacity = new QSvgOpacityStyle(qBound(qreal(0.0), op, qreal(1.0))); node->appendStyleProperty(opacity, someId(attributes)); } } diff --git a/src/xmlpatterns/data/qatomicvalue.cpp b/src/xmlpatterns/data/qatomicvalue.cpp index 24f1a01..8559c80 100644 --- a/src/xmlpatterns/data/qatomicvalue.cpp +++ b/src/xmlpatterns/data/qatomicvalue.cpp @@ -134,7 +134,7 @@ Item AtomicValue::toXDM(const QVariant &value) Q_ASSERT_X(value.isValid(), Q_FUNC_INFO, "QVariants sent to Patternist must be valid."); - switch(value.type()) + switch(value.userType()) { case QVariant::Char: /* Fallthrough. A single codepoint is a string in XQuery. */ @@ -166,6 +166,8 @@ Item AtomicValue::toXDM(const QVariant &value) return Date::fromDateTime(QDateTime(value.toDate(), QTime(), Qt::UTC)); case QVariant::DateTime: return DateTime::fromDateTime(value.toDateTime()); + case QMetaType::Float: + return Item(Double::fromValue(value.toFloat())); case QVariant::Double: return Item(Double::fromValue(value.toDouble())); default: -- cgit v0.12