diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Common/Decoder.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Common/Decoder.cpp index 363ab0681533151bc275742aed5d4ab95a7c962a..3b4b541b48a7b212553ea769f462a105d5126c2f 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Common/Decoder.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Common/Decoder.cpp @@ -179,10 +179,10 @@ void Decoder::updateRunsTableViewFromModel(QtRunsTableView *view, for (auto groupIndex = 0u; groupIndex < groups.size(); ++groupIndex) { // Update view for groups auto group = groups[groupIndex]; - // MantidQt::MantidWidgets::Batch::RowLocation location( - // {static_cast<int>(groupIndex)}); - // MantidQt::MantidWidgets::Batch::Cell groupCell(group.name()); - // jobTreeView->setCellAt({location}, 0, groupCell); + MantidQt::MantidWidgets::Batch::RowLocation location( + {static_cast<int>(groupIndex)}); + MantidQt::MantidWidgets::Batch::Cell groupCell(group.name()); + jobTreeView->setCellAt({location}, 0, groupCell); // Update view for rows auto rows = groups[groupIndex].rows(); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Common/DecoderTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Common/DecoderTest.h index 3f6a8dc48505c22dd4b34473b9d4861462be22d0..d881dab51363e191c4c2d5847e3992dbe247db5b 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Common/DecoderTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Common/DecoderTest.h @@ -99,7 +99,7 @@ public: void test_decodeBatch() { CoderCommonTester tester; - auto map = MantidQt::API::loadJSONfromString(JSON_STRING); + auto map = MantidQt::API::loadJSONFromString(JSON_STRING); MantidQt::CustomInterfaces::QtMainWindowView mwv; mwv.initLayout(); auto gui = dynamic_cast<QtBatchView *>(mwv.batches()[0]); diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index 92b51ef06db151f154e2faba1dfa1e1dab80884a..76b943f63c3b87fc28ace0d1b8fa4bc75c85326f 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -902,6 +902,7 @@ set(TEST_FILES test/SelectionNotificationServiceTest.h test/SignalBlockerTest.h test/TrackedActionTest.h + test/QtJSONUtilsTest.h test/Batch/BuildSubtreeItemsTest.h test/Batch/ExtractSubtreesTest.h test/Batch/FindSubtreeRootsTest.h @@ -955,6 +956,7 @@ set(QT5_TEST_FILES test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h test/InterfaceManagerTest.h + test/QtJSONUtilsTest.h test/Batch/BuildSubtreeItemsTest.h test/Batch/ExtractSubtreesTest.h test/Batch/FindSubtreeRootsTest.h diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJSONUtils.h b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJSONUtils.h index c4bdfca2b1bdaeb5b0933b36a0ad817b1827d95d..34b69f5c946a341a2a8f89d5d6a6ec538f800c17 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJSONUtils.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJSONUtils.h @@ -25,7 +25,7 @@ QMap<QString, QVariant> EXPORT_OPT_MANTIDQT_COMMON loadJSONFromFile(const QString &filename); QMap<QString, QVariant> - EXPORT_OPT_MANTIDQT_COMMON loadJSONfromString(const QString &json); + EXPORT_OPT_MANTIDQT_COMMON loadJSONFromString(const QString &json); } // namespace API } // namespace MantidQt diff --git a/qt/widgets/common/src/QtJSONUtils.cpp b/qt/widgets/common/src/QtJSONUtils.cpp index ea5cec84386f3c662b3d31543612e3281132557b..c60cbf93edcec85011d90a679700025008458304 100644 --- a/qt/widgets/common/src/QtJSONUtils.cpp +++ b/qt/widgets/common/src/QtJSONUtils.cpp @@ -38,6 +38,8 @@ public: obj.setProperty(i.key(), i.value().toInt()); else if (i.value().type() == QVariant::Double) obj.setProperty(i.key(), i.value().toDouble()); + else if (i.value().type() == QVariant::Bool) + obj.setProperty(i.key(), i.value().toBool()); else if (i.value().type() == QVariant::List) obj.setProperty(i.key(), qScriptValueFromSequence(engine, i.value().toList())); @@ -135,7 +137,7 @@ QMap<QString, QVariant> loadJSONFromFile(const QString &filename) { QFile jsonFile(filename); jsonFile.open(QFile::ReadOnly); QString json(jsonFile.readAll()); - return loadJSONfromString(json); + return loadJSONFromString(json); #else /* https://stackoverflow.com/questions/19822211/qt-parsing-json-using-qjsondocument-qjsonobject-qjsonarray * is the source for a large portion of the source code for the Qt5 @@ -152,12 +154,12 @@ QMap<QString, QVariant> loadJSONFromFile(const QString &filename) { json = text.readAll(); file.close(); - return loadJSONfromString(json); + return loadJSONFromString(json); #endif } -QMap<QString, QVariant> loadJSONfromString(const QString &json) { +QMap<QString, QVariant> loadJSONFromString(const QString &json) { #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) JSON JSON; return JSON.decode(json); diff --git a/qt/widgets/common/test/QtJSONUtilsTest.h b/qt/widgets/common/test/QtJSONUtilsTest.h new file mode 100644 index 0000000000000000000000000000000000000000..2db0ca760d8eeaa5cc3f97d99c287b8276583bc8 --- /dev/null +++ b/qt/widgets/common/test/QtJSONUtilsTest.h @@ -0,0 +1,81 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source +// & Institut Laue - Langevin +// SPDX - License - Identifier: GPL - 3.0 + + +#ifndef MANTIDQT_MANTIDWIDGETS_QTJSONUTILSTEST_H +#define MANTIDQT_MANTIDWIDGETS_QTJSONUTILSTEST_H + +#include "MantidQtWidgets/Common/QtJSONUtils.h" + +#include <cxxtest/TestSuite.h> + +#include <QFile> +#include <QMap> +#include <QString> +#include <QVariant> + +static QString JSON{ + "{\"int\": 1, \"double\": 1.0, \"string\": \"text\", \"bool\": true, " + "\"list\":[1,2,3]}"}; + +class QtJSONUtilsTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static QtJSONUtilsTest *createSuite() { return new QtJSONUtilsTest(); } + + static void destroySuite(QtJSONUtilsTest *suite) { delete suite; } + + void test_saveJSONToFile_and_loadJSONFromFile() { + QString filename("/tmp/tempFile"); + auto map1 = constructJSONMap(); + MantidQt::API::saveJSONToFile(filename, map1); + + auto map2 = MantidQt::API::loadJSONFromFile(filename); + testMaps(map1, map2); + + QFile file(filename); + file.remove(); + } + + void test_loadJSONFromString() { + auto map = MantidQt::API::loadJSONFromString(JSON); + testMaps(map, constructJSONMap()); + } + +private: + QMap<QString, QVariant> constructJSONMap() { + QMap<QString, QVariant> map; + map.insert(QString("int"), QVariant(1)); + map.insert(QString("double"), QVariant(1.0)); + map.insert(QString("string"), QVariant(QString("text"))); + map.insert(QString("bool"), QVariant(true)); + QList<QVariant> list{QVariant(1), QVariant(2), QVariant(3)}; + map.insert(QString("list"), QVariant(list)); + return map; + } + + void testMaps(const QMap<QString, QVariant> &map1, + const QMap<QString, QVariant> &map2) { + TS_ASSERT_EQUALS(map1[QString("int")].toInt(), 1) + TS_ASSERT_EQUALS(map2[QString("int")].toInt(), map1[QString("int")].toInt()) + TS_ASSERT_EQUALS(map1[QString("double")].toDouble(), 1.0) + TS_ASSERT_EQUALS(map2[QString("double")].toDouble(), + map1[QString("double")].toDouble()) + TS_ASSERT_EQUALS(map1[QString("string")].toString(), QString("text")) + TS_ASSERT_EQUALS(map2[QString("string")].toString(), + map1[QString("string")].toString()) + TS_ASSERT_EQUALS(map1[QString("bool")].toBool(), true) + TS_ASSERT_EQUALS(map2[QString("bool")].toBool(), + map1[QString("bool")].toBool()) + QList<QVariant> list{QVariant(1), QVariant(2), QVariant(3)}; + TS_ASSERT_EQUALS(list, map1[QString("list")].toList()) + TS_ASSERT_EQUALS(map2[QString("list")].toList(), + map1[QString("list")].toList()) + } +}; + +#endif /* MANTIDQT_MANTIDWIDGETS_QTJSONUTILSTEST_H */ \ No newline at end of file