mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Fix QRegularExpression
-add isValid -add debug
This commit is contained in:
@@ -569,11 +569,23 @@ void ElementPictureFactory::setPainterStyle(const QDomElement &dom, QPainter &pa
|
|||||||
#pragma message("@TODO remove code for QT 5.14 or later")
|
#pragma message("@TODO remove code for QT 5.14 or later")
|
||||||
const QStringList styles = dom.attribute("style").split(";", Qt::SkipEmptyParts);
|
const QStringList styles = dom.attribute("style").split(";", Qt::SkipEmptyParts);
|
||||||
#endif
|
#endif
|
||||||
QRegularExpression rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$");
|
QRegularExpression rx("^(?<name>[a-z-]+): (?<value>[a-z-]+)$");
|
||||||
|
if (!rx.isValid())
|
||||||
|
{
|
||||||
|
qWarning() <<"this is an error in the code"
|
||||||
|
<< rx.errorString()
|
||||||
|
<< rx.patternErrorOffset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (QString style : styles) {
|
for (QString style : styles) {
|
||||||
if (rx==QRegularExpression(style)) {
|
QRegularExpressionMatch match = rx.match(style);
|
||||||
QString style_name = rx.namedCaptureGroups().at(1);
|
if (!match.hasMatch())
|
||||||
QString style_value = rx.namedCaptureGroups().at(2);
|
{
|
||||||
|
qDebug()<<"no Match"
|
||||||
|
<<style;
|
||||||
|
}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") pen.setStyle(Qt::DashLine);
|
if (style_value == "dashed") pen.setStyle(Qt::DashLine);
|
||||||
else if (style_value == "dotted") pen.setStyle(Qt::DotLine);
|
else if (style_value == "dotted") pen.setStyle(Qt::DotLine);
|
||||||
|
|||||||
@@ -2102,14 +2102,28 @@ template <class T> void QETApp::addWindowsListToMenu(
|
|||||||
or -1 if none could be found.
|
or -1 if none could be found.
|
||||||
*/
|
*/
|
||||||
int QETApp::projectIdFromString(const QString &url) {
|
int QETApp::projectIdFromString(const QString &url) {
|
||||||
QRegularExpression embedded("^project([0-9]+)\\+embed.*$", QRegularExpression::CaseInsensitiveOption);
|
QRegularExpression embedded(
|
||||||
if (embedded==QRegularExpression(url)) {
|
"^project(?<project_id>[0-9]+)\\+embed.*$",
|
||||||
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
|
if (!embedded.isValid())
|
||||||
|
{
|
||||||
|
qWarning() <<"this is an error in the code"
|
||||||
|
<< embedded.errorString()
|
||||||
|
<< embedded.patternErrorOffset();
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
QRegularExpressionMatch match = embedded.match(url);
|
||||||
|
if (!match.hasMatch())
|
||||||
|
{
|
||||||
|
qDebug()<<"no Match => return"
|
||||||
|
<<url;
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
bool conv_ok = false;
|
bool conv_ok = false;
|
||||||
int project_id = embedded.namedCaptureGroups().at(1).toInt(&conv_ok);
|
int project_id = match.captured("project_id").toUInt(&conv_ok);
|
||||||
if (conv_ok) {
|
if (conv_ok) {
|
||||||
return(project_id);
|
return(project_id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -36,7 +37,7 @@ QFileNameEdit::QFileNameEdit(QWidget *parent) : QLineEdit(parent) {
|
|||||||
*/
|
*/
|
||||||
QFileNameEdit::QFileNameEdit(const QString &contents, QWidget *parent) : QLineEdit(parent) {
|
QFileNameEdit::QFileNameEdit(const QString &contents, QWidget *parent) : QLineEdit(parent) {
|
||||||
init();
|
init();
|
||||||
if (!contents.isEmpty() && regexp_==QRegularExpression(contents)) {
|
if (!contents.isEmpty() && regexp_.match(contents).hasMatch()) {
|
||||||
setText(contents);
|
setText(contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,7 @@ bool QFileNameEdit::isEmpty()
|
|||||||
*/
|
*/
|
||||||
bool QFileNameEdit::isValid()
|
bool QFileNameEdit::isValid()
|
||||||
{
|
{
|
||||||
return(regexp_==QRegularExpression(text()));
|
return(regexp_.match(text()).hasMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user