From d1d666c9e08984c100ac0aab64cda5ab86681cdf Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@nokia.com> Date: Wed, 20 Jul 2011 13:45:53 +0200 Subject: [PATCH] QmlDesigner.rewriter: fix for assert In some cases we get a string and have to convert the string explicitly. Task-number: QTCREATORBUG-5503 Change-Id: I1008deffeb8ede54911f1a7031edd41b5827c010 Reviewed-on: http://codereview.qt.nokia.com/1842 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com> --- .../designercore/model/texttomodelmerger.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index e3cafdab66e..9f6a7642128 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -644,9 +644,13 @@ using namespace QmlDesigner::Internal; static inline bool smartVeryFuzzyCompare(QVariant value1, QVariant value2) { //we ignore slight changes on doubles and only check three digits - if ((value1.type() == QVariant::Double) && (value2.type() == QVariant::Double)) { - int a = value1.toDouble() * 1000; - int b = value2.toDouble() * 1000; + if ((value1.type() == QVariant::Double) || (value2.type() == QVariant::Double)) { + bool ok1, ok2; + int a = value1.toDouble(&ok1) * 1000; + int b = value2.toDouble(&ok2) * 1000; + + if (!ok1 || !ok2) + return false; if (qFuzzyCompare((qreal(a) / 1000), (qreal(b) / 1000))) { return true; @@ -657,8 +661,8 @@ static inline bool smartVeryFuzzyCompare(QVariant value1, QVariant value2) static inline bool equals(const QVariant &a, const QVariant &b) { - if (a.type() == QVariant::Double && b.type() == QVariant::Double) - return smartVeryFuzzyCompare(a.toDouble(), b.toDouble()); + if (smartVeryFuzzyCompare(a, b)) + return true; else return a == b; } -- GitLab