Mod: replace QRegExp with QRegularExpression

This commit is contained in:
wmayer
2022-10-07 14:03:53 +02:00
parent c4f2a81317
commit 840fc70106
14 changed files with 107 additions and 85 deletions

View File

@@ -25,8 +25,8 @@
#ifndef _PreComp_
# include <QCheckBox>
# include <QDialogButtonBox>
# include <QRegExp>
# include <QRegExpValidator>
# include <QRegularExpression>
# include <QRegularExpressionValidator>
# include <QVBoxLayout>
# include <Interface_Static.hxx>
#endif
@@ -148,13 +148,13 @@ DlgExportHeaderStep::DlgExportHeaderStep(QWidget* parent)
ui->lineEditProduct->setReadOnly(true);
QRegExp rx;
QRegularExpression rx;
rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+"));
QRegExpValidator* companyValidator = new QRegExpValidator(ui->lineEditCompany);
companyValidator->setRegExp(rx);
QRegularExpressionValidator* companyValidator = new QRegularExpressionValidator(ui->lineEditCompany);
companyValidator->setRegularExpression(rx);
ui->lineEditCompany->setValidator(companyValidator);
QRegExpValidator* authorValidator = new QRegExpValidator(ui->lineEditAuthor);
authorValidator->setRegExp(rx);
QRegularExpressionValidator* authorValidator = new QRegularExpressionValidator(ui->lineEditAuthor);
authorValidator->setRegularExpression(rx);
ui->lineEditAuthor->setValidator(authorValidator);
}

View File

@@ -23,8 +23,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QButtonGroup>
# include <QRegExp>
# include <QRegExpValidator>
# include <QRegularExpression>
# include <QRegularExpressionValidator>
# include <QVBoxLayout>
# include <Interface_Static.hxx>
#endif
@@ -98,13 +98,13 @@ DlgImportExportIges::DlgImportExportIges(QWidget* parent)
bg->addButton(ui->radioButtonBRepOff, 0);
bg->addButton(ui->radioButtonBRepOn, 1);
QRegExp rx;
QRegularExpression rx;
rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+"));
QRegExpValidator* companyValidator = new QRegExpValidator(ui->lineEditCompany);
companyValidator->setRegExp(rx);
QRegularExpressionValidator* companyValidator = new QRegularExpressionValidator(ui->lineEditCompany);
companyValidator->setRegularExpression(rx);
ui->lineEditCompany->setValidator(companyValidator);
QRegExpValidator* authorValidator = new QRegExpValidator(ui->lineEditAuthor);
authorValidator->setRegExp(rx);
QRegularExpressionValidator* authorValidator = new QRegularExpressionValidator(ui->lineEditAuthor);
authorValidator->setRegularExpression(rx);
ui->lineEditAuthor->setValidator(authorValidator);
}

View File

@@ -31,7 +31,7 @@
# include <cfloat>
# include <QMessageBox>
# include <QRegExp>
# include <QRegularExpression>
# include <QTreeWidget>
#endif
@@ -142,7 +142,7 @@ bool Mirroring::accept()
activeDoc->openTransaction("Mirroring");
QString shape, label;
QRegExp rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$"));
QRegularExpression rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$"));
QList<QTreeWidgetItem *> items = ui->shapes->selectedItems();
float normx=0, normy=0, normz=0;
int index = ui->comboBox->currentIndex();

View File

