Fixed old Qt5 versions compatibility

This commit is contained in:
Vadim Kuznetsov 2023-01-26 16:40:28 +03:00
parent 0d870cb83a
commit d3843c82a9
4 changed files with 106 additions and 2 deletions

View File

@ -14,6 +14,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "misc.h"
#include "changedialog.h"
#include "node.h"
#include "schematic.h"
@ -129,7 +130,11 @@ void ChangeDialog::slotButtReplace()
{
//Expr.setPatternSyntax(QRegExp::Wildcard); // switch into wildcard mode
//Expr.setPattern(CompNameEdit->text());
#if QT_VERSION >= 0x050f00
Expr = QRegularExpression(QRegularExpression::wildcardToRegularExpression(CompNameEdit->text()));
#else
Expr = QRegularExpression(misc::wildcardToRegularExpression(CompNameEdit->text(),false));
#endif
if(!Expr.isValid()) {
QMessageBox::critical(this, tr("Error"),
tr("Regular expression for component name is invalid."));

View File

@ -521,6 +521,104 @@ QStringList misc::parseCmdArgs(const QString &program)
return args;
}
QString misc::wildcardToRegularExpression(const QString &wc_str, const bool enableEscaping)
{
const int wclen = wc_str.length();
QString rx;
int i = 0;
bool isEscaping = false; // the previous character is '\'
const QChar *wc = wc_str.unicode();
while (i < wclen) {
const QChar c = wc[i++];
switch (c.unicode()) {
case '\\':
if (enableEscaping) {
if (isEscaping) {
rx += QLatin1String("\\\\");
} // we insert the \\ later if necessary
if (i+1 == wclen) { // the end
rx += QLatin1String("\\\\");
}
} else {
rx += QLatin1String("\\\\");
}
isEscaping = true;
break;
case '*':
if (isEscaping) {
rx += QLatin1String("\\*");
isEscaping = false;
} else {
rx += QLatin1String(".*");
}
break;
case '?':
if (isEscaping) {
rx += QLatin1String("\\?");
isEscaping = false;
} else {
rx += QLatin1Char('.');
}
break;
case '$':
case '(':
case ')':
case '+':
case '.':
case '^':
case '{':
case '|':
case '}':
if (isEscaping) {
isEscaping = false;
rx += QLatin1String("\\\\");
}
rx += QLatin1Char('\\');
rx += c;
break;
case '[':
if (isEscaping) {
isEscaping = false;
rx += QLatin1String("\\[");
} else {
rx += c;
if (wc[i] == QLatin1Char('^'))
rx += wc[i++];
if (i < wclen) {
if (rx[i] == QLatin1Char(']'))
rx += wc[i++];
while (i < wclen && wc[i] != QLatin1Char(']')) {
if (wc[i] == QLatin1Char('\\'))
rx += QLatin1Char('\\');
rx += wc[i++];
}
}
}
break;
case ']':
if(isEscaping){
isEscaping = false;
rx += QLatin1String("\\");
}
rx += c;
break;
default:
if(isEscaping){
isEscaping = false;
rx += QLatin1String("\\\\");
}
rx += c;
}
}
return rx;
}
VersionTriplet::VersionTriplet(){
major = minor = patch = 0;
}

View File

@ -92,6 +92,7 @@ namespace misc {
QStringList parseCmdArgs(const QString &program);
QString getIconPath(const QString &file, int icon_type);
bool isDarkTheme();
QString wildcardToRegularExpression(const QString &wc_str, const bool enableEscaping);
}
/*! handle the application version string

View File

@ -49,10 +49,10 @@ SymbolWidget::SymbolWidget(QWidget *parent) : QWidget(parent)
PaintText = tr("Symbol:");
setFont(QucsSettings.font);
QFontMetrics metrics(QucsSettings.font, 0); // use the the screen-compatible metric
TextWidth = metrics.horizontalAdvance(PaintText) + 4; // get size of text
TextWidth = metrics.size(0,PaintText).width() + 4; // get size of text
DragNDropText = tr("! Drag n'Drop me !");
DragNDropWidth = metrics.horizontalAdvance(DragNDropText); // get size of text
DragNDropWidth = metrics.size(0,DragNDropText).width(); // get size of text
TextHeight = metrics.lineSpacing();
///setPaletteBackgroundColor(Qt::white);