From 434a1d0acf651221943a07d638603384ac0a61a4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 24 Oct 2023 11:03:04 +0300 Subject: [PATCH] Fix deprecation warnings. --- qbs/modules/buildconfig/buildconfig.qbs | 2 +- src/app/puzzle/main.cpp | 30 ++++++++- src/app/puzzle/vpmainwindow.cpp | 18 +++-- src/app/tape/main.cpp | 31 ++++++++- src/app/tape/tmainwindow.cpp | 20 ++++-- .../dialogs/dialogfinalmeasurements.cpp | 7 +- .../valentina/dialogs/dialogincrements.cpp | 2 +- src/app/valentina/main.cpp | 29 ++++++++ src/app/valentina/mainwindow.cpp | 23 ++++--- src/libs/vlayout/dialogs/watermarkwindow.cpp | 18 +++-- src/libs/vmisc/compatibility.h | 38 +++++++++++ src/libs/vmisc/def.cpp | 12 ++-- .../vpropertyexplorer/checkablemessagebox.cpp | 13 ++-- src/libs/vtest/abstracttest.cpp | 20 +++--- .../dialogs/support/dialogeditlabel.cpp | 9 +-- .../CollectionTest/tst_tapecommandline.cpp | 2 +- .../tst_valentinacommandline.cpp | 4 +- .../TranslationsTest/tst_abstractregexp.cpp | 23 ++----- .../tst_abstracttranslation.cpp | 12 ++-- .../tst_measurementregexp.cpp | 31 ++++----- .../tst_qmuparsererrormsg.cpp | 23 ++----- src/test/ValentinaTest/tst_vspline.cpp | 66 +++++++++---------- 22 files changed, 277 insertions(+), 156 deletions(-) diff --git a/qbs/modules/buildconfig/buildconfig.qbs b/qbs/modules/buildconfig/buildconfig.qbs index c219b4a2b..b87567940 100644 --- a/qbs/modules/buildconfig/buildconfig.qbs +++ b/qbs/modules/buildconfig/buildconfig.qbs @@ -110,7 +110,7 @@ Module { // You can make your code fail to compile if it uses deprecated APIs. // In order to do so, uncomment the following line. - "QT_DISABLE_DEPRECATED_BEFORE=0x060000", // disables all the APIs deprecated before Qt 6.0.0 + "QT_DISABLE_DEPRECATED_BEFORE=0x060600", // disables all the APIs deprecated before Qt 6.6.0 // Since Qt 5.4.0 the source code location is recorded only in debug builds. // We need this information also in release builds. For this need define QT_MESSAGELOGCONTEXT. diff --git a/src/app/puzzle/main.cpp b/src/app/puzzle/main.cpp index 7675bf68f..62746f1c8 100644 --- a/src/app/puzzle/main.cpp +++ b/src/app/puzzle/main.cpp @@ -29,7 +29,6 @@ #include // For QT_REQUIRE_VERSION #include -#include "../vmisc/def.h" #include "vpapplication.h" #if defined(APPIMAGE) && defined(Q_OS_LINUX) @@ -45,6 +44,35 @@ #include #endif +// Fix bug in Qt. Deprecation warning in QMessageBox::critical. +#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) +#undef QT_REQUIRE_VERSION +#define QT_REQUIRE_VERSION(argc, argv, str) \ + { \ + QString s = QString::fromLatin1(str); \ + QString sq = QString::fromLatin1(qVersion()); \ + if ((sq.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (sq.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + sq.section(QChar::fromLatin1('.'), 2, 2).toInt() < \ + (s.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (s.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + s.section(QChar::fromLatin1('.'), 2, 2).toInt()) \ + { \ + if (!qApp) \ + { \ + new QApplication(argc, argv); \ + } \ + QString s = QApplication::tr("Executable '%1' requires Qt %2, found Qt %3.") \ + .arg(qAppName()) \ + .arg(QString::fromLatin1(str)) \ + .arg(QString::fromLatin1(qVersion())); \ + QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"), s, QMessageBox::Abort, \ + static_cast(0)); \ + qFatal("%s", s.toLatin1().data()); \ + } \ + } +#endif + auto main(int argc, char *argv[]) -> int { #if defined(APPIMAGE) && defined(Q_OS_LINUX) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index eeb052907..cfeadd190 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -1737,15 +1737,23 @@ auto VPMainWindow::MaybeSave() -> bool // TODO: Implement maybe save check if (this->isWindowModified()) { - QScopedPointer messageBox(new QMessageBox( - tr("Unsaved changes"), tr("Layout has been modified. Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel, this, Qt::Sheet)); + QScopedPointer messageBox( + new QMessageBox(QMessageBox::Warning, tr("Unsaved changes"), + tr("Layout has been modified. Do you want to save your changes?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); - messageBox->setButtonText(QMessageBox::Yes, curFile.isEmpty() || IsLayoutReadOnly() ? tr("Save…") : tr("Save")); - messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + if (QAbstractButton *button = messageBox->button(QMessageBox::Yes)) + { + button->setText(curFile.isEmpty() || IsLayoutReadOnly() ? tr("Save…") : tr("Save")); + } + + if (QAbstractButton *button = messageBox->button(QMessageBox::No)) + { + button->setText(tr("Don't Save")); + } messageBox->setWindowModality(Qt::ApplicationModal); const auto ret = static_cast(messageBox->exec()); diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp index de1e2a8b2..f465e343f 100644 --- a/src/app/tape/main.cpp +++ b/src/app/tape/main.cpp @@ -44,6 +44,35 @@ #include #endif +// Fix bug in Qt. Deprecation warning in QMessageBox::critical. +#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) +#undef QT_REQUIRE_VERSION +#define QT_REQUIRE_VERSION(argc, argv, str) \ + { \ + QString s = QString::fromLatin1(str); \ + QString sq = QString::fromLatin1(qVersion()); \ + if ((sq.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (sq.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + sq.section(QChar::fromLatin1('.'), 2, 2).toInt() < \ + (s.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (s.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + s.section(QChar::fromLatin1('.'), 2, 2).toInt()) \ + { \ + if (!qApp) \ + { \ + new QApplication(argc, argv); \ + } \ + QString s = QApplication::tr("Executable '%1' requires Qt %2, found Qt %3.") \ + .arg(qAppName()) \ + .arg(QString::fromLatin1(str)) \ + .arg(QString::fromLatin1(qVersion())); \ + QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"), s, QMessageBox::Abort, \ + static_cast(0)); \ + qFatal("%s", s.toLatin1().data()); \ + } \ + } +#endif + auto main(int argc, char *argv[]) -> int { #if defined(APPIMAGE) && defined(Q_OS_LINUX) @@ -90,7 +119,7 @@ auto main(int argc, char *argv[]) -> int MApplication app(argc, argv); app.InitOptions(); - QT_REQUIRE_VERSION(argc, argv, "5.6.0") // clazy:exclude=qstring-arg,qstring-allocations NOLINT + QT_REQUIRE_VERSION(argc, argv, "5.6.0"); // clazy:exclude=qstring-arg,qstring-allocations NOLINT #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) MApplication::setDesktopFileName(QStringLiteral("ua.com.smart-pattern.tape.desktop")); diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 582c46792..7643be530 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -3494,15 +3494,23 @@ auto TMainWindow::MaybeSave() -> bool return true; // Don't ask if file was created without modifications. } - QScopedPointer messageBox(new QMessageBox( - tr("Unsaved changes"), tr("Measurements have been modified. Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel, this, Qt::Sheet)); + QScopedPointer messageBox( + new QMessageBox(QMessageBox::Warning, tr("Unsaved changes"), + tr("Measurements have been modified. Do you want to save your changes?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); - messageBox->setButtonText(QMessageBox::Yes, m_curFile.isEmpty() || m_mIsReadOnly ? tr("Save…") : tr("Save")); - messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + if (QAbstractButton *button = messageBox->button(QMessageBox::Yes)) + { + button->setText(m_curFile.isEmpty() || m_mIsReadOnly ? tr("Save…") : tr("Save")); + } + + if (QAbstractButton *button = messageBox->button(QMessageBox::No)) + { + button->setText(tr("Don't Save")); + } messageBox->setWindowModality(Qt::ApplicationModal); const auto ret = static_cast(messageBox->exec()); @@ -3533,7 +3541,7 @@ auto TMainWindow::MaybeSave() -> bool auto TMainWindow::AddCell(const QString &text, int row, int column, int aligment, bool ok) -> QTableWidgetItem * { auto *item = new QTableWidgetItem(text); - item->setTextAlignment(aligment); + SetTextAlignment(item, static_cast(aligment)); item->setToolTip(text); // set the item non-editable (view only), and non-selectable diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index 78581b592..fab3197ac 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -28,6 +28,7 @@ #include "dialogfinalmeasurements.h" #include "../qmuparser/qmudef.h" +#include "../vmisc/compatibility.h" #include "../vmisc/theme/vtheme.h" #include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vvalentinasettings.h" @@ -38,10 +39,6 @@ #include -#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) -#include "../vmisc/compatibility.h" -#endif - using namespace Qt::Literals::StringLiterals; constexpr int DIALOG_MAX_FORMULA_HEIGHT = 64; @@ -571,7 +568,7 @@ void DialogFinalMeasurements::ShowUnits() void DialogFinalMeasurements::AddCell(const QString &text, int row, int column, int aligment, bool ok) { auto *item = new QTableWidgetItem(text); - item->setTextAlignment(aligment); + SetTextAlignment(item, static_cast(aligment)); // set the item non-editable (view only), and non-selectable Qt::ItemFlags flags = item->flags(); diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index bf58b0d9c..410244f77 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -331,7 +331,7 @@ auto DialogIncrements::AddCell(QTableWidget *table, const QString &text, int row SCASSERT(table != nullptr) auto *item = new QTableWidgetItem(text); - item->setTextAlignment(aligment); + SetTextAlignment(item, static_cast(aligment)); item->setToolTip(text); // set the item non-editable (view only), and non-selectable diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index d0bdea3bb..1f969e96f 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -48,6 +48,35 @@ #include #endif +// Fix bug in Qt. Deprecation warning in QMessageBox::critical. +#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) +#undef QT_REQUIRE_VERSION +#define QT_REQUIRE_VERSION(argc, argv, str) \ + { \ + QString s = QString::fromLatin1(str); \ + QString sq = QString::fromLatin1(qVersion()); \ + if ((sq.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (sq.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + sq.section(QChar::fromLatin1('.'), 2, 2).toInt() < \ + (s.section(QChar::fromLatin1('.'), 0, 0).toInt() << 16) + \ + (s.section(QChar::fromLatin1('.'), 1, 1).toInt() << 8) + \ + s.section(QChar::fromLatin1('.'), 2, 2).toInt()) \ + { \ + if (!qApp) \ + { \ + new QApplication(argc, argv); \ + } \ + QString s = QApplication::tr("Executable '%1' requires Qt %2, found Qt %3.") \ + .arg(qAppName()) \ + .arg(QString::fromLatin1(str)) \ + .arg(QString::fromLatin1(qVersion())); \ + QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"), s, QMessageBox::Abort, \ + static_cast(0)); \ + qFatal("%s", s.toLatin1().data()); \ + } \ + } +#endif + //--------------------------------------------------------------------------------------------------------------------- auto main(int argc, char *argv[]) -> int diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 17720c8c3..5cfc770fc 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -5652,18 +5652,25 @@ auto MainWindow::MaybeSave() -> bool { if (this->isWindowModified() && m_guiEnabled) { - QScopedPointer messageBox(new QMessageBox( - tr("Unsaved changes"), tr("The pattern has been modified. Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel, this, Qt::Sheet)); + QScopedPointer messageBox( + new QMessageBox(QMessageBox::Warning, tr("Unsaved changes"), + tr("The pattern has been modified. Do you want to save your changes?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); - messageBox->setButtonText(QMessageBox::Yes, - VAbstractValApplication::VApp()->GetPatternPath().isEmpty() || m_patternReadOnly - ? tr("Save…") - : tr("Save")); - messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + if (QAbstractButton *button = messageBox->button(QMessageBox::Yes)) + { + button->setText(VAbstractValApplication::VApp()->GetPatternPath().isEmpty() || m_patternReadOnly + ? tr("Save…") + : tr("Save")); + } + + if (QAbstractButton *button = messageBox->button(QMessageBox::No)) + { + button->setText(tr("Don't Save")); + } messageBox->setWindowModality(Qt::ApplicationModal); const auto ret = static_cast(messageBox->exec()); diff --git a/src/libs/vlayout/dialogs/watermarkwindow.cpp b/src/libs/vlayout/dialogs/watermarkwindow.cpp index aa757137d..deca7b4ab 100644 --- a/src/libs/vlayout/dialogs/watermarkwindow.cpp +++ b/src/libs/vlayout/dialogs/watermarkwindow.cpp @@ -496,15 +496,23 @@ auto WatermarkWindow::MaybeSave() -> bool { if (this->isWindowModified()) { - QScopedPointer messageBox(new QMessageBox( - tr("Unsaved changes"), tr("The watermark has been modified. Do you want to save your changes?"), - QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel, this, Qt::Sheet)); + QScopedPointer messageBox( + new QMessageBox(QMessageBox::Warning, tr("Unsaved changes"), + tr("The watermark has been modified. Do you want to save your changes?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, this, Qt::Sheet)); messageBox->setDefaultButton(QMessageBox::Yes); messageBox->setEscapeButton(QMessageBox::Cancel); - messageBox->setButtonText(QMessageBox::Yes, m_curFile.isEmpty() ? tr("Save") : tr("Save as")); - messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + if (QAbstractButton *button = messageBox->button(QMessageBox::Yes)) + { + button->setText(m_curFile.isEmpty() ? tr("Save") : tr("Save as")); + } + + if (QAbstractButton *button = messageBox->button(QMessageBox::No)) + { + button->setText(tr("Don't Save")); + } messageBox->setWindowModality(Qt::ApplicationModal); const auto ret = static_cast(messageBox->exec()); diff --git a/src/libs/vmisc/compatibility.h b/src/libs/vmisc/compatibility.h index c463e7668..e7a272e97 100644 --- a/src/libs/vmisc/compatibility.h +++ b/src/libs/vmisc/compatibility.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -437,4 +438,41 @@ inline auto FontFromString(const QString &descrip) -> QFont return font; } +//--------------------------------------------------------------------------------------------------------------------- +template inline auto TerritoryToString(const T &territory) -> QString +{ + using namespace Qt::Literals::StringLiterals; + +// Since Qt 5.12 country names have spaces +#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) + return QLocale::countryToString(territory).remove(' '_L1); +#else + return QLocale::territoryToString(territory).remove(' '_L1); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) +template <> inline auto TerritoryToString(const QLocale &loc) -> QString +{ + using namespace Qt::Literals::StringLiterals; + +// Since Qt 5.12 country names have spaces +#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) + return QLocale::countryToString(loc.country()).remove(' '_L1); +#else + return QLocale::territoryToString(loc.territory()).remove(' '_L1); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +template inline void SetTextAlignment(T *item, Qt::Alignment alignment) +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + item->setTextAlignment(alignment); +#else + item->setTextAlignment(static_cast(alignment)); +#endif +} + #endif // COMPATIBILITY_H diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 744f6c234..ec5585a4e 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -59,11 +59,8 @@ #include "vdatastreamenum.h" #endif #include "../ifc/exception/vexception.h" -#include "literals.h" - -#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) #include "compatibility.h" -#endif +#include "literals.h" using namespace Qt::Literals::StringLiterals; @@ -118,8 +115,7 @@ void InitLanguageList(QComboBox *combobox) QLocale loc = QLocale(locale); QString lang = loc.nativeLanguageName(); - // Since Qt 5.12 country names have spaces - QString country = QLocale::countryToString(loc.country()).remove(' '); + QString country = TerritoryToString(loc); if (country == "Czechia"_L1) { country = "CzechRepublic"_L1; @@ -133,7 +129,9 @@ void InitLanguageList(QComboBox *combobox) { // English language is internal and doens't have own *.qm file. // Since Qt 5.12 country names have spaces - QIcon ico(u"://flags/%1.png"_s.arg(QLocale::countryToString(QLocale::UnitedStates).remove(' '))); + QIcon ico(u"://flags/%1.png"_s.arg(TerritoryToString(QLocale::UnitedStates)) + + ); QString lang = QLocale(en_US).nativeLanguageName(); combobox->addItem(ico, lang, en_US); } diff --git a/src/libs/vpropertyexplorer/checkablemessagebox.cpp b/src/libs/vpropertyexplorer/checkablemessagebox.cpp index 61aa17f81..4957f379b 100644 --- a/src/libs/vpropertyexplorer/checkablemessagebox.cpp +++ b/src/libs/vpropertyexplorer/checkablemessagebox.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -166,8 +167,10 @@ auto CheckableMessageBox::iconPixmap() const -> QPixmap return QPixmap(*p); } return QPixmap(); -#else +#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return d->pixmapLabel->pixmap(Qt::ReturnByValue); +#else + return d->pixmapLabel->pixmap(); #endif } @@ -260,7 +263,7 @@ auto CheckableMessageBox::question(QWidget *parent, const QString &title, const { CheckableMessageBox mb(parent); mb.setWindowTitle(title); - mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question)); + mb.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32)); mb.setText(question); mb.setCheckBoxText(checkBoxText); mb.setChecked(*checkBoxSetting); @@ -279,7 +282,7 @@ auto CheckableMessageBox::information(QWidget *parent, const QString &title, con { CheckableMessageBox mb(parent); mb.setWindowTitle(title); - mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Information)); + mb.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(32, 32)); mb.setText(text); mb.setCheckBoxText(checkBoxText); mb.setChecked(*checkBoxSetting); @@ -320,7 +323,9 @@ void CheckableMessageBox::initDoNotAskAgainMessageBox(CheckableMessageBox &messa { messageBox.setWindowTitle(title); messageBox.setIconPixmap( - QMessageBox::standardIcon(type == Information ? QMessageBox::Information : QMessageBox::Question)); + QApplication::style() + ->standardIcon(type == Information ? QStyle::SP_MessageBoxInformation : QStyle::SP_MessageBoxQuestion) + .pixmap(32, 32)); messageBox.setText(text); messageBox.setCheckBoxVisible(true); messageBox.setCheckBoxText(type == Information ? CheckableMessageBox::msgDoNotShowAgain() diff --git a/src/libs/vtest/abstracttest.cpp b/src/libs/vtest/abstracttest.cpp index 857aff9b5..08e97f1bd 100644 --- a/src/libs/vtest/abstracttest.cpp +++ b/src/libs/vtest/abstracttest.cpp @@ -471,8 +471,7 @@ auto AbstractTest::CopyRecursively(const QString &srcFilePath, const QString &tg const QString dirName = QFileInfo(tgtFilePath).fileName(); if (not targetDir.mkdir(dirName)) { - const QString msg = QStringLiteral("Can't create dir '%1'.").arg(dirName); - QWARN(qUtf8Printable(msg)); + qWarning("Can't create dir '%s'.", qUtf8Printable(dirName)); return false; } QDir sourceDir(srcFilePath); @@ -492,16 +491,15 @@ auto AbstractTest::CopyRecursively(const QString &srcFilePath, const QString &tg { if (QFileInfo::exists(tgtFilePath)) { - const QString msg = QStringLiteral("File '%1' exists.").arg(srcFilePath); - QWARN(qUtf8Printable(msg)); + qWarning("File '%s' exists.", qUtf8Printable(srcFilePath)); if (QFile::remove(tgtFilePath)) { - QWARN("File successfully removed."); + qWarning("File successfully removed."); } else { - QWARN("Can't remove file."); + qWarning("Can't remove file."); return false; } } @@ -510,18 +508,16 @@ auto AbstractTest::CopyRecursively(const QString &srcFilePath, const QString &tg QFile srcFile(srcFilePath); if (not srcFile.open(QFile::ReadOnly)) { - const QString msg = - QStringLiteral("Can't copy file '%1'. Error: %2").arg(srcFilePath, srcFile.errorString()); - QWARN(qUtf8Printable(msg)); + qWarning("Can't copy file '%s'. Error: %s", qUtf8Printable(srcFilePath), + qUtf8Printable(srcFile.errorString())); return false; } srcFile.close(); if (not srcFile.copy(tgtFilePath)) { - const QString msg = QStringLiteral("Can't copy file '%1' to '%2'. Error: %3") - .arg(srcFilePath, tgtFilePath, srcFile.errorString()); - QWARN(qUtf8Printable(msg)); + qWarning("Can't copy file '%s' to '%s'. Error: %s", qUtf8Printable(srcFilePath), + qUtf8Printable(tgtFilePath), qUtf8Printable(srcFile.errorString())); return false; } } diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 255ff7202..5f1509271 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -39,6 +39,7 @@ #include "../ifc/xml/vlabeltemplateconverter.h" #include "../tools/dialogtool.h" #include "../vformat/vlabeltemplate.h" +#include "../vmisc/compatibility.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/variables/vmeasurement.h" @@ -52,10 +53,6 @@ #include #include -#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) -#include "../vmisc/compatibility.h" -#endif - using namespace Qt::Literals::StringLiterals; //--------------------------------------------------------------------------------------------------------------------- @@ -773,7 +770,7 @@ void DialogEditLabel::SetTemplate(const QVector &lines) for (const auto &line : lines) { auto *item = new QListWidgetItem(line.line); - item->setTextAlignment(line.alignment); + SetTextAlignment(item, static_cast(line.alignment)); item->setData(Qt::UserRole, line.fontSizeIncrement); QFont font = item->font(); @@ -855,7 +852,7 @@ void DialogEditLabel::InitPreviewLines(const QVector &lines) for (const auto &line : lines) { auto *item = new QListWidgetItem(ReplacePlaceholders(line.line)); - item->setTextAlignment(line.alignment); + SetTextAlignment(item, static_cast(line.alignment)); item->setData(Qt::UserRole, line.fontSizeIncrement); QFont font = item->font(); diff --git a/src/test/CollectionTest/tst_tapecommandline.cpp b/src/test/CollectionTest/tst_tapecommandline.cpp index 7223c8bc6..2882f4075 100644 --- a/src/test/CollectionTest/tst_tapecommandline.cpp +++ b/src/test/CollectionTest/tst_tapecommandline.cpp @@ -130,6 +130,6 @@ void TST_TapeCommandLine::cleanupTestCase() QDir tmpDir(*tmpTestFolder); if (not tmpDir.removeRecursively()) { - QWARN("Fail to remove temp directory."); + qWarning("Fail to remove temp directory."); } } diff --git a/src/test/CollectionTest/tst_valentinacommandline.cpp b/src/test/CollectionTest/tst_valentinacommandline.cpp index f418f86c9..39c38da75 100644 --- a/src/test/CollectionTest/tst_valentinacommandline.cpp +++ b/src/test/CollectionTest/tst_valentinacommandline.cpp @@ -273,7 +273,7 @@ void TST_ValentinaCommandLine::cleanupTestCase() QDir tmpDir(*tmpTestFolder); if (not tmpDir.removeRecursively()) { - QWARN("Fail to remove test temp directory."); + qWarning("Fail to remove test temp directory."); } } @@ -281,7 +281,7 @@ void TST_ValentinaCommandLine::cleanupTestCase() QDir tmpDir(*tmpTestCollectionFolder); if (not tmpDir.removeRecursively()) { - QWARN("Fail to remove collection temp directory."); + qWarning("Fail to remove collection temp directory."); } } } diff --git a/src/test/TranslationsTest/tst_abstractregexp.cpp b/src/test/TranslationsTest/tst_abstractregexp.cpp index 07a36636b..edbf8ffdd 100644 --- a/src/test/TranslationsTest/tst_abstractregexp.cpp +++ b/src/test/TranslationsTest/tst_abstractregexp.cpp @@ -72,10 +72,8 @@ auto TST_AbstractRegExp::LoadVariables(const QString &checkedLocale) -> int if (QFileInfo(path + '/'_L1 + file).size() <= 34) { - const QString message = - u"Translation variables for locale = %1 is empty. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Translation variables for locale = %s is empty. \nFull path: %s/%s", qUtf8Printable(checkedLocale), + qUtf8Printable(path), qUtf8Printable(file)); return ErrorSize; } @@ -83,23 +81,17 @@ auto TST_AbstractRegExp::LoadVariables(const QString &checkedLocale) -> int if (not m_vTranslator->load(file, path)) { - const QString message = - u"Can't load translation variables for locale = %1. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Can't load translation variables for locale = %s. \nFull path: %s/%s", qUtf8Printable(checkedLocale), + qUtf8Printable(path), qUtf8Printable(file)); delete m_vTranslator; - return ErrorLoad; } if (not QCoreApplication::installTranslator(m_vTranslator)) { - const QString message = - u"Can't install translation variables for locale = %1. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Can't install translation variables for locale = %s. \nFull path: %s/%s", + qUtf8Printable(checkedLocale), qUtf8Printable(path), qUtf8Printable(file)); delete m_vTranslator; - return ErrorInstall; } @@ -115,8 +107,7 @@ void TST_AbstractRegExp::RemoveTrVariables(const QString &checkedLocale) if (result == false) { - const QString message = u"Can't remove translation variables for locale = %1"_s.arg(checkedLocale); - QWARN(qUtf8Printable(message)); + qWarning("Can't remove translation variables for locale = %s", qUtf8Printable(checkedLocale)); } delete m_vTranslator; } diff --git a/src/test/TranslationsTest/tst_abstracttranslation.cpp b/src/test/TranslationsTest/tst_abstracttranslation.cpp index f1367ccf7..3d5253d9b 100644 --- a/src/test/TranslationsTest/tst_abstracttranslation.cpp +++ b/src/test/TranslationsTest/tst_abstracttranslation.cpp @@ -60,15 +60,13 @@ auto TST_AbstractTranslation::LoadTSFile(const QString &filename) -> QDomNodeLis tsFile = QSharedPointer(new QFile(u"%1/%2"_s.arg(TS_DIR, filename))); if (not tsFile->exists()) { - const QString message = u"Can't find '%1'.\n%2."_s.arg(filename, tsFile->errorString()); - QWARN(qUtf8Printable(message)); + qWarning("Can't find '%s'.\n%s.", qUtf8Printable(filename), qUtf8Printable(tsFile->errorString())); return QDomNodeList(); } if (tsFile->open(QIODevice::ReadOnly) == false) { - const QString message = u"Can't open file '%1'.\n%2."_s.arg(filename, tsFile->errorString()); - QWARN(qUtf8Printable(message)); + qWarning("Can't open file '%s'.\n%s.", qUtf8Printable(filename), qUtf8Printable(tsFile->errorString())); return QDomNodeList(); } @@ -79,16 +77,14 @@ auto TST_AbstractTranslation::LoadTSFile(const QString &filename) -> QDomNodeLis tsXML = QSharedPointer(new QDomDocument()); if (tsXML->setContent(tsFile.data(), &errorMsg, &errorLine, &errorColumn) == false) { - const QString message = - u"Parsing error file %1 in line %2 column %3."_s.arg(filename).arg(errorLine).arg(errorColumn); - QWARN(qUtf8Printable(message)); + qWarning("Parsing error file %s in line %d column %d.", qUtf8Printable(filename), errorLine, errorColumn); return QDomNodeList(); } const QDomNodeList messages = tsXML->elementsByTagName(TagMessage); if (messages.isEmpty()) { - QWARN("File doesn't contain any messages."); + qWarning("File doesn't contain any messages."); return QDomNodeList(); } diff --git a/src/test/TranslationsTest/tst_measurementregexp.cpp b/src/test/TranslationsTest/tst_measurementregexp.cpp index 693279c97..4e277fb58 100644 --- a/src/test/TranslationsTest/tst_measurementregexp.cpp +++ b/src/test/TranslationsTest/tst_measurementregexp.cpp @@ -240,19 +240,17 @@ auto TST_MeasurementRegExp::LoadMeasurements(const QString &checkedSystem, const if (not info.exists()) { - const QString message = - u"File for translation for system = %1 and locale = %2 doesn't exists. \nFull path: %3/%4"_s.arg( - checkedSystem, checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("File for translation for system = %s and locale = %s doesn't exists. \nFull path: %s/%s", + qUtf8Printable(checkedSystem), qUtf8Printable(checkedLocale), qUtf8Printable(path), + qUtf8Printable(file)); return ErrorMissing; } if (QFileInfo(path + '/'_L1 + file).size() <= 34) { - const QString message = u"Translation for system = %1 and locale = %2 is empty. \nFull path: %3/%4"_s.arg( - checkedSystem, checkedLocale, path, file); - QWARN(qUtf8Printable(message)); + qWarning("Translation for system = %s and locale = %s is empty. \nFull path: %s/%s", + qUtf8Printable(checkedSystem), qUtf8Printable(checkedLocale), qUtf8Printable(path), + qUtf8Printable(file)); return ErrorSize; } @@ -262,9 +260,9 @@ auto TST_MeasurementRegExp::LoadMeasurements(const QString &checkedSystem, const if (not m_pmsTranslator->load(file, path)) { - const QString message = u"Can't load translation for system = %1 and locale = %2. \nFull path: %3/%4"_s.arg( - checkedSystem, checkedLocale, path, file); - QWARN(qUtf8Printable(message)); + qWarning("Can't load translation for system = %s and locale = %s. \nFull path: %s/%s", + qUtf8Printable(checkedSystem), qUtf8Printable(checkedLocale), qUtf8Printable(path), + qUtf8Printable(file)); delete m_pmsTranslator; @@ -273,9 +271,9 @@ auto TST_MeasurementRegExp::LoadMeasurements(const QString &checkedSystem, const if (not QCoreApplication::installTranslator(m_pmsTranslator)) { - const QString message = u"Can't install translation for system = %1 and locale = %2. \nFull path: %3/%4"_s.arg( - checkedSystem, checkedLocale, path, file); - QWARN(qUtf8Printable(message)); + qWarning("Can't install translation for system = %s and locale = %s. \nFull path: %s/%s", + qUtf8Printable(checkedSystem), qUtf8Printable(checkedLocale), qUtf8Printable(path), + qUtf8Printable(file)); delete m_pmsTranslator; @@ -294,9 +292,8 @@ void TST_MeasurementRegExp::RemoveTrMeasurements(const QString &checkedSystem, c if (result == false) { - const QString message = - u"Can't remove translation for system = %1 and locale = %2"_s.arg(checkedSystem, checkedLocale); - QWARN(qUtf8Printable(message)); + qWarning("Can't remove translation for system = %s and locale = %s", qUtf8Printable(checkedSystem), + qUtf8Printable(checkedLocale)); } delete m_pmsTranslator; } diff --git a/src/test/TranslationsTest/tst_qmuparsererrormsg.cpp b/src/test/TranslationsTest/tst_qmuparsererrormsg.cpp index f12c32bc4..190865130 100644 --- a/src/test/TranslationsTest/tst_qmuparsererrormsg.cpp +++ b/src/test/TranslationsTest/tst_qmuparsererrormsg.cpp @@ -160,10 +160,8 @@ auto TST_QmuParserErrorMsg::LoadTranslation(const QString &checkedLocale) -> int if (QFileInfo(path + '/'_L1 + file).size() <= 34) { - const QString message = - u"Translation for locale = %1 is empty. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Translation for locale = %s is empty. \nFull path: %s/%s", qUtf8Printable(checkedLocale), + qUtf8Printable(path), qUtf8Printable(file)); return ErrorSize; } @@ -171,23 +169,17 @@ auto TST_QmuParserErrorMsg::LoadTranslation(const QString &checkedLocale) -> int if (not appTranslator->load(file, path)) { - const QString message = - u"Can't load translation for locale = %1. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Can't load translation for locale = %s. \nFull path: %s/%s", qUtf8Printable(checkedLocale), + qUtf8Printable(path), qUtf8Printable(file)); delete appTranslator; - return ErrorLoad; } if (not QCoreApplication::installTranslator(appTranslator)) { - const QString message = - u"Can't install translation for locale = %1. \nFull path: %2/%3"_s.arg(checkedLocale, path, file); - QWARN(qUtf8Printable(message)); - + qWarning("Can't install translation for locale = %s. \nFull path: %s/%s", qUtf8Printable(checkedLocale), + qUtf8Printable(path), qUtf8Printable(file)); delete appTranslator; - return ErrorInstall; } @@ -206,8 +198,7 @@ void TST_QmuParserErrorMsg::RemoveTranslation() if (result == false) { - const QString message = u"Can't remove translation for locale = %1"_s.arg(m_locale); - QWARN(qUtf8Printable(message)); + qWarning("Can't remove translation for locale = %s", qUtf8Printable(m_locale)); } delete appTranslator; } diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index 907e7f7a8..edfa490d5 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -34,7 +34,7 @@ //--------------------------------------------------------------------------------------------------------------------- TST_VSpline::TST_VSpline(QObject *parent) - :AbstractTest(parent) + : AbstractTest(parent) { } @@ -386,8 +386,8 @@ void TST_VSpline::GetSegmentPoints_NullSegment() VSpline spl(p1, p2, p3, p4, 1); spl.SetApproximationScale(10); - const QPointF begin (146.3718263928647, 6.419281580065625); - const QPointF end (146.3718263928647, 6.419281580065625); + const QPointF begin(146.3718263928647, 6.419281580065625); + const QPointF end(146.3718263928647, 6.419281580065625); QVector points; points << spl.GetSegmentPoints(begin, end, true); @@ -543,7 +543,7 @@ void TST_VSpline::GetSegmentPoints_RotateTool() spl.SetApproximationScale(10); const QPointF begin(237.32422843061005, 485.80074940371367); - const QPointF end (46.623829088412336, 167.78988631718659); + const QPointF end(46.623829088412336, 167.78988631718659); QVector points; points << spl.GetSegmentPoints(begin, end, true); @@ -638,7 +638,7 @@ void TST_VSpline::GetSegmentPoints_issue767() // Test issue with method IsPointOnLineSegment. const QPointF begin(3964.650771379471, 3212.2173150777817); - const QPointF end (4200.023629188538, 2559.9039118110236); + const QPointF end(4200.023629188538, 2559.9039118110236); QVector points; points.append(QPointF(3964.650771379471, 3212.2173150777817)); @@ -704,17 +704,17 @@ void TST_VSpline::CompareThreeWays() VSpline spl2(spl1.GetP1(), static_cast(spl1.GetP2()), static_cast(spl1.GetP3()), spl1.GetP4(), 1); spl2.SetApproximationScale(10); - VSpline spl3(spl1.GetP1(), spl1.GetP4(), spl1.GetStartAngle(), QString(), spl2.GetEndAngle(), QString(), spl2.GetC1Length(), QString(), - spl2.GetC2Length(), QString(), 1); + VSpline spl3(spl1.GetP1(), spl1.GetP4(), spl1.GetStartAngle(), QString(), spl2.GetEndAngle(), QString(), + spl2.GetC1Length(), QString(), spl2.GetC2Length(), QString(), 1); spl3.SetApproximationScale(10); - QWARN("Comparing first and second splines."); + qWarning("Comparing first and second splines."); CompareSplines(spl1, spl2); - QWARN("Comparing second and third splines."); + qWarning("Comparing second and third splines."); CompareSplines(spl2, spl3); - QWARN("Comparing third and first splines."); + qWarning("Comparing third and first splines."); CompareSplines(spl3, spl1); } @@ -737,8 +737,7 @@ void TST_VSpline::TestParametrT_data() { QTest::newRow(qUtf8Printable(QStringLiteral("Curve 1. Step = %1").arg(step))) << spl << base * step; step += 0.001; - } - while(step <= 1); + } while (step <= 1); p1 = VPointF(3476.6410658375944, 334.08136371135333, QStringLiteral("p1"), -141.34148031496062, 109.00951181102363); p4 = VPointF(3483.5141183177025, 333.72231804361377, QStringLiteral("p4"), 48, 102.99930708661418); @@ -753,8 +752,7 @@ void TST_VSpline::TestParametrT_data() { QTest::newRow(qUtf8Printable(QStringLiteral("Curve 2. Step = %1").arg(step))) << spl << base * step; step += 0.001; - } - while(step <= 1); + } while (step <= 1); QTest::newRow(qUtf8Printable(QStringLiteral("Curve 2. Bug.").arg(step))) << spl << 4.7813492845686536; } @@ -783,7 +781,7 @@ void TST_VSpline::TestLengthByPoint_data() QTest::addColumn("length"); const qreal length = spl.GetLength(); - const qreal testLength = length*(2.0/3.0); + const qreal testLength = length * (2.0 / 3.0); VSpline spl1, spl2; const QPointF p = spl.CutSpline(testLength, spl1, spl2, QString()); @@ -857,33 +855,33 @@ void TST_VSpline::TestCutSpline_data() QTest::addColumn("name"); { - VPointF p1(187.31716535433043, 51.31464566929152, QStringLiteral("p1"), 140.42872440944885, -22.62372283464567); - VPointF p4(-991.8954330708666, 9.739842519685212, QStringLiteral("p4"), 9.999987401574804, 15.0); + VPointF p1(187.31716535433043, 51.31464566929152, QStringLiteral("p1"), 140.42872440944885, -22.62372283464567); + VPointF p4(-991.8954330708666, 9.739842519685212, QStringLiteral("p4"), 9.999987401574804, 15.0); - VSpline spl(p1, p4, 181.0, QStringLiteral("181"), 356.0, QStringLiteral("356"), 548.7874015748031, - QStringLiteral("Line_Г3_Г6*1.1"), 226.7716535433071, QStringLiteral("6")); - spl.SetApproximationScale(0.5); + VSpline spl(p1, p4, 181.0, QStringLiteral("181"), 356.0, QStringLiteral("356"), 548.7874015748031, + QStringLiteral("Line_Г3_Г6*1.1"), 226.7716535433071, QStringLiteral("6")); + spl.SetApproximationScale(0.5); - QString name(QStringLiteral("з")); - qreal result = 1.35; // Correct distance in cm. + QString name(QStringLiteral("з")); + qreal result = 1.35; // Correct distance in cm. - // See file valentina_private_collection/bugs/men_jacket/issue_cut_spline.val (private collection) - // Size 54 produces incorrect spline segment distance - QTest::newRow("Size 54") << spl << result << name; + // See file valentina_private_collection/bugs/men_jacket/issue_cut_spline.val (private collection) + // Size 54 produces incorrect spline segment distance + QTest::newRow("Size 54") << spl << result << name; } { - VPointF p1(1898.0384322000489, -143.17624447113994, QStringLiteral("p1"), 9.999987401574804, -105.35848818897638); - VPointF p4(1557.8809518850883, -143.17624447113994, QStringLiteral("p4"), 9.999987401574804, 15.0); + VPointF p1(1898.0384322000489, -143.17624447113994, QStringLiteral("p1"), 9.999987401574804, + -105.35848818897638); + VPointF p4(1557.8809518850883, -143.17624447113994, QStringLiteral("p4"), 9.999987401574804, 15.0); - VSpline spl(p1, p4, 175.0, QStringLiteral("175"), 5.0, QStringLiteral("5"), 151.18110236220474, - QStringLiteral("4"), 151.18110236220474, QStringLiteral("4")); + VSpline spl(p1, p4, 175.0, QStringLiteral("175"), 5.0, QStringLiteral("5"), 151.18110236220474, + QStringLiteral("4"), 151.18110236220474, QStringLiteral("4")); - - QString name(QStringLiteral("А193")); - const qreal result = 4.5090698038574057; // Correct distance in cm. - // See file valentina_private_collection/bugs/coat/coat.val (private collection) - QTest::newRow("Half of a curve") << spl << result << name; + QString name(QStringLiteral("А193")); + const qreal result = 4.5090698038574057; // Correct distance in cm. + // See file valentina_private_collection/bugs/coat/coat.val (private collection) + QTest::newRow("Half of a curve") << spl << result << name; } }