From 13b294838bf6d2fc784a83c81c71d546c999f125 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 21 Jul 2025 00:37:10 +0200 Subject: [PATCH] Replaced deprecated QRegExp by QRegularExpression --- retroshare-gui/src/gui/advsearch/guiexprelement.cpp | 10 ++++++---- retroshare-gui/src/gui/advsearch/guiexprelement.h | 6 ++++-- retroshare-gui/src/gui/chat/ChatStyle.cpp | 7 ++++--- retroshare-gui/src/gui/msgs/MessageWidget.cpp | 2 +- retroshare-gui/src/rshare.cpp | 6 +++--- retroshare-gui/src/util/HandleRichText.cpp | 5 +++-- retroshare-gui/src/util/RichTextEdit.cpp | 4 ++-- retroshare-gui/src/util/RsSyntaxHighlighter.cpp | 4 +++- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp index baf4264a3..26d623bde 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp @@ -20,6 +20,8 @@ * * *******************************************************************************/ +#include + #include "guiexprelement.h" #include "util/DateTime.h" @@ -400,10 +402,10 @@ void ExprParamElement::adjustForSearchType(ExprSearchType type) { // record which search type is active searchType = type; - QRegExp regExp("0|[1-9][0-9]*"); - numValidator = new QRegExpValidator(regExp, this); - QRegExp hexRegExp("[A-Fa-f0-9]*"); - hexValidator = new QRegExpValidator(hexRegExp, this); + QRegularExpression regExp("0|[1-9][0-9]*"); + numValidator = new QRegularExpressionValidator(regExp, this); + QRegularExpression hexRegExp("[A-Fa-f0-9]*"); + hexValidator = new QRegularExpressionValidator(hexRegExp, this); QHBoxLayout* hbox = static_cast(layout()); clearLayout(hbox); diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.h b/retroshare-gui/src/gui/advsearch/guiexprelement.h index 50ebeaa15..c64e15bcb 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.h +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.h @@ -34,6 +34,8 @@ #include +class QRegularExpressionValidator; + enum ExprSearchType { NameSearch, @@ -191,8 +193,8 @@ public: virtual QString toString(); private: - QRegExpValidator * numValidator; - QRegExpValidator * hexValidator; + QRegularExpressionValidator * numValidator; + QRegularExpressionValidator * hexValidator; QFrame * rangeParamsFrame; bool inRangedConfig; uint64_t getIntValueFromField(QString fieldName, bool isToField=false,bool *ok = NULL); diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index 481f87e95..dab12f082 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -103,6 +103,7 @@ #include #include #include +#include #include "ChatStyle.h" #include "gui/settings/rsharesettings.h" @@ -376,7 +377,7 @@ QString ChatStyle::formatMessage(enumFormatMessage type QString strDate = DateTime::formatDate(timestamp.date()).prepend(QString("")).append(QString("")); QString strTime = DateTime::formatTime(timestamp.time()).prepend(QString("")).append(QString("")); - int bi = name.lastIndexOf(QRegExp(" \\(.*\\)")); //trim location from the end + int bi = name.lastIndexOf(QRegularExpression(" \\(.*\\)")); //trim location from the end QString strShortName = RsHtml::plainText(name.left(bi)).prepend(QString("")).append(QString("")); //handle /me @@ -384,9 +385,9 @@ QString ChatStyle::formatMessage(enumFormatMessage type //meName class for modifying the style of the name in the palce of /me if(me){ messageBody = messageBody.replace(messageBody.indexOf("/me "), 3, strShortName.prepend(QString("")).append(QString(""))); //replace only the first /me - style = style.remove(QRegExp("%nome%.*%/nome%")).remove("%me%").remove("%/me%"); + style = style.remove(QRegularExpression("%nome%.*%/nome%")).remove("%me%").remove("%/me%"); } else { - style = style.remove(QRegExp("%me%.*%/me%")).remove("%nome%").remove("%/nome%"); + style = style.remove(QRegularExpression("%me%.*%/me%")).remove("%nome%").remove("%/nome%"); } QString formatMsg = style.replace("%name%", strName) diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 6e1a3d39b..52994454b 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -640,7 +640,7 @@ void MessageWidget::fill(const std::string &msgId) ui.trans_ToText->setText(to_text); - int recipientsCount = ui.trans_ToText->toPlainText().split(QRegExp("(\\s|\\n|\\r)+"), QtSkipEmptyParts).count(); + int recipientsCount = ui.trans_ToText->toPlainText().split(QRegularExpression("(\\s|\\n|\\r)+"), QtSkipEmptyParts).count(); ui.expandButton->setText( QString::number(recipientsCount)+ " " + tr("more")); if (recipientsCount >=20) { diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index 1cb0b5766..5dc08cc2e 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -311,8 +311,8 @@ void RsApplication::customizeDateFormat() QLocale locale = QLocale(); // set to default locale /* get long date format without weekday */ options.dateformat = locale.dateFormat(QLocale::LongFormat); - options.dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), ""); - options.dateformat.replace(QRegExp(",* *dddd"), ""); + options.dateformat.replace(QRegularExpression("^dddd,*[^ ]* *('[^']+' )*"), ""); + options.dateformat.replace(QRegularExpression(",* *dddd"), ""); options.dateformat = options.dateformat.trimmed(); } diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index fcfe6d2b9..e74cc9071 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "HandleRichText.h" #include "gui/RetroShareLink.h" @@ -1171,7 +1172,7 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/ { // remove doctype - text.remove(QRegExp("]*>")); + text.remove(QRegularExpression("]*>")); //remove all prepend char that make doc.setContent() fail text.remove(0,text.indexOf("<")); // Save Space and Tab because doc loose it. @@ -1253,7 +1254,7 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser) { text = browser->toPlainText(); } - QStringList sl = text.split(QRegExp("[\r\n]"),QtSkipEmptyParts); + QStringList sl = text.split(QRegularExpression("[\r\n]"),QtSkipEmptyParts); text = sl.join("\n> "); text.replace("\n> >","\n>>"); // Don't add space for already quotted lines. text.replace(QChar(-4)," ");//Char used when image on text. diff --git a/retroshare-gui/src/util/RichTextEdit.cpp b/retroshare-gui/src/util/RichTextEdit.cpp index 020b13db9..8233058f9 100644 --- a/retroshare-gui/src/util/RichTextEdit.cpp +++ b/retroshare-gui/src/util/RichTextEdit.cpp @@ -547,9 +547,9 @@ void RichTextEdit::slotClipboardDataChanged() { QString RichTextEdit::toHtml() const { QString s = f_textedit->toHtml(); // convert emails to links - s = s.replace(QRegExp("(<[^a][^>]+>(?:]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1\\2"); + s = s.replace(QRegularExpression("(<[^a][^>]+>(?:]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1\\2"); // convert links - s = s.replace(QRegExp("(<[^a][^>]+>(?:]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1\\2"); + s = s.replace(QRegularExpression("(<[^a][^>]+>(?:]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1\\2"); // see also: Utils::linkify() return s; } diff --git a/retroshare-gui/src/util/RsSyntaxHighlighter.cpp b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp index ed05b702c..c204932a7 100644 --- a/retroshare-gui/src/util/RsSyntaxHighlighter.cpp +++ b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp @@ -18,6 +18,8 @@ * * *******************************************************************************/ +#include + #include "RsSyntaxHighlighter.h" RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent) @@ -65,7 +67,7 @@ void RsSyntaxHighlighter::highlightBlock(const QString &text) { if (text == "") return; - QRegExp endl("[\\r\\n\\x2028]"); //Usually 0x2028 character is used for newline, no idea why + QRegularExpression endl("[\\r\\n\\x2028]"); //Usually 0x2028 character is used for newline, no idea why int index = 0; QStringList lines = text.split(endl); foreach (const QString &cLine, lines) {