Commit 6b19e159 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.rewriter: fixing compare function

Comparing doubles is hard.
I forgot to round properly.
I also added some early rejects.

Task-number: QTCREATORBUG-5503
Change-Id: I959abbe28a312aea63a170d9c769b5555ac6a30e
Reviewed-on: http://codereview.qt.nokia.com/2032

Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent d943015c
......@@ -646,13 +646,20 @@ 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)) {
bool ok1, ok2;
int a = value1.toDouble(&ok1) * 1000;
int b = value2.toDouble(&ok2) * 1000;
qreal a = value1.toDouble(&ok1);
qreal b = value2.toDouble(&ok2);
if (!ok1 || !ok2)
return false;
if (qFuzzyCompare((qreal(a) / 1000), (qreal(b) / 1000))) {
if (qFuzzyCompare(a, b)) {
return true;
}
int ai = qRound(a * 1000);
int bi = qRound(b * 1000);
if (qFuzzyCompare((qreal(ai) / 1000), (qreal(bi) / 1000))) {
return true;
}
}
......@@ -661,10 +668,11 @@ static inline bool smartVeryFuzzyCompare(QVariant value1, QVariant value2)
static inline bool equals(const QVariant &a, const QVariant &b)
{
if (a == b)
return true;
if (smartVeryFuzzyCompare(a, b))
return true;
else
return a == b;
return false;
}
TextToModelMerger::TextToModelMerger(RewriterView *reWriterView) :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment