replaced obsolete QXmlDefaultHandler by QXmlStreamReader in mupp
This commit is contained in:
parent
c42bbd16f3
commit
35760525bb
@ -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
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -315,21 +302,16 @@ 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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user