Skip to content

Commit

Permalink
Remove Qt Deprecated Warnings Part 3 (#5457)
Browse files Browse the repository at this point in the history
* StatCumProb, BundleResults, and Statistics

* remove unused xml readers

* remove XmlHandler from headers

* removed all XmlStackedHandler

* BundleSettings and BundleUtilities

* Uncomment Serialization Tests

* updated test docs

* Fixes to BundleSolution

* more BundleSolution fixes

* small fixes

* fix compile error

* more fixes
  • Loading branch information
amystamile-usgs authored Jul 19, 2024
1 parent 6025736 commit a4bc28d
Show file tree
Hide file tree
Showing 91 changed files with 1,348 additions and 5,682 deletions.
1 change: 1 addition & 0 deletions isis/src/base/apps/mosrange/mosrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find files of those names at the top level of this repository. **/

#include <QPair>
#include <QList>
#include <QFile>

#include "Camera.h"
#include "Cube.h"
Expand Down
152 changes: 67 additions & 85 deletions isis/src/base/objs/StatCumProbDistDynCalc/StatCumProbDistDynCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ find files of those names at the top level of this repository. **/
#include <QList>
#include <QUuid>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>

#include <float.h>
#include <math.h>
Expand All @@ -20,7 +21,6 @@ find files of those names at the top level of this repository. **/
#include "IException.h"
#include "IString.h"
#include "Project.h"
#include "XmlStackedHandlerReader.h"

#include "Pvl.h"
#include <iostream>
Expand All @@ -41,14 +41,75 @@ namespace Isis {
}


// TODO: should project be const ???
StatCumProbDistDynCalc::StatCumProbDistDynCalc(Project *project,
XmlStackedHandlerReader *xmlReader,
QObject *parent) { // TODO: does xml stuff need project???
StatCumProbDistDynCalc::StatCumProbDistDynCalc(QXmlStreamReader *xmlReader, QObject *parent) {
initialize();
xmlReader->pushContentHandler(new XmlHandler(this, project)); // TODO: does xml stuff need project???
readStatistics(xmlReader);
}

void StatCumProbDistDynCalc::readStatistics(QXmlStreamReader *xmlReader) {
Q_ASSERT(xmlReader->name() == "statCumProbDistDynCalc");
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "numberCells") {
try {
m_numberCells = toDouble(xmlReader->readElementText());
}
catch (IException &e) {
m_numberCells = 0.0;
}
}
else if (xmlReader->qualifiedName() == "numberQuantiles") {
try {
m_numberQuantiles = toDouble(xmlReader->readElementText());
}
catch (IException &e) {
m_numberQuantiles = 0.0;
}
}
else if (xmlReader->qualifiedName() == "numberObservations") {
try {
m_numberObservations = toDouble(xmlReader->readElementText());
}
catch (IException &e) {
m_numberObservations = 0.0;
}
}
else if (xmlReader->qualifiedName() == "distributionData") {
m_quantiles.clear();
m_observationValues.clear();
m_idealNumObsBelowQuantile.clear();
m_numObsBelowQuantile.clear();
for (unsigned int i = 0; i < m_numberQuantiles; i++) {
while (xmlReader->readNextStartElement()) {
if (xmlReader->qualifiedName() == "quantileInfo") {
QStringRef quantile = xmlReader->attributes().value("quantile");
if (!quantile.isEmpty()) {
m_quantiles.append(quantile.toDouble());
}
QStringRef dataValue = xmlReader->attributes().value("dataValue");
if (!dataValue.isEmpty()) {
m_observationValues.append(dataValue.toDouble());
}
QStringRef idealNumObsBelowQuantile = xmlReader->attributes().value("idealNumObsBelowQuantile");
if (!idealNumObsBelowQuantile.isEmpty()) {
m_idealNumObsBelowQuantile.append(idealNumObsBelowQuantile.toDouble());
}
QStringRef actualNumObsBelowQuantile = xmlReader->attributes().value("actualNumObsBelowQuantile");

if (!actualNumObsBelowQuantile.isEmpty()) {
m_numObsBelowQuantile.append(actualNumObsBelowQuantile.toInt());
}
}
else {
xmlReader->skipCurrentElement();
}
}
}
}
else {
xmlReader->skipCurrentElement();
}
}
}


StatCumProbDistDynCalc::StatCumProbDistDynCalc(const StatCumProbDistDynCalc &other)
Expand Down Expand Up @@ -512,83 +573,6 @@ namespace Isis {

}



// TODO: should project be const ???
StatCumProbDistDynCalc::XmlHandler::XmlHandler(StatCumProbDistDynCalc *probabilityCalc,
Project *project) { // TODO: does xml stuff need project???
m_xmlHandlerCumProbCalc = probabilityCalc;
m_xmlHandlerProject = project; // TODO: does xml stuff need project???
m_xmlHandlerCharacters = "";
}



