Fix QRegularExpression

-add isValid
-add debug
This commit is contained in:
Simon De Backer 2020-09-23 22:19:13 +02:00
parent b5ae1237e3
commit 2fe53ba6e8

View File

@ -19,6 +19,7 @@
#include <QPainter> #include <QPainter>
#include <QMetaEnum> #include <QMetaEnum>
#include <QRegularExpression> #include <QRegularExpression>
#include <QtDebug>
/** /**
Constructeur par defaut Constructeur par defaut
*/ */
@ -789,16 +790,32 @@ void ConductorProperties::readStyle(const QString &style_string) {
QStringList styles = style_string.split(";", Qt::SkipEmptyParts); QStringList styles = style_string.split(";", Qt::SkipEmptyParts);
#endif #endif
QRegularExpression Rx("^\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*$"); QRegularExpression Rx("^(?<name>[a-z-]+): (?<value>[a-z-]+)$");
foreach (QString style_str, styles) { if (!Rx.isValid())
if (Rx==QRegularExpression(style_str)) { {
qWarning() <<"this is an error in the code"
QString style_name = Rx.namedCaptureGroups().at(1); << Rx.errorString()
QString style_value = Rx.namedCaptureGroups().at(2); << Rx.patternErrorOffset();
return;
}
foreach (QString style_str, styles)
{
QRegularExpressionMatch match = Rx.match(style_str);
if (!match.hasMatch())
{
qDebug()<<"no Match"
<<style_str;
} else {
QString style_name = match.captured("name");
QString style_value = match.captured("value");
if (style_name == "line-style") { if (style_name == "line-style") {
if (style_value == "dashed") style = Qt::DashLine; if (style_value == "dashed") style = Qt::DashLine;
else if (style_value == "dashdotted") style = Qt::DashDotLine; else if (style_value == "dashdotted") style = Qt::DashDotLine;
else if (style_value == "normal") style = Qt::SolidLine; else if (style_value == "normal") style = Qt::SolidLine;
else {
qWarning()<<"style_value not known"
<<style_value;
}
} }
} }
} }