Commit c5b43352 authored by Julius Künzel's avatar Julius Künzel
Browse files

Replace QRegExp (removed in Qt6) by QRegularExression

Related to #1003
parent e22eccc2
Pipeline #73505 canceled with stage
......@@ -60,10 +60,10 @@ bool AssetFilter::filterName(const std::shared_ptr<TreeItem> &item) const
return true;
}
QString itemId = item->dataColumn(AssetTreeModel::idCol).toString().toUtf8().constData();
itemId = itemId.normalized(QString::NormalizationForm_D).remove(QRegExp(QStringLiteral("[^a-zA-Z0-9\\s]")));
itemId = itemId.normalized(QString::NormalizationForm_D).remove(QRegularExpression(QStringLiteral("[^a-zA-Z0-9\\s]")));
QString itemText = i18n(item->dataColumn(AssetTreeModel::nameCol).toString().toUtf8().constData());
itemText = itemText.normalized(QString::NormalizationForm_D).remove(QRegExp(QStringLiteral("[^a-zA-Z0-9\\s]")));
QString patt = m_name_value.normalized(QString::NormalizationForm_D).remove(QRegExp(QStringLiteral("[^a-zA-Z0-9\\s]")));
itemText = itemText.normalized(QString::NormalizationForm_D).remove(QRegularExpression(QStringLiteral("[^a-zA-Z0-9\\s]")));
QString patt = m_name_value.normalized(QString::NormalizationForm_D).remove(QRegularExpression(QStringLiteral("[^a-zA-Z0-9\\s]")));
return itemText.contains(patt, Qt::CaseInsensitive) || itemId.contains(patt, Qt::CaseInsensitive);
}
......
......@@ -141,11 +141,11 @@ AssetParameterModel::AssetParameterModel(std::unique_ptr<Mlt::Properties> asset,
case ParamType::KeyframeParam:
case ParamType::Position:
// Fix values like <position>=1,5
value.replace(QRegExp(R"((=\d+),(\d+))"), "\\1.\\2");
value.replace(QRegularExpression(R"((=\d+),(\d+))"), "\\1.\\2");
break;
case ParamType::AnimatedRect:
// Fix values like <position>=50 20 1920 1080 0,75
value.replace(QRegExp(R"((=\d+ \d+ \d+ \d+ \d+),(\d+))"), "\\1.\\2");
value.replace(QRegularExpression(R"((=\d+ \d+ \d+ \d+ \d+),(\d+))"), "\\1.\\2");
break;
case ParamType::ColorWheel:
// Colour wheel has 3 separate properties: prop_r, prop_g and prop_b, always numbers
......
......@@ -120,8 +120,8 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QMap<QString, QString> mappable_a
m_configMisc.kcfg_use_exiftool->setEnabled(!QStandardPaths::findExecutable(QStringLiteral("exiftool")).isEmpty());
QRegExp rx(R"((\+|-)?\d{2}:\d{2}:\d{2}(:||,)\d{2})");
QValidator *validator = new QRegExpValidator(rx, this);
QRegularExpression reg(R"((\+|-)?\d{2}:\d{2}:\d{2}(:||,)\d{2})");
QValidator *validator = new QRegularExpressionValidator(reg, this);
m_configMisc.kcfg_color_duration->setInputMask(pCore->timecode().mask());
m_configMisc.kcfg_color_duration->setValidator(validator);
m_configMisc.kcfg_title_duration->setInputMask(pCore->timecode().mask());
......
......@@ -1568,7 +1568,8 @@ void RenderWidget::generateRenderFiles(QDomDocument doc, const QString &playlist
// Image sequence, ensure we have a %0xd at file end
QString extension = renderedFile.section(QLatin1Char('.'), -1);
// format string for counter
if (!QRegExp(QStringLiteral(".*%[0-9]*d.*")).exactMatch(renderedFile)) {
QRegularExpression rx(QRegularExpression::anchoredPattern(QStringLiteral(".*%[0-9]*d.*")));
if (!rx.match(renderedFile).hasMatch()) {
renderedFile = renderedFile.section(QLatin1Char('.'), 0, -2) + QStringLiteral("_%05d.") + extension;
}
}
......
......@@ -1784,8 +1784,8 @@ auto DocumentValidator::upgradeTo100(const QLocale &documentLocale) -> QString {
qDebug() << "Decimal point is NOT OK and needs fixing. Converting to . from " << decimalPoint;
auto fixTimecode = [decimalPoint] (QString &value) {
QRegExp reTimecode(R"((\d+:\d+:\d+))" + QString(decimalPoint) + "(\\d+)");
QRegExp reValue("(=\\d+)" + QString(decimalPoint) + "(\\d+)");
QRegularExpression reTimecode(R"((\d+:\d+:\d+))" + QString(decimalPoint) + "(\\d+)");
QRegularExpression reValue("(=\\d+)" + QString(decimalPoint) + "(\\d+)");
value.replace(reTimecode, "\\1.\\2")
.replace(reValue, "\\1.\\2");
};
......@@ -1819,7 +1819,7 @@ auto DocumentValidator::upgradeTo100(const QLocale &documentLocale) -> QString {
QString value(originalValue);
if (propName == "resource") {
// Fix entries like <property name="resource">0,500000:/path/to/video
value.replace(QRegExp("^(\\d+)" + QString(decimalPoint) + "(\\d+:)"), "\\1.\\2");
value.replace(QRegularExpression("^(\\d+)" + QString(decimalPoint) + "(\\d+:)"), "\\1.\\2");
} else if (autoReplace) {
// Just replace decimal point
value.replace(decimalPoint, '.');
......
......@@ -891,9 +891,9 @@ void MainWindow::updateActionsToolTip()
if (tempAction == m_timeFormatButton) {
continue;
}
// find the shortcut pattern and delete (note the preceding space in the RegEx)
// find the shortcut pattern and delete (note the preceding space in the QRegularExpression)
QString toolTip = KLocalizedString::removeAcceleratorMarker(tempAction->toolTip());
QString strippedTooltip = toolTip.remove(QRegExp(QStringLiteral("\\s\\(.*\\)")));
QString strippedTooltip = toolTip.remove(QRegularExpression(QStringLiteral("\\s\\(.*\\)")));
QKeySequence shortCut = tempAction->shortcut();
if (shortCut == QKeySequence()) {
tempAction->setToolTip(strippedTooltip);
......@@ -2487,7 +2487,7 @@ void MainWindow::slotPreferences(int page, int option)
// Get the mappable actions in localized form
QMap<QString, QString> actions;
KActionCollection *collection = actionCollection();
QRegExp ampEx("&{1,1}");
QRegularExpression ampEx("&{1,1}");
for (const QString &action_name : qAsConst(m_actionNames)) {
QString action_text = collection->action(action_name)->text();
action_text.remove(ampEx);
......
......@@ -338,7 +338,7 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
m_playAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
m_playAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause")));
QString strippedTooltip = m_playAction->toolTip().remove(QRegExp(QStringLiteral("\\s\\(.*\\)")));
QString strippedTooltip = m_playAction->toolTip().remove(QRegularExpression(QStringLiteral("\\s\\(.*\\)")));
// append shortcut if it exists for action
if (originalPlayAction->shortcut() == QKeySequence(0)) {
m_playAction->setToolTip(strippedTooltip);
......
......@@ -403,7 +403,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QStringList
QString ext = filter.section(QLatin1Char('.'), -1);
filter = filter.section(QLatin1Char('%'), 0, -2);
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp);
QRegularExpression rx(QRegularExpression::anchoredPattern(regexp));
QStringList slideImages;
QString directory = dir.absolutePath();
if (!directory.endsWith(QLatin1Char('/'))) {
......@@ -411,7 +411,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QStringList
}
qint64 totalSize = 0;
for (const QString &path : qAsConst(result)) {
if (rx.exactMatch(path)) {
if (rx.match(path).hasMatch()) {
totalSize += QFileInfo(directory + path).size();
slideImages << directory + path;
}
......@@ -498,11 +498,11 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QMap<QStrin
QString ext = filter.section(QLatin1Char('.'), -1).section(QLatin1Char('?'), 0, 0);
filter = filter.section(QLatin1Char('%'), 0, -2);
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp);
QRegularExpression rx(QRegularExpression::anchoredPattern(regexp));
QStringList slideImages;
qint64 totalSize = 0;
for (const QString &path : qAsConst(result)) {
if (rx.exactMatch(path)) {
if (rx.match(path).hasMatch()) {
totalSize += QFileInfo(dir.absoluteFilePath(path)).size();
slideImages << dir.absoluteFilePath(path);
}
......
......@@ -684,11 +684,11 @@ QStringList ProjectSettings::extractSlideshowUrls(const QString &url)
QString ext = filter.section(QLatin1Char('.'), -1);
filter = filter.section(QLatin1Char('%'), 0, -2);
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp);
QRegularExpression rx(QRegularExpression::anchoredPattern(regexp));
int count = 0;
const QStringList result = dir.entryList(QDir::Files);
for (const QString &p : result) {
if (rx.exactMatch(p)) {
if (rx.match(p).hasMatch()) {
count++;
}
}
......
......@@ -285,11 +285,11 @@ void SlideshowClip::parseFolder()
}
// qCDebug(KDENLIVE_LOG) << " / /" << path_pattern << " / " << ext << " / " << filter;
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp);
QRegularExpression rx(QRegularExpression::anchoredPattern(regexp));
QStringList entries;
int ix;
for (const QString &p : qAsConst(result)) {
if (rx.exactMatch(p)) {
if (rx.match(p).hasMatch()) {
if (offset > 0) {
// make sure our image is in the range we want (> begin)
ix = p.section(filter, 1).section(QLatin1Char('.'), 0, 0).toInt();
......
......@@ -14,6 +14,8 @@
#include <QPushButton>
#include <QVBoxLayout>
#include <QWheelEvent>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <KSharedConfig>
#include <klocalizedstring.h>
......@@ -64,13 +66,14 @@ UnicodeWidget::UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *pare
connect(arrowUp, &QAbstractButton::clicked, this, &UnicodeWidget::slotPrevUnicode);
connect(arrowDown, &QAbstractButton::clicked, this, &UnicodeWidget::slotNextUnicode);
switch (m_inputMethod) {
case UnicodeDialog::InputHex:
if(m_inputMethod == UnicodeDialog::InputHex) {
unicodeNumber->setMaxLength(MAX_LENGTH_HEX);
break;
QRegularExpression rx("([0-9]|[a-f])*", QRegularExpression::CaseInsensitiveOption);
QValidator *validator = new QRegularExpressionValidator(rx, this);
unicodeNumber->setValidator(validator);
case UnicodeDialog::InputDec:
break;
} else { // UnicodeDialog::InputDec
// TODO Validator
}
arrowUp->setShortcut(Qt::Key_Up);
......@@ -215,29 +218,6 @@ QString UnicodeWidget::unicodeInfo(const QString &unicode)
return infoText;
}
QString UnicodeWidget::validateText(const QString &text)
{
QRegExp regex("([0-9]|[a-f])", Qt::CaseInsensitive, QRegExp::RegExp2);
QString newText;
int pos = 0;
switch (m_inputMethod) {
case UnicodeDialog::InputHex:
// Remove all characters we don't want
while ((pos = regex.indexIn(text, pos)) != -1) {
newText += regex.cap(1);
pos++;
}
break;
case UnicodeDialog::InputDec:
// TODO
break;
}
return newText;
}
void UnicodeWidget::updateOverviewChars(uint unicode)
{
QString left;
......@@ -331,8 +311,8 @@ void UnicodeWidget::slotTextChanged(const QString &text)
{
unicodeNumber->blockSignals(true);
QString newText = validateText(text);
if (newText.isEmpty()) {
//QString newText = validateText(text);
if (text.isEmpty()) {
unicodeChar->clear();
unicodeNumber->clear();
clearOverviewChars();
......@@ -344,7 +324,7 @@ void UnicodeWidget::slotTextChanged(const QString &text)
int cursorPos = unicodeNumber->cursorPosition();
unicodeNumber->setText(newText);
//unicodeNumber->setText(newText);
unicodeNumber->setCursorPosition(cursorPos);
// Get the decimal number as uint to create the QChar from
......@@ -352,10 +332,10 @@ void UnicodeWidget::slotTextChanged(const QString &text)
uint value = 0;
switch (m_inputMethod) {
case UnicodeDialog::InputHex:
value = newText.toUInt(&ok, 16);
value = text.toUInt(&ok, 16);
break;
case UnicodeDialog::InputDec:
value = newText.toUInt(&ok, 10);
value = text.toUInt(&ok, 10);
break;
}
updateOverviewChars(value);
......@@ -366,14 +346,14 @@ void UnicodeWidget::slotTextChanged(const QString &text)
// If an invalid character has been entered:
// Reset the cursor position because the entered char has been deleted.
if (text != newText && newText == m_lastUnicodeNumber) {
if (text != text && text == m_lastUnicodeNumber) {
unicodeNumber->setCursorPosition(m_lastCursorPos);
}
m_lastCursorPos = unicodeNumber->cursorPosition();
m_lastUnicodeNumber = newText;
m_lastUnicodeNumber = text;
labelInfoText->setText(unicodeInfo(newText));
labelInfoText->setText(unicodeInfo(text));
unicodeChar->setText(QChar(value));
}
......
......@@ -55,8 +55,6 @@ private:
/** Selected input method */
UnicodeDialog::InputMethod m_inputMethod;
/** \brief Validates text and removes all invalid characters (non-hex e.g.) */
QString validateText(const QString &text);
/** \brief Removes all leading zeros */
QString trimmedUnicodeNumber(QString text);
/** \brief Checks whether the given string is a control character */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment