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

@@ -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;