From c9542b0538e0ceadba244b6208099b5513951976 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 23 Apr 2012 17:46:55 +0200 Subject: [PATCH] Don't use the QRegExp methods that modify the object [Designer] QRegExp matching methods modify the object, which we don't want to. In particular, when we receive a QRegExp from the user or we store in a context that might require thread-safety, make sure we make a copy before using it. QRegularExpression has no such shortcoming. Task-number: QTBUG-25064 Change-Id: I58984ddce6a44cca7fe5a7b36e4595bad791d976 Reviewed-by: Friedemann Kleint --- src/designer/src/components/formeditor/formwindowsettings.cpp | 2 +- .../src/components/formeditor/layout_propertysheet.cpp | 2 +- .../src/components/widgetbox/widgetboxcategorylistview.cpp | 2 +- src/designer/src/components/widgetbox/widgetboxtreewidget.cpp | 2 +- src/designer/src/lib/shared/formlayoutmenu.cpp | 2 +- src/designer/src/lib/shared/qdesigner_widgetbox.cpp | 2 +- src/designer/src/lib/shared/signalslotdialog.cpp | 10 ++++++---- src/designer/src/lib/shared/textpropertyeditor.cpp | 4 ++-- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/designer/src/components/formeditor/formwindowsettings.cpp b/src/designer/src/components/formeditor/formwindowsettings.cpp index 2b546be..371315e 100644 --- a/src/designer/src/components/formeditor/formwindowsettings.cpp +++ b/src/designer/src/components/formeditor/formwindowsettings.cpp @@ -226,7 +226,7 @@ FormWindowData FormWindowSettings::data() const if (!hints.isEmpty()) { rc.includeHints = hints.split(QString(QLatin1Char('\n'))); // Purge out any lines consisting of blanks only - const QRegExp blankLine = QRegExp(QStringLiteral("^\\s*$")); + QRegExp blankLine = QRegExp(QStringLiteral("^\\s*$")); Q_ASSERT(blankLine.isValid()); for (QStringList::iterator it = rc.includeHints.begin(); it != rc.includeHints.end(); ) if (blankLine.exactMatch(*it)) { diff --git a/src/designer/src/components/formeditor/layout_propertysheet.cpp b/src/designer/src/components/formeditor/layout_propertysheet.cpp index 08048d1..2b79043 100644 --- a/src/designer/src/components/formeditor/layout_propertysheet.cpp +++ b/src/designer/src/components/formeditor/layout_propertysheet.cpp @@ -107,7 +107,7 @@ namespace { static bool isIntegerList(const QString &s) { // Check for empty string or comma-separated list of integers - static const QRegExp re(QStringLiteral("[0-9]+(,[0-9]+)+")); + static QRegExp re(QStringLiteral("[0-9]+(,[0-9]+)+")); Q_ASSERT(re.isValid()); return s.isEmpty() || re.exactMatch(s); } diff --git a/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp b/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp index f32e797..14eb167 100644 --- a/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp +++ b/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp @@ -364,7 +364,7 @@ QWidget *WidgetBoxCategoryEntryDelegate::createEditor(QWidget *parent, { QWidget *result = QItemDelegate::createEditor(parent, option, index); if (QLineEdit *line_edit = qobject_cast(result)) { - const QRegExp re = QRegExp(QStringLiteral("[_a-zA-Z][_a-zA-Z0-9]*")); + QRegExp re = QRegExp(QStringLiteral("[_a-zA-Z][_a-zA-Z0-9]*")); Q_ASSERT(re.isValid()); line_edit->setValidator(new QRegExpValidator(re, line_edit)); } diff --git a/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp b/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp index d302a39..a489d3a 100644 --- a/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp +++ b/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp @@ -971,7 +971,7 @@ void WidgetBoxTreeWidget::dropWidgets(const QList &i void WidgetBoxTreeWidget::filter(const QString &f) { const bool empty = f.isEmpty(); - const QRegExp re = empty ? QRegExp() : QRegExp(f, Qt::CaseInsensitive, QRegExp::FixedString); + QRegExp re = empty ? QRegExp() : QRegExp(f, Qt::CaseInsensitive, QRegExp::FixedString); const int numTopLevels = topLevelItemCount(); bool changed = false; for (int i = 0; i < numTopLevels; i++) { diff --git a/src/designer/src/lib/shared/formlayoutmenu.cpp b/src/designer/src/lib/shared/formlayoutmenu.cpp index 713e930..fd7aa27 100644 --- a/src/designer/src/lib/shared/formlayoutmenu.cpp +++ b/src/designer/src/lib/shared/formlayoutmenu.cpp @@ -130,7 +130,7 @@ private: void updateOkButton(); // Check for buddy marker in string - const QRegExp m_buddyMarkerRegexp; + QRegExp m_buddyMarkerRegexp; Ui::FormLayoutRowDialog m_ui; bool m_labelNameEdited; diff --git a/src/designer/src/lib/shared/qdesigner_widgetbox.cpp b/src/designer/src/lib/shared/qdesigner_widgetbox.cpp index 0b868f4..31a49f5 100644 --- a/src/designer/src/lib/shared/qdesigner_widgetbox.cpp +++ b/src/designer/src/lib/shared/qdesigner_widgetbox.cpp @@ -170,7 +170,7 @@ bool QDesignerWidgetBox::findWidget(const QDesignerWidgetBoxInterface *wbox, QString pattern = QStringLiteral("^categoryCount(); for (int c = 0; c < catCount; c++) { diff --git a/src/designer/src/lib/shared/signalslotdialog.cpp b/src/designer/src/lib/shared/signalslotdialog.cpp index d261a24..73c409f 100644 --- a/src/designer/src/lib/shared/signalslotdialog.cpp +++ b/src/designer/src/lib/shared/signalslotdialog.cpp @@ -138,8 +138,8 @@ namespace { virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; private: - const QRegExp m_signatureRegexp; - const QRegExp m_methodNameRegexp; + QRegExp m_signatureRegexp; + QRegExp m_methodNameRegexp; }; SignatureDelegate::SignatureDelegate(QObject * parent) : @@ -166,8 +166,10 @@ namespace { Q_ASSERT(le); // Did the user just type a name? .. Add parentheses QString signature = le->text(); - if (!m_signatureRegexp.exactMatch(signature )) { - if (m_methodNameRegexp.exactMatch(signature )) { + QRegExp signatureRegexp = m_signatureRegexp; + QRegExp methodNameRegexp = m_methodNameRegexp; + if (!signatureRegexp.exactMatch(signature )) { + if (methodNameRegexp.exactMatch(signature )) { signature += QStringLiteral("()"); le->setText(signature); } else { diff --git a/src/designer/src/lib/shared/textpropertyeditor.cpp b/src/designer/src/lib/shared/textpropertyeditor.cpp index 3471abc..da97a8a 100644 --- a/src/designer/src/lib/shared/textpropertyeditor.cpp +++ b/src/designer/src/lib/shared/textpropertyeditor.cpp @@ -168,7 +168,7 @@ namespace { QUrl UrlValidator::guessUrlFromString(const QString &string) const { const QString urlStr = string.trimmed(); - const QRegExp qualifiedUrl(QStringLiteral("^[a-zA-Z]+\\:.*")); + QRegExp qualifiedUrl(QStringLiteral("^[a-zA-Z]+\\:.*")); // Check if it looks like a qualified URL. Try parsing it and see. const bool hasSchema = qualifiedUrl.exactMatch(urlStr); @@ -299,7 +299,7 @@ namespace qdesigner_internal { void TextPropertyEditor::setRegExpValidator(const QString &pattern) { - const QRegExp regExp(pattern); + QRegExp regExp(pattern); Q_ASSERT(regExp.isValid()); m_lineEdit->setValidator(new QRegExpValidator(regExp,m_lineEdit)); } -- 2.7.4