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:01:19 +02:00
parent 215ddbd878
commit c7f138a0e3

View File

@@ -1,23 +1,25 @@
/* /*
Copyright 2006-2020 The QElectroTech Team Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech. This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
QElectroTech is distributed in the hope that it will be useful, QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "diagramcontextwidget.h" #include "diagramcontextwidget.h"
#include "ui_diagramcontextwidget.h" #include "ui_diagramcontextwidget.h"
#include <QRegularExpression>
DiagramContextWidget::DiagramContextWidget(QWidget *parent) : DiagramContextWidget::DiagramContextWidget(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::DiagramContextWidget) ui(new Ui::DiagramContextWidget)
@@ -38,7 +40,7 @@ DiagramContextWidget::~DiagramContextWidget()
DiagramContext DiagramContextWidget::context() const DiagramContext DiagramContextWidget::context() const
{ {
DiagramContext context; DiagramContext context;
for (int i = 0 ; i < ui->m_table-> rowCount() ; ++ i) for (int i = 0 ; i < ui->m_table-> rowCount() ; ++ i)
{ {
QTableWidgetItem *qtwi_name = ui->m_table-> item(i, 0); QTableWidgetItem *qtwi_name = ui->m_table-> item(i, 0);
@@ -46,16 +48,16 @@ DiagramContext DiagramContextWidget::context() const
if (!qtwi_name || !qtwi_value) { if (!qtwi_name || !qtwi_value) {
continue; continue;
} }
QString key = qtwi_name -> text(); QString key = qtwi_name -> text();
if (key.isEmpty()) { if (key.isEmpty()) {
continue; continue;
} }
QString value = qtwi_value -> text(); QString value = qtwi_value -> text();
context.addValue(key, value); context.addValue(key, value);
} }
return(context); return(context);
} }
@@ -67,7 +69,7 @@ DiagramContext DiagramContextWidget::context() const
void DiagramContextWidget::setContext (const DiagramContext &context) void DiagramContextWidget::setContext (const DiagramContext &context)
{ {
clear(); clear();
int i = 0; int i = 0;
for (QString key : context.keys(DiagramContext::Alphabetical)) for (QString key : context.keys(DiagramContext::Alphabetical))
{ {
@@ -75,7 +77,7 @@ void DiagramContextWidget::setContext (const DiagramContext &context)
ui->m_table->setItem(i, 1, new QTableWidgetItem(context[key].toString())); ui->m_table->setItem(i, 1, new QTableWidgetItem(context[key].toString()));
++ i; ++ i;
} }
checkTableRows(); checkTableRows();
} }
@@ -93,7 +95,7 @@ int DiagramContextWidget::nameLessRowsCount() const
++ name_less_rows_count; ++ name_less_rows_count;
} }
} }
return(name_less_rows_count); return(name_less_rows_count);
} }
@@ -107,7 +109,7 @@ void DiagramContextWidget::clear()
for (int i = 1 ; i < ui->m_table->rowCount() ; ++ i) { for (int i = 1 ; i < ui->m_table->rowCount() ; ++ i) {
ui->m_table->removeRow(i); ui->m_table->removeRow(i);
} }
refreshFormatLabel(); refreshFormatLabel();
} }
@@ -118,10 +120,10 @@ void DiagramContextWidget::clear()
*/ */
int DiagramContextWidget::highlightNonAcceptableKeys() int DiagramContextWidget::highlightNonAcceptableKeys()
{ {
static QRegExp re(DiagramContext::validKeyRegExp()); static QRegularExpression re(DiagramContext::validKeyRegExp());
QBrush fg_brush = ui->m_table->palette().brush(QPalette::WindowText); QBrush fg_brush = ui->m_table->palette().brush(QPalette::WindowText);
int invalid_keys = 0; int invalid_keys = 0;
for (int i = 0 ; i < ui->m_table->rowCount() ; ++ i) for (int i = 0 ; i < ui->m_table->rowCount() ; ++ i)
{ {
@@ -129,11 +131,11 @@ int DiagramContextWidget::highlightNonAcceptableKeys()
if (!qtwi_name) { if (!qtwi_name) {
continue; continue;
} }
bool highlight = false; bool highlight = false;
if (!qtwi_name -> text().isEmpty()) if (!qtwi_name -> text().isEmpty())
{ {
if (!re.exactMatch(qtwi_name -> text())) if (re!=QRegularExpression(qtwi_name -> text()))
{ {
highlight = true; highlight = true;
++ invalid_keys; ++ invalid_keys;
@@ -141,7 +143,7 @@ int DiagramContextWidget::highlightNonAcceptableKeys()
} }
qtwi_name -> setForeground(highlight ? Qt::red : fg_brush); qtwi_name -> setForeground(highlight ? Qt::red : fg_brush);
} }
return(invalid_keys); return(invalid_keys);
} }
@@ -156,7 +158,7 @@ void DiagramContextWidget::refreshFormatLabel()
"Les noms ne peuvent contenir que des lettres minuscules, des " "Les noms ne peuvent contenir que des lettres minuscules, des "
"chiffres et des tirets." "chiffres et des tirets."
); );
if (highlightNonAcceptableKeys()) { if (highlightNonAcceptableKeys()) {
format_text = QString("<span style=\"color: red;\">%1</span>").arg(format_text); format_text = QString("<span style=\"color: red;\">%1</span>").arg(format_text);
} }