aboutsummaryrefslogtreecommitdiffstats
path: root/src/ivicore/qivisimulationglobalobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ivicore/qivisimulationglobalobject.cpp')
-rw-r--r--src/ivicore/qivisimulationglobalobject.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/ivicore/qivisimulationglobalobject.cpp b/src/ivicore/qivisimulationglobalobject.cpp
index db312b6..853d7a2 100644
--- a/src/ivicore/qivisimulationglobalobject.cpp
+++ b/src/ivicore/qivisimulationglobalobject.cpp
@@ -2,6 +2,7 @@
**
** Copyright (C) 2019 Luxoft Sweden AB
** Copyright (C) 2018 Pelagicore AG
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtIvi module of the Qt Toolkit.
@@ -42,6 +43,7 @@
#include "qivisimulationglobalobject_p.h"
#include <QtDebug>
+#include <QJsonDocument>
QT_BEGIN_NAMESPACE
@@ -301,7 +303,7 @@ QVariantMap QIviSimulationGlobalObject::findData(const QVariantMap &data, const
int index = key.indexOf('.');
if (index == -1)
break;
- key = key.right(key.count() - index);
+ key = key.right(key.count() - index - 1);
}
return QVariantMap();
@@ -395,18 +397,18 @@ QString QIviSimulationGlobalObject::constraint(const QVariantMap &data, const QS
if (maxDomain.isValid())
return QStringLiteral("<= ") + maxDomain.toString();
if (domainDomain.isValid())
- return domainDomain.toString();
+ return QString::fromUtf8(QJsonDocument::fromVariant(domainDomain).toJson(QJsonDocument::Compact));
return QString();
}
/*!
- \qmlmethod IviSimulator::checkSettings(object data, var data, string zone)
+ \qmlmethod IviSimulator::checkSettings(object data, var value, string zone)
Searches for all boundary settings in \a data for the given \a zone and returns whether the
- provided \a value meets this contraint.
+ provided \a value meets this constraint.
- To show meaningful error messages when the value is not within the boundaries, the contraint()
+ To show meaningful error messages when the value is not within the boundaries, the constraint()
function can be used.
\sa constraint()
@@ -427,17 +429,33 @@ bool QIviSimulationGlobalObject::checkSettings(const QVariantMap &data, const QV
}
}
const QVariant domainDomain = parseDomainValue(data, domainLiteral, zone);
-
- if (unsupportedDomain.isValid())
- return unsupportedDomain.toBool();
- if (minDomain.isValid() && maxDomain.isValid())
- return !(value < minDomain || value > maxDomain);
- if (minDomain.isValid())
- return value >= minDomain;
- if (maxDomain.isValid())
- return value <= maxDomain;
- if (domainDomain.isValid())
+ bool valueToDouble = value.canConvert(QVariant::Double);
+ bool minDomainToDouble = minDomain.canConvert(QVariant::Double);
+ bool maxDomainToDouble = maxDomain.canConvert(QVariant::Double);
+
+ if (unsupportedDomain.isValid()) {
+ return !unsupportedDomain.toBool();
+ } else if (minDomain.isValid() && maxDomain.isValid()) {
+ if (!valueToDouble || !minDomainToDouble || !maxDomainToDouble) {
+ qWarning() << "Can't compare values: " << value << minDomain << maxDomain;
+ return false;
+ }
+ return !(value.toDouble() < minDomain.toDouble() || value.toDouble() > maxDomain.toDouble());
+ } else if (minDomain.isValid()) {
+ if (!valueToDouble || !minDomainToDouble) {
+ qWarning() << "Can't compare values: " << value << minDomain;
+ return false;
+ }
+ return value.toDouble() >= minDomain.toDouble();
+ } else if (maxDomain.isValid()) {
+ if (!valueToDouble || !maxDomainToDouble) {
+ qWarning() << "Can't compare values: " << value << maxDomain;
+ return false;
+ }
+ return value.toDouble() <= maxDomain.toDouble();
+ } if (domainDomain.isValid()) {
return domainDomain.toList().contains(value);
+ }
return true;
}
@@ -461,8 +479,8 @@ QVariant QIviSimulationGlobalObject::parseDomainValue(const QVariantMap &data, c
if (zone.isEmpty())
z = QStringLiteral("=");
- if (domainMap.contains(zone))
- return qtivi_convertFromJSON(domainMap.value(zone));
+ if (domainMap.contains(z))
+ return qtivi_convertFromJSON(domainMap.value(z));
}
return qtivi_convertFromJSON(domainData);