@@ -26,7 +26,8 @@
#ifndef _PreComp_
# include <sstream>
# include <QMessageBox>
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
# include <Standard_Failure.hxx>
#endif
@@ -616,34 +617,43 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx)
} else {
// TODO: check validity of the text that was entered: Does subElement actually reference to an element on the obj?
// We must expect that "text" is the translation of "Face", "Edge" or "Vertex" followed by an ID.
QRegExp rx;
std::stringstream ss;
auto getSubshapeName = [](const QString& part) -> std::string {
// We must expect that "text" is the translation of "Face", "Edge" or "Vertex" followed by an ID.
QRegularExpression rx;
QRegularExpressionMatch match;
std::stringstream ss;
rx.setPattern(QString::fromLatin1("^") + tr("Face") + QString::fromLatin1("(\\d+)$"));
if (parts[1].indexOf(rx) >= 0) {
int faceId = rx.cap(1).toInt();
ss << "Face" << faceId;
} else {
rx.setPattern(QString::fromLatin1("^") + tr("Edge") + QString::fromLatin1("(\\d+)$"));
if (parts[1].indexOf(rx) >= 0) {
int lineId = rx.cap(1).toInt();
ss << "Edge" << lineId;
} else {
rx.setPattern(QString::fromLatin1("^") + tr("Vertex") + QString::fromLatin1("(\\d+)$"));
if (parts[1].indexOf(rx) >= 0) {
int vertexId = rx.cap(1).toInt();
ss << "Vertex" << vertexId;
} else {
//none of Edge/Vertex/Face. May be empty string.
//Feed in whatever user supplied, even if invalid.
ss << parts[1].toLatin1().constData();
}
rx.setPattern(QString::fromLatin1("^") + tr("Face") + QString::fromLatin1("(\\d+)$"));
if (part.indexOf(rx, 0, &match) >= 0) {
int faceId = match.captured(1).toInt();
ss << "Face" << faceId;
return ss.str();
}
}
line->setProperty("RefName", QByteArray(ss.str().c_str()));
subElement = ss.str();
rx.setPattern(QString::fromLatin1("^") + tr("Edge") + QString::fromLatin1("(\\d+)$"));
if (part.indexOf(rx, 0, &match) >= 0) {
int lineId = match.captured(1).toInt();
ss << "Edge" << lineId;
return ss.str();
}
rx.setPattern(QString::fromLatin1("^") + tr("Vertex") + QString::fromLatin1("(\\d+)$"));
if (part.indexOf(rx, 0, &match) >= 0) {
int vertexId = match.captured(1).toInt();
ss << "Vertex" << vertexId;
return ss.str();
}
//none of Edge/Vertex/Face. May be empty string.
//Feed in whatever user supplied, even if invalid.
ss << part.toLatin1().constData();
return ss.str();
};
auto name = getSubshapeName(parts[1]);
line->setProperty("RefName", QByteArray(name.c_str()));
subElement = name;
}
Part::AttachExtension* pcAttach = ViewProvider->getObject()->getExtensionByType<Part::AttachExtension>();

View File

@@ -25,7 +25,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
# include <QTextStream>
#endif
@@ -158,16 +159,17 @@ QVariant TaskSketchBasedParameters::setUpToFace(const QString& text)
QString name;
QTextStream str(&name);
str << "^" << tr("Face") << "(\\d+)$";
QRegExp rx(name);
if (parts[1].indexOf(rx) < 0) {
QRegularExpression rx(name);
QRegularExpressionMatch match;
if (parts[1].indexOf(rx, 0, &match) < 0) {
return QVariant();
}
int faceId = rx.cap(1).toInt();
int faceId = match.captured(1).toInt();
std::stringstream ss;
ss << "Face" << faceId;
std::vector<std::string> upToFaces(1,ss.str());
std::vector<std::string> upToFaces(1, ss.str());
PartDesign::ProfileBased* pcSketchBased = static_cast<PartDesign::ProfileBased*>(vp->getObject());
pcSketchBased->UpToFace.setValue(obj, upToFaces);
recomputeFeature();

View File

@@ -24,6 +24,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QRegularExpression>
#endif
#include "TaskDlgPathCompound.h"
@@ -86,7 +87,7 @@ std::vector<std::string> TaskWidgetPathCompound::getList() const {
QListWidgetItem* item = ui->PathsList->item(i);
QString name = item->text();
QStringList result;
result = name.split(QRegExp(QString::fromLatin1("\\s+")));
result = name.split(QRegularExpression(QString::fromLatin1("\\s+")));
std::cout << result[0].toStdString() << std::endl;
names.push_back(result[0].toStdString());
}

View File

@@ -23,7 +23,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
#endif
#include "PovrayHighlighter.h"
@@ -95,12 +96,13 @@ void PovrayHighlighter::highlightBlock(const QString &text)
state = InsideCStyleComment;
}
else if (text.mid(i,1) == QLatin1String("#")) {
QRegExp rx(QLatin1String("#\\s*(\\w*)"));
int pos = text.indexOf(rx, i);
if (pos != -1) {
if (d->keywords.contains(rx.cap(1)) != 0)
setFormat(i, rx.matchedLength(), this->colorByType(SyntaxHighlighter::Keyword));
i += rx.matchedLength();
QRegularExpression rx(QLatin1String("#\\s*(\\w*)"));
QRegularExpressionMatch match;
text.indexOf(rx, i, &match);
if (match.hasMatch()) {
if (d->keywords.contains(match.captured(1)) != 0)
setFormat(i, match.capturedLength(), this->colorByType(SyntaxHighlighter::Keyword));
i += match.capturedLength();
}
}
else if (text[i] == QLatin1Char('"')) {

View File

@@ -53,6 +53,8 @@
# include <Inventor/SbVec3f.h>
# include <Inventor/SbImage.h>
# include <QRegularExpression>
# include <memory>
#endif // #ifndef _PreComp_
@@ -1669,7 +1671,7 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint *c
if (QString::compare(baseUnitStr, unitStr)==0)
{
// Example code from: Mod/TechDraw/App/DrawViewDimension.cpp:372
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
QRegularExpression rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
valueStr.remove(rxUnits); //getUserString(defaultDecimals) without units
}
}

View File

@@ -27,7 +27,8 @@
# include <cmath>
# include <QContextMenuEvent>
# include <QMenu>
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
# include <QString>
# include <QMessageBox>
# include <QStyledItemDelegate>
@@ -976,12 +977,13 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
if (strcmp(msg.pDocName,sketchView->getSketchObject()->getDocument()->getName())==0 &&
strcmp(msg.pObjectName,sketchView->getSketchObject()->getNameInDocument())== 0) {
if (msg.pSubName) {
QRegExp rx(QString::fromLatin1("^Constraint(\\d+)$"));
QRegularExpression rx(QString::fromLatin1("^Constraint(\\d+)$"));
QRegularExpressionMatch match;
QString expr = QString::fromLatin1(msg.pSubName);
int pos = expr.indexOf(rx);
if (pos > -1) { // is a constraint
expr.indexOf(rx, 0, &match);
if (match.hasMatch()) { // is a constraint
bool ok;
int ConstrId = rx.cap(1).toInt(&ok) - 1;
int ConstrId = match.captured(1).toInt(&ok) - 1;
if (ok) {
int countItems = ui->listWidgetConstraints->count();
for (int i=0; i < countItems; i++) {
@@ -1025,25 +1027,26 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
void TaskSketcherConstraints::getSelectionGeoId(QString expr, int & geoid, Sketcher::PointPos & pointpos)
{
QRegExp rxEdge(QString::fromLatin1("^Edge(\\d+)$"));
int pos = expr.indexOf(rxEdge);
QRegularExpression rxEdge(QString::fromLatin1("^Edge(\\d+)$"));
QRegularExpressionMatch match;
expr.indexOf(rxEdge, 0, &match);
geoid = Sketcher::GeoEnum::GeoUndef;
pointpos = Sketcher::PointPos::none;
if (pos > -1) {
if (match.hasMatch()) {
bool ok;
int edgeId = rxEdge.cap(1).toInt(&ok) - 1;
int edgeId = match.captured(1).toInt(&ok) - 1;
if (ok) {
geoid = edgeId;
}
}
else {
QRegExp rxVertex(QString::fromLatin1("^Vertex(\\d+)$"));
pos = expr.indexOf(rxVertex);
QRegularExpression rxVertex(QString::fromLatin1("^Vertex(\\d+)$"));
expr.indexOf(rxVertex, 0, &match);
if (pos > -1) {
if (match.hasMatch()) {
bool ok;
int vertexId = rxVertex.cap(1).toInt(&ok) - 1;
int vertexId = match.captured(1).toInt(&ok) - 1;
if (ok) {
const Sketcher::SketchObject * sketch = sketchView->getSketchObject();
sketch->getGeoVertexIndex(vertexId, geoid, pointpos);

View File

@@ -26,7 +26,8 @@
#ifndef _PreComp_
# include <QContextMenuEvent>
# include <QMenu>
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
# include <QShortcut>
# include <QString>
# include <QImage>
@@ -360,11 +361,12 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg)
std::string shapetype(msg.pSubName);
// if-else edge vertex
if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") {
QRegExp rx(QString::fromLatin1("^Edge(\\d+)$"));
int pos = expr.indexOf(rx);
if (pos > -1) {
QRegularExpression rx(QString::fromLatin1("^Edge(\\d+)$"));
QRegularExpressionMatch match;
expr.indexOf(rx, 0, &match);
if (match.hasMatch()) {
bool ok;
int ElementId = rx.cap(1).toInt(&ok) - 1;
int ElementId = match.captured(1).toInt(&ok) - 1;
if (ok) {
int countItems = ui->listWidgetElements->count();
for (int i=0; i < countItems; i++) {
@@ -379,11 +381,12 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}
else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex"){
QRegExp rx(QString::fromLatin1("^Vertex(\\d+)$"));
int pos = expr.indexOf(rx);
if (pos > -1) {
QRegularExpression rx(QString::fromLatin1("^Vertex(\\d+)$"));
QRegularExpressionMatch match;
expr.indexOf(rx, 0, &match);
if (match.hasMatch()) {
bool ok;
int ElementId = rx.cap(1).toInt(&ok) - 1;
int ElementId = match.captured(1).toInt(&ok) - 1;
if (ok) {
// Get the GeoID&Pos
int GeoId;

View File

@@ -32,7 +32,6 @@
#include <boost/regex.hpp>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QChar>
#include <QPointF>

View File

@@ -29,7 +29,6 @@
#include <QGraphicsView>
#include <QMessageBox>
#include <QPainter>
#include <QRegExp>
#include <QStringBuilder>
#include <QSvgGenerator>
#include <QSvgRenderer>

View File

@@ -31,7 +31,6 @@
# include <QComboBox>
# include <QString>
# include <QStringList>
# include <QRegExp>
# include <QMessageBox>
# include <QRectF>
# include <QPointF>

View File

@@ -32,7 +32,8 @@
# include <QMessageBox>
# include <QMouseEvent>
# include <QNetworkRequest>
# include <QRegExp>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
# include <QScreen>
# include <QSignalMapper>
# include <QStatusBar>
@@ -97,11 +98,12 @@ public:
if (info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeLink) {
// wash out windows file:///C:/something ->file://C:/something
QUrl url = info.requestUrl();
QRegExp re(QLatin1String("^/([a-zA-Z]\\:.*)")); // match & catch drive letter forward
QRegularExpression re(QLatin1String("^/([a-zA-Z]\\:.*)")); // match & catch drive letter forward
QRegularExpressionMatch match = re.match(url.path());
if (url.host().isEmpty() && url.isLocalFile() && re.exactMatch(url.path()))
if (url.host().isEmpty() && url.isLocalFile() && match.hasMatch())
// clip / in file urs ie /C:/something -> C:/something
url.setPath(re.cap(1));
url.setPath(match.captured(1));
// invoke thread safe.
QMetaObject::invokeMethod(m_parent, "urlFilter", Q_ARG(QUrl, url));