diff --git a/src/musredit_qt5/musrWiz/PAdmin.cpp b/src/musredit_qt5/musrWiz/PAdmin.cpp index d6ec9d73..319c33b6 100644 --- a/src/musredit_qt5/musrWiz/PAdmin.cpp +++ b/src/musredit_qt5/musrWiz/PAdmin.cpp @@ -36,6 +36,9 @@ using namespace std; #include #include #include +#include + +#include #include "PAdmin.h" @@ -47,28 +50,78 @@ using namespace std; * * \param admin pointer to an admin class instance. */ -PFuncXMLParser::PFuncXMLParser(PAdmin *admin) : fAdmin(admin) +PFuncXMLParser::PFuncXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin) { + fValid = false; fKeyWord = eEmpty; + + QFile file(fln); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + // warning and create default - STILL MISSING + } + + fValid = parse(&file); } //-------------------------------------------------------------------------- /** - *

+ *

parse musrfit_funcs.xml + * + * \param device QFile object of musrfit_funcs.xml + * + * @return true on success, false otherwise */ -bool PFuncXMLParser::startDocument() +bool PFuncXMLParser::parse(QIODevice *device) { + fXml.setDevice(device); + + bool expectChars = false; + while (!fXml.atEnd()) { + fXml.readNext(); + if (fXml.isStartDocument()) { + startDocument(); + } else if (fXml.isStartElement()) { + startElement(); + expectChars = true; + } else if (fXml.isCharacters() && expectChars) { + characters(); + } else if (fXml.isEndElement()) { + endElement(); + expectChars = false; + } else if (fXml.isEndDocument()) { + endDocument(); + } + } + if (fXml.hasError()) { + QString msg; + msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber()); + QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton); + return false; + } + return true; } //-------------------------------------------------------------------------- /** - *

+ *

