diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2018-11-20 16:22:52 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-11-27 12:17:50 +0000 |
commit | b0125a461ddf7e8c1c4964592f7f5d76dbce3f83 (patch) | |
tree | e4fc2daedd9bde616178e4055c9be729e6ba953e | |
parent | a1d02709580ad86c260edbd171795e31e6111bd5 (diff) | |
download | qtivi-b0125a461ddf7e8c1c4964592f7f5d76dbce3f83.tar.gz |
Add better error reporting for loading the simulation data
The errors now also state the data file and also uses the
simulationengine logging category
Change-Id: I27da67ede62658a4d237d3df3c0215b1d8296b4d
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/ivicore/qivisimulationengine.cpp | 22 | ||||
-rw-r--r-- | src/ivicore/qivisimulationproxy.cpp | 1 | ||||
-rw-r--r-- | src/ivicore/qivisimulationproxy.h | 3 |
3 files changed, 17 insertions, 9 deletions
diff --git a/src/ivicore/qivisimulationengine.cpp b/src/ivicore/qivisimulationengine.cpp index 69a0ddb..12bc04b 100644 --- a/src/ivicore/qivisimulationengine.cpp +++ b/src/ivicore/qivisimulationengine.cpp @@ -47,6 +47,7 @@ #include <QJsonDocument> #include <QDebug> #include <QQmlContext> +#include <QLoggingCategory> QT_BEGIN_NAMESPACE @@ -228,17 +229,22 @@ QIviSimulationEngine::QIviSimulationEngine(QObject *parent) void QIviSimulationEngine::loadSimulationData(const QString &dataFile) { - if (!QFile::exists(dataFile)) + qCDebug(qLcIviSimulationEngine) << "loading SimulationData" << dataFile; + + QFile file(dataFile); + if (!file.open(QFile::ReadOnly)) { + qCCritical(qLcIviSimulationEngine, "Cannot open the simulation data file %s: %s", qPrintable(dataFile), qPrintable(file.errorString())); return; + } - QFile file(QDir::current().absoluteFilePath(dataFile)); - if (file.open(QFile::ReadOnly)) { - QJsonParseError pe; - QJsonDocument document = QJsonDocument::fromJson(file.readAll(), &pe); - if (pe.error != QJsonParseError::NoError) - qCritical() << "Error parsing the provided simulation data: " << pe.errorString(); - m_globalObject->setSimulationData(document.toVariant()); + QJsonParseError pe; + QByteArray data = file.readAll(); + QJsonDocument document = QJsonDocument::fromJson(data, &pe); + if (pe.error != QJsonParseError::NoError) { + qCCritical(qLcIviSimulationEngine, "Error parsing the simulation data in %s: %s", qPrintable(dataFile), qPrintable(pe.errorString())); + qCCritical(qLcIviSimulationEngine, "Error context:\n %s", data.mid(qMax(pe.offset - 20, 0), 40).data()); } + m_globalObject->setSimulationData(document.toVariant()); } /*! diff --git a/src/ivicore/qivisimulationproxy.cpp b/src/ivicore/qivisimulationproxy.cpp index b3ce374..75a5631 100644 --- a/src/ivicore/qivisimulationproxy.cpp +++ b/src/ivicore/qivisimulationproxy.cpp @@ -43,7 +43,6 @@ #include "qivisimulationengine.h" #include <QDebug> -#include <QLoggingCategory> #include <QQmlInfo> #include <private/qmetaobjectbuilder_p.h> diff --git a/src/ivicore/qivisimulationproxy.h b/src/ivicore/qivisimulationproxy.h index 69ff1cb..b5af29a 100644 --- a/src/ivicore/qivisimulationproxy.h +++ b/src/ivicore/qivisimulationproxy.h @@ -45,12 +45,15 @@ #include <QtIviCore/QtIviCoreModule> #include <QtCore/QObject> +#include <QtCore/QLoggingCategory> #include <QtCore/QVariant> #include <QtCore/QMetaObject> #include <QtQml/QQmlParserStatus> QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(qLcIviSimulationEngine) + class QIviSimulationEngine; // The classes here can't be moved to a private header as they are used in macros in the user code |