From e2dcecec844eef1c88ef7308d552c51c2db4b969 Mon Sep 17 00:00:00 2001 From: acpaquette Date: Fri, 12 Jan 2024 13:39:53 -0700 Subject: [PATCH] Implemented xml read for statistics object --- isis/src/base/objs/Statistics/Statistics.cpp | 79 ++++++++++++++++++++ isis/src/base/objs/Statistics/Statistics.h | 3 + 2 files changed, 82 insertions(+) diff --git a/isis/src/base/objs/Statistics/Statistics.cpp b/isis/src/base/objs/Statistics/Statistics.cpp index 67c14a4903..7460a88487 100644 --- a/isis/src/base/objs/Statistics/Statistics.cpp +++ b/isis/src/base/objs/Statistics/Statistics.cpp @@ -11,6 +11,7 @@ find files of those names at the top level of this repository. **/ #include #include #include +#include #include @@ -31,6 +32,84 @@ namespace Isis { Reset(); // initialize } + Statistics::Statistics(QXmlStreamReader *xmlReader, QObject *parent) { // TODO: does xml stuff need project??? +// m_id = NULL; + SetValidRange(); + Reset(); // initialize + readStatistics(xmlReader); + } + + void Statistics::readStatistics(QXmlStreamReader *xmlReader) { + Q_ASSERT(xmlReader->name() == "statistics"); + while (xmlReader->readNextStartElement()) { + if (xmlReader->qualifiedName() == "sum") { + m_sum = toDouble(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "sumSquares") { + m_sumsum = toDouble(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "range") { + while (xmlReader->readNextStartElement()) { + if (xmlReader->qualifiedName() == "minimum") { + m_minimum = toDouble(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "maximum") { + m_maximum = toDouble(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "validMinimum") { + m_validMinimum = toDouble(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "validMaximum") { + m_validMaximum = toDouble(xmlReader->readElementText()); + } + else { + xmlReader->skipCurrentElement(); + } + } + } + else if (xmlReader->qualifiedName() == "pixelCounts") { + while (xmlReader->readNextStartElement()) { + if (xmlReader->qualifiedName() == "totalPixels") { + m_totalPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "validPixels") { + m_validPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "nullPixels") { + m_nullPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "lisPixels") { + m_lisPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "lrsPixels") { + m_lrsPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "hisPixels") { + m_hisPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "hrsPixels") { + m_hrsPixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "underRangePixels") { + m_underRangePixels = toBigInt(xmlReader->readElementText()); + } + else if (xmlReader->qualifiedName() == "overRangePixels") { + m_overRangePixels = toBigInt(xmlReader->readElementText()); + } + else { + xmlReader->skipCurrentElement(); + } + } + } + else if (xmlReader->qualifiedName() == "removedData") { + m_removedData = toBool(xmlReader->readElementText()); + } + else { + xmlReader->skipCurrentElement(); + } + } + } + /** * Constructs a Statistics object from an input Pvl * diff --git a/isis/src/base/objs/Statistics/Statistics.h b/isis/src/base/objs/Statistics/Statistics.h index ac93e194e6..ed0ddbf435 100644 --- a/isis/src/base/objs/Statistics/Statistics.h +++ b/isis/src/base/objs/Statistics/Statistics.h @@ -17,6 +17,7 @@ find files of those names at the top level of this repository. **/ class QDataStream; class QUuid; class QXmlStreamWriter; +class QXmlStreamReader; namespace Isis { class Project;// ??? does xml stuff need project??? @@ -93,6 +94,8 @@ namespace Isis { Q_OBJECT public: Statistics(QObject *parent = 0); + Statistics(QXmlStreamReader *xmlReader, QObject *parent = 0); + void readStatistics(QXmlStreamReader *xmlReader); Statistics(const PvlGroup &inStats, QObject *parent = 0); // TODO: does xml read/write stuff need Project input??? Statistics(const Statistics &other);