Replace QRegExp with QRegularExpression (#7133)

* replace QRegExp with QRegularExpression (find n replace)

* follow up to fix errors

* removed rpmalloc

* Fix compilation for qt5, to be fixed when qt6 fully supported.

Co-authored-by: Kevin Zander <veratil@gmail.com>

* Added QtGlobal header for version finding fix

* Use the other syntax to try fix compilation.

* Check for 5.12 instead.

* Fix the header

* Attempt at fixing it further.

* Use version checks properly in header file

* Use QT_VERSION_CHECK macro in sources

* Apply suggestions from messmerd's review

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>

---------

Co-authored-by: Kevin Zander <veratil@gmail.com>
Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
Rossmaxx
2024-03-16 11:04:01 +05:30
committed by GitHub
parent b9ebc24e13
commit 4120a04d0b
13 changed files with 46 additions and 27 deletions

View File

@@ -25,9 +25,10 @@
#ifndef LMMS_AUTOMATABLE_MODEL_H
#define LMMS_AUTOMATABLE_MODEL_H
#include <cmath>
#include <QMap>
#include <QMutex>
#include <cmath>
#include <QRegularExpression>
#include "JournallingObject.h"
#include "Model.h"

View File

@@ -33,7 +33,7 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QScrollArea>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
@@ -65,10 +65,19 @@ protected:
QString name = sourceModel()->data(nameIndex, Qt::DisplayRole).toString();
QString type = sourceModel()->data(typeIndex, Qt::DisplayRole).toString();
QRegExp nameRegExp(filterRegExp());
nameRegExp.setCaseSensitivity(Qt::CaseInsensitive);
// TODO: cleanup once we drop Qt5 support
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
QRegularExpression nameRegularExpression(filterRegularExpression());
nameRegularExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
bool nameFilterPassed = nameRegularExpression.match(name).capturedStart() != -1;
#else
QRegExp nameRegularExpression(filterRegExp());
nameRegularExpression.setCaseSensitivity(Qt::CaseInsensitive);
bool nameFilterPassed = nameRegularExpression.indexIn(name) != -1;
#endif
bool nameFilterPassed = nameRegExp.indexIn(name) != -1;
bool typeFilterPassed = type.contains(m_effectTypeFilter, Qt::CaseInsensitive);
return nameFilterPassed && typeFilterPassed;

View File

@@ -26,6 +26,8 @@
#ifndef LMMS_LADSPA_BASE_H
#define LMMS_LADSPA_BASE_H
#include <QRegularExpression>
#include "LadspaManager.h"
#include "Plugin.h"
@@ -75,7 +77,7 @@ inline Plugin::Descriptor::SubPluginFeatures::Key ladspaKeyToSubPluginKey(
{
Plugin::Descriptor::SubPluginFeatures::Key::AttributeMap m;
QString file = _key.first;
m["file"] = file.remove( QRegExp( "\\.so$" ) ).remove( QRegExp( "\\.dll$" ) );
m["file"] = file.remove(QRegularExpression("\\.so$")).remove(QRegularExpression("\\.dll$"));
m["plugin"] = _key.second;
return Plugin::Descriptor::SubPluginFeatures::Key( _desc, _name, m );
}

View File

@@ -33,6 +33,7 @@
#include <QCloseEvent>
#include <QDomElement>
#include <QMutex>
#include <QRegularExpression>
// carla/source/includes
#include "carlabase_export.h"
@@ -89,8 +90,8 @@ public:
// From AutomatableModel.h, it's private there.
inline static bool mustQuoteName(const QString &name)
{
QRegExp reg("^[A-Za-z0-9._-]+$");
return !reg.exactMatch(name);
QRegularExpression reg("^[A-Za-z0-9._-]+$");
return !reg.match(name).hasMatch();
}
inline void loadSettings(const QDomElement& element, const QString& name = QString("value")) override

View File

@@ -171,8 +171,7 @@ ladspa_key_t LadspaSubPluginFeatures::subPluginKeyToLadspaKey(
const Key * _key )
{
QString file = _key->attributes["file"];
return( ladspa_key_t( file.remove( QRegExp( "\\.so$" ) ).
remove( QRegExp( "\\.dll$" ) ) +
return(ladspa_key_t(file.remove(QRegularExpression("\\.so$")).remove(QRegularExpression("\\.dll$")) +
#ifdef LMMS_BUILD_WIN32
".dll"
#else

View File

@@ -311,7 +311,7 @@ void ZynAddSubFxInstrument::loadFile( const QString & _file )
m_pluginMutex.unlock();
}
instrumentTrack()->setName( QFileInfo( _file ).baseName().replace( QRegExp( "^[0-9]{4}-" ), QString() ) );
instrumentTrack()->setName(QFileInfo(_file).baseName().replace(QRegularExpression("^[0-9]{4}-"), QString()));
m_modifiedControllers.clear();

View File

@@ -97,8 +97,8 @@ bool AutomatableModel::isAutomated() const
bool AutomatableModel::mustQuoteName(const QString& name)
{
QRegExp reg("^[A-Za-z0-9._-]+$");
return !reg.exactMatch(name);
QRegularExpression reg("^[A-Za-z0-9._-]+$");
return !reg.match(name).hasMatch();
}
void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, const QString& name )

View File

@@ -35,6 +35,7 @@
#include <QFileInfo>
#include <QDir>
#include <QMessageBox>
#include <QRegularExpression>
#include <QSaveFile>
#include "base64.h"
@@ -973,8 +974,7 @@ void DataFile::upgrade_0_4_0_20080622()
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "name" );
s.replace( QRegExp( "^Beat/Baseline " ),
"Beat/Bassline " );
s.replace(QRegularExpression("^Beat/Baseline "), "Beat/Bassline");
el.setAttribute( "name", s );
}
}
@@ -1109,7 +1109,7 @@ void DataFile::upgrade_1_1_91()
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "src" );
s.replace( QRegExp("/samples/bassloopes/"), "/samples/bassloops/" );
s.replace(QRegularExpression("/samples/bassloopes/"), "/samples/bassloops/");
el.setAttribute( "src", s );
}

