Merged muonspin/musrfit:root6 into master
This commit is contained in:
commit
268772e953
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringRef>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
@ -82,9 +83,56 @@ void PmuppColor::setRGB(const int r, const int g, const int b)
|
|||||||
*
|
*
|
||||||
* \param admin pointer to an admin class instance.
|
* \param admin pointer to an admin class instance.
|
||||||
*/
|
*/
|
||||||
PmuppAdminXMLParser::PmuppAdminXMLParser(PmuppAdmin *admin) : fAdmin(admin)
|
PmuppAdminXMLParser::PmuppAdminXMLParser(const QString& fln, PmuppAdmin *admin) : fAdmin(admin)
|
||||||
{
|
{
|
||||||
|
fValid = false;
|
||||||
fKeyWord = eEmpty;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QFile file(fln);
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
// warning and create default - STILL MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
fValid = parse(&file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>parse the mupp startup xml-file.
|
||||||
|
*
|
||||||
|
* \param device QFile object of the mupp startup xml-file
|
||||||
|
*
|
||||||
|
* @return true on success, false otherwise
|
||||||
|
*/
|
||||||
|
bool PmuppAdminXMLParser::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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -93,6 +141,7 @@ PmuppAdminXMLParser::PmuppAdminXMLParser(PmuppAdmin *admin) : fAdmin(admin)
|
|||||||
*/
|
*/
|
||||||
bool PmuppAdminXMLParser::startDocument()
|
bool PmuppAdminXMLParser::startDocument()
|
||||||
{
|
{
|
||||||
|
// nothing to be done here for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,13 +149,11 @@ bool PmuppAdminXMLParser::startDocument()
|
|||||||
/**
|
/**
|
||||||
* <p>Routine called when a new XML tag is found. Here it is used
|
* <p>Routine called when a new XML tag is found. Here it is used
|
||||||
* to set a tag for filtering afterwards the content.
|
* to set a tag for filtering afterwards the content.
|
||||||
*
|
|
||||||
* \param qName name of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PmuppAdminXMLParser::startElement( const QString&, const QString&,
|
bool PmuppAdminXMLParser::startElement()
|
||||||
const QString& qName,
|
|
||||||
const QXmlAttributes& )
|
|
||||||
{
|
{
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
if (qName == "path_file_name") {
|
if (qName == "path_file_name") {
|
||||||
fKeyWord = eRecentFile;
|
fKeyWord = eRecentFile;
|
||||||
} else if (qName == "dark_theme") {
|
} else if (qName == "dark_theme") {
|
||||||
@ -125,10 +172,8 @@ bool PmuppAdminXMLParser::startElement( const QString&, const QString&,
|
|||||||
* <p>Routine called when the end XML tag is found. It is used to
|
* <p>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
|
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||||
* the entry was a theory function.
|
* the entry was a theory function.
|
||||||
*
|
|
||||||
* \param qName name of the element.
|
|
||||||
*/
|
*/
|
||||||
bool PmuppAdminXMLParser::endElement( const QString&, const QString&, const QString& )
|
bool PmuppAdminXMLParser::endElement()
|
||||||
{
|
{
|
||||||
fKeyWord = eEmpty;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
@ -139,11 +184,13 @@ bool PmuppAdminXMLParser::endElement( const QString&, const QString&, const QStr
|
|||||||
/**
|
/**
|
||||||
* <p>This routine delivers the content of an XML tag. It fills the
|
* <p>This routine delivers the content of an XML tag. It fills the
|
||||||
* content into the load data structure.
|
* content into the load data structure.
|
||||||
*
|
|
||||||
* \param str keeps the content of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PmuppAdminXMLParser::characters(const QString& str)
|
bool PmuppAdminXMLParser::characters()
|
||||||
{
|
{
|
||||||
|
QString str = *fXml.text().string();
|
||||||
|
if (str.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int ival, r, g, b;
|
int ival, r, g, b;
|
||||||
double dval;
|
double dval;
|
||||||
@ -218,66 +265,6 @@ bool PmuppAdminXMLParser::endDocument()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report XML warnings.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML warning
|
|
||||||
*/
|
|
||||||
bool PmuppAdminXMLParser::warning( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**WARNING** while parsing mupp_startup.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report recoverable XML errors.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML recoverable errors.
|
|
||||||
*/
|
|
||||||
bool PmuppAdminXMLParser::error( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**ERROR** while parsing mupp_startup.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report fatal XML errors.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML fatal errors.
|
|
||||||
*/
|
|
||||||
bool PmuppAdminXMLParser::fatalError( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**FATAL ERROR** while parsing mupp_startup.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 PmuppAdmin class
|
// implementation of PmuppAdmin class
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -316,20 +303,15 @@ PmuppAdmin::PmuppAdmin() : QObject(), fDarkTheme(false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QFile::exists(pathFln)) { // administration file present
|
if (QFile::exists(pathFln)) { // administration file present
|
||||||
PmuppAdminXMLParser handler(this);
|
PmuppAdminXMLParser handler(pathFln, this);
|
||||||
QFile xmlFile(pathFln);
|
if (!handler.isValid()) {
|
||||||
QXmlInputSource source( &xmlFile );
|
QMessageBox::critical(0, "**ERROR**",
|
||||||
QXmlSimpleReader reader;
|
|
||||||
reader.setContentHandler( &handler );
|
|
||||||
reader.setErrorHandler( &handler );
|
|
||||||
if (!reader.parse( source )) {
|
|
||||||
QMessageBox::critical(0, "ERROR",
|
|
||||||
"Error parsing mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
"Error parsing mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||||
QMessageBox::Ok, QMessageBox::NoButton);
|
QMessageBox::Ok, QMessageBox::NoButton);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(0, "ERROR",
|
QMessageBox::critical(0, "**ERROR**",
|
||||||
"Couldn't find the mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
"Couldn't find the mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||||
QMessageBox::Ok, QMessageBox::NoButton);
|
QMessageBox::Ok, QMessageBox::NoButton);
|
||||||
return;
|
return;
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QtXml>
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
#include "mupp.h"
|
#include "mupp.h"
|
||||||
|
|
||||||
@ -93,29 +93,28 @@ class PmuppMarker {
|
|||||||
* necessary informations about executable pathes, online help informations,
|
* necessary informations about executable pathes, online help informations,
|
||||||
* default font sizes, etc.
|
* default font sizes, etc.
|
||||||
*/
|
*/
|
||||||
class PmuppAdminXMLParser : public QXmlDefaultHandler
|
class PmuppAdminXMLParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PmuppAdminXMLParser(PmuppAdmin*);
|
PmuppAdminXMLParser(const QString &fln, PmuppAdmin*);
|
||||||
virtual ~PmuppAdminXMLParser() {}
|
virtual ~PmuppAdminXMLParser() {}
|
||||||
|
|
||||||
|
virtual bool isValid() { return fValid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor};
|
enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor};
|
||||||
|
|
||||||
|
bool parse(QIODevice *device);
|
||||||
bool startDocument();
|
bool startDocument();
|
||||||
bool startElement( const QString&, const QString&, const QString& ,
|
bool startElement();
|
||||||
const QXmlAttributes& );
|
bool endElement();
|
||||||
bool endElement( const QString&, const QString&, const QString& );
|
bool characters();
|
||||||
|
|
||||||
bool characters(const QString&);
|
|
||||||
bool endDocument();
|
bool endDocument();
|
||||||
|
|
||||||
bool warning( const QXmlParseException & exception );
|
QXmlStreamReader fXml; ///< xml stream reader object
|
||||||
bool error( const QXmlParseException & exception );
|
bool fValid; ///< flag showing if XML read has been successful
|
||||||
bool fatalError( const QXmlParseException & exception );
|
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||||
|
PmuppAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
|
||||||
PmuppAdmin *fAdmin; ///< a pointer to the main administration class object
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "mupp_version.h"
|
#include "mupp_version.h"
|
||||||
#include "PmuppScript.h"
|
#include "PmuppScript.h"
|
||||||
|
@ -36,6 +36,9 @@ using namespace std;
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QXmlStreamAttributes>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "PAdmin.h"
|
#include "PAdmin.h"
|
||||||
|
|
||||||
@ -47,28 +50,78 @@ using namespace std;
|
|||||||
*
|
*
|
||||||
* \param admin pointer to an admin class instance.
|
* \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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QFile file(fln);
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
// warning and create default - STILL MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
fValid = parse(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>Routine called at the beginning of the XML parsing process.
|
||||||
*/
|
*/
|
||||||
bool PFuncXMLParser::startElement(const QString&, const QString&,
|
bool PFuncXMLParser::startDocument()
|
||||||
const QString& qName,
|
|
||||||
const QXmlAttributes& qAttr)
|
|
||||||
{
|
{
|
||||||
|
// nothing to be done here for now
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>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("");
|
QString errMsg("");
|
||||||
int ival;
|
int ival;
|
||||||
double dval;
|
double dval;
|
||||||
@ -83,29 +136,26 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
|||||||
} else if (qName == "theo_fun") {
|
} else if (qName == "theo_fun") {
|
||||||
fKeyWord = eTemplateFunc;
|
fKeyWord = eTemplateFunc;
|
||||||
} else if (qName == "theo_map") {
|
} else if (qName == "theo_map") {
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
if (qAttr.count() != 2) {
|
if (qAttr.count() != 2) {
|
||||||
errMsg = QString("theo_map should have 2 attributes, called 'no', and 'name', found %1").arg(qAttr.count());
|
errMsg = QString("theo_map should have 2 attributes, called 'no', and 'name', found %1").arg(qAttr.count());
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PParam map;
|
PParam map;
|
||||||
for (int i=0; i<qAttr.count(); i++) {
|
// get map number
|
||||||
if (qAttr.qName(i) == "no") {
|
str = qAttr.value("no").toString();
|
||||||
ival = qAttr.value(i).toInt(&ok);
|
ival = str.toInt(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
errMsg = QString("theo_map attribute 'no' is not a number (%1)").arg(qAttr.value(i));
|
errMsg = QString("theo_map attribute 'no' is not a number (%1)").arg(str);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
map.setNumber(ival);
|
|
||||||
} else if (qAttr.qName(i) == "name") {
|
|
||||||
map.setName(qAttr.value(i));
|
|
||||||
} else {
|
|
||||||
errMsg = QString("found unkown theo_map attribute (%1)").arg(qAttr.qName(i));
|
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
map.setNumber(ival);
|
||||||
|
// get map name
|
||||||
|
str = qAttr.value("name").toString();
|
||||||
|
map.setName(str);
|
||||||
|
|
||||||
// check that all necessary attributes where found
|
// check that all necessary attributes where found
|
||||||
if ((map.getName() == "UnDef") || (map.getNumber() == -1)) {
|
if ((map.getName() == "UnDef") || (map.getNumber() == -1)) {
|
||||||
errMsg = QString("found theo_map with missing attribute(s)");
|
errMsg = QString("found theo_map with missing attribute(s)");
|
||||||
@ -114,45 +164,51 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
|||||||
}
|
}
|
||||||
fTheoTemplate.appendMap(map);
|
fTheoTemplate.appendMap(map);
|
||||||
} else if (qName == "template_param") {
|
} else if (qName == "template_param") {
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
if ((qAttr.count() != 4) && (qAttr.count() != 6)) {
|
if ((qAttr.count() != 4) && (qAttr.count() != 6)) {
|
||||||
errMsg = QString("template_param should have 4 or 6 attributes, called\n'no', 'name', 'value', 'step', ['boundLow', 'boundHigh'] found %1").arg(qAttr.count());
|
errMsg = QString("template_param should have 4 or 6 attributes, called\n'no', 'name', 'value', 'step', ['boundLow', 'boundHigh'] found %1").arg(qAttr.count());
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PParam param;
|
PParam param;
|
||||||
for (int i=0; i<qAttr.count(); i++) {
|
// parameter number
|
||||||
if (qAttr.qName(i) == "no") {
|
str = qAttr.value("no").toString();
|
||||||
ival = qAttr.value(i).toInt(&ok);
|
ival = str.toInt(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
errMsg = QString("template_param attribute 'no' is not a number (%1)").arg(qAttr.value(i));
|
errMsg = QString("template_param attribute 'no' is not a number (%1)").arg(str);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
param.setNumber(ival);
|
|
||||||
} else if (qAttr.qName(i) == "name") {
|
|
||||||
param.setName(qAttr.value(i));
|
|
||||||
} else if (qAttr.qName(i) == "value") {
|
|
||||||
dval = qAttr.value(i).toDouble(&ok);
|
|
||||||
if (!ok) {
|
|
||||||
errMsg = QString("template_param attribute 'value' is not a number (%1)").arg(qAttr.value(i));
|
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
param.setValue(dval);
|
|
||||||
} else if (qAttr.qName(i) == "step") {
|
|
||||||
dval = qAttr.value(i).toDouble(&ok);
|
|
||||||
if (!ok) {
|
|
||||||
errMsg = QString("template_param attribute 'step' is not a number (%1)").arg(qAttr.value(i));
|
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
param.setStep(dval);
|
|
||||||
} else if (qAttr.qName(i) == "boundLow") {
|
|
||||||
param.setBoundLow(qAttr.qName(i));
|
|
||||||
} else if (qAttr.qName(i) == "boundHigh") {
|
|
||||||
param.setBoundHigh(qAttr.qName(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
param.setNumber(ival);
|
||||||
|
// parameter name
|
||||||
|
str = qAttr.value("name").toString();
|
||||||
|
param.setName(str);
|
||||||
|
// parameter value
|
||||||
|
str = qAttr.value("value").toString();
|
||||||
|
dval = str.toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
errMsg = QString("template_param attribute 'value' is not a number (%1)").arg(str);
|
||||||
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
param.setValue(dval);
|
||||||
|
// parameter step
|
||||||
|
str = qAttr.value("step").toString();
|
||||||
|
dval = str.toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
errMsg = QString("template_param attribute 'step' is not a number (%1)").arg(str);
|
||||||
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
param.setStep(dval);
|
||||||
|
// parameter lower bound
|
||||||
|
str = qAttr.value("boundLow").toString();
|
||||||
|
if (!str.isEmpty())
|
||||||
|
param.setBoundLow(str);
|
||||||
|
// parameter upper bound
|
||||||
|
str = qAttr.value("boundHigh").toString();
|
||||||
|
if (!str.isEmpty())
|
||||||
|
param.setBoundHigh(str);
|
||||||
fTheoTemplate.appendParam(param);
|
fTheoTemplate.appendParam(param);
|
||||||
} else if (qName == "func") {
|
} else if (qName == "func") {
|
||||||
fFunc.initFunc();
|
fFunc.initFunc();
|
||||||
@ -177,12 +233,16 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
if (qName == "theo_template") {
|
if (qName == "theo_template") {
|
||||||
fAdmin->fTheoTemplate.push_back(fTheoTemplate);
|
fAdmin->fTheoTemplate.push_back(fTheoTemplate);
|
||||||
} else if (qName == "func") {
|
} else if (qName == "func") {
|
||||||
@ -196,10 +256,15 @@ bool PFuncXMLParser::endElement( const QString&, const QString&, const QString &
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>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;
|
bool ok;
|
||||||
int ival;
|
int ival;
|
||||||
double dval;
|
double dval;
|
||||||
@ -246,82 +311,77 @@ bool PFuncXMLParser::characters(const QString &str)
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>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()
|
bool PFuncXMLParser::endDocument()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*/
|
|
||||||
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
|
// implementation of PInstrumentDefXMLParser class
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>XML Parser class for the instrument definition file(s).
|
* <p>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.
|
* \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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
fInstituteName = "";
|
fInstituteName = "";
|
||||||
fInstrument = 0;
|
fInstrument = 0;
|
||||||
fSetup = 0;
|
fSetup = 0;
|
||||||
|
|
||||||
|
QFile file(fln);
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
// warning and create default - STILL MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
fValid = parse(&file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>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()
|
bool PInstrumentDefXMLParser::startDocument()
|
||||||
{
|
{
|
||||||
|
// nothing to be done here for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,13 +398,11 @@ bool PInstrumentDefXMLParser::startDocument()
|
|||||||
/**
|
/**
|
||||||
* <p>Routine called when a new XML tag is found. Here it is used
|
* <p>Routine called when a new XML tag is found. Here it is used
|
||||||
* to set a tag for filtering afterwards the content.
|
* to set a tag for filtering afterwards the content.
|
||||||
*
|
|
||||||
* \param qName name of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
bool PInstrumentDefXMLParser::startElement()
|
||||||
const QString& qName,
|
|
||||||
const QXmlAttributes& qAttr)
|
|
||||||
{
|
{
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
double dval;
|
double dval;
|
||||||
double ival;
|
double ival;
|
||||||
@ -356,6 +415,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
|||||||
fKeyWord = eInstitute;
|
fKeyWord = eInstitute;
|
||||||
} else if (qName == "instrument") {
|
} else if (qName == "instrument") {
|
||||||
fKeyWord = eInstrument;
|
fKeyWord = eInstrument;
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
if (qAttr.count() != 1) {
|
if (qAttr.count() != 1) {
|
||||||
errMsg = QString("instrument should have 1 attribute, called 'name', found %1").arg(qAttr.count());
|
errMsg = QString("instrument should have 1 attribute, called 'name', found %1").arg(qAttr.count());
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
@ -369,7 +429,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
|||||||
// create an instrument object
|
// create an instrument object
|
||||||
fInstrument = new PInstrument();
|
fInstrument = new PInstrument();
|
||||||
fInstrument->setInstitue(fInstituteName);
|
fInstrument->setInstitue(fInstituteName);
|
||||||
fInstrument->setName(qAttr.value(0));
|
fInstrument->setName(qAttr.value("name").toString());
|
||||||
} else if (qName == "run_name_template") {
|
} else if (qName == "run_name_template") {
|
||||||
fKeyWord = eRunNameTemplate;
|
fKeyWord = eRunNameTemplate;
|
||||||
} else if (qName == "beamline") {
|
} else if (qName == "beamline") {
|
||||||
@ -378,23 +438,26 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
|||||||
fKeyWord = eDataFileFormat;
|
fKeyWord = eDataFileFormat;
|
||||||
} else if (qName == "tf") {
|
} else if (qName == "tf") {
|
||||||
fKeyWord = eTf;
|
fKeyWord = eTf;
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
fSetup = new PSetup();
|
fSetup = new PSetup();
|
||||||
if (qAttr.count() == 1)
|
if (qAttr.count() == 1)
|
||||||
fSetup->setName(qAttr.value(0));
|
fSetup->setName(qAttr.value("name").toString());
|
||||||
else
|
else
|
||||||
fSetup->setName("Default");
|
fSetup->setName("Default");
|
||||||
} else if (qName == "zf") {
|
} else if (qName == "zf") {
|
||||||
fKeyWord = eZf;
|
fKeyWord = eZf;
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
fSetup = new PSetup();
|
fSetup = new PSetup();
|
||||||
if (qAttr.count() == 1)
|
if (qAttr.count() == 1)
|
||||||
fSetup->setName(qAttr.value(0));
|
fSetup->setName(qAttr.value("name").toString());
|
||||||
else
|
else
|
||||||
fSetup->setName("Default");
|
fSetup->setName("Default");
|
||||||
} else if (qName == "lf") {
|
} else if (qName == "lf") {
|
||||||
fKeyWord = eLf;
|
fKeyWord = eLf;
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
fSetup = new PSetup();
|
fSetup = new PSetup();
|
||||||
if (qAttr.count() == 1)
|
if (qAttr.count() == 1)
|
||||||
fSetup->setName(qAttr.value(0));
|
fSetup->setName(qAttr.value("name").toString());
|
||||||
else
|
else
|
||||||
fSetup->setName("Default");
|
fSetup->setName("Default");
|
||||||
} else if (qName == "no_of_detectors") {
|
} else if (qName == "no_of_detectors") {
|
||||||
@ -406,94 +469,78 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
|||||||
} else if (qName == "asym_bkg_range") {
|
} else if (qName == "asym_bkg_range") {
|
||||||
fKeyWord = eBkgRange;
|
fKeyWord = eBkgRange;
|
||||||
} else if (qName == "logic_detector") {
|
} else if (qName == "logic_detector") {
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
if (qAttr.count() < 3)
|
if (qAttr.count() < 3)
|
||||||
return false;
|
return false;
|
||||||
PDetector detect;
|
PDetector detect;
|
||||||
int count=0;
|
// detector name
|
||||||
for (int i=0; i<qAttr.count(); i++) {
|
str = qAttr.value("name").toString();
|
||||||
if (qAttr.localName(i) == "name") {
|
detect.setName(str);
|
||||||
detect.setName(qAttr.value(i)); // detector name
|
// detector relative phase
|
||||||
count++;
|
str = qAttr.value("rel_phase").toString();
|
||||||
} else if (qAttr.localName(i) == "rel_phase") {
|
dval = str.toDouble(&ok);
|
||||||
str = qAttr.value(i);
|
if (!ok) {
|
||||||
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; j<strL.size(); j++) {
|
|
||||||
ival = strL[j].toInt(&ok);
|
|
||||||
if (!ok)
|
|
||||||
return false;
|
|
||||||
forward.push_back(ival);
|
|
||||||
}
|
|
||||||
detect.setForwards(forward);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count != 3) // i.e. didn't find all needed attributes
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
detect.setRelGeomPhase(dval);
|
||||||
|
// detector number(s)
|
||||||
|
str = qAttr.value("forward").toString();
|
||||||
|
strL.clear();
|
||||||
|
strL = str.split(' ');
|
||||||
|
forward.clear();
|
||||||
|
for (int j=0; j<strL.size(); j++) {
|
||||||
|
ival = strL[j].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return false;
|
||||||
|
forward.push_back(ival);
|
||||||
|
}
|
||||||
|
detect.setForwards(forward);
|
||||||
fSetup->addDetector(detect);
|
fSetup->addDetector(detect);
|
||||||
} else if (qName == "logic_asym_detector") {
|
} else if (qName == "logic_asym_detector") {
|
||||||
|
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||||
if (qAttr.count() != 5)
|
if (qAttr.count() != 5)
|
||||||
return false;
|
return false;
|
||||||
PDetector detect;
|
PDetector detect;
|
||||||
int count=0;
|
// detector name
|
||||||
for (int i=0; i<5; i++) {
|
str = qAttr.value("name").toString();
|
||||||
if (qAttr.localName(i) == "name") {
|
detect.setName(str);
|
||||||
detect.setName(qAttr.value(i)); // detector name
|
// detector relative phase
|
||||||
count++;
|
str = qAttr.value("rel_phase").toString();
|
||||||
} else if (qAttr.localName(i) == "rel_phase") {
|
dval = str.toDouble(&ok);
|
||||||
str = qAttr.value(i);
|
if (!ok) {
|
||||||
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; j<strL.size(); j++) {
|
|
||||||
ival = strL[j].toInt(&ok);
|
|
||||||
if (!ok)
|
|
||||||
return false;
|
|
||||||
forward.push_back(ival);
|
|
||||||
}
|
|
||||||
detect.setForwards(forward);
|
|
||||||
count++;
|
|
||||||
} else if (qAttr.localName(i) == "backward") {
|
|
||||||
str = qAttr.value(i);
|
|
||||||
strL.clear();
|
|
||||||
strL = str.split(' ');
|
|
||||||
backward.clear();
|
|
||||||
for (int j=0; j<strL.size(); j++) {
|
|
||||||
ival = strL[j].toInt(&ok);
|
|
||||||
if (!ok)
|
|
||||||
return false;
|
|
||||||
backward.push_back(ival);
|
|
||||||
}
|
|
||||||
detect.setBackwards(backward);
|
|
||||||
count++;
|
|
||||||
} else if (qAttr.localName(i) == "alpha") {
|
|
||||||
str = qAttr.value(i);
|
|
||||||
dval = str.toDouble(&ok);
|
|
||||||
if (!ok)
|
|
||||||
return false;
|
|
||||||
detect.setAlpha(dval);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count != 5) // i.e. didn't find all needed attributes
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
detect.setRelGeomPhase(dval);
|
||||||
|
// detector forward
|
||||||
|
str = qAttr.value("forward").toString();
|
||||||
|
strL.clear();
|
||||||
|
strL = str.split(' ');
|
||||||
|
forward.clear();
|
||||||
|
for (int j=0; j<strL.size(); j++) {
|
||||||
|
ival = strL[j].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return false;
|
||||||
|
forward.push_back(ival);
|
||||||
|
}
|
||||||
|
detect.setForwards(forward);
|
||||||
|
// detector backward
|
||||||
|
str = qAttr.value("backward").toString();
|
||||||
|
strL.clear();
|
||||||
|
strL = str.split(' ');
|
||||||
|
backward.clear();
|
||||||
|
for (int j=0; j<strL.size(); j++) {
|
||||||
|
ival = strL[j].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return false;
|
||||||
|
backward.push_back(ival);
|
||||||
|
}
|
||||||
|
detect.setForwards(backward);
|
||||||
|
// detector alpha
|
||||||
|
str = qAttr.value("alpha").toString();
|
||||||
|
dval = str.toDouble(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return false;
|
||||||
|
detect.setAlpha(dval);
|
||||||
fSetup->addAsymDetector(detect);
|
fSetup->addAsymDetector(detect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,13 +552,13 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
|||||||
* <p>Routine called when the end XML tag is found. It is used to
|
* <p>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
|
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||||
* the entry was a theory function.
|
* 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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
if (qName == "instrument") {
|
if (qName == "instrument") {
|
||||||
// store instrument
|
// store instrument
|
||||||
fAdmin->addInstrument(fInstituteName, *fInstrument);
|
fAdmin->addInstrument(fInstituteName, *fInstrument);
|
||||||
@ -557,11 +604,13 @@ bool PInstrumentDefXMLParser::endElement( const QString&, const QString&, const
|
|||||||
/**
|
/**
|
||||||
* <p>This routine delivers the content of an XML tag. It fills the
|
* <p>This routine delivers the content of an XML tag. It fills the
|
||||||
* content into the load data structure.
|
* 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;
|
bool ok;
|
||||||
int ival, start, end;
|
int ival, start, end;
|
||||||
QString errMsg;
|
QString errMsg;
|
||||||
@ -649,66 +698,6 @@ bool PInstrumentDefXMLParser::endDocument()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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
|
// implementation of PMusrWizDefault class
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -730,9 +719,56 @@ PMusrWizDefault::PMusrWizDefault()
|
|||||||
*
|
*
|
||||||
* \param admin pointer to an admin class instance.
|
* \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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QFile file(fln);
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
// warning and create default - STILL MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
fValid = parse(&file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>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()
|
bool PMusrWizDefaultXMLParser::startDocument()
|
||||||
{
|
{
|
||||||
|
// nothing to be done here for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,13 +785,11 @@ bool PMusrWizDefaultXMLParser::startDocument()
|
|||||||
/**
|
/**
|
||||||
* <p>Routine called when a new XML tag is found. Here it is used
|
* <p>Routine called when a new XML tag is found. Here it is used
|
||||||
* to set a tag for filtering afterwards the content.
|
* to set a tag for filtering afterwards the content.
|
||||||
*
|
|
||||||
* \param qName name of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&,
|
bool PMusrWizDefaultXMLParser::startElement()
|
||||||
const QString& qName,
|
|
||||||
const QXmlAttributes& )
|
|
||||||
{
|
{
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
if (qName == "institute") {
|
if (qName == "institute") {
|
||||||
fKeyWord = eInstitute;
|
fKeyWord = eInstitute;
|
||||||
} else if (qName == "instrument") {
|
} else if (qName == "instrument") {
|
||||||
@ -771,10 +806,8 @@ bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&,
|
|||||||
* <p>Routine called when the end XML tag is found. It is used to
|
* <p>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
|
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||||
* the entry was a theory function.
|
* 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;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
@ -785,11 +818,13 @@ bool PMusrWizDefaultXMLParser::endElement( const QString&, const QString&, const
|
|||||||
/**
|
/**
|
||||||
* <p>This routine delivers the content of an XML tag. It fills the
|
* <p>This routine delivers the content of an XML tag. It fills the
|
||||||
* content into the load data structure.
|
* 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) {
|
switch (fKeyWord) {
|
||||||
case eInstitute:
|
case eInstitute:
|
||||||
fDefault.setInstitute(str);
|
fDefault.setInstitute(str);
|
||||||
@ -818,66 +853,6 @@ bool PMusrWizDefaultXMLParser::endDocument()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>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
|
// implementation of PAdmin class
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -1245,12 +1220,8 @@ int PAdmin::loadMusrWizDefault(QString fln)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PMusrWizDefaultXMLParser handler(this);
|
PMusrWizDefaultXMLParser handler(fln, this);
|
||||||
QFile xmlFile(fln);
|
if (!handler.isValid()) {
|
||||||
QXmlInputSource source( &xmlFile );
|
|
||||||
QXmlSimpleReader reader;
|
|
||||||
reader.setContentHandler( &handler );
|
|
||||||
if (!reader.parse(source)) {
|
|
||||||
QString errMsg = QString("Error parsing %1 file.").arg(fln);
|
QString errMsg = QString("Error parsing %1 file.").arg(fln);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return 1;
|
return 1;
|
||||||
@ -1282,12 +1253,8 @@ int PAdmin::loadMusrfitFunc(QString fln)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PFuncXMLParser handler(this);
|
PFuncXMLParser handler(fln, this);
|
||||||
QFile xmlFile(fln);
|
if (!handler.isValid()) {
|
||||||
QXmlInputSource source( &xmlFile );
|
|
||||||
QXmlSimpleReader reader;
|
|
||||||
reader.setContentHandler( &handler );
|
|
||||||
if (!reader.parse(source)) {
|
|
||||||
QString errMsg = QString("Error parsing %1 musrfit func file.").arg(fln);
|
QString errMsg = QString("Error parsing %1 musrfit func file.").arg(fln);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return 1;
|
return 1;
|
||||||
@ -1326,12 +1293,8 @@ int PAdmin::loadInstrumentDef(QString path, QString fln)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PInstrumentDefXMLParser handler(this);
|
PInstrumentDefXMLParser handler(pathFln, this);
|
||||||
QFile xmlFile(pathFln);
|
if (!handler.isValid()) {
|
||||||
QXmlInputSource source( &xmlFile );
|
|
||||||
QXmlSimpleReader reader;
|
|
||||||
reader.setContentHandler( &handler );
|
|
||||||
if (!reader.parse(source)) {
|
|
||||||
QString errMsg = QString("Error parsing %1 instrument def file.").arg(pathFln);
|
QString errMsg = QString("Error parsing %1 instrument def file.").arg(pathFln);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -32,7 +32,10 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QtXml>
|
#include <QXmlStreamReader>
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
#include "PTheoTemplate.h"
|
#include "PTheoTemplate.h"
|
||||||
#include "PMusrfitFunc.h"
|
#include "PMusrfitFunc.h"
|
||||||
@ -41,32 +44,32 @@
|
|||||||
class PAdmin;
|
class PAdmin;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
class PFuncXMLParser : public QXmlDefaultHandler
|
class PFuncXMLParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PFuncXMLParser(PAdmin*);
|
PFuncXMLParser(const QString &fln, PAdmin*);
|
||||||
virtual ~PFuncXMLParser() {}
|
virtual ~PFuncXMLParser() {}
|
||||||
|
|
||||||
|
virtual bool isValid() { return fValid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EFuncKeyWords {eEmpty,
|
enum EFuncKeyWords {eEmpty,
|
||||||
eTemplateName, eTemplateTheo, eTemplateFunc,
|
eTemplateName, eTemplateTheo, eTemplateFunc,
|
||||||
eName, eAbbrv, eNoOfParam, eParam,
|
eName, eAbbrv, eNoOfParam, eParam,
|
||||||
eParamName, eParamValue, eParamMap};
|
eParamName, eParamValue, eParamMap};
|
||||||
|
|
||||||
|
bool parse(QIODevice *device);
|
||||||
bool startDocument();
|
bool startDocument();
|
||||||
bool startElement(const QString&, const QString&, const QString& ,
|
bool startElement();
|
||||||
const QXmlAttributes& qAttr);
|
bool endElement();
|
||||||
bool endElement( const QString&, const QString&, const QString& );
|
bool characters();
|
||||||
|
|
||||||
bool characters(const QString&);
|
|
||||||
bool endDocument();
|
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
|
QXmlStreamReader fXml; ///< xml stream reader object
|
||||||
PAdmin *fAdmin; ///< a pointer to the main administration class 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;
|
PTheoTemplate fTheoTemplate;
|
||||||
PMusrfitFunc fFunc;
|
PMusrfitFunc fFunc;
|
||||||
@ -74,32 +77,31 @@ class PFuncXMLParser : public QXmlDefaultHandler
|
|||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
class PInstrumentDefXMLParser : public QXmlDefaultHandler
|
class PInstrumentDefXMLParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PInstrumentDefXMLParser(PAdmin*);
|
PInstrumentDefXMLParser(const QString &fln, PAdmin*);
|
||||||
virtual ~PInstrumentDefXMLParser() {}
|
virtual ~PInstrumentDefXMLParser() {}
|
||||||
|
|
||||||
|
virtual bool isValid() { return fValid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EKeyWords {eEmpty, eInstitute, eInstrument, eRunNameTemplate,
|
enum EKeyWords {eEmpty, eInstitute, eInstrument, eRunNameTemplate,
|
||||||
eBeamline, eDataFileFormat, eTf, eZf, eLf,
|
eBeamline, eDataFileFormat, eTf, eZf, eLf,
|
||||||
eNoOfDetectors, eFgbOffset, eLgb, eBkgRange,
|
eNoOfDetectors, eFgbOffset, eLgb, eBkgRange,
|
||||||
eLogicDetector};
|
eLogicDetector};
|
||||||
|
|
||||||
|
bool parse(QIODevice *device);
|
||||||
bool startDocument();
|
bool startDocument();
|
||||||
bool startElement(const QString&, const QString&, const QString& ,
|
bool startElement();
|
||||||
const QXmlAttributes& qAttr);
|
bool endElement();
|
||||||
bool endElement( const QString&, const QString&, const QString& );
|
bool characters();
|
||||||
|
|
||||||
bool characters(const QString&);
|
|
||||||
bool endDocument();
|
bool endDocument();
|
||||||
|
|
||||||
bool warning( const QXmlParseException & exception );
|
QXmlStreamReader fXml; ///< xml stream reader object
|
||||||
bool error( const QXmlParseException & exception );
|
bool fValid; ///< flag showing if XML read has been successful
|
||||||
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
|
||||||
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
|
||||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
|
||||||
|
|
||||||
QString fInstituteName;
|
QString fInstituteName;
|
||||||
PInstrument *fInstrument;
|
PInstrument *fInstrument;
|
||||||
@ -128,27 +130,26 @@ class PMusrWizDefault
|
|||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
class PMusrWizDefaultXMLParser : public QXmlDefaultHandler
|
class PMusrWizDefaultXMLParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PMusrWizDefaultXMLParser(PAdmin*);
|
PMusrWizDefaultXMLParser(const QString &fln, PAdmin*);
|
||||||
virtual ~PMusrWizDefaultXMLParser() {}
|
virtual ~PMusrWizDefaultXMLParser() {}
|
||||||
|
|
||||||
|
virtual bool isValid() { return fValid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EKeyWords {eEmpty, eInstitute, eInstrument, eFitType};
|
enum EKeyWords {eEmpty, eInstitute, eInstrument, eFitType};
|
||||||
|
|
||||||
|
bool parse(QIODevice *device);
|
||||||
bool startDocument();
|
bool startDocument();
|
||||||
bool startElement(const QString&, const QString&, const QString& ,
|
bool startElement();
|
||||||
const QXmlAttributes& );
|
bool endElement();
|
||||||
bool endElement( const QString&, const QString&, const QString& );
|
bool characters();
|
||||||
|
|
||||||
bool characters(const QString&);
|
|
||||||
bool endDocument();
|
bool endDocument();
|
||||||
|
|
||||||
bool warning( const QXmlParseException & exception );
|
QXmlStreamReader fXml; ///< xml stream reader object
|
||||||
bool error( const QXmlParseException & exception );
|
bool fValid; ///< flag showing if XML read has been successful
|
||||||
bool fatalError( const QXmlParseException & exception );
|
|
||||||
|
|
||||||
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||||
|
|
||||||
|
@ -27,21 +27,76 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringRef>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "PChangeDefaultPathsDialog.h"
|
#include "PChangeDefaultPathsDialog.h"
|
||||||
|
|
||||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
/**
|
/**
|
||||||
* @brief PDefaultPathsXMLParser::PDefaultPathsXMLParser
|
* <p>XML Parser class for the musrfit administration file.
|
||||||
|
*
|
||||||
|
* \param fln file name of the musredit startup xml-file
|
||||||
* @param defaultPaths
|
* @param defaultPaths
|
||||||
*/
|
*/
|
||||||
PDefaultPathsXMLParser::PDefaultPathsXMLParser(PDefaultPaths *defaultPaths) :
|
PDefaultPathsXMLParser::PDefaultPathsXMLParser(const QString& fln, PDefaultPaths *defaultPaths) :
|
||||||
fDefaultPaths(defaultPaths)
|
fDefaultPaths(defaultPaths)
|
||||||
{
|
{
|
||||||
|
fValid = false;
|
||||||
fKeyWord = eEmpty;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
|
QFile file(fln);
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
|
// warning and create default - STILL MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
fValid = parse(&file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>parse the musrfit startup xml-file.
|
||||||
|
*
|
||||||
|
* \param device QFile object of the musrfit startup xml-file
|
||||||
|
*
|
||||||
|
* @return true on success, false otherwise
|
||||||
|
*/
|
||||||
|
bool PDefaultPathsXMLParser::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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -50,6 +105,7 @@ PDefaultPathsXMLParser::PDefaultPathsXMLParser(PDefaultPaths *defaultPaths) :
|
|||||||
*/
|
*/
|
||||||
bool PDefaultPathsXMLParser::startDocument()
|
bool PDefaultPathsXMLParser::startDocument()
|
||||||
{
|
{
|
||||||
|
// nothing to be done here for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,13 +113,11 @@ bool PDefaultPathsXMLParser::startDocument()
|
|||||||
/**
|
/**
|
||||||
* <p>Routine called when a new XML tag is found. Here it is used
|
* <p>Routine called when a new XML tag is found. Here it is used
|
||||||
* to set a tag for filtering afterwards the content.
|
* to set a tag for filtering afterwards the content.
|
||||||
*
|
|
||||||
* \param qName name of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PDefaultPathsXMLParser::startElement( const QString&, const QString&,
|
bool PDefaultPathsXMLParser::startElement()
|
||||||
const QString& qName,
|
|
||||||
const QXmlAttributes& )
|
|
||||||
{
|
{
|
||||||
|
QStringRef qName = fXml.name();
|
||||||
|
|
||||||
if (qName == "data_path") {
|
if (qName == "data_path") {
|
||||||
fKeyWord = eDataPath;
|
fKeyWord = eDataPath;
|
||||||
}
|
}
|
||||||
@ -75,10 +129,8 @@ bool PDefaultPathsXMLParser::startElement( const QString&, const QString&,
|
|||||||
/**
|
/**
|
||||||
* <p>Routine called when the end XML tag is found. It is used to
|
* <p>Routine called when the end XML tag is found. It is used to
|
||||||
* put the filtering tag to 'empty'.
|
* put the filtering tag to 'empty'.
|
||||||
*
|
|
||||||
* \param qName name of the element.
|
|
||||||
*/
|
*/
|
||||||
bool PDefaultPathsXMLParser::endElement( const QString&, const QString&, const QString & )
|
bool PDefaultPathsXMLParser::endElement()
|
||||||
{
|
{
|
||||||
fKeyWord = eEmpty;
|
fKeyWord = eEmpty;
|
||||||
|
|
||||||
@ -89,11 +141,13 @@ bool PDefaultPathsXMLParser::endElement( const QString&, const QString&, const Q
|
|||||||
/**
|
/**
|
||||||
* <p>This routine delivers the content of an XML tag. It fills the
|
* <p>This routine delivers the content of an XML tag. It fills the
|
||||||
* content into the load data structure.
|
* content into the load data structure.
|
||||||
*
|
|
||||||
* \param str keeps the content of the XML tag.
|
|
||||||
*/
|
*/
|
||||||
bool PDefaultPathsXMLParser::characters(const QString& str)
|
bool PDefaultPathsXMLParser::characters()
|
||||||
{
|
{
|
||||||
|
QString str = *fXml.text().string();
|
||||||
|
if (str.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
switch (fKeyWord) {
|
switch (fKeyWord) {
|
||||||
case eDataPath:
|
case eDataPath:
|
||||||
fDefaultPaths->appendDefaultPath(str);
|
fDefaultPaths->appendDefaultPath(str);
|
||||||
@ -115,67 +169,10 @@ bool PDefaultPathsXMLParser::endDocument()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report XML warnings.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML warning
|
|
||||||
*/
|
|
||||||
bool PDefaultPathsXMLParser::warning( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**WARNING** while parsing musrfit_startup.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report recoverable XML errors.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML recoverable errors.
|
|
||||||
*/
|
|
||||||
bool PDefaultPathsXMLParser::error( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**ERROR** while parsing musrfit_startup.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* <p>Report fatal XML errors.
|
|
||||||
*
|
|
||||||
* \param exception holds the information of the XML fatal errors.
|
|
||||||
*/
|
|
||||||
bool PDefaultPathsXMLParser::fatalError( const QXmlParseException & exception )
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
|
|
||||||
msg = QString("**FATAL ERROR** while parsing musrfit_startup.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
/**
|
||||||
|
* @brief PDefaultPaths::PDefaultPaths
|
||||||
|
*/
|
||||||
PDefaultPaths::PDefaultPaths() : QObject()
|
PDefaultPaths::PDefaultPaths() : QObject()
|
||||||
{
|
{
|
||||||
fValid = true;
|
fValid = true;
|
||||||
@ -204,13 +201,8 @@ PDefaultPaths::PDefaultPaths() : QObject()
|
|||||||
fPrefPathName = pathFln;
|
fPrefPathName = pathFln;
|
||||||
|
|
||||||
// read musrfit_startup.xml and extract default data file search paths
|
// read musrfit_startup.xml and extract default data file search paths
|
||||||
PDefaultPathsXMLParser handler(this);
|
PDefaultPathsXMLParser handler(fPrefPathName, this);
|
||||||
QFile xmlFile(fPrefPathName);
|
if (!handler.isValid()) {
|
||||||
QXmlInputSource source( &xmlFile );
|
|
||||||
QXmlSimpleReader reader;
|
|
||||||
reader.setContentHandler( &handler );
|
|
||||||
reader.setErrorHandler( &handler );
|
|
||||||
if (!reader.parse( source )) {
|
|
||||||
fValid = false;
|
fValid = false;
|
||||||
QMessageBox::critical(0, "ERROR",
|
QMessageBox::critical(0, "ERROR",
|
||||||
"Error parsing musrfit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
"Error parsing musrfit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||||
|
@ -32,36 +32,36 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QtXml>
|
#include <QXmlStreamReader>
|
||||||
|
#include <QIODevice>
|
||||||
|
|
||||||
#include "ui_PChangeDefaultPathsDialog.h"
|
#include "ui_PChangeDefaultPathsDialog.h"
|
||||||
|
|
||||||
class PDefaultPaths;
|
class PDefaultPaths;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
class PDefaultPathsXMLParser : public QXmlDefaultHandler
|
class PDefaultPathsXMLParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PDefaultPathsXMLParser(PDefaultPaths *defaultPaths);
|
PDefaultPathsXMLParser(const QString &fln, PDefaultPaths *defaultPaths);
|
||||||
virtual ~PDefaultPathsXMLParser() {}
|
virtual ~PDefaultPathsXMLParser() {}
|
||||||
|
|
||||||
|
virtual bool isValid() { return fValid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EAdminKeyWords {eEmpty, eDataPath};
|
enum EAdminKeyWords {eEmpty, eDataPath};
|
||||||
|
|
||||||
|
bool parse(QIODevice *device);
|
||||||
bool startDocument();
|
bool startDocument();
|
||||||
bool startElement( const QString&, const QString&, const QString& ,
|
bool startElement();
|
||||||
const QXmlAttributes& );
|
bool endElement();
|
||||||
bool endElement( const QString&, const QString&, const QString& );
|
bool characters();
|
||||||
|
|
||||||
bool characters(const QString&);
|
|
||||||
bool endDocument();
|
bool endDocument();
|
||||||
|
|
||||||
bool warning( const QXmlParseException & exception );
|
QXmlStreamReader fXml; ///< xml stream reader object
|
||||||
bool error( const QXmlParseException & exception );
|
bool fValid; ///< flag showing if XML read has been successful
|
||||||
bool fatalError( const QXmlParseException & exception );
|
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||||
|
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
|
||||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
|
||||||
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user