Fix deprecated QRegExp

Use QRegularExpression instead.

https://doc.qt.io/qt-5/qregularexpression.html#notes-for-qregexp-users

This function was introduced in Qt 5
This commit is contained in:
Simon De Backer
2020-09-18 23:05:29 +02:00
parent 93055c6a96
commit 3eca82baad

View File

@@ -28,6 +28,7 @@
#include <iostream> #include <iostream>
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QGraphicsSimpleTextItem> #include <QGraphicsSimpleTextItem>
#include <QRegularExpression>
ElementPictureFactory* ElementPictureFactory::m_factory = nullptr; ElementPictureFactory* ElementPictureFactory::m_factory = nullptr;
@@ -44,14 +45,14 @@ void ElementPictureFactory::getPictures(const ElementsLocation &location, QPictu
if(!location.exist()) { if(!location.exist()) {
return; return;
} }
QUuid uuid = location.uuid(); QUuid uuid = location.uuid();
if(Q_UNLIKELY(uuid.isNull())) if(Q_UNLIKELY(uuid.isNull()))
{ {
build(location, &picture, &low_picture); build(location, &picture, &low_picture);
return; return;
} }
if(m_pictures_H.keys().contains(uuid)) if(m_pictures_H.keys().contains(uuid))
{ {
picture = m_pictures_H.value(uuid); picture = m_pictures_H.value(uuid);
@@ -76,11 +77,11 @@ void ElementPictureFactory::getPictures(const ElementsLocation &location, QPictu
QPixmap ElementPictureFactory::pixmap(const ElementsLocation &location) QPixmap ElementPictureFactory::pixmap(const ElementsLocation &location)
{ {
QUuid uuid = location.uuid(); QUuid uuid = location.uuid();
if (m_pixmap_H.contains(uuid)) { if (m_pixmap_H.contains(uuid)) {
return m_pixmap_H.value(uuid); return m_pixmap_H.value(uuid);
} }
if(build(location)) if(build(location))
{ {
auto doc = location.pugiXml(); auto doc = location.pugiXml();
@@ -95,19 +96,19 @@ QPixmap ElementPictureFactory::pixmap(const ElementsLocation &location)
QPixmap pix(w, h); QPixmap pix(w, h);
pix.fill(QColor(255, 255, 255, 0)); pix.fill(QColor(255, 255, 255, 0));
QPainter painter(&pix); QPainter painter(&pix);
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.translate(hsx, hsy); painter.translate(hsx, hsy);
painter.drawPicture(0, 0, m_pictures_H.value(uuid)); painter.drawPicture(0, 0, m_pictures_H.value(uuid));
if (!uuid.isNull()) { if (!uuid.isNull()) {
m_pixmap_H.insert(uuid, pix); m_pixmap_H.insert(uuid, pix);
} }
return pix; return pix;
} }
return QPixmap(); return QPixmap();
} }
@@ -122,7 +123,7 @@ ElementPictureFactory::primitives ElementPictureFactory::getPrimitives(
{ {
if(!m_primitives_H.contains(location.uuid())) if(!m_primitives_H.contains(location.uuid()))
build(location); build(location);
return m_primitives_H.value(location.uuid()); return m_primitives_H.value(location.uuid());
} }
@@ -143,14 +144,14 @@ ElementPictureFactory::~ElementPictureFactory()
this function draw on it and don't store it. this function draw on it and don't store it.
if null, this function create a QPicture for normal and low zoom, if null, this function create a QPicture for normal and low zoom,
draw on it and store it in m_pictures_H and m_low_pictures_H draw on it and store it in m_pictures_H and m_low_pictures_H
@return @return
*/ */
bool ElementPictureFactory::build(const ElementsLocation &location, bool ElementPictureFactory::build(const ElementsLocation &location,
QPicture *picture, QPicture *picture,
QPicture *low_picture) QPicture *low_picture)
{ {
QDomElement dom = location.xml(); QDomElement dom = location.xml();
//Check if the curent version can read the xml description //Check if the curent version can read the xml description
if (dom.hasAttribute("version")) if (dom.hasAttribute("version"))
{ {
@@ -165,7 +166,7 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
) << std::endl; ) << std::endl;
} }
} }
//This attributes must be present and valid //This attributes must be present and valid
int w, h, hot_x, hot_y; int w, h, hot_x, hot_y;
if (!QET::attributeIsAnInteger(dom, QString("width"), &w) ||\ if (!QET::attributeIsAnInteger(dom, QString("width"), &w) ||\
@@ -175,7 +176,7 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
{ {
return(false); return(false);
} }
QPainter painter; QPainter painter;
QPicture pic; QPicture pic;
primitives primitives_; primitives primitives_;
@@ -188,8 +189,8 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::TextAntialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform,true); painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
QPainter low_painter; QPainter low_painter;
QPicture low_pic; QPicture low_pic;
if (low_picture) { if (low_picture) {
@@ -201,12 +202,12 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
low_painter.setRenderHint(QPainter::Antialiasing, true); low_painter.setRenderHint(QPainter::Antialiasing, true);
low_painter.setRenderHint(QPainter::TextAntialiasing, true); low_painter.setRenderHint(QPainter::TextAntialiasing, true);
low_painter.setRenderHint(QPainter::SmoothPixmapTransform,true); low_painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
QPen tmp; QPen tmp;
tmp.setWidthF(1.0); //Vaudoo line to take into account the setCosmetic - don't remove tmp.setWidthF(1.0); //Vaudoo line to take into account the setCosmetic - don't remove
tmp.setCosmetic(true); tmp.setCosmetic(true);
low_painter.setPen(tmp); low_painter.setPen(tmp);
//scroll of the Children of the Definition: Parts of the Drawing //scroll of the Children of the Definition: Parts of the Drawing
for (QDomNode node = dom.firstChild() ; !node.isNull() ; node = node.nextSibling()) for (QDomNode node = dom.firstChild() ; !node.isNull() ; node = node.nextSibling())
{ {
@@ -214,9 +215,9 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
if (elmts.isNull()) { if (elmts.isNull()) {
continue; continue;
} }
if (elmts.tagName() == "description") if (elmts.tagName() == "description")
{ {
//Manage the graphic description = part of drawing //Manage the graphic description = part of drawing
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
{ {
@@ -230,7 +231,7 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
} }
} }
} }
//End of the drawing //End of the drawing
painter.end(); painter.end();
low_painter.end(); low_painter.end();
@@ -458,7 +459,7 @@ void ElementPictureFactory::parsePolygon(const QDomElement &dom, QPainter &paint
if (i < 3) { if (i < 3) {
return; return;
} }
QVector<QPointF> points; // empty vector created instead of default initialized vector with i-1 elements. QVector<QPointF> points; // empty vector created instead of default initialized vector with i-1 elements.
for (int j = 1 ; j < i ; ++ j) { for (int j = 1 ; j < i ; ++ j) {
points.insert( points.insert(
@@ -568,11 +569,11 @@ 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
QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$"); QRegularExpression rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$");
for (QString style : styles) { for (QString style : styles) {
if (rx.exactMatch(style)) { if (rx==QRegularExpression(style)) {
QString style_name = rx.cap(1); QString style_name = rx.namedCaptureGroups().at(1);
QString style_value = rx.cap(2); QString style_value = rx.namedCaptureGroups().at(2);
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);