Unverified Commit a4bc28d4 authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Remove Qt Deprecated Warnings Part 3 (#5457)

* 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
parent 60257369
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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"
+67 −85
Original line number Diff line number Diff line
@@ -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>
@@ -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>
@@ -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)
@@ -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
@@ -600,8 +584,6 @@ namespace Isis {
    return stream;
  }



  QDataStream &StatCumProbDistDynCalc::read(QDataStream &stream) {
    QString id;
    qint32 numCells, numQuantiles, numObservations;
+3 −31
Original line number Diff line number Diff line
@@ -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
@@ -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);
@@ -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.*/
      
+31 −16
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ 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>

@@ -15,7 +16,7 @@ find files of those names at the top level of this repository. **/
#include "IException.h"
#include "Preference.h"
#include "StatCumProbDistDynCalc.h"
#include "XmlStackedHandlerReader.h"
#include "Statistics.h"

using namespace std;
using namespace Isis;
@@ -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);
@@ -50,14 +50,14 @@ 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() {
@@ -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.";
@@ -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();
@@ -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() << "";
+156 −98
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ find files of those names at the top level of this repository. **/
#include <QString>
#include <QUuid>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>

#include <float.h>

@@ -19,7 +20,6 @@ find files of those names at the top level of this repository. **/
#include "Project.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"
#include "XmlStackedHandlerReader.h"

using namespace std;

@@ -32,12 +32,163 @@ namespace Isis {
    Reset(); // initialize
  }


  Statistics::Statistics(Project *project, XmlStackedHandlerReader *xmlReader, QObject *parent) {   // TODO: does xml stuff need project???
  Statistics::Statistics(QXmlStreamReader *xmlReader, QObject *parent) {   // TODO: does xml stuff need project???
//    m_id = NULL;
    SetValidRange();
    Reset(); // initialize
    xmlReader->pushContentHandler(new XmlHandler(this, project));   // TODO: does xml stuff need project???
    readStatistics(xmlReader);
  }

  void Statistics::readStatistics(QXmlStreamReader *xmlReader) {
    Q_ASSERT(xmlReader->name() == "statistics");
    while (xmlReader->readNextStartElement()) {
      if (xmlReader->qualifiedName() == "sum") {
        try {
          m_sum = toDouble(xmlReader->readElementText());
        }
        catch (IException &e) {
          m_sum = 0.0;
        }
      }
      else if (xmlReader->qualifiedName() == "sumSquares") {
        try {
          m_sumsum = toDouble(xmlReader->readElementText());
        }
        catch (IException &e) {
          m_sumsum = 0.0;
        }
      }
      else if (xmlReader->qualifiedName() == "range") {
        while (xmlReader->readNextStartElement()) {
          if (xmlReader->qualifiedName() == "minimum") {
            try {
              m_minimum = toDouble(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_minimum = DBL_MAX;
            }
          }
          else if (xmlReader->qualifiedName() == "maximum") {
            try {
              m_maximum = toDouble(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_maximum = -DBL_MAX;
            }
          }
          else if (xmlReader->qualifiedName() == "validMinimum") {
            try {
              m_validMinimum = toDouble(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_validMinimum = Isis::ValidMinimum;
            }
          }
          else if (xmlReader->qualifiedName() == "validMaximum") {
            try {
              m_validMaximum = toDouble(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_validMaximum = Isis::ValidMaximum;
            }
          }
          else {
            xmlReader->skipCurrentElement();
          }
        }
      }
      else if (xmlReader->qualifiedName() == "pixelCounts") {
        while (xmlReader->readNextStartElement()) {
          if (xmlReader->qualifiedName() == "totalPixels") {
            try {
              m_totalPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_totalPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "validPixels") {
            try {
              m_validPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_validPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "nullPixels") {
            try {
              m_nullPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_nullPixels = 0.0;
            }

          }
          else if (xmlReader->qualifiedName() == "lisPixels") {
            try {
              m_lisPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_lisPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "lrsPixels") {
            try {
              m_lrsPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_lrsPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "hisPixels") {
            try {
              m_hisPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_hisPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "hrsPixels") {
            try {
              m_hrsPixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_hrsPixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "underRangePixels") {
            try {
              m_underRangePixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_underRangePixels = 0.0;
            }
          }
          else if (xmlReader->qualifiedName() == "overRangePixels") {
            try {
              m_overRangePixels = toBigInt(xmlReader->readElementText());
            }
            catch (IException &e) {
              m_overRangePixels = 0.0;
            }
          }
          else {
            xmlReader->skipCurrentElement();
          }
        }
      }
      else if (xmlReader->qualifiedName() == "removedData") {
        try {
          m_removedData = toBool(xmlReader->readElementText());
        }
        catch (IException &e) {
          m_removedData = false;
        }
      }
      else {
        xmlReader->skipCurrentElement();
      }
    }
  }

  /**
@@ -756,99 +907,6 @@ namespace Isis {
  }


  Statistics::XmlHandler::XmlHandler(Statistics *statistics, Project *project) {   // TODO: does xml stuff need project???
    m_xmlHandlerStatistics = statistics;
    m_xmlHandlerProject = project;   // TODO: does xml stuff need project???
    m_xmlHandlerCharacters = "";
  }


  Statistics::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 Statistics::XmlHandler::startElement(const QString &namespaceURI, 
                                                                const QString &localName,
                                                                const QString &qName,
                                                                const QXmlAttributes &atts) {
    m_xmlHandlerCharacters = "";
    if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
      // no element attibutes to evaluate
    }
    return true;
  }


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


  bool Statistics::XmlHandler::endElement(const QString &namespaceURI, const QString &localName,
                                     const QString &qName) {
    if (!m_xmlHandlerCharacters.isEmpty()) {
      if (localName == "id") {
//        m_xmlHandlerStatistics->m_id = NULL;
//        m_xmlHandlerStatistics->m_id = new QUuid(m_xmlHandlerCharacters);
      }
      if (localName == "sum") {
        m_xmlHandlerStatistics->m_sum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "sumSquares") {
        m_xmlHandlerStatistics->m_sumsum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "minimum") {
        m_xmlHandlerStatistics->m_minimum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "maximum") {
        m_xmlHandlerStatistics->m_maximum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "validMinimum") {
        m_xmlHandlerStatistics->m_validMinimum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "validMaximum") {
        m_xmlHandlerStatistics->m_validMaximum = toDouble(m_xmlHandlerCharacters);
      }
      if (localName == "totalPixels") {
        m_xmlHandlerStatistics->m_totalPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "validPixels") {
        m_xmlHandlerStatistics->m_validPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "nullPixels") {
        m_xmlHandlerStatistics->m_nullPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "lisPixels") {
        m_xmlHandlerStatistics->m_lisPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "lrsPixels") {
        m_xmlHandlerStatistics->m_lrsPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "hisPixels") {
        m_xmlHandlerStatistics->m_hisPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "hrsPixels") {
        m_xmlHandlerStatistics->m_hrsPixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "underRangePixels") {
        m_xmlHandlerStatistics->m_underRangePixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "overRangePixels") {
        m_xmlHandlerStatistics->m_overRangePixels = toBigInt(m_xmlHandlerCharacters);
      }
      if (localName == "removedData") {
        m_xmlHandlerStatistics->m_removedData = toBool(m_xmlHandlerCharacters);
      }
      m_xmlHandlerCharacters = "";
    }
    return XmlStackedHandler::endElement(namespaceURI, localName, qName);
  }


  /** 
   * Order saved must match the offsets in the static compoundH5DataType() 
   * method. 
Loading