StatCumProbDistDynCalc::XmlHandler::~XmlHandler() {
// do not delete this pointer... we don't own it, do we??? passed into StatCumProbDistDynCalc constructor as pointer
// delete m_xmlHandlerProject; // TODO: does xml stuff need project???
m_xmlHandlerProject = NULL;
}



bool StatCumProbDistDynCalc::XmlHandler::startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &atts) {

m_xmlHandlerCharacters = "";
if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
if (qName == "quantileInfo") {

QString quantile = atts.value("quantile");
QString obsValue = atts.value("dataValue");
QString idealObs = atts.value("idealNumObsBelowQuantile");
QString actualObs = atts.value("actualNumObsBelowQuantile");

if (!quantile.isEmpty() && !obsValue.isEmpty()
&& !idealObs.isEmpty() && !actualObs.isEmpty()) {
m_xmlHandlerCumProbCalc->m_quantiles.append(toDouble(quantile));
m_xmlHandlerCumProbCalc->m_observationValues.append(toDouble(obsValue));
m_xmlHandlerCumProbCalc->m_idealNumObsBelowQuantile.append(toDouble(idealObs));
m_xmlHandlerCumProbCalc->m_numObsBelowQuantile.append(toDouble(actualObs));
}
}

}
return true;
}



bool StatCumProbDistDynCalc::XmlHandler::characters(const QString &ch) {
m_xmlHandlerCharacters += ch;
return XmlStackedHandler::characters(ch);
}



bool StatCumProbDistDynCalc::XmlHandler::endElement(const QString &namespaceURI,
const QString &localName,
const QString &qName) {
if (!m_xmlHandlerCharacters.isEmpty()) {
if (qName == "numberCells") {
m_xmlHandlerCumProbCalc->m_numberCells = toInt(m_xmlHandlerCharacters);
}
else if (qName == "numberQuantiles") {
m_xmlHandlerCumProbCalc->m_numberQuantiles = toInt(m_xmlHandlerCharacters);
}
else if (qName == "numberObservations") {
m_xmlHandlerCumProbCalc->m_numberObservations = toInt(m_xmlHandlerCharacters);
}

m_xmlHandlerCharacters = "";
}
return XmlStackedHandler::endElement(namespaceURI, localName, qName);
}