Routine called at the beginning of the XML parsing process. */ -bool PFuncXMLParser::startElement(const QString&, const QString&, - const QString& qName, - const QXmlAttributes& qAttr) +bool PFuncXMLParser::startDocument() { + // nothing to be done here for now + return true; +} + +//-------------------------------------------------------------------------- +/** + *

Routine called when a new XML tag is found. Here it is used + * to set a tag for filtering afterwards the content. + */ +bool PFuncXMLParser::startElement() +{ + QStringRef qName = fXml.name(); + QString str; + QString errMsg(""); int ival; double dval; @@ -83,29 +136,26 @@ bool PFuncXMLParser::startElement(const QString&, const QString&, } else if (qName == "theo_fun") { fKeyWord = eTemplateFunc; } else if (qName == "theo_map") { + QXmlStreamAttributes qAttr = fXml.attributes(); if (qAttr.count() != 2) { errMsg = QString("theo_map should have 2 attributes, called 'no', and 'name', found %1").arg(qAttr.count()); QMessageBox::critical(0, "ERROR", errMsg); return false; } PParam map; - for (int i=0; i + *

Routine called when the end XML tag is found. It is used to + * put the filtering tag to 'empty'. It also resets the fFunc flag in case + * the entry was a theory function. */ -bool PFuncXMLParser::endElement( const QString&, const QString&, const QString &qName ) +bool PFuncXMLParser::endElement() { fKeyWord = eEmpty; + QStringRef qName = fXml.name(); + if (qName == "theo_template") { fAdmin->fTheoTemplate.push_back(fTheoTemplate); } else if (qName == "func") { @@ -196,10 +256,15 @@ bool PFuncXMLParser::endElement( const QString&, const QString&, const QString & //-------------------------------------------------------------------------- /** - *

+ *

This routine delivers the content of an XML tag. It fills the + * content into the load data structure. */ -bool PFuncXMLParser::characters(const QString &str) +bool PFuncXMLParser::characters() { + QString str = *fXml.text().string(); + if (str.isEmpty()) + return true; + bool ok; int ival; double dval; @@ -246,82 +311,77 @@ bool PFuncXMLParser::characters(const QString &str) //-------------------------------------------------------------------------- /** - *

+ *

Called at the end of the XML parse process. It checks if default paths + * contain system variables, and if so expand them for the further use. */ bool PFuncXMLParser::endDocument() { return true; } -//-------------------------------------------------------------------------- -/** - *

- */ -bool PFuncXMLParser::warning( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**WARNING** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**WARNING MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

- */ -bool PFuncXMLParser::error( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**ERROR** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::warning(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

- */ -bool PFuncXMLParser::fatalError( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**FATAL ERROR** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**FATAL ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::warning(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - //-------------------------------------------------------------------------- // implementation of PInstrumentDefXMLParser class //-------------------------------------------------------------------------- /** *

XML Parser class for the instrument definition file(s). * + * \param file name of the instrument definition file(s). * \param admin pointer to an admin class instance. */ -PInstrumentDefXMLParser::PInstrumentDefXMLParser(PAdmin *admin) : fAdmin(admin) +PInstrumentDefXMLParser::PInstrumentDefXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin) { + fValid = false; fKeyWord = eEmpty; fInstituteName = ""; fInstrument = 0; fSetup = 0; + + QFile file(fln); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + // warning and create default - STILL MISSING + } + + fValid = parse(&file); +} + +//-------------------------------------------------------------------------- +/** + *

parse the instrument definition xml-file(s). + * + * \param device QFile object of the instrument definition xml-file(s). + * + * @return true on success, false otherwise + */ +bool PInstrumentDefXMLParser::parse(QIODevice *device) +{ + fXml.setDevice(device); + + bool expectChars = false; + while (!fXml.atEnd()) { + fXml.readNext(); + if (fXml.isStartDocument()) { + startDocument(); + } else if (fXml.isStartElement()) { + startElement(); + expectChars = true; + } else if (fXml.isCharacters() && expectChars) { + characters(); + } else if (fXml.isEndElement()) { + endElement(); + expectChars = false; + } else if (fXml.isEndDocument()) { + endDocument(); + } + } + if (fXml.hasError()) { + QString msg; + msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber()); + QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton); + return false; + } + + return true; } //-------------------------------------------------------------------------- @@ -330,6 +390,7 @@ PInstrumentDefXMLParser::PInstrumentDefXMLParser(PAdmin *admin) : fAdmin(admin) */ bool PInstrumentDefXMLParser::startDocument() { + // nothing to be done here for now return true; } @@ -337,13 +398,11 @@ bool PInstrumentDefXMLParser::startDocument() /** *

Routine called when a new XML tag is found. Here it is used * to set a tag for filtering afterwards the content. - * - * \param qName name of the XML tag. */ -bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, - const QString& qName, - const QXmlAttributes& qAttr) +bool PInstrumentDefXMLParser::startElement() { + QStringRef qName = fXml.name(); + bool ok; double dval; double ival; @@ -356,6 +415,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, fKeyWord = eInstitute; } else if (qName == "instrument") { fKeyWord = eInstrument; + QXmlStreamAttributes qAttr = fXml.attributes(); if (qAttr.count() != 1) { errMsg = QString("instrument should have 1 attribute, called 'name', found %1").arg(qAttr.count()); QMessageBox::critical(0, "ERROR", errMsg); @@ -369,7 +429,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, // create an instrument object fInstrument = new PInstrument(); fInstrument->setInstitue(fInstituteName); - fInstrument->setName(qAttr.value(0)); + fInstrument->setName(qAttr.value("name").toString()); } else if (qName == "run_name_template") { fKeyWord = eRunNameTemplate; } else if (qName == "beamline") { @@ -378,23 +438,26 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, fKeyWord = eDataFileFormat; } else if (qName == "tf") { fKeyWord = eTf; + QXmlStreamAttributes qAttr = fXml.attributes(); fSetup = new PSetup(); if (qAttr.count() == 1) - fSetup->setName(qAttr.value(0)); + fSetup->setName(qAttr.value("name").toString()); else fSetup->setName("Default"); } else if (qName == "zf") { fKeyWord = eZf; + QXmlStreamAttributes qAttr = fXml.attributes(); fSetup = new PSetup(); if (qAttr.count() == 1) - fSetup->setName(qAttr.value(0)); + fSetup->setName(qAttr.value("name").toString()); else fSetup->setName("Default"); } else if (qName == "lf") { fKeyWord = eLf; + QXmlStreamAttributes qAttr = fXml.attributes(); fSetup = new PSetup(); if (qAttr.count() == 1) - fSetup->setName(qAttr.value(0)); + fSetup->setName(qAttr.value("name").toString()); else fSetup->setName("Default"); } else if (qName == "no_of_detectors") { @@ -406,94 +469,78 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, } else if (qName == "asym_bkg_range") { fKeyWord = eBkgRange; } else if (qName == "logic_detector") { + QXmlStreamAttributes qAttr = fXml.attributes(); if (qAttr.count() < 3) return false; PDetector detect; - int count=0; - for (int i=0; iaddDetector(detect); } else if (qName == "logic_asym_detector") { + QXmlStreamAttributes qAttr = fXml.attributes(); if (qAttr.count() != 5) return false; PDetector detect; - int count=0; - for (int i=0; i<5; i++) { - if (qAttr.localName(i) == "name") { - detect.setName(qAttr.value(i)); // detector name - count++; - } else if (qAttr.localName(i) == "rel_phase") { - str = qAttr.value(i); - dval = str.toDouble(&ok); - if (ok) { - detect.setRelGeomPhase(dval); - count++; - } - } else if (qAttr.localName(i) == "forward") { - str = qAttr.value(i); - strL.clear(); - strL = str.split(' '); - forward.clear(); - for (int j=0; jaddAsymDetector(detect); } @@ -505,13 +552,13 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&, *

Routine called when the end XML tag is found. It is used to * put the filtering tag to 'empty'. It also resets the fFunc flag in case * the entry was a theory function. - * - * \param qName name of the element. */ -bool PInstrumentDefXMLParser::endElement( const QString&, const QString&, const QString &qName ) +bool PInstrumentDefXMLParser::endElement() { fKeyWord = eEmpty; + QStringRef qName = fXml.name(); + if (qName == "instrument") { // store instrument fAdmin->addInstrument(fInstituteName, *fInstrument); @@ -557,11 +604,13 @@ bool PInstrumentDefXMLParser::endElement( const QString&, const QString&, const /** *

This routine delivers the content of an XML tag. It fills the * content into the load data structure. - * - * \param str keeps the content of the XML tag. */ -bool PInstrumentDefXMLParser::characters(const QString& str) +bool PInstrumentDefXMLParser::characters() { + QString str = *fXml.text().string(); + if (str.isEmpty()) + return true; + bool ok; int ival, start, end; QString errMsg; @@ -649,66 +698,6 @@ bool PInstrumentDefXMLParser::endDocument() return true; } -//-------------------------------------------------------------------------- -/** - *

Report XML warnings. - * - * \param exception holds the information of the XML warning - */ -bool PInstrumentDefXMLParser::warning( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**WARNING** while parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**WARNING MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

Report recoverable XML errors. - * - * \param exception holds the information of the XML recoverable errors. - */ -bool PInstrumentDefXMLParser::error( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**ERROR** while parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

Report fatal XML errors. - * - * \param exception holds the information of the XML fatal errors. - */ -bool PInstrumentDefXMLParser::fatalError( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**FATAL ERROR** while parsing parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**FATAL ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - //-------------------------------------------------------------------------- // implementation of PMusrWizDefault class //-------------------------------------------------------------------------- @@ -730,9 +719,56 @@ PMusrWizDefault::PMusrWizDefault() * * \param admin pointer to an admin class instance. */ -PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(PAdmin *admin) : fAdmin(admin) +PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin) { + fValid = false; fKeyWord = eEmpty; + + QFile file(fln); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + // warning and create default - STILL MISSING + } + + fValid = parse(&file); +} + +//-------------------------------------------------------------------------- +/** + *

parse the musrWiz startup xml-file. + * + * \param device QFile object of the musrWiz startup xml-file + * + * @return true on success, false otherwise + */ +bool PMusrWizDefaultXMLParser::parse(QIODevice *device) +{ + fXml.setDevice(device); + + bool expectChars = false; + while (!fXml.atEnd()) { + fXml.readNext(); + if (fXml.isStartDocument()) { + startDocument(); + } else if (fXml.isStartElement()) { + startElement(); + expectChars = true; + } else if (fXml.isCharacters() && expectChars) { + characters(); + } else if (fXml.isEndElement()) { + endElement(); + expectChars = false; + } else if (fXml.isEndDocument()) { + endDocument(); + } + } + if (fXml.hasError()) { + QString msg; + msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber()); + QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton); + return false; + } + + return true; } //-------------------------------------------------------------------------- @@ -741,6 +777,7 @@ PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(PAdmin *admin) : fAdmin(admin */ bool PMusrWizDefaultXMLParser::startDocument() { + // nothing to be done here for now return true; } @@ -748,13 +785,11 @@ bool PMusrWizDefaultXMLParser::startDocument() /** *

Routine called when a new XML tag is found. Here it is used * to set a tag for filtering afterwards the content. - * - * \param qName name of the XML tag. */ -bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&, - const QString& qName, - const QXmlAttributes& ) +bool PMusrWizDefaultXMLParser::startElement() { + QStringRef qName = fXml.name(); + if (qName == "institute") { fKeyWord = eInstitute; } else if (qName == "instrument") { @@ -771,10 +806,8 @@ bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&, *

Routine called when the end XML tag is found. It is used to * put the filtering tag to 'empty'. It also resets the fFunc flag in case * the entry was a theory function. - * - * \param qName name of the element. */ -bool PMusrWizDefaultXMLParser::endElement( const QString&, const QString&, const QString& ) +bool PMusrWizDefaultXMLParser::endElement() { fKeyWord = eEmpty; @@ -785,11 +818,13 @@ bool PMusrWizDefaultXMLParser::endElement( const QString&, const QString&, const /** *

This routine delivers the content of an XML tag. It fills the * content into the load data structure. - * - * \param str keeps the content of the XML tag. */ -bool PMusrWizDefaultXMLParser::characters(const QString& str) +bool PMusrWizDefaultXMLParser::characters() { + QString str = *fXml.text().string(); + if (str.isEmpty()) + return true; + switch (fKeyWord) { case eInstitute: fDefault.setInstitute(str); @@ -818,66 +853,6 @@ bool PMusrWizDefaultXMLParser::endDocument() return true; } -//-------------------------------------------------------------------------- -/** - *

Report XML warnings. - * - * \param exception holds the information of the XML warning - */ -bool PMusrWizDefaultXMLParser::warning( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**WARNING** while parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**WARNING MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

Report recoverable XML errors. - * - * \param exception holds the information of the XML recoverable errors. - */ -bool PMusrWizDefaultXMLParser::error( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**ERROR** while parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - -//-------------------------------------------------------------------------- -/** - *

Report fatal XML errors. - * - * \param exception holds the information of the XML fatal errors. - */ -bool PMusrWizDefaultXMLParser::fatalError( const QXmlParseException & exception ) -{ - QString msg; - - msg = QString("**FATAL ERROR** while parsing parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber()); - msg += QString("**FATAL ERROR MESSAGE** ") + exception.message(); - - qWarning() << endl << msg << endl; - - QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton); - - return true; -} - //-------------------------------------------------------------------------- // implementation of PAdmin class //-------------------------------------------------------------------------- @@ -1245,12 +1220,8 @@ int PAdmin::loadMusrWizDefault(QString fln) } } - PMusrWizDefaultXMLParser handler(this); - QFile xmlFile(fln); - QXmlInputSource source( &xmlFile ); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - if (!reader.parse(source)) { + PMusrWizDefaultXMLParser handler(fln, this); + if (!handler.isValid()) { QString errMsg = QString("Error parsing %1 file.").arg(fln); QMessageBox::critical(0, "ERROR", errMsg); return 1; @@ -1282,12 +1253,8 @@ int PAdmin::loadMusrfitFunc(QString fln) } } - PFuncXMLParser handler(this); - QFile xmlFile(fln); - QXmlInputSource source( &xmlFile ); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - if (!reader.parse(source)) { + PFuncXMLParser handler(fln, this); + if (!handler.isValid()) { QString errMsg = QString("Error parsing %1 musrfit func file.").arg(fln); QMessageBox::critical(0, "ERROR", errMsg); return 1; @@ -1326,12 +1293,8 @@ int PAdmin::loadInstrumentDef(QString path, QString fln) } } - PInstrumentDefXMLParser handler(this); - QFile xmlFile(pathFln); - QXmlInputSource source( &xmlFile ); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - if (!reader.parse(source)) { + PInstrumentDefXMLParser handler(pathFln, this); + if (!handler.isValid()) { QString errMsg = QString("Error parsing %1 instrument def file.").arg(pathFln); QMessageBox::critical(0, "ERROR", errMsg); return 1; diff --git a/src/musredit_qt5/musrWiz/PAdmin.h b/src/musredit_qt5/musrWiz/PAdmin.h index a43237d2..6d7175a6 100644 --- a/src/musredit_qt5/musrWiz/PAdmin.h +++ b/src/musredit_qt5/musrWiz/PAdmin.h @@ -32,7 +32,10 @@ #include #include -#include +#include +#include +#include +#include #include "PTheoTemplate.h" #include "PMusrfitFunc.h" @@ -41,32 +44,32 @@ class PAdmin; //--------------------------------------------------------------------------- -class PFuncXMLParser : public QXmlDefaultHandler +class PFuncXMLParser { public: - PFuncXMLParser(PAdmin*); + PFuncXMLParser(const QString &fln, PAdmin*); virtual ~PFuncXMLParser() {} + virtual bool isValid() { return fValid; } + private: enum EFuncKeyWords {eEmpty, eTemplateName, eTemplateTheo, eTemplateFunc, eName, eAbbrv, eNoOfParam, eParam, eParamName, eParamValue, eParamMap}; + bool parse(QIODevice *device); bool startDocument(); - bool startElement(const QString&, const QString&, const QString& , - const QXmlAttributes& qAttr); - bool endElement( const QString&, const QString&, const QString& ); - - bool characters(const QString&); + bool startElement(); + bool endElement(); + bool characters(); bool endDocument(); - bool warning( const QXmlParseException & exception ); - bool error( const QXmlParseException & exception ); - bool fatalError( const QXmlParseException & exception ); - EFuncKeyWords fKeyWord; ///< key word tag to know how to handle the content - PAdmin *fAdmin; ///< a pointer to the main administration class object + QXmlStreamReader fXml; ///< xml stream reader object + bool fValid; ///< flag showing if XML read has been successful + EFuncKeyWords fKeyWord; ///< key word tag to know how to handle the content + PAdmin *fAdmin; ///< a pointer to the main administration class object PTheoTemplate fTheoTemplate; PMusrfitFunc fFunc; @@ -74,32 +77,31 @@ class PFuncXMLParser : public QXmlDefaultHandler }; //--------------------------------------------------------------------------- -class PInstrumentDefXMLParser : public QXmlDefaultHandler +class PInstrumentDefXMLParser { public: - PInstrumentDefXMLParser(PAdmin*); + PInstrumentDefXMLParser(const QString &fln, PAdmin*); virtual ~PInstrumentDefXMLParser() {} + virtual bool isValid() { return fValid; } + private: enum EKeyWords {eEmpty, eInstitute, eInstrument, eRunNameTemplate, eBeamline, eDataFileFormat, eTf, eZf, eLf, eNoOfDetectors, eFgbOffset, eLgb, eBkgRange, eLogicDetector}; + bool parse(QIODevice *device); bool startDocument(); - bool startElement(const QString&, const QString&, const QString& , - const QXmlAttributes& qAttr); - bool endElement( const QString&, const QString&, const QString& ); - - bool characters(const QString&); + bool startElement(); + bool endElement(); + bool characters(); bool endDocument(); - bool warning( const QXmlParseException & exception ); - bool error( const QXmlParseException & exception ); - bool fatalError( const QXmlParseException & exception ); - - EKeyWords fKeyWord; ///< key word tag to know how to handle the content - PAdmin *fAdmin; ///< a pointer to the main administration class object + QXmlStreamReader fXml; ///< xml stream reader object + bool fValid; ///< flag showing if XML read has been successful + EKeyWords fKeyWord; ///< key word tag to know how to handle the content + PAdmin *fAdmin; ///< a pointer to the main administration class object QString fInstituteName; PInstrument *fInstrument; @@ -128,27 +130,26 @@ class PMusrWizDefault }; //--------------------------------------------------------------------------- -class PMusrWizDefaultXMLParser : public QXmlDefaultHandler +class PMusrWizDefaultXMLParser { public: - PMusrWizDefaultXMLParser(PAdmin*); + PMusrWizDefaultXMLParser(const QString &fln, PAdmin*); virtual ~PMusrWizDefaultXMLParser() {} + virtual bool isValid() { return fValid; } + private: enum EKeyWords {eEmpty, eInstitute, eInstrument, eFitType}; + bool parse(QIODevice *device); bool startDocument(); - bool startElement(const QString&, const QString&, const QString& , - const QXmlAttributes& ); - bool endElement( const QString&, const QString&, const QString& ); - - bool characters(const QString&); + bool startElement(); + bool endElement(); + bool characters(); bool endDocument(); - bool warning( const QXmlParseException & exception ); - bool error( const QXmlParseException & exception ); - bool fatalError( const QXmlParseException & exception ); - + QXmlStreamReader fXml; ///< xml stream reader object + bool fValid; ///< flag showing if XML read has been successful EKeyWords fKeyWord; ///< key word tag to know how to handle the content PAdmin *fAdmin; ///< a pointer to the main administration class object