Fix compilation with -no-feature-regularexpression

This -no-feature has probably not been tested for a while
and seems to have rotted a bit, both some unprotected
uses and some warnings on unused parameters.

Change-Id: Ie20a06c78d3b4c36860dab49d6615eaa8ffc9077
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2020-03-16 08:47:45 +01:00
parent dee55af0a5
commit cfcf88e259
7 changed files with 39 additions and 4 deletions

View File

@ -46,7 +46,9 @@
#include <qdebug.h>
#include <qvector.h>
#include <qregexp.h>
#include <qregularexpression.h>
#if QT_CONFIG(regularexpression)
# include <qregularexpression.h>
#endif
#include <qstack.h>
#include <qbitarray.h>
#include <qdatetime.h>
@ -2359,7 +2361,9 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
bool wrap = flags & Qt::MatchWrap;
bool allHits = (hits == -1);
QString text; // only convert to a string if it is needed
#if QT_CONFIG(regularexpression)
QRegularExpression rx; // only create it if needed
#endif
const int column = start.column();
QModelIndex p = parent(start);
int from = start.row();
@ -2377,6 +2381,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
if (value == v)
result.append(idx);
} else { // QString or regular expression based matching
#if QT_CONFIG(regularexpression)
if (matchType == Qt::MatchRegularExpression) {
if (rx.pattern().isEmpty()) {
if (value.userType() == QMetaType::QRegularExpression) {
@ -2392,7 +2397,9 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
rx.setPattern(QRegularExpression::wildcardToRegularExpression(value.toString()));
if (cs == Qt::CaseInsensitive)
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
} else {
} else
#endif
{
if (text.isEmpty()) // lazy conversion
text = value.toString();
}
@ -2405,12 +2412,15 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
result.append(idx);
break;
#endif
#if QT_CONFIG(regularexpression)
case Qt::MatchRegularExpression:
Q_FALLTHROUGH();
case Qt::MatchWildcard:
if (t.contains(rx))
result.append(idx);
break;
#endif
case Qt::MatchStartsWith:
if (t.startsWith(text, cs))
result.append(idx);

View File

@ -111,6 +111,13 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId();
#define QT_FOR_EACH_STATIC_ITEMMODEL_CLASS(F)
#endif
#if QT_CONFIG(regularexpression)
# define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) \
F(QRegularExpression, 44, QRegularExpression)
#else
# define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F)
#endif
#define QT_FOR_EACH_STATIC_CORE_CLASS(F)\
F(QChar, 7, QChar) \
F(QString, 10, QString) \
@ -134,7 +141,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId();
QT_FOR_EACH_STATIC_EASINGCURVE(F) \
F(QUuid, 30, QUuid) \
F(QVariant, 41, QVariant) \
F(QRegularExpression, 44, QRegularExpression) \
QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) \
F(QJsonValue, 45, QJsonValue) \
F(QJsonObject, 46, QJsonObject) \
F(QJsonArray, 47, QJsonArray) \

View File

@ -3606,7 +3606,9 @@ bool QVariant::canConvert(int targetTypeId) const
case QMetaType::QByteArray:
case QMetaType::QDateTime:
case QMetaType::QUrl:
#if QT_CONFIG(regularexpression)
case QMetaType::QRegularExpression:
#endif
case QMetaType::QUuid:
case QMetaType::QVariantList:
case QMetaType::QVariantMap:

View File

@ -161,7 +161,9 @@ class Q_CORE_EXPORT QVariant
Point = QMetaType::QPoint,
PointF = QMetaType::QPointF,
RegExp = QMetaType::QRegExp,
#if QT_CONFIG(regularexpression)
RegularExpression = QMetaType::QRegularExpression,
#endif
Hash = QMetaType::QVariantHash,
#if QT_CONFIG(easingcurve)
EasingCurve = QMetaType::QEasingCurve,

View File

@ -790,6 +790,7 @@ QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter)
f = match.captured(2);
return f.split(QLatin1Char(' '), Qt::SkipEmptyParts);
#else
Q_UNUSED(filter)
return QStringList();
#endif
}

View File

@ -55,7 +55,9 @@
#include <QtGui/qcolor.h>
#include <QtCore/qdebug.h>
#include <QtCore/qregularexpression.h>
#if QT_CONFIG(regularexpression)
# include <QtCore/qregularexpression.h>
#endif
#include <QtCore/qtimer.h>
#include <QtCore/qdir.h>
#include <QtCore/qscopedpointer.h>
@ -1034,9 +1036,12 @@ static QList<FilterSpec> filterSpecs(const QStringList &filters,
result.reserve(filters.size());
*totalStringLength = 0;
#if QT_CONFIG(regularexpression)
const QRegularExpression filterSeparatorRE(QStringLiteral("[;\\s]+"));
const QString separator = QStringLiteral(";");
Q_ASSERT(filterSeparatorRE.isValid());
#endif
// Split filter specification as 'Texts (*.txt[;] *.doc)', '*.txt[;] *.doc'
// into description and filters specification as '*.txt;*.doc'
for (const QString &filterString : filters) {
@ -1049,7 +1054,11 @@ static QList<FilterSpec> filterSpecs(const QStringList &filters,
filterString.mid(openingParenPos + 1, closingParenPos - openingParenPos - 1).trimmed();
if (filterSpec.filter.isEmpty())
filterSpec.filter += u'*';
#if QT_CONFIG(regularexpression)
filterSpec.filter.replace(filterSeparatorRE, separator);
#else
filterSpec.filter.replace(QLatin1Char(' '), QLatin1Char(';'));
#endif
filterSpec.description = filterString;
if (hideFilterDetails && openingParenPos != -1) { // Do not show pattern in description
filterSpec.description.truncate(openingParenPos);

View File

@ -1709,6 +1709,8 @@ void QFileSystemModel::setNameFilters(const QStringList &filters)
d->nameFilters = filters;
d->forceSort = true;
d->delayedSort();
#else
Q_UNUSED(filters)
#endif
}
@ -2158,6 +2160,8 @@ bool QFileSystemModelPrivate::passNameFilters(const QFileSystemNode *node) const
}
return false;
}
#else
Q_UNUSED(node)
#endif
return true;
}