QDataStream &StatCumProbDistDynCalc::write(QDataStream &stream) const {
stream << (qint32)m_numberCells
<< (qint32)m_numberQuantiles
Expand All @@ -600,8 +584,6 @@ namespace Isis {
return stream;
}



QDataStream &StatCumProbDistDynCalc::read(QDataStream &stream) {
QString id;
qint32 numCells, numQuantiles, numObservations;
Expand Down
34 changes: 3 additions & 31 deletions isis/src/base/objs/StatCumProbDistDynCalc/StatCumProbDistDynCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ find files of those names at the top level of this repository. **/
#include <QObject>
#include <QVector>

#include "XmlStackedHandler.h"

class QDataStream;
class QUuid;
class QXmlStreamWriter;
class QXmlStreamReader;

namespace Isis {
class Project;// ??? does xml stuff need project???
class XmlStackedHandlerReader;

/**
* @brief This class is used to approximate cumulative probibility distributions of a stream of
Expand Down Expand Up @@ -70,8 +68,8 @@ namespace Isis {
// Observations"
public:
StatCumProbDistDynCalc(unsigned int nodes=20, QObject *parent = 0); //individual qunatile value to be calculated
StatCumProbDistDynCalc(Project *project, XmlStackedHandlerReader *xmlReader,
QObject *parent = 0); // TODO: does xml stuff need project???
StatCumProbDistDynCalc(QXmlStreamReader *xmlReader, QObject *parent = 0);
void readStatistics(QXmlStreamReader *xmlReader);
StatCumProbDistDynCalc(const StatCumProbDistDynCalc &other);
~StatCumProbDistDynCalc();
StatCumProbDistDynCalc &operator=(const StatCumProbDistDynCalc &other);
Expand All @@ -92,32 +90,6 @@ namespace Isis {
QDataStream &write(QDataStream &stream) const;
QDataStream &read(QDataStream &stream);

private:
/**
*
* @author 2014-07-28 Jeannie Backer
*
* @internal
*/
class XmlHandler : public XmlStackedHandler {
public:
XmlHandler(StatCumProbDistDynCalc *probabilityCalc, Project *project); // TODO: does xml stuff need project???
~XmlHandler();

virtual bool startElement(const QString &namespaceURI, const QString &localName,
const QString &qName, const QXmlAttributes &atts);
virtual bool characters(const QString &ch);
virtual bool endElement(const QString &namespaceURI, const QString &localName,
const QString &qName);

private:
Q_DISABLE_COPY(XmlHandler);

StatCumProbDistDynCalc *m_xmlHandlerCumProbCalc;
Project *m_xmlHandlerProject; // TODO: does xml stuff need project???
QString m_xmlHandlerCharacters;
};

unsigned int m_numberCells; /**< The number of cells or histogram bins that are being used to
model the probility density function.*/

Expand Down
47 changes: 31 additions & 16 deletions isis/src/base/objs/StatCumProbDistDynCalc/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ find files of those names at the top level of this repository. **/
#include <QDataStream>
#include <QDebug>
#include <QXmlStreamWriter>
#include <QXmlInputSource>
#include <QXmlStreamReader>
#include <QFile>

#include <iostream>

#include "FileName.h"
#include "IException.h"
#include "Preference.h"
#include "StatCumProbDistDynCalc.h"
#include "XmlStackedHandlerReader.h"
#include "Statistics.h"

using namespace std;
using namespace Isis;
Expand All @@ -38,8 +39,7 @@ using namespace Isis;
namespace Isis {
class StatisticsXmlHandlerTester : public StatCumProbDistDynCalc {
public:
StatisticsXmlHandlerTester(Project *project, XmlStackedHandlerReader *reader,
FileName xmlFile) : StatCumProbDistDynCalc(project, reader) {
StatisticsXmlHandlerTester(QXmlStreamReader *reader, FileName xmlFile) : StatCumProbDistDynCalc() {

QString xmlPath(xmlFile.expanded());
QFile file(xmlPath);
Expand All @@ -50,16 +50,16 @@ namespace Isis {
_FILEINFO_);
}

QXmlInputSource xmlInputSource(&file);
bool success = reader->parse(xmlInputSource);
if (!success) {
throw IException(IException::Unknown,
QString("Failed to parse xml file, [%1]").arg(xmlPath),
_FILEINFO_);
if (reader->readNextStartElement()) {
if (reader->name() == "statCumProbDistDynCalc") {
readStatistics(reader);
}
else {
reader->raiseError(QObject::tr("Incorrect file"));
}
}
}

}

~StatisticsXmlHandlerTester() {
}

Expand Down Expand Up @@ -174,8 +174,15 @@ int main(int argc, char *argv[]) {
// read xml with no attributes or values
FileName emptyXmlFile("./unitTest_NoElementValues.xml");
Project *project = NULL;
XmlStackedHandlerReader reader;
StatisticsXmlHandlerTester statsFromEmptyXml(project, &reader, emptyXmlFile);
QFile xml(emptyXmlFile.expanded());
if(!xml.open(QFile::ReadOnly | QFile::Text)){
throw IException(IException::Unknown,
QString("Failed to parse xml file, [%1]").arg(xml.fileName()),
_FILEINFO_);
}

QXmlStreamReader reader(&xml);
StatisticsXmlHandlerTester statsFromEmptyXml(&reader, emptyXmlFile);
qDebug() << "Testing XML: read XML with no attributes or values "
"to StatCumProbDistDynCalc object... Then try to get "
"min from object with no observations.";
Expand Down Expand Up @@ -470,7 +477,7 @@ int main(int argc, char *argv[]) {
qDebug() << "percent error: " << (temp-1.0)/100 << "%";
qDebug() << "";
qDebug() << "";
StatCumProbDistDynCalc assignedStats(0);
StatCumProbDistDynCalc assignedStats;
assignedStats = copyStats;
qDebug() << "Min = " << assignedStats.min();
qDebug() << "Max = " << assignedStats.max();
Expand Down Expand Up @@ -633,7 +640,15 @@ int main(int argc, char *argv[]) {
qXmlFile.close();
// read xml
qDebug() << "Testing XML: read XML to StatCumProbDistDynCalc object...";
StatisticsXmlHandlerTester statsFromXml(project, &reader, xmlFile);
QFile xml2(xmlFile.expanded());
if(!xml2.open(QFile::ReadOnly | QFile::Text)){
throw IException(IException::Unknown,
QString("Failed to parse xml file, [%1]").arg(xml2.fileName()),
_FILEINFO_);
}

QXmlStreamReader reader2(&xml2);
StatisticsXmlHandlerTester statsFromXml(&reader2, xmlFile);
qDebug() << "Min = " << statsFromXml.min();
qDebug() << "Max = " << statsFromXml.max();
qDebug() << "";
Expand Down
Loading

0 comments on commit a4bc28d

Please sign in to comment.