View File

@@ -23,6 +23,7 @@
*/
#include <QDir>
#include <QRegularExpression>
#include "RenderManager.h"
@@ -182,7 +183,7 @@ QString RenderManager::pathForTrack(const Track *track, int num)
{
QString extension = ProjectRenderer::getFileExtensionFromFormat( m_format );
QString name = track->name();
name = name.remove(QRegExp(FILENAME_FILTER));
name = name.remove(QRegularExpression(FILENAME_FILTER));
name = QString( "%1_%2%3" ).arg( num ).arg( name ).arg( extension );
return QDir(m_outputPath).filePath(name);
}

View File

@@ -31,7 +31,7 @@
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QTextStream>
#include "ComboBox.h"
@@ -342,7 +342,7 @@ bool MicrotunerConfig::validateScaleForm()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
if (firstSection.contains('.')) // cent mode
{
bool ok = true;
@@ -357,7 +357,7 @@ bool MicrotunerConfig::validateScaleForm()
if (!ok) {fail(tr("Numerator of an interval defined as a ratio cannot be converted to a number")); return false;}
if (line.contains('/'))
{
den = line.split('/').at(1).section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt(&ok);
den = line.split('/').at(1).section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt(&ok);
}
if (!ok) {fail(tr("Denominator of an interval defined as a ratio cannot be converted to a number")); return false;}
if (num * den < 0) {fail(tr("Interval defined as a ratio cannot be negative")); return false;}
@@ -390,7 +390,7 @@ bool MicrotunerConfig::validateKeymapForm()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty);
if (firstSection == "x") {continue;} // not mapped
// otherwise must contain a number
bool ok = true;
@@ -424,7 +424,7 @@ bool MicrotunerConfig::applyScale()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
if (firstSection.contains('.')) // cent mode
{
newIntervals.emplace_back(firstSection.toFloat());
@@ -435,7 +435,7 @@ bool MicrotunerConfig::applyScale()
num = firstSection.toInt();
if (line.contains('/'))
{
den = line.split('/').at(1).section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt();
den = line.split('/').at(1).section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt();
}
newIntervals.emplace_back(num, den);
}
@@ -470,7 +470,7 @@ bool MicrotunerConfig::applyKeymap()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty);
if (firstSection == "x")
{
newMap.push_back(-1); // not mapped

View File

@@ -420,7 +420,7 @@ void InstrumentTrackWindow::saveSettingsBtnClicked()
sfd.setDirectory(presetRoot + m_track->instrumentName());
sfd.setFileMode( FileDialog::AnyFile );
QString fname = m_track->name();
sfd.selectFile(fname.remove(QRegExp(FILENAME_FILTER)));
sfd.selectFile(fname.remove(QRegularExpression(FILENAME_FILTER)));
sfd.setDefaultSuffix( "xpf");
if( sfd.exec() == QDialog::Accepted &&

View File

@@ -34,6 +34,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QRegularExpression>
#include <QScrollArea>
#include <QVBoxLayout>
@@ -126,7 +127,12 @@ EffectSelectDialog::EffectSelectDialog(QWidget* parent) :
m_filterEdit = new QLineEdit(this);
connect(m_filterEdit, &QLineEdit::textChanged, this, [this](const QString &text) {
// TODO: Cleanup when we don't support Qt5 anymore
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
m_model.setFilterRegularExpression(QRegularExpression(text, QRegularExpression::CaseInsensitiveOption));
#else
m_model.setFilterRegExp(QRegExp(text, Qt::CaseInsensitive));
#endif
});
connect(m_filterEdit, &QLineEdit::textChanged, this, &EffectSelectDialog::updateSelection);
m_filterEdit->setFocus();

View File

@@ -89,9 +89,9 @@ VersionedSaveDialog::VersionedSaveDialog( QWidget *parent,
bool VersionedSaveDialog::changeFileNameVersion(QString &fileName, bool increment )
{
static QRegExp regexp( "[- ]\\d+(\\.\\w+)?$" );
static QRegularExpression regex( "[- ]\\d+(\\.\\w+)?$" );
int idx = regexp.indexIn( fileName );
int idx = regex.match(fileName).capturedStart();
// For file names without extension (no ".mmpz")
int insertIndex = fileName.lastIndexOf( '.' );
if ( insertIndex < idx+1 )