From 94dc3bddd5f2eb3de7993e4dbefec3777fb34aa9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 30 Mar 2024 18:02:45 +0200 Subject: [PATCH] Refactoring. Use the init-statement to declare a variable inside the if/switch statement. --- src/app/puzzle/carousel/vpcarrouselpiece.cpp | 3 +- .../puzzlepreferencesconfigurationpage.cpp | 7 +- .../puzzlepreferenceslayoutpage.cpp | 6 +- .../configpages/puzzlepreferencespathpage.cpp | 3 +- .../dialogs/dialogpuzzlepreferences.cpp | 3 +- .../puzzle/dialogs/dialogsavemanuallayout.cpp | 13 +- src/app/puzzle/layout/vplayout.cpp | 7 +- src/app/puzzle/layout/vppiece.cpp | 31 ++-- src/app/puzzle/layout/vpsheet.cpp | 33 ++--- src/app/puzzle/scene/vpgraphicspiece.cpp | 34 ++--- .../puzzle/scene/vpgraphicspiececontrols.cpp | 36 ++--- src/app/puzzle/scene/vpgraphicssheet.cpp | 31 ++-- src/app/puzzle/scene/vpgraphicstilegrid.cpp | 4 +- src/app/puzzle/scene/vpmaingraphicsview.cpp | 41 ++---- .../undocommands/vpundomovepieceonsheet.cpp | 3 +- .../puzzle/undocommands/vpundooriginmove.cpp | 14 +- .../puzzle/undocommands/vpundopiecemove.cpp | 43 +++--- .../puzzle/undocommands/vpundopiecerotate.cpp | 17 +-- .../undocommands/vpundopiecezvaluemove.cpp | 57 ++++---- src/app/puzzle/vpapplication.cpp | 16 +-- src/app/puzzle/vpmainwindow.cpp | 71 ++++------ src/app/puzzle/vptilefactory.cpp | 40 ++---- src/app/puzzle/xml/vplayoutfilereader.cpp | 23 ++- src/app/puzzle/xml/vplayoutfilewriter.cpp | 4 +- .../tapepreferencesconfigurationpage.cpp | 4 +- .../configpages/tapepreferencespathpage.cpp | 3 +- .../tape/dialogs/dialogdimensionlabels.cpp | 3 +- .../dialogknownmeasurementscsvcolumns.cpp | 6 +- src/app/tape/dialogs/dialogmdatabase.cpp | 7 +- .../dialogs/dialogmeasurementscsvcolumns.cpp | 6 +- .../tape/dialogs/dialogtapepreferences.cpp | 3 +- src/app/tape/mapplication.cpp | 13 +- src/app/tape/tkmmainwindow.cpp | 77 ++++------ src/app/tape/tmainwindow.cpp | 133 ++++++------------ src/app/valentina/core/vapplication.cpp | 12 +- src/app/valentina/core/vcmdexport.cpp | 13 +- src/app/valentina/core/vformulaproperty.cpp | 37 +++-- .../core/vtooloptionspropertybrowser.cpp | 15 +- .../preferencesconfigurationpage.cpp | 9 +- .../configpages/preferencespathpage.cpp | 3 +- .../configpages/preferencespatternpage.cpp | 9 +- .../dialogs/dialogfinalmeasurements.cpp | 6 +- src/app/valentina/dialogs/dialoghistory.cpp | 3 +- .../dialogs/dialogpatternproperties.cpp | 10 +- .../valentina/dialogs/dialogpreferences.cpp | 3 +- .../valentina/dialogs/dialogsavelayout.cpp | 10 +- src/app/valentina/mainwindow.cpp | 24 ++-- src/app/valentina/mainwindowsnogui.cpp | 6 +- src/libs/vlayout/dialogs/watermarkwindow.cpp | 3 +- src/libs/vmisc/crashhandler/crashhandler.cpp | 3 +- src/libs/vtools/dialogs/dialogtoolbox.cpp | 4 +- src/libs/vtools/dialogs/tools/dialogarc.cpp | 4 +- .../dialogs/tools/dialogarcwithlength.cpp | 4 +- .../dialogs/tools/dialogcubicbezier.cpp | 4 +- .../dialogs/tools/dialogcubicbezierpath.cpp | 4 +- .../dialogs/tools/dialogellipticalarc.cpp | 4 +- .../vtools/dialogs/tools/dialogspline.cpp | 5 +- .../vtools/dialogs/tools/dialogsplinepath.cpp | 5 +- .../vtools/dialogs/tools/dialogtruedarts.cpp | 4 +- .../drawTools/toolcurve/vabstractspline.cpp | 5 +- .../toolsinglepoint/toolcut/vtoolcut.cpp | 10 +- src/libs/vtools/tools/toolsdef.cpp | 5 +- src/libs/vwidgets/vabstractmainwindow.cpp | 3 +- 63 files changed, 407 insertions(+), 615 deletions(-) diff --git a/src/app/puzzle/carousel/vpcarrouselpiece.cpp b/src/app/puzzle/carousel/vpcarrouselpiece.cpp index c08d44b82..7450a7d5d 100644 --- a/src/app/puzzle/carousel/vpcarrouselpiece.cpp +++ b/src/app/puzzle/carousel/vpcarrouselpiece.cpp @@ -141,8 +141,7 @@ auto VPCarrouselPiece::CreatePieceIcon(const QSize &size, bool isDragIcon) const : style.CarrouselPieceForegroundColor())); bool togetherWithNotches = false; - VPLayoutPtr const pieceLayout = piece->Layout(); - if (not pieceLayout.isNull()) + if (VPLayoutPtr const pieceLayout = piece->Layout(); not pieceLayout.isNull()) { togetherWithNotches = pieceLayout->LayoutSettings().IsBoundaryTogetherWithNotches(); } diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp index c212fb6cb..513b62226 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp @@ -62,8 +62,7 @@ PuzzlePreferencesConfigurationPage::PuzzlePreferencesConfigurationPage(QWidget * // Theme SetThemeModeComboBox(); - int const index = ui->comboBoxThemeMode->findData(static_cast(settings->GetThemeMode())); - if (index != -1) + if (int const index = ui->comboBoxThemeMode->findData(static_cast(settings->GetThemeMode())); index != -1) { ui->comboBoxThemeMode->setCurrentIndex(index); } @@ -145,8 +144,8 @@ auto PuzzlePreferencesConfigurationPage::Apply() -> QStringList settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); - auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); - if (settings->GetThemeMode() != themeMode) + if (auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); + settings->GetThemeMode() != themeMode) { QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp index 9698757c6..48d6a5098 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp @@ -694,8 +694,7 @@ void PuzzlePreferencesLayoutPage::FindTemplate(QComboBox *box, qreal width, qrea VAbstractLayoutDialog::RoundTemplateSize(height, width, paperUnit) == tmplSize) { box->blockSignals(true); - const int index = box->findData(i); - if (index != -1) + if (const int index = box->findData(i); index != -1) { box->setCurrentIndex(index); } @@ -705,8 +704,7 @@ void PuzzlePreferencesLayoutPage::FindTemplate(QComboBox *box, qreal width, qrea } box->blockSignals(true); - const int index = box->findData(max); - if (index != -1) + if (const int index = box->findData(max); index != -1) { box->setCurrentIndex(index); } diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp index 9b232d201..c4a20e8c8 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp @@ -128,8 +128,7 @@ void PuzzlePreferencesPathPage::EditPath() } bool usedNotExistedDir = false; - QDir const directory(path); - if (not directory.exists()) + if (QDir const directory(path); not directory.exists()) { usedNotExistedDir = directory.mkpath(QChar('.')); } diff --git a/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp index 09c4b0279..073cd1edc 100644 --- a/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp +++ b/src/app/puzzle/dialogs/dialogpuzzlepreferences.cpp @@ -93,8 +93,7 @@ void DialogPuzzlePreferences::showEvent(QShowEvent *event) } // do your init stuff here - QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); - if (not sz.isEmpty()) + if (QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); not sz.isEmpty()) { resize(sz); } diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp index 1d9e2aa59..ff040cf6a 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp @@ -468,11 +468,11 @@ void DialogSaveManualLayout::Save() if (QFile::exists(name)) { - QMessageBox::StandardButton const res = QMessageBox::question( - this, tr("Name conflict"), - tr("Folder already contain file with name %1. Rewrite all conflict file names?").arg(name), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (res == QMessageBox::No) + if (QMessageBox::StandardButton const res = QMessageBox::question( + this, tr("Name conflict"), + tr("Folder already contain file with name %1. Rewrite all conflict file names?").arg(name), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + res == QMessageBox::No) { reject(); return; @@ -591,8 +591,7 @@ void DialogSaveManualLayout::ShowExample() auto DialogSaveManualLayout::SupportPSTest() -> bool { static bool havePdf = false; - static bool tested = false; - if (!tested) + if (static bool tested = false; !tested) { havePdf = VLayoutExporter::SupportPDFConversion(); tested = true; diff --git a/src/app/puzzle/layout/vplayout.cpp b/src/app/puzzle/layout/vplayout.cpp index c506ede3f..93f80a20f 100644 --- a/src/app/puzzle/layout/vplayout.cpp +++ b/src/app/puzzle/layout/vplayout.cpp @@ -303,10 +303,9 @@ auto VPLayout::GetSheets() const -> QList //--------------------------------------------------------------------------------------------------------------------- auto VPLayout::GetSheet(const QUuid &uuid) -> VPSheetPtr { - auto sheet = std::find_if(m_sheets.begin(), m_sheets.end(), - [uuid](const VPSheetPtr &sheet) { return sheet->Uuid() == uuid; }); - - if (sheet != m_sheets.end()) + if (auto sheet = std::find_if(m_sheets.begin(), m_sheets.end(), + [uuid](const VPSheetPtr &sheet) { return sheet->Uuid() == uuid; }); + sheet != m_sheets.end()) { return *sheet; } diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index fc33c8741..cc123d43a 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -334,14 +334,12 @@ void VPPiece::FlipHorizontally() //--------------------------------------------------------------------------------------------------------------------- auto VPPiece::StickyPosition(qreal &dx, qreal &dy) const -> bool { - VPLayoutPtr const layout = Layout(); - if (layout.isNull() || not layout->LayoutSettings().GetStickyEdges()) + if (VPLayoutPtr const layout = Layout(); layout.isNull() || not layout->LayoutSettings().GetStickyEdges()) { return false; } - VPSheetPtr const sheet = Sheet(); - if (sheet.isNull()) + if (VPSheetPtr const sheet = Sheet(); sheet.isNull()) { return false; } @@ -486,11 +484,10 @@ auto VPPiece::StickySheet(VStickyDistance &match) const -> bool } const qreal stickyDistance = maxStickyDistance; - QRectF const stickyZone = - QRectF(boundingRect.topLeft().x() - stickyDistance, boundingRect.topLeft().y() - stickyDistance, - boundingRect.width() + stickyDistance * 2, boundingRect.height() + stickyDistance * 2); - - if (!stickyZone.intersects(sheetRect)) + if (QRectF const stickyZone = + QRectF(boundingRect.topLeft().x() - stickyDistance, boundingRect.topLeft().y() - stickyDistance, + boundingRect.width() + stickyDistance * 2, boundingRect.height() + stickyDistance * 2); + !stickyZone.intersects(sheetRect)) { return true; } @@ -503,8 +500,8 @@ auto VPPiece::StickySheet(VStickyDistance &match) const -> bool QVector const sheetPath{sheetRect.topLeft(), sheetRect.topRight(), sheetRect.bottomRight(), sheetRect.bottomLeft(), sheetRect.topLeft()}; QVector const sheetStickyPath = PrepareStickyPath(sheetPath); - QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); - if (match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) + if (QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); + match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) { match.m_closestDistance = distance; } @@ -530,8 +527,8 @@ auto VPPiece::StickySheet(VStickyDistance &match) const -> bool } QVector const sheetStickyPath = PrepareStickyPath(sheetPath); - QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); - if (match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) + if (QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); + match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) { match.m_closestDistance = distance; } @@ -552,8 +549,8 @@ auto VPPiece::StickySheet(VStickyDistance &match) const -> bool } QVector const sheetStickyPath = PrepareStickyPath(sheetPath); - QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); - if (match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) + if (QLineF const distance = ClosestDistance(stickyPath, sheetStickyPath); + match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) { match.m_closestDistance = distance; } @@ -615,8 +612,8 @@ auto VPPiece::StickyPieces(VStickyDistance &match) const -> bool if (not VPPiece::PathsSuperposition(path, piecePath)) { QVector const pieceStickyPath = PrepareStickyPath(piecePath); - QLineF const distance = ClosestDistance(stickyPath, pieceStickyPath); - if (match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) + if (QLineF const distance = ClosestDistance(stickyPath, pieceStickyPath); + match.m_closestDistance.isNull() || distance.length() < match.m_closestDistance.length()) { match.m_closestDistance = distance; match.m_pieceGap = pieceGap; diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index 81b2892cd..9e776816c 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -140,8 +140,7 @@ void VPSheetSceneData::PrepareForExport() m_rotationControls->setVisible(false); m_rotationOrigin->setVisible(false); - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { m_showGridTmp = layout->LayoutSettings().GetShowGrid(); layout->LayoutSettings().SetShowGrid(false); @@ -182,8 +181,7 @@ void VPSheetSceneData::CleanAfterExport() m_rotationControls->setVisible(true); - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { layout->LayoutSettings().SetShowGrid(m_showGridTmp); layout->LayoutSettings().SetShowTiles(m_showTilesTmp); @@ -234,11 +232,10 @@ auto VPSheetSceneData::RotationControls() const -> VPGraphicsPieceControls * //--------------------------------------------------------------------------------------------------------------------- auto VPSheetSceneData::ScenePiece(const VPPiecePtr &piece) const -> VPGraphicsPiece * { - auto _graphicsPiece = - std::find_if(m_graphicsPieces.begin(), m_graphicsPieces.end(), - [piece](VPGraphicsPiece *graphicPiece) { return graphicPiece->GetPiece() == piece; }); - - if (_graphicsPiece != m_graphicsPieces.end()) + if (auto _graphicsPiece = + std::find_if(m_graphicsPieces.begin(), m_graphicsPieces.end(), + [piece](VPGraphicsPiece *graphicPiece) { return graphicPiece->GetPiece() == piece; }); + _graphicsPiece != m_graphicsPieces.end()) { return *_graphicsPiece; } @@ -274,8 +271,7 @@ void VPSheetSceneData::SetTextAsPaths(bool textAsPaths) const //--------------------------------------------------------------------------------------------------------------------- void VPSheetSceneData::PrepareTilesScheme() { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { m_showTilesSchemeTmp = layout->LayoutSettings().GetShowTiles(); layout->LayoutSettings().SetShowTiles(true); @@ -290,8 +286,7 @@ void VPSheetSceneData::PrepareTilesScheme() //--------------------------------------------------------------------------------------------------------------------- void VPSheetSceneData::ClearTilesScheme() { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { layout->LayoutSettings().SetShowTiles(m_showTilesSchemeTmp); layout->LayoutSettings().SetShowWatermark(m_showTilesWatermarkSchemeTmp); @@ -362,8 +357,7 @@ auto VPSheet::GetLayout() const -> VPLayoutPtr //--------------------------------------------------------------------------------------------------------------------- auto VPSheet::GetPieces() const -> QList { - VPLayoutPtr const layout = GetLayout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = GetLayout(); not layout.isNull()) { return layout->PiecesForSheet(m_uuid); } @@ -374,8 +368,7 @@ auto VPSheet::GetPieces() const -> QList //--------------------------------------------------------------------------------------------------------------------- auto VPSheet::GetSelectedPieces() const -> QList { - VPLayoutPtr const layout = GetLayout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = GetLayout(); not layout.isNull()) { QList const list = layout->PiecesForSheet(m_uuid); @@ -692,8 +685,7 @@ void VPSheet::CheckPiecePositionValidity(const VPPiecePtr &piece) const return; } - QList const pieces = GetPieces(); - if (piece.isNull() || not pieces.contains(piece)) + if (QList const pieces = GetPieces(); piece.isNull() || not pieces.contains(piece)) { return; } @@ -746,8 +738,7 @@ auto VPSheet::GetSheetOrientation() const -> QPageLayout::Orientation //--------------------------------------------------------------------------------------------------------------------- auto VPSheet::SheetUnits() const -> Unit { - VPLayoutPtr const layout = GetLayout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = GetLayout(); not layout.isNull()) { return layout->LayoutSettings().GetUnit(); } diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 2a6d87232..58ef21de4 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -293,11 +293,9 @@ void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) setCursor(Qt::OpenHandCursor); emit HideTransformationHandles(false); - VPPiecePtr const piece = m_piece.toStrongRef(); - if (not piece.isNull()) + if (VPPiecePtr const piece = m_piece.toStrongRef(); not piece.isNull()) { - VPLayoutPtr const layout = piece->Layout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = piece->Layout(); not layout.isNull()) { if (layout->LayoutSettings().GetStickyEdges() && m_hasStickyPosition) { @@ -854,17 +852,19 @@ void VPGraphicsPiece::PaintPassmarks(QPainter *painter, const VPPiecePtr &piece) m_passmarks.addPath(passmarkPath); - QLineF const seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine(); - if (!seamAllowanceMirrorLine.isNull() && piece->IsShowFullPiece() && !VGObject::IsPointOnLineviaPDP(passmark.baseLine.p1(), seamAllowanceMirrorLine.p1(), seamAllowanceMirrorLine.p2())) + if (QLineF const seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine(); + !seamAllowanceMirrorLine.isNull() && piece->IsShowFullPiece() && + !VGObject::IsPointOnLineviaPDP(passmark.baseLine.p1(), seamAllowanceMirrorLine.p1(), + seamAllowanceMirrorLine.p2())) { - QPainterPath mirroredPassmaksPath; - for (const auto &line : passmark.lines) - { - mirroredPassmaksPath.moveTo(line.p1()); - mirroredPassmaksPath.lineTo(line.p2()); - } - const QTransform matrix = VGObject::FlippingMatrix(seamAllowanceMirrorLine); - m_passmarks.addPath(matrix.map(mirroredPassmaksPath)); + QPainterPath mirroredPassmaksPath; + for (const auto &line : passmark.lines) + { + mirroredPassmaksPath.moveTo(line.p1()); + mirroredPassmaksPath.lineTo(line.p2()); + } + const QTransform matrix = VGObject::FlippingMatrix(seamAllowanceMirrorLine); + m_passmarks.addPath(matrix.map(mirroredPassmaksPath)); } if (painter != nullptr) @@ -893,7 +893,8 @@ void VPGraphicsPiece::PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piec for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) + { return VAbstractPiece::MapPoint(point, matrix); }); } path.addPath(VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(shape))); @@ -1078,8 +1079,7 @@ void VPGraphicsPiece::GroupMove(const QPointF &pos) { QList pieces; - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { return sheet->GetSelectedPieces(); } diff --git a/src/app/puzzle/scene/vpgraphicspiececontrols.cpp b/src/app/puzzle/scene/vpgraphicspiececontrols.cpp index 1d2878dfe..1ee0637b0 100644 --- a/src/app/puzzle/scene/vpgraphicspiececontrols.cpp +++ b/src/app/puzzle/scene/vpgraphicspiececontrols.cpp @@ -58,8 +58,7 @@ const qreal centerRadius2 = 10; auto TransformationOrigin(const VPLayoutPtr &layout, const QRectF &boundingRect) -> VPTransformationOrigon { SCASSERT(layout != nullptr) - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { return sheet->TransformationOrigin(); } @@ -170,11 +169,9 @@ void VPGraphicsTransformationOrigin::mousePressEvent(QGraphicsSceneMouseEvent *e //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsTransformationOrigin::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { VPTransformationOrigon origin = sheet->TransformationOrigin(); origin.origin = event->scenePos(); @@ -420,8 +417,7 @@ void VPGraphicsPieceControls::mousePressEvent(QGraphicsSceneMouseEvent *event) } else { - QGraphicsView *view = ItemView(); - if (view != nullptr) + if (QGraphicsView *view = ItemView(); view != nullptr) { setCursor(view->viewport()->cursor()); // clazy:exclude=clazy-qt6-deprecated-api-fixes } @@ -503,8 +499,7 @@ void VPGraphicsPieceControls::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } else { - QGraphicsView *view = ItemView(); - if (view != nullptr) + if (QGraphicsView *view = ItemView(); view != nullptr) { setCursor(view->viewport()->cursor()); // clazy:exclude=clazy-qt6-deprecated-api-fixes } @@ -512,11 +507,9 @@ void VPGraphicsPieceControls::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (m_originSaved) { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { if (not m_savedOrigin.custom) { @@ -721,11 +714,9 @@ auto VPGraphicsPieceControls::SelectedPieces() const -> QList { QList pieces; - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { pieces = sheet->GetSelectedPieces(); } @@ -752,11 +743,9 @@ auto VPGraphicsPieceControls::PiecesBoundingRect(const QList &select //--------------------------------------------------------------------------------------------------------------------- auto VPGraphicsPieceControls::ItemView() -> QGraphicsView * { - QGraphicsScene *scene = this->scene(); - if (scene != nullptr) + if (QGraphicsScene *scene = this->scene(); scene != nullptr) { - QList const views = scene->views(); - if (not views.isEmpty()) + if (QList const views = scene->views(); not views.isEmpty()) { return views.at(0); } @@ -776,8 +765,7 @@ void VPGraphicsPieceControls::UpdateCursor(VPHandleCorner corner) } else { - QGraphicsView *view = ItemView(); - if (view != nullptr) + if (QGraphicsView *view = ItemView(); view != nullptr) { setCursor(view->viewport()->cursor()); // clazy:exclude=clazy-qt6-deprecated-api-fixes } diff --git a/src/app/puzzle/scene/vpgraphicssheet.cpp b/src/app/puzzle/scene/vpgraphicssheet.cpp index 03d5389f6..b44497881 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.cpp +++ b/src/app/puzzle/scene/vpgraphicssheet.cpp @@ -162,9 +162,8 @@ void VPGraphicsSheet::RefreshBoundingRect() //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsSheet::PaintVerticalFold(QPainter *painter, const QRectF &sheetRect) const { - VPLayoutPtr const layout = m_layout.toStrongRef(); - - if (not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); + not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) { QString const foldText = FoldText(); painter->save(); @@ -223,9 +222,8 @@ void VPGraphicsSheet::PaintVerticalFold(QPainter *painter, const QRectF &sheetRe //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsSheet::PaintHorizontalFold(QPainter *painter, const QRectF &sheetRect) const { - VPLayoutPtr const layout = m_layout.toStrongRef(); - - if (not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); + not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) { QString const foldText = FoldText(); painter->save(); @@ -299,8 +297,7 @@ void VPGraphicsSheet::PaintMargins(QPainter *painter) const } bool ignoreMargins = true; - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (!sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); !sheet.isNull()) { ignoreMargins = sheet->IgnoreMargins(); } @@ -333,9 +330,8 @@ void VPGraphicsSheet::PaintBorder(QPainter *painter) const painter->setPen(pen); painter->drawRect(sheetRect); - VPLayoutPtr const layout = m_layout.toStrongRef(); - - if (!layout.isNull() && layout->LayoutSettings().IsCutOnFold()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); + !layout.isNull() && layout->LayoutSettings().IsCutOnFold()) { if (sheetRect.width() >= sheetRect.height()) { @@ -354,8 +350,7 @@ void VPGraphicsSheet::PaintBorder(QPainter *painter) const //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsSheet::PaintFold(QPainter *painter) const { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (!layout.isNull() && layout->LayoutSettings().IsCutOnFold()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); !layout.isNull() && layout->LayoutSettings().IsCutOnFold()) { QRectF const sheetRect = GetSheetRect(); QRectF const foldField = m_showBorder ? sheetRect : FoldField(GetMarginsRect()); @@ -387,8 +382,7 @@ void VPGraphicsSheet::PaintGrid(QPainter *painter) const QRectF const sheetRect = GetSheetRect(); - qreal const colWidth = layout->LayoutSettings().GetGridColWidth(); - if (colWidth > 0) + if (qreal const colWidth = layout->LayoutSettings().GetGridColWidth(); colWidth > 0) { qreal colX = colWidth; while (colX < sheetRect.right()) @@ -399,8 +393,7 @@ void VPGraphicsSheet::PaintGrid(QPainter *painter) const } } - qreal const rowHeight = layout->LayoutSettings().GetGridRowHeight(); - if (rowHeight > 0) + if (qreal const rowHeight = layout->LayoutSettings().GetGridRowHeight(); rowHeight > 0) { qreal rowY = rowHeight; @@ -447,9 +440,9 @@ auto VPGraphicsSheet::FoldText() -> QString auto VPGraphicsSheet::boundingRect() const -> QRectF { QRectF boundingRect = GetSheetRect(); - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); + not layout.isNull() && layout->LayoutSettings().IsCutOnFold()) { QString const foldText = FoldText(); QFont font = QApplication::font(); diff --git a/src/app/puzzle/scene/vpgraphicstilegrid.cpp b/src/app/puzzle/scene/vpgraphicstilegrid.cpp index 750b6de2e..d04254a0f 100644 --- a/src/app/puzzle/scene/vpgraphicstilegrid.cpp +++ b/src/app/puzzle/scene/vpgraphicstilegrid.cpp @@ -115,8 +115,8 @@ VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, const QUuid &s //--------------------------------------------------------------------------------------------------------------------- auto VPGraphicsTileGrid::boundingRect() const -> QRectF { - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull() && layout->LayoutSettings().GetShowTiles()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); + not layout.isNull() && layout->LayoutSettings().GetShowTiles()) { VPSheetPtr const sheet = layout->GetSheet(m_sheetUuid); diff --git a/src/app/puzzle/scene/vpmaingraphicsview.cpp b/src/app/puzzle/scene/vpmaingraphicsview.cpp index cde66c733..57269844e 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.cpp +++ b/src/app/puzzle/scene/vpmaingraphicsview.cpp @@ -314,8 +314,7 @@ void VPMainGraphicsView::keyReleaseEvent(QKeyEvent *event) return; } - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { sheet->SceneData()->RotationControls()->SetIgnorePieceTransformation(false); sheet->SceneData()->RotationControls()->on_UpdateControls(); @@ -331,8 +330,7 @@ void VPMainGraphicsView::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::contextMenuEvent(QContextMenuEvent *event) { - QGraphicsItem *item = itemAt(event->pos()); - if (item != nullptr && item->type() == VPGraphicsPiece::Type) + if (QGraphicsItem *item = itemAt(event->pos()); item != nullptr && item->type() == VPGraphicsPiece::Type) { VMainGraphicsView::contextMenuEvent(event); return; @@ -429,8 +427,7 @@ void VPMainGraphicsView::RotatePiecesByAngle(qreal angle) auto PreparePieces = [this]() { QList pieces; - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { VPSheetPtr const sheet = layout->GetFocusedSheet(); if (not sheet.isNull()) @@ -458,9 +455,7 @@ void VPMainGraphicsView::RotatePiecesByAngle(qreal angle) m_rotationSum = angle; } - QList const pieces = PreparePieces(); - - if (pieces.size() == 1) + if (QList const pieces = PreparePieces(); pieces.size() == 1) { auto *command = new VPUndoPieceRotate(pieces.constFirst(), origin, angle, m_rotationSum, m_allowChangeMerge); layout->UndoStack()->push(command); @@ -496,8 +491,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) return; } - VPPiecePtr const piece = graphicsPieces.constFirst()->GetPiece(); - if (piece.isNull()) + if (VPPiecePtr const piece = graphicsPieces.constFirst()->GetPiece(); piece.isNull()) { return; } @@ -505,11 +499,9 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) auto PreparePieces = [this]() { QList pieces; - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { pieces = sheet->GetSelectedPieces(); } @@ -518,8 +510,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) return pieces; }; - QList const pieces = PreparePieces(); - if (pieces.size() == 1) + if (QList const pieces = PreparePieces(); pieces.size() == 1) { const VPPiecePtr &p = pieces.constFirst(); auto *command = new VPUndoPieceMove(p, dx, dy, m_allowChangeMerge); @@ -541,8 +532,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) m_hasStickyPosition = false; } - VPGraphicsPiece *gPiece = sheet->SceneData()->ScenePiece(p); - if (gPiece != nullptr) + if (VPGraphicsPiece *gPiece = sheet->SceneData()->ScenePiece(p); gPiece != nullptr) { gPiece->SetStickyPoints(path); } @@ -684,16 +674,15 @@ void VPMainGraphicsView::MovePiece(QKeyEvent *event) return; } - const QList &graphicsPieces = sheet->SceneData()->GraphicsPieces(); - if (m_hasStickyPosition && not graphicsPieces.isEmpty()) + if (const QList &graphicsPieces = sheet->SceneData()->GraphicsPieces(); + m_hasStickyPosition && not graphicsPieces.isEmpty()) { if (layout->LayoutSettings().GetStickyEdges()) { auto PreparePieces = [layout]() { QList pieces; - VPSheetPtr const sheet = layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull()) { pieces = sheet->GetSelectedPieces(); } @@ -701,16 +690,14 @@ void VPMainGraphicsView::MovePiece(QKeyEvent *event) return pieces; }; - QList const pieces = PreparePieces(); - if (pieces.size() == 1) + if (QList const pieces = PreparePieces(); pieces.size() == 1) { const VPPiecePtr &p = pieces.constFirst(); auto *command = new VPUndoPieceMove(p, m_stickyTranslateX, m_stickyTranslateY, m_allowChangeMerge); layout->UndoStack()->push(command); - VPGraphicsPiece *gPiece = sheet->SceneData()->ScenePiece(p); - if (gPiece != nullptr) + if (VPGraphicsPiece *gPiece = sheet->SceneData()->ScenePiece(p); gPiece != nullptr) { gPiece->SetStickyPoints(QVector()); } diff --git a/src/app/puzzle/undocommands/vpundomovepieceonsheet.cpp b/src/app/puzzle/undocommands/vpundomovepieceonsheet.cpp index 32e849ac8..a2a54ae05 100644 --- a/src/app/puzzle/undocommands/vpundomovepieceonsheet.cpp +++ b/src/app/puzzle/undocommands/vpundomovepieceonsheet.cpp @@ -41,8 +41,7 @@ VPUndoMovePieceOnSheet::VPUndoMovePieceOnSheet(const VPSheetPtr &sheet, const VP m_oldSheet = piece->Sheet(); - VPLayoutPtr const layout = piece->Layout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = piece->Layout(); not layout.isNull()) { m_followGrainline = layout->LayoutSettings().GetFollowGrainline(); } diff --git a/src/app/puzzle/undocommands/vpundooriginmove.cpp b/src/app/puzzle/undocommands/vpundooriginmove.cpp index 8243fca49..bf51ee836 100644 --- a/src/app/puzzle/undocommands/vpundooriginmove.cpp +++ b/src/app/puzzle/undocommands/vpundooriginmove.cpp @@ -26,16 +26,16 @@ ** *************************************************************************/ #include "vpundooriginmove.h" -#include "../vmisc/def.h" -#include "../layout/vpsheet.h" #include "../layout/vplayout.h" +#include "../layout/vpsheet.h" +#include "../vmisc/def.h" //--------------------------------------------------------------------------------------------------------------------- VPUndoOriginMove::VPUndoOriginMove(const VPSheetPtr &sheet, const VPTransformationOrigon &origin, bool allowMerge, QUndoCommand *parent) - : VPUndoCommand(allowMerge, parent), - m_sheet(sheet), - m_origin(origin) + : VPUndoCommand(allowMerge, parent), + m_sheet(sheet), + m_origin(origin) { SCASSERT(not sheet.isNull()) @@ -104,8 +104,8 @@ auto VPUndoOriginMove::mergeWith(const QUndoCommand *command) -> bool const auto *moveCommand = dynamic_cast(command); SCASSERT(moveCommand != nullptr) - VPSheetPtr const sheet = Sheet(); - if (moveCommand->Sheet().isNull() || sheet.isNull() || not moveCommand->AllowMerge()) + if (VPSheetPtr const sheet = Sheet(); + moveCommand->Sheet().isNull() || sheet.isNull() || not moveCommand->AllowMerge()) { return false; } diff --git a/src/app/puzzle/undocommands/vpundopiecemove.cpp b/src/app/puzzle/undocommands/vpundopiecemove.cpp index da9ef646f..187beba4c 100644 --- a/src/app/puzzle/undocommands/vpundopiecemove.cpp +++ b/src/app/puzzle/undocommands/vpundopiecemove.cpp @@ -26,16 +26,16 @@ ** *************************************************************************/ #include "vpundopiecemove.h" -#include "../vmisc/def.h" -#include "../layout/vppiece.h" #include "../layout/vplayout.h" +#include "../layout/vppiece.h" +#include "../vmisc/def.h" //--------------------------------------------------------------------------------------------------------------------- VPUndoPieceMove::VPUndoPieceMove(const VPPiecePtr &piece, qreal dx, qreal dy, bool allowMerge, QUndoCommand *parent) - : VPUndoCommand(allowMerge, parent), - m_piece(piece), - m_dx(dx), - m_dy(dy) + : VPUndoCommand(allowMerge, parent), + m_piece(piece), + m_dx(dx), + m_dy(dy) { SCASSERT(not piece.isNull()) @@ -104,9 +104,8 @@ auto VPUndoPieceMove::mergeWith(const QUndoCommand *command) -> bool const auto *moveCommand = dynamic_cast(command); SCASSERT(moveCommand != nullptr) - VPPiecePtr const piece = Piece(); - if (moveCommand->Piece().isNull() || piece.isNull() || moveCommand->Piece() != piece || - not moveCommand->AllowMerge()) + if (VPPiecePtr const piece = Piece(); moveCommand->Piece().isNull() || piece.isNull() || + moveCommand->Piece() != piece || not moveCommand->AllowMerge()) { return false; } @@ -126,13 +125,13 @@ auto VPUndoPieceMove::id() const -> int //--------------------------------------------------------------------------------------------------------------------- VPUndoPiecesMove::VPUndoPiecesMove(const QList &pieces, qreal dx, qreal dy, bool allowMerge, QUndoCommand *parent) - : VPUndoCommand(allowMerge, parent), - m_dx(dx), - m_dy(dy) + : VPUndoCommand(allowMerge, parent), + m_dx(dx), + m_dy(dy) { setText(QObject::tr("move pieces")); - for (const auto& piece : pieces) + for (const auto &piece : pieces) { if (not piece.isNull()) { @@ -156,13 +155,12 @@ void VPUndoPiecesMove::undo() return; } - VPSheetPtr const sheet = Sheet(); - if (layout->GetFocusedSheet() != sheet) + if (VPSheetPtr const sheet = Sheet(); layout->GetFocusedSheet() != sheet) { layout->SetFocusedSheet(sheet); } - for (const auto& piece : qAsConst(m_pieces)) + for (const auto &piece : qAsConst(m_pieces)) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -190,13 +188,12 @@ void VPUndoPiecesMove::redo() return; } - VPSheetPtr const sheet = Sheet(); - if (layout->GetFocusedSheet() != sheet) + if (VPSheetPtr const sheet = Sheet(); layout->GetFocusedSheet() != sheet) { layout->SetFocusedSheet(sheet); } - for (const auto& piece : qAsConst(m_pieces)) + for (const auto &piece : qAsConst(m_pieces)) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -244,7 +241,7 @@ auto VPUndoPiecesMove::id() const -> int //--------------------------------------------------------------------------------------------------------------------- auto VPUndoPiecesMove::Layout() const -> VPLayoutPtr { - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -257,9 +254,9 @@ auto VPUndoPiecesMove::Layout() const -> VPLayoutPtr } //--------------------------------------------------------------------------------------------------------------------- -auto VPUndoPiecesMove::Sheet() const -> VPSheetPtr +auto VPUndoPiecesMove::Sheet() const -> VPSheetPtr { - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -275,7 +272,7 @@ auto VPUndoPiecesMove::Sheet() const -> VPSheetPtr inline auto VPUndoPiecesMove::PieceIds() const -> QSet { QSet ids; - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) diff --git a/src/app/puzzle/undocommands/vpundopiecerotate.cpp b/src/app/puzzle/undocommands/vpundopiecerotate.cpp index e5d4faf1e..cf33704e1 100644 --- a/src/app/puzzle/undocommands/vpundopiecerotate.cpp +++ b/src/app/puzzle/undocommands/vpundopiecerotate.cpp @@ -52,8 +52,7 @@ VPUndoPieceRotate::VPUndoPieceRotate(const VPPiecePtr &piece, const VPTransforma m_oldTransform = piece->GetMatrix(); - VPLayoutPtr const layout = piece->Layout(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = piece->Layout(); not layout.isNull()) { m_followGrainline = layout->LayoutSettings().GetFollowGrainline(); } @@ -147,10 +146,10 @@ auto VPUndoPieceRotate::mergeWith(const QUndoCommand *command) -> bool const auto *moveCommand = dynamic_cast(command); SCASSERT(moveCommand != nullptr) - VPPiecePtr const piece = Piece(); - if (not moveCommand->AllowMerge() || (moveCommand->Piece().isNull() || piece.isNull()) || - moveCommand->Piece() != piece || moveCommand->Origin() != m_origin || - moveCommand->FollowGrainline() != m_followGrainline) + if (VPPiecePtr const piece = Piece(); not moveCommand->AllowMerge() || + (moveCommand->Piece().isNull() || piece.isNull()) || + moveCommand->Piece() != piece || moveCommand->Origin() != m_origin || + moveCommand->FollowGrainline() != m_followGrainline) { return false; } @@ -207,8 +206,7 @@ void VPUndoPiecesRotate::undo() return; } - VPSheetPtr const sheet = Sheet(); - if (layout->GetFocusedSheet() != sheet) + if (VPSheetPtr const sheet = Sheet(); layout->GetFocusedSheet() != sheet) { layout->SetFocusedSheet(sheet); } @@ -241,8 +239,7 @@ void VPUndoPiecesRotate::redo() return; } - VPSheetPtr const sheet = Sheet(); - if (layout->GetFocusedSheet() != sheet) + if (VPSheetPtr const sheet = Sheet(); layout->GetFocusedSheet() != sheet) { layout->SetFocusedSheet(sheet); } diff --git a/src/app/puzzle/undocommands/vpundopiecezvaluemove.cpp b/src/app/puzzle/undocommands/vpundopiecezvaluemove.cpp index fd77ca16c..e58077350 100644 --- a/src/app/puzzle/undocommands/vpundopiecezvaluemove.cpp +++ b/src/app/puzzle/undocommands/vpundopiecezvaluemove.cpp @@ -26,8 +26,8 @@ ** *************************************************************************/ #include "vpundopiecezvaluemove.h" -#include "../layout/vppiece.h" #include "../layout/vplayout.h" +#include "../layout/vppiece.h" #include "../layout/vpsheet.h" #include "undocommands/vpundocommand.h" @@ -49,19 +49,19 @@ auto CorrectedZValues(const QList> &order) -> QHash &level = order.at(i); for (const auto &pieceId : level) { - correctedZValues.insert(pieceId, i*step); + correctedZValues.insert(pieceId, i * step); } } return correctedZValues; } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- VPUndoPieceZValueMove::VPUndoPieceZValueMove(const VPPiecePtr &piece, ML::ZValueMove move, QUndoCommand *parent) - : VPUndoCommand(parent), - m_piece(piece), - m_move(move) + : VPUndoCommand(parent), + m_piece(piece), + m_move(move) { setText(QObject::tr("z value move piece")); @@ -69,7 +69,7 @@ VPUndoPieceZValueMove::VPUndoPieceZValueMove(const VPPiecePtr &piece, ML::ZValue if (not sheet.isNull()) { const QList pieces = sheet->GetPieces(); - for(const auto& p : pieces) + for (const auto &p : pieces) { if (not p.isNull()) { @@ -107,7 +107,7 @@ void VPUndoPieceZValueMove::undo() const QList pieces = sheet->GetPieces(); - for (const auto &p: pieces) + for (const auto &p : pieces) { if (not p.isNull()) { @@ -158,7 +158,7 @@ void VPUndoPieceZValueMove::redo() else if (m_move == ML::ZValueMove::Up) { const qreal step = LevelStep(pieces); - for (const auto &p: pieces) + for (const auto &p : pieces) { if (p->GetUniqueID() != piece->GetUniqueID()) { @@ -171,7 +171,7 @@ void VPUndoPieceZValueMove::redo() else if (m_move == ML::ZValueMove::Down) { const qreal step = LevelStep(pieces); - for (const auto &p: pieces) + for (const auto &p : pieces) { if (p->GetUniqueID() != piece->GetUniqueID()) { @@ -188,7 +188,7 @@ void VPUndoPieceZValueMove::redo() } QHash const correctedZValues = CorrectedZValues(order); - for (const auto &p: pieces) + for (const auto &p : pieces) { if (not p.isNull()) { @@ -215,8 +215,7 @@ auto VPUndoPieceZValueMove::Piece() const -> VPPiecePtr //--------------------------------------------------------------------------------------------------------------------- auto VPUndoPieceZValueMove::Sheet() const -> VPSheetPtr { - VPPiecePtr const p = Piece(); - if (not p.isNull()) + if (VPPiecePtr const p = Piece(); not p.isNull()) { return p->Sheet(); } @@ -225,7 +224,7 @@ auto VPUndoPieceZValueMove::Sheet() const -> VPSheetPtr } //--------------------------------------------------------------------------------------------------------------------- -auto VPUndoPieceZValueMove::Levels(const QList &pieces, bool skip) const -> QList > +auto VPUndoPieceZValueMove::Levels(const QList &pieces, bool skip) const -> QList> { VPPiecePtr const piece = Piece(); if (piece.isNull()) @@ -235,7 +234,7 @@ auto VPUndoPieceZValueMove::Levels(const QList &pieces, bool skip) c QMap> levels; - for (const auto &p: pieces) + for (const auto &p : pieces) { if (p.isNull() || (skip && p->GetUniqueID() == piece->GetUniqueID())) { @@ -273,13 +272,13 @@ auto VPUndoPieceZValueMove::LevelStep(const QList &pieces) const -> // Z value pieces VPUndoPiecesZValueMove::VPUndoPiecesZValueMove(const QList &pieces, ML::ZValueMove move, QUndoCommand *parent) - : VPUndoCommand(parent), - m_move(move) + : VPUndoCommand(parent), + m_move(move) { setText(QObject::tr("z value move pieces")); m_pieces.reserve(pieces.size()); - for(const auto& p : pieces) + for (const auto &p : pieces) { m_pieces.append(p); } @@ -288,7 +287,7 @@ VPUndoPiecesZValueMove::VPUndoPiecesZValueMove(const QList &pieces, if (not sheet.isNull()) { const QList pieces = sheet->GetPieces(); - for(const auto& p : pieces) + for (const auto &p : pieces) { if (not p.isNull()) { @@ -325,7 +324,7 @@ void VPUndoPiecesZValueMove::undo() const QList pieces = sheet->GetPieces(); - for (const auto &p: pieces) + for (const auto &p : pieces) { if (not p.isNull()) { @@ -376,7 +375,7 @@ void VPUndoPiecesZValueMove::redo() else if (m_move == ML::ZValueMove::Up) { const qreal step = LevelStep(allPieces); - for (const auto &p: allPieces) + for (const auto &p : allPieces) { if (not ids.contains(p->GetUniqueID())) { @@ -389,7 +388,7 @@ void VPUndoPiecesZValueMove::redo() else if (m_move == ML::ZValueMove::Down) { const qreal step = LevelStep(allPieces); - for (const auto &p: allPieces) + for (const auto &p : allPieces) { if (not ids.contains(p->GetUniqueID())) { @@ -406,7 +405,7 @@ void VPUndoPiecesZValueMove::redo() } QHash const correctedZValues = CorrectedZValues(order); - for (const auto &p: allPieces) + for (const auto &p : allPieces) { if (not p.isNull()) { @@ -427,7 +426,7 @@ auto VPUndoPiecesZValueMove::id() const -> int //--------------------------------------------------------------------------------------------------------------------- auto VPUndoPiecesZValueMove::Layout() const -> VPLayoutPtr { - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -442,7 +441,7 @@ auto VPUndoPiecesZValueMove::Layout() const -> VPLayoutPtr //--------------------------------------------------------------------------------------------------------------------- auto VPUndoPiecesZValueMove::Sheet() const -> VPSheetPtr { - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -460,7 +459,7 @@ auto VPUndoPiecesZValueMove::PieceIds() const -> QVector QVector ids; ids.reserve(m_pieces.size()); - for (const auto& piece : m_pieces) + for (const auto &piece : m_pieces) { VPPiecePtr const p = piece.toStrongRef(); if (not p.isNull()) @@ -473,12 +472,12 @@ auto VPUndoPiecesZValueMove::PieceIds() const -> QVector } //--------------------------------------------------------------------------------------------------------------------- -auto VPUndoPiecesZValueMove::Levels(const QList &allPieces, const QVector &skipPieces, - bool skip) -> QList > +auto VPUndoPiecesZValueMove::Levels(const QList &allPieces, const QVector &skipPieces, bool skip) + -> QList> { QMap> levels; - for (const auto &p: allPieces) + for (const auto &p : allPieces) { if (p.isNull() || (skip && skipPieces.contains(p->GetUniqueID()))) { diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index d25396fc7..4bb773326 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -538,9 +538,9 @@ void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd) { const QStringList rawLayouts = cmd->OptionRawLayouts(); const QStringList args = cmd->OptionFileNames(); - bool const success = !args.isEmpty() ? StartWithFiles(cmd, rawLayouts) : SingleStart(cmd, rawLayouts); - if (not success) + if (bool const success = !args.isEmpty() ? StartWithFiles(cmd, rawLayouts) : SingleStart(cmd, rawLayouts); + not success) { return; } @@ -577,11 +577,9 @@ auto VPApplication::event(QEvent *e) -> bool { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) auto *fileOpenEvent = static_cast(e); - const QString macFileOpen = fileOpenEvent->file(); - if (not macFileOpen.isEmpty()) + if (const QString macFileOpen = fileOpenEvent->file(); not macFileOpen.isEmpty()) { - VPMainWindow *mw = MainWindow(); - if (mw != nullptr) + if (VPMainWindow *mw = MainWindow(); mw != nullptr) { mw->LoadFile(macFileOpen); // open file in existing window } @@ -595,8 +593,7 @@ auto VPApplication::event(QEvent *e) -> bool if (static_cast(e)->applicationState() == Qt::ApplicationActive) { Clean(); - VPMainWindow *mw = MainWindow(); - if (mw && not mw->isMinimized()) + if (VPMainWindow *mw = MainWindow(); mw && not mw->isMinimized()) { mw->show(); } @@ -635,8 +632,7 @@ void VPApplication::NewLocalSocketConnection() } socket->waitForReadyRead(1000); QTextStream stream(socket.data()); - const QString arg = stream.readAll(); - if (not arg.isEmpty()) + if (const QString arg = stream.readAll(); not arg.isEmpty()) { ParseCommandLine(SocketConnection::Server, arg.split(QStringLiteral(";;"))); } diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index acfe0ccd2..97b8a2ca6 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -204,8 +204,9 @@ void SetPrinterSheetPageSettings(const QSharedPointer &printer, const qreal const width = FromPixel(imageRect.width() * xScale + margins.left() + margins.right(), Unit::Mm); qreal const height = FromPixel(imageRect.height() * yScale + margins.top() + margins.bottom(), Unit::Mm); - QSizeF const pageSize = sheetOrientation == QPageLayout::Portrait ? QSizeF(width, height) : QSizeF(height, width); - if (not printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter))) + if (QSizeF const pageSize = + (sheetOrientation == QPageLayout::Portrait ? QSizeF(width, height) : QSizeF(height, width)); + not printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter))) { qWarning() << QObject::tr("Cannot set printer page size"); } @@ -470,9 +471,9 @@ auto VPMainWindow::LoadFile(const QString &path) -> bool // Check if file already opened QList list = VPApplication::VApp()->MainWindows(); - auto w = - std::find_if(list.begin(), list.end(), [path](VPMainWindow *window) { return window->CurrentFile() == path; }); - if (w != list.end()) + if (auto w = std::find_if(list.begin(), list.end(), + [path](VPMainWindow *window) { return window->CurrentFile() == path; }); + w != list.end()) { (*w)->activateWindow(); if (this != *w) @@ -520,8 +521,7 @@ auto VPMainWindow::LoadFile(const QString &path) -> bool { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -940,8 +940,7 @@ void VPMainWindow::InitPropertyTabCurrentSheet() ui->comboBoxLayoutUnit->addItem(tr("Pixels"), QVariant(UnitsToStr(Unit::Px))); VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); - const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(settings->LayoutUnit())); - if (indexUnit != -1) + if (const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(settings->LayoutUnit())); indexUnit != -1) { ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); } @@ -1385,8 +1384,9 @@ void VPMainWindow::SetPropertyTabSheetData() SetLineEditValue(ui->lineEditSheetName, sheet->GetName()); ui->groupBoxPaperFormat->setDisabled(false); - const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(m_layout->LayoutSettings().GetUnit())); - if (indexUnit != -1) + if (const qint32 indexUnit = + ui->comboBoxLayoutUnit->findData(UnitsToStr(m_layout->LayoutSettings().GetUnit())); + indexUnit != -1) { ui->comboBoxLayoutUnit->blockSignals(true); ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); @@ -1819,9 +1819,8 @@ auto VPMainWindow::MaybeSave() -> bool messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setFixedSize(300, 85); - const auto ret = static_cast(messageBox->exec()); - switch (ret) + switch (static_cast(messageBox->exec())) { case QMessageBox::Yes: if (IsLayoutReadOnly()) @@ -1856,8 +1855,7 @@ void VPMainWindow::CreateWindowMenu(QMenu *menu) VPMainWindow *window = windows.at(i); QString title = QStringLiteral("%1. %2").arg(i + 1).arg(window->windowTitle()); - const vsizetype index = title.lastIndexOf("[*]"_L1); - if (index != -1) + if (const vsizetype index = title.lastIndexOf("[*]"_L1); index != -1) { window->isWindowModified() ? title.replace(index, 3, '*'_L1) : title.replace(index, 3, QString()); } @@ -2152,8 +2150,7 @@ void VPMainWindow::FindTemplate(QComboBox *box, qreal width, qreal height) VAbstractLayoutDialog::RoundTemplateSize(height, width, paperUnit) == tmplSize) { box->blockSignals(true); - const int index = box->findData(i); - if (index != -1) + if (const int index = box->findData(i); index != -1) { box->setCurrentIndex(index); } @@ -2163,8 +2160,7 @@ void VPMainWindow::FindTemplate(QComboBox *box, qreal width, qreal height) } box->blockSignals(true); - const int index = box->findData(max); - if (index != -1) + if (const int index = box->findData(max); index != -1) { box->setCurrentIndex(index); } @@ -2875,8 +2871,7 @@ auto VPMainWindow::DrawTilesScheme(QPrinter *printer, QPainter *painter, const V sheet->SceneData()->Scene()->render(painter, target, source, Qt::KeepAspectRatio); - VWatermarkData const watermarkData = m_layout->TileFactory()->WatermarkData(); - if (watermarkData.opacity > 0) + if (VWatermarkData const watermarkData = m_layout->TileFactory()->WatermarkData(); watermarkData.opacity > 0) { if (watermarkData.showImage && not watermarkData.path.isEmpty()) { @@ -3126,9 +3121,9 @@ void VPMainWindow::PrintLayoutTiledSheets(QPrinter *printer, const QListpageOrder() == QPrinter::FirstPageFirst ? firstPageNumber + j : lastPageNumber - j; - const VPLayoutPrinterPage &page = pages.at(index); - if (not PrintLayoutTiledSheetPage(printer, painter, page, firstPage)) + if (const VPLayoutPrinterPage &page = pages.at(index); + not PrintLayoutTiledSheetPage(printer, painter, page, firstPage)) { return; } @@ -3274,8 +3269,7 @@ void VPMainWindow::ZValueMove(int move) auto VPMainWindow::ImportRawLayout(const QString &rawLayout) -> bool { VRawLayout rawLayoutReader; - VRawLayoutData data; - if (rawLayoutReader.ReadFile(rawLayout, data)) + if (VRawLayoutData data; rawLayoutReader.ReadFile(rawLayout, data)) { return AddLayoutPieces(data.pieces); } @@ -3302,8 +3296,7 @@ auto VPMainWindow::AddLayoutPieces(const QVector &pieces) -> bool VPPiecePtr const piece(new VPPiece(rawPiece)); piece->SetCopyNumber(i); - QString error; - if (not piece->IsValid(error)) + if (QString error; not piece->IsValid(error)) { qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid. %2").arg(piece->GetName(), error)); @@ -3594,8 +3587,7 @@ auto VPMainWindow::on_actionSave_triggered() -> bool return false; } - QString error; - if (not SaveLayout(curFile, error)) + if (QString error; not SaveLayout(curFile, error)) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -3638,8 +3630,7 @@ auto VPMainWindow::on_actionSaveAs_triggered() -> bool return false; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -3667,8 +3658,7 @@ auto VPMainWindow::on_actionSaveAs_triggered() -> bool } QString error; - bool const result = SaveLayout(fileName, error); - if (not result) + if (bool const result = SaveLayout(fileName, error); not result) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -3749,8 +3739,7 @@ void VPMainWindow::on_SheetSizeChanged() { if (not m_layout.isNull()) { - VPSheetPtr const sheet = m_layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = m_layout->GetFocusedSheet(); not sheet.isNull()) { sheet->SetSheetSizeConverted(ui->doubleSpinBoxSheetPaperWidth->value(), ui->doubleSpinBoxSheetPaperHeight->value()); @@ -3777,8 +3766,7 @@ void VPMainWindow::on_SheetOrientationChanged(bool checked) SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, height); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, width); - VPSheetPtr const sheet = m_layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = m_layout->GetFocusedSheet(); not sheet.isNull()) { sheet->SetSheetSizeConverted(height, width); // NOLINT(readability-suspicious-call-argument) } @@ -3796,8 +3784,7 @@ void VPMainWindow::on_SheetMarginChanged() { if (not m_layout.isNull()) { - VPSheetPtr const sheet = m_layout->GetFocusedSheet(); - if (not sheet.isNull()) + if (VPSheetPtr const sheet = m_layout->GetFocusedSheet(); not sheet.isNull()) { sheet->SetSheetMarginsConverted( ui->doubleSpinBoxSheetMarginLeft->value(), ui->doubleSpinBoxSheetMarginTop->value(), @@ -4711,8 +4698,7 @@ void VPMainWindow::AskDefaultSettings() if (settings->IsAskCollectStatistic() || settings->IsAskSendCrashReport()) { - DialogAskCollectStatistic dialog(this); - if (dialog.exec() == QDialog::Accepted) + if (DialogAskCollectStatistic dialog(this); dialog.exec() == QDialog::Accepted) { settings->SetCollectStatistic(dialog.CollectStatistic()); #if defined(CRASH_REPORTING) @@ -4730,9 +4716,8 @@ void VPMainWindow::AskDefaultSettings() auto *statistic = VGAnalytics::Instance(); statistic->SetGUILanguage(settings->GetLocale()); - QString clientID = settings->GetClientID(); bool freshID = false; - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 3919f85e9..4590633c0 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -48,13 +48,13 @@ auto WatermarkImageFromCache(const VWatermarkData &watermarkData, const QString { QPixmap pixmap; QString const imagePath = AbsoluteMPath(watermarkPath, watermarkData.path); - QString const imageCacheKey = - QStringLiteral("puzzle=path%1+rotation%3+grayscale%4+xscale%5+yxcale%6") - .arg(imagePath, QString::number(watermarkData.imageRotation), watermarkData.grayscale ? trueStr : falseStr) - .arg(xScale) - .arg(yScale); - if (not QPixmapCache::find(imageCacheKey, &pixmap)) + if (QString const imageCacheKey = QStringLiteral("puzzle=path%1+rotation%3+grayscale%4+xscale%5+yxcale%6") + .arg(imagePath, QString::number(watermarkData.imageRotation), + watermarkData.grayscale ? trueStr : falseStr) + .arg(xScale) + .arg(yScale); + not QPixmapCache::find(imageCacheKey, &pixmap)) { QImageReader imageReader(imagePath); QImage watermark = imageReader.read(); @@ -157,12 +157,6 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet SCASSERT(painter != nullptr) SCASSERT(printer != nullptr) - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (layout.isNull()) - { - return; - } - if (sheet.isNull()) { return; @@ -260,8 +254,7 @@ auto VPTileFactory::RowNb(const VPSheetPtr &sheet) const -> int } qreal yScale = 1; - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { yScale = layout->LayoutSettings().VerticalScale(); } @@ -279,8 +272,7 @@ auto VPTileFactory::ColNb(const VPSheetPtr &sheet) const -> int } qreal xScale = 1; - VPLayoutPtr const layout = m_layout.toStrongRef(); - if (not layout.isNull()) + if (VPLayoutPtr const layout = m_layout.toStrongRef(); not layout.isNull()) { xScale = layout->LayoutSettings().HorizontalScale(); } @@ -700,11 +692,11 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co } QPixmap watermark; - QString const imagePath = - QStringLiteral("puzzle=colorScheme%1+path%2+opacity%3_broken") - .arg(colorScheme, AbsoluteMPath(watermarkPath, watermarkData.path), QString::number(opacity)); - if (not QPixmapCache::find(imagePath, &watermark)) + if (QString const imagePath = + QStringLiteral("puzzle=colorScheme%1+path%2+opacity%3_broken") + .arg(colorScheme, AbsoluteMPath(watermarkPath, watermarkData.path), QString::number(opacity)); + not QPixmapCache::find(imagePath, &watermark)) { QScopedPointer const svgRenderer(new QSvgRenderer()); @@ -734,9 +726,8 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co if (watermarkImage.isNull()) { - QPixmap const watermarkPixmap = BrokenImage(); - - if (watermarkPixmap.width() < img.width() && watermarkPixmap.height() < img.height()) + if (QPixmap const watermarkPixmap = BrokenImage(); + watermarkPixmap.width() < img.width() && watermarkPixmap.height() < img.height()) { QRect imagePosition(0, 0, watermarkPixmap.width(), watermarkPixmap.height()); imagePosition.translate(img.center().toPoint() - imagePosition.center()); @@ -754,9 +745,8 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co qint64 const pixelSize = fileSize / watermarkImage.height() / watermarkImage.width(); QSize const scaledSize(qRound(watermarkImage.width() / xScale), qRound(watermarkImage.height() / yScale)); qint64 const scaledImageSize = pixelSize * scaledSize.width() * scaledSize.height() / 1024; - int const limit = QPixmapCache::cacheLimit(); - if (scaledImageSize > limit && (xScale < 1 || yScale < 1)) + if (int const limit = QPixmapCache::cacheLimit(); scaledImageSize > limit && (xScale < 1 || yScale < 1)) { QScopedPointer const svgRenderer(new QSvgRenderer()); diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 6c0041766..1df5fc014 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -65,8 +65,7 @@ namespace //--------------------------------------------------------------------------------------------------------------------- auto StringToTransfrom(const QString &matrix) -> QTransform { - QStringList const elements = matrix.split(ML::groupSep); - if (elements.count() == 9) + if (QStringList const elements = matrix.split(ML::groupSep); elements.count() == 9) { qreal const m11 = elements.at(0).toDouble(); qreal const m12 = elements.at(1).toDouble(); @@ -86,8 +85,7 @@ auto StringToTransfrom(const QString &matrix) -> QTransform //--------------------------------------------------------------------------------------------------------------------- auto StringToPoint(const QString &point) -> QPointF { - QStringList const coordinates = point.split(ML::coordintatesSep); - if (coordinates.count() == 2) + if (QStringList const coordinates = point.split(ML::coordintatesSep); coordinates.count() == 2) { return {coordinates.at(0).toDouble(), coordinates.at(1).toDouble()}; } @@ -179,8 +177,7 @@ auto StringToGrainlineArrowDirrection(const QString &dirrection) -> GrainlineArr //--------------------------------------------------------------------------------------------------------------------- auto StringToLine(const QString &string) -> QLineF { - QStringList const points = string.split(ML::groupSep); - if (points.count() == 2) + if (QStringList const points = string.split(ML::groupSep); points.count() == 2) { return {StringToPoint(points.at(0)), StringToPoint(points.at(1))}; } @@ -210,8 +207,7 @@ auto StringToLines(const QString &string) -> QVector //--------------------------------------------------------------------------------------------------------------------- auto StringToRect(const QString &string) -> QRectF { - QStringList const points = string.split(ML::groupSep); - if (points.count() == 4) + if (QStringList const points = string.split(ML::groupSep); points.count() == 4) { return {points.at(0).toDouble(), points.at(1).toDouble(), points.at(2).toDouble(), points.at(3).toDouble()}; } @@ -478,8 +474,7 @@ void VPLayoutFileReader::ReadPieces(const VPLayoutPtr &layout, const VPSheetPtr VPPiecePtr const piece(new VPPiece()); ReadPiece(piece); - QString error; - if (not piece->IsValid(error)) + if (QString error; not piece->IsValid(error)) { throw VException(tr("Piece %1 invalid. %2").arg(piece->GetName(), error)); } @@ -889,8 +884,8 @@ auto VPLayoutFileReader::ReadLabelLines() -> VTextManager QXmlStreamAttributes const attribs = attributes(); text.SetFont(FontFromString(ReadAttributeEmptyString(attribs, ML::AttrFont))); - QStringList const svgFontData = ReadAttributeEmptyString(attribs, ML::AttrSVGFont).split(','); - if (!svgFontData.isEmpty()) + if (QStringList const svgFontData = ReadAttributeEmptyString(attribs, ML::AttrSVGFont).split(','); + !svgFontData.isEmpty()) { text.SetSVGFontFamily(svgFontData.constFirst()); @@ -968,8 +963,8 @@ void VPLayoutFileReader::ReadMirrorLines(const VPPiecePtr &piece) piece->SetFoldLineLabel(ReadAttributeEmptyString(attribs, ML::AttrFoldLineLabel)); piece->SetFoldLineOutlineFont(FontFromString(ReadAttributeEmptyString(attribs, ML::AttrFont))); - QStringList const svgFontData = ReadAttributeEmptyString(attribs, ML::AttrSVGFont).split(','_L1); - if (!svgFontData.isEmpty()) + if (QStringList const svgFontData = ReadAttributeEmptyString(attribs, ML::AttrSVGFont).split(','_L1); + !svgFontData.isEmpty()) { piece->SetFoldLineSVGFontFamily(svgFontData.constFirst()); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index d66744d5e..76d705567 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -380,8 +380,8 @@ void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece) writeEndElement(); QLineF const seamMirrorLine = piece->GetSeamMirrorLine(); - QLineF const seamAllowenceMirrorLine = piece->GetSeamAllowanceMirrorLine(); - if (!seamMirrorLine.isNull() || !seamAllowenceMirrorLine.isNull()) + if (QLineF const seamAllowenceMirrorLine = piece->GetSeamAllowanceMirrorLine(); + !seamMirrorLine.isNull() || !seamAllowenceMirrorLine.isNull()) { writeStartElement(ML::TagMirrorLine); diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp index 554bacb2d..79bdaae34 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -144,8 +144,8 @@ auto TapePreferencesConfigurationPage::Apply() -> QStringList settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); - auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); - if (settings->GetThemeMode() != themeMode) + if (auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); + settings->GetThemeMode() != themeMode) { QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp index d67b14938..585a50180 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp @@ -118,8 +118,7 @@ void TapePreferencesPathPage::EditPath() } bool usedNotExistedDir = false; - QDir const directory(path); - if (not directory.exists()) + if (QDir const directory(path); not directory.exists()) { usedNotExistedDir = directory.mkpath(QChar('.')); } diff --git a/src/app/tape/dialogs/dialogdimensionlabels.cpp b/src/app/tape/dialogs/dialogdimensionlabels.cpp index 159bea96f..6300b4c70 100644 --- a/src/app/tape/dialogs/dialogdimensionlabels.cpp +++ b/src/app/tape/dialogs/dialogdimensionlabels.cpp @@ -64,8 +64,7 @@ void DialogDimensionLabels::changeEvent(QEvent *event) InitDimensions(); - int const index = ui->comboBoxDimensionLabels->findData(static_cast(type)); - if (index != -1) + if (int const index = ui->comboBoxDimensionLabels->findData(static_cast(type)); index != -1) { ui->comboBoxDimensionLabels->blockSignals(true); ui->comboBoxDimensionLabels->setCurrentIndex(index); diff --git a/src/app/tape/dialogs/dialogknownmeasurementscsvcolumns.cpp b/src/app/tape/dialogs/dialogknownmeasurementscsvcolumns.cpp index 4179434b2..fb1d13f06 100644 --- a/src/app/tape/dialogs/dialogknownmeasurementscsvcolumns.cpp +++ b/src/app/tape/dialogs/dialogknownmeasurementscsvcolumns.cpp @@ -488,8 +488,7 @@ void DialogKnownMeasurementsCSVColumns::CheckStatus() QSharedPointer const csv = DialogKnownMeasurementsCSVColumns::CSVModel(); - const int columns = csv->columnCount(); - if (columns < MinimumColumns()) + if (const int columns = csv->columnCount(); columns < MinimumColumns()) { SetStatus(false); ui->labelStatus->setText( @@ -497,8 +496,7 @@ void DialogKnownMeasurementsCSVColumns::CheckStatus() return; } - const int rows = csv->rowCount(); - if (rows < 1) + if (const int rows = csv->rowCount(); rows < 1) { SetStatus(false); ui->labelStatus->setText( diff --git a/src/app/tape/dialogs/dialogmdatabase.cpp b/src/app/tape/dialogs/dialogmdatabase.cpp index 3fc0a20e0..cbb925474 100644 --- a/src/app/tape/dialogs/dialogmdatabase.cpp +++ b/src/app/tape/dialogs/dialogmdatabase.cpp @@ -88,8 +88,7 @@ auto DialogMDataBase::GetNewNames() const -> QStringList QTreeWidgetItemIterator::NoChildren | QTreeWidgetItemIterator::Checked); while (*it) { - const QString name = (*it)->data(0, Qt::UserRole).toString(); - if (not m_usedMeasurements.contains(name)) + if (const QString name = (*it)->data(0, Qt::UserRole).toString(); not m_usedMeasurements.contains(name)) { newNames.append(name); } @@ -305,8 +304,8 @@ void DialogMDataBase::InitDataBase(const QStringList &usedMeasurements) VKnownMeasurementsDatabase *db = MApplication::VApp()->KnownMeasurementsDatabase(); VKnownMeasurements const knownDB = db->KnownMeasurements(m_knownId); - QMap const measurements = knownDB.OrderedGroupMeasurements(QString()); - if (!measurements.isEmpty()) + if (QMap const measurements = knownDB.OrderedGroupMeasurements(QString()); + !measurements.isEmpty()) { m_generalGroup = InitGroup(tr("General", "Measurement section"), measurements, usedMeasurements); m_groups.append(m_generalGroup); diff --git a/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp index e573946cc..88ab25f54 100644 --- a/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp +++ b/src/app/tape/dialogs/dialogmeasurementscsvcolumns.cpp @@ -840,16 +840,14 @@ void DialogMeasurementsCSVColumns::CheckStatus() QSharedPointer const csv = DialogMeasurementsCSVColumns::CSVModel(); - const int columns = csv->columnCount(); - if (columns < MinimumColumns()) + if (const int columns = csv->columnCount(); columns < MinimumColumns()) { SetStatus(false); ui->labelStatus->setText(QCoreApplication::translate("DialogMeasurementsCSVColumns", "Not enough columns")); return; } - const int rows = csv->rowCount(); - if (rows < 1) + if (const int rows = csv->rowCount(); rows < 1) { SetStatus(false); ui->labelStatus->setText( diff --git a/src/app/tape/dialogs/dialogtapepreferences.cpp b/src/app/tape/dialogs/dialogtapepreferences.cpp index 441ec0b3c..1641f7a1f 100644 --- a/src/app/tape/dialogs/dialogtapepreferences.cpp +++ b/src/app/tape/dialogs/dialogtapepreferences.cpp @@ -94,8 +94,7 @@ void DialogTapePreferences::showEvent(QShowEvent *event) } // do your init stuff here - QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); - if (not sz.isEmpty()) + if (QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); not sz.isEmpty()) { resize(sz); } diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 4e0f89146..23b977591 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -189,8 +189,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con } QString logMsg = msg; - const bool isWarningMessage = VAbstractApplication::VApp()->IsWarningMessage(msg); - if (isWarningMessage) + if (const bool isWarningMessage = VAbstractApplication::VApp()->IsWarningMessage(msg); isWarningMessage) { logMsg = logMsg.remove(VAbstractApplication::warningMessageSignature); } @@ -546,8 +545,7 @@ auto MApplication::event(QEvent *e) -> bool { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) auto *fileOpenEvent = static_cast(e); - const QString macFileOpen = fileOpenEvent->file(); - if (not macFileOpen.isEmpty()) + if (const QString macFileOpen = fileOpenEvent->file(); not macFileOpen.isEmpty()) { if (macFileOpen.endsWith(".vkm"_L1)) { @@ -665,9 +663,8 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS } const QStringList args = parser.positionalArguments(); - bool const success = !args.isEmpty() ? StartWithFiles(parser) : SingleStart(parser); - if (not success) + if (bool const success = !args.isEmpty() ? StartWithFiles(parser) : SingleStart(parser); not success) { return; } @@ -867,8 +864,8 @@ void MApplication::NewLocalSocketConnection() } socket->waitForReadyRead(1000); QTextStream stream(socket); - const QString arg = stream.readAll(); - if (not arg.isEmpty()) + + if (const QString arg = stream.readAll(); not arg.isEmpty()) { ParseCommandLine(SocketConnection::Server, arg.split(QStringLiteral(";;"))); } diff --git a/src/app/tape/tkmmainwindow.cpp b/src/app/tape/tkmmainwindow.cpp index 238f2cd60..82513f0dd 100644 --- a/src/app/tape/tkmmainwindow.cpp +++ b/src/app/tape/tkmmainwindow.cpp @@ -184,9 +184,9 @@ auto TKMMainWindow::LoadFile(const QString &path) -> bool // Check if file already opened const QList list = MApplication::VApp()->MainKMWindows(); - auto w = - std::find_if(list.begin(), list.end(), [path](TKMMainWindow *window) { return window->CurrentFile() == path; }); - if (w != list.end()) + if (auto w = std::find_if(list.begin(), list.end(), + [path](TKMMainWindow *window) { return window->CurrentFile() == path; }); + w != list.end()) { (*w)->activateWindow(); close(); @@ -211,13 +211,11 @@ auto TKMMainWindow::LoadFile(const QString &path) -> bool m_m = new VKnownMeasurementsDocument(); m_m->setXMLContent(converter.Convert()); - VCommonSettings *settings = VAbstractApplication::VApp()->Settings(); - if (settings->IsCollectStatistic()) + if (VCommonSettings *settings = VAbstractApplication::VApp()->Settings(); settings->IsCollectStatistic()) { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -296,8 +294,7 @@ void TKMMainWindow::UpdateWindowTitle() } else { - auto index = MApplication::VApp()->MainKMWindows().indexOf(this); - if (index != -1) + if (auto index = MApplication::VApp()->MainKMWindows().indexOf(this); index != -1) { showName = tr("untitled %1").arg(index + 1); } @@ -384,8 +381,7 @@ void TKMMainWindow::changeEvent(QEvent *event) InitMeasurementDiagramList(); - int const i = ui->comboBoxDiagram->findData(current); - if (i != -1) + if (int const i = ui->comboBoxDiagram->findData(current); i != -1) { ui->comboBoxDiagram->setCurrentIndex(i); } @@ -554,8 +550,7 @@ auto TKMMainWindow::FileSave() -> bool return false; } - QString error; - if (not SaveKnownMeasurements(m_curFile, error)) + if (QString error; not SaveKnownMeasurements(m_curFile, error)) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -586,8 +581,7 @@ auto TKMMainWindow::FileSaveAs() -> bool VTapeSettings *settings = MApplication::VApp()->TapeSettings(); const QString dir = settings->GetPathKnownMeasurements(); - QDir const directory(dir); - if (not directory.exists()) + if (QDir const directory(dir); not directory.exists()) { directory.mkpath(QChar('.')); } @@ -605,8 +599,7 @@ auto TKMMainWindow::FileSaveAs() -> bool return false; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -630,8 +623,7 @@ auto TKMMainWindow::FileSaveAs() -> bool m_mIsReadOnly = false; QString error; - bool const result = SaveKnownMeasurements(fileName, error); - if (not result) + if (bool const result = SaveKnownMeasurements(fileName, error); not result) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -710,8 +702,7 @@ void TKMMainWindow::ImportDataFromCSV() return; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -1001,8 +992,7 @@ void TKMMainWindow::SaveImage() } QString path = settings->GetPathCustomImage() + QDir::separator() + title; - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { path += '.'_L1 + suffixes.at(0); } @@ -1058,8 +1048,7 @@ void TKMMainWindow::ShowImage() QMimeType const mime = image.MimeTypeFromData(); QString name = QDir::tempPath() + QDir::separator() + "image.XXXXXX"_L1; - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { name += '.'_L1 + suffixes.at(0); } @@ -1243,8 +1232,7 @@ void TKMMainWindow::SaveMName() QString newName = ui->lineEditName->text().isEmpty() ? GenerateMeasurementName() : ui->lineEditName->text(); - QHash const m = m_known.Measurements(); - if (m.contains(newName)) + if (QHash const m = m_known.Measurements(); m.contains(newName)) { qint32 num = 2; QString name = newName; @@ -1515,8 +1503,7 @@ void TKMMainWindow::AskDefaultSettings() if (settings->IsAskCollectStatistic() || settings->IsAskSendCrashReport()) { - DialogAskCollectStatistic dialog(this); - if (dialog.exec() == QDialog::Accepted) + if (DialogAskCollectStatistic dialog(this); dialog.exec() == QDialog::Accepted) { settings->SetCollectStatistic(dialog.CollectStatistic()); #if defined(CRASH_REPORTING) @@ -1534,9 +1521,8 @@ void TKMMainWindow::AskDefaultSettings() auto *statistic = VGAnalytics::Instance(); statistic->SetGUILanguage(settings->GetLocale()); - QString clientID = settings->GetClientID(); bool freshID = false; - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -1948,9 +1934,8 @@ auto TKMMainWindow::MaybeSave() -> bool messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setFixedSize(300, 85); - const auto ret = static_cast(messageBox->exec()); - switch (ret) + switch (static_cast(messageBox->exec())) { case QMessageBox::Yes: if (m_mIsReadOnly) @@ -2051,8 +2036,7 @@ void TKMMainWindow::InitIcons() ui->toolButtonAddImage->setIcon(VTheme::GetIconResource(iconResource, QStringLiteral("16x16/insert-image.png"))); ui->toolButtonRemoveImage->setIcon(VTheme::GetIconResource(iconResource, QStringLiteral("16x16/remove-image.png"))); - int const index = ui->tabWidget->indexOf(ui->tabImages); - if (index != -1) + if (int const index = ui->tabWidget->indexOf(ui->tabImages); index != -1) { ui->tabWidget->setTabIcon(index, VTheme::GetIconResource(iconResource, QStringLiteral("16x16/viewimage.png"))); } @@ -2166,8 +2150,7 @@ void TKMMainWindow::CreateWindowMenu(QMenu *menu) TKMMainWindow *window = windows.at(i); QString title = QStringLiteral("%1. %2").arg(i + 1).arg(window->windowTitle()); - const auto index = title.lastIndexOf("[*]"_L1); - if (index != -1) + if (const auto index = title.lastIndexOf("[*]"_L1); index != -1) { window->isWindowModified() ? title.replace(index, 3, '*'_L1) : title.replace(index, 3, QString()); } @@ -2458,8 +2441,7 @@ void TKMMainWindow::InitMeasurementUnits() ui->comboBoxMUnits->addItem(tr("Length units"), QVariant(static_cast(MUnits::Table))); ui->comboBoxMUnits->addItem(tr("Degrees"), QVariant(static_cast(MUnits::Degrees))); - int const i = ui->comboBoxMUnits->findData(current); - if (i != -1) + if (int const i = ui->comboBoxMUnits->findData(current); i != -1) { ui->comboBoxMUnits->setCurrentIndex(i); } @@ -2527,8 +2509,7 @@ auto TKMMainWindow::CheckMName(const QString &name, const QSet &importe throw VException(tr("Imported file must not contain the same name twice.")); } - QRegularExpression const rx(NameRegExp(VariableRegex::KnownMeasurement)); - if (not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp(VariableRegex::KnownMeasurement)); not rx.match(name).hasMatch()) { throw VException(tr("Measurement '%1' doesn't match regex pattern.").arg(name)); } @@ -2588,26 +2569,24 @@ auto TKMMainWindow::ReadCSV(const QxtCsvModel &csv, const QVector &map, boo importedNames.insert(mName); measurement.name = mName; - const int nameGroup = map.at(static_cast(KnownMeasurementsColumns::Group)); - if (nameGroup >= 0) + if (const int nameGroup = map.at(static_cast(KnownMeasurementsColumns::Group)); nameGroup >= 0) { measurement.group = csv.text(i, nameGroup).simplified(); } - const int nameFullName = map.at(static_cast(KnownMeasurementsColumns::FullName)); - if (nameFullName >= 0) + if (const int nameFullName = map.at(static_cast(KnownMeasurementsColumns::FullName)); + nameFullName >= 0) { measurement.fullName = csv.text(i, nameFullName); } - const int nameFormula = map.at(static_cast(KnownMeasurementsColumns::Formula)); - if (nameFormula >= 0) + if (const int nameFormula = map.at(static_cast(KnownMeasurementsColumns::Formula)); nameFormula >= 0) { measurement.formula = csv.text(i, nameFormula); } - const int nameDescription = map.at(static_cast(KnownMeasurementsColumns::Description)); - if (nameDescription >= 0) + if (const int nameDescription = map.at(static_cast(KnownMeasurementsColumns::Description)); + nameDescription >= 0) { measurement.description = csv.text(i, nameDescription); } diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index df50d01b7..3091c37c2 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -333,16 +333,13 @@ auto TMainWindow::CurrentFile() const -> QString //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDimensionABase(qreal base) { - const QList dimensions = m_m->Dimensions().values(); - - if (dimensions.isEmpty()) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.isEmpty()) { qCWarning(tMainWindow, "%s\n", qPrintable(tr("The table doesn't provide dimensions"))); return; } - const qint32 i = m_gradationDimensionA->findData(base); - if (i != -1) + if (const qint32 i = m_gradationDimensionA->findData(base); i != -1) { m_gradationDimensionA->setCurrentIndex(i); } @@ -357,16 +354,13 @@ void TMainWindow::SetDimensionABase(qreal base) //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDimensionBBase(qreal base) { - const QList dimensions = m_m->Dimensions().values(); - - if (dimensions.size() <= 1) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.size() <= 1) { qCWarning(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension B"))); return; } - const qint32 i = m_gradationDimensionB->findData(base); - if (i != -1) + if (const qint32 i = m_gradationDimensionB->findData(base); i != -1) { m_gradationDimensionB->setCurrentIndex(i); } @@ -381,16 +375,13 @@ void TMainWindow::SetDimensionBBase(qreal base) //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDimensionCBase(qreal base) { - const QList dimensions = m_m->Dimensions().values(); - - if (dimensions.size() <= 2) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.size() <= 2) { qCWarning(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension C"))); return; } - const qint32 i = m_gradationDimensionC->findData(base); - if (i != -1) + if (const qint32 i = m_gradationDimensionC->findData(base); i != -1) { m_gradationDimensionC->setCurrentIndex(i); } @@ -430,9 +421,9 @@ auto TMainWindow::LoadFile(const QString &path) -> bool // Check if file already opened const QList list = MApplication::VApp()->MainTapeWindows(); - auto w = - std::find_if(list.begin(), list.end(), [path](TMainWindow *window) { return window->CurrentFile() == path; }); - if (w != list.end()) + if (auto w = std::find_if(list.begin(), list.end(), + [path](TMainWindow *window) { return window->CurrentFile() == path; }); + w != list.end()) { (*w)->activateWindow(); close(); @@ -475,8 +466,7 @@ auto TMainWindow::LoadFile(const QString &path) -> bool { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -501,8 +491,7 @@ auto TMainWindow::LoadFile(const QString &path) -> bool { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -865,8 +854,7 @@ void TMainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int { columns = 5; - const QList dimensions = m_m->Dimensions().values(); - if (dimensions.size() > 1) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.size() > 1) { columns += qMin(static_cast(dimensions.size()), 2); } @@ -932,8 +920,7 @@ auto TMainWindow::FileSave() -> bool return false; } - QString error; - if (not SaveMeasurements(m_curFile, error)) + if (QString error; not SaveMeasurements(m_curFile, error)) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -993,8 +980,7 @@ auto TMainWindow::FileSaveAs() -> bool return false; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -1026,8 +1012,7 @@ auto TMainWindow::FileSaveAs() -> bool m_mIsReadOnly = false; QString error; - bool const result = SaveMeasurements(fileName, error); - if (not result) + if (bool const result = SaveMeasurements(fileName, error); not result) { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Warning); @@ -1114,8 +1099,7 @@ void TMainWindow::ImportDataFromCSV() return; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -1556,9 +1540,7 @@ void TMainWindow::RemoveImage() //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SaveImage() { - const int row = ui->tableWidget->currentRow(); - - if (row == -1) + if (const int row = ui->tableWidget->currentRow(); row == -1) { ui->toolButtonSaveImage->setDisabled(true); return; @@ -1593,8 +1575,7 @@ void TMainWindow::SaveImage() QMimeType const mime = image.MimeTypeFromData(); QString path = settings->GetPathCustomImage() + QDir::separator() + tr("untitled"); - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { path += '.'_L1 + suffixes.at(0); } @@ -1624,9 +1605,7 @@ void TMainWindow::SaveImage() //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::ShowImage() { - const int row = ui->tableWidget->currentRow(); - - if (row == -1) + if (const int row = ui->tableWidget->currentRow(); row == -1) { return; } @@ -1658,8 +1637,7 @@ void TMainWindow::ShowImage() QMimeType const mime = image.MimeTypeFromData(); QString name = QDir::tempPath() + QDir::separator() + "image.XXXXXX"_L1; - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { name += '.'_L1 + suffixes.at(0); } @@ -1713,8 +1691,7 @@ void TMainWindow::AddKnown() { if (m_m->KnownMeasurements().isNull()) { - DialogNoKnownMeasurements dialog(this); - if (dialog.exec() == QDialog::Accepted) + if (DialogNoKnownMeasurements dialog(this); dialog.exec() == QDialog::Accepted) { MApplication::VApp()->NewMainKMWindow(); } @@ -1829,8 +1806,7 @@ void TMainWindow::ImportFromPattern() return; } - VLockGuard const tmp(mPath); - if (not tmp.IsLocked()) + if (VLockGuard const tmp(mPath); not tmp.IsLocked()) { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); return; @@ -1849,8 +1825,7 @@ void TMainWindow::ImportFromPattern() { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -1908,8 +1883,7 @@ void TMainWindow::DimensionABaseChanged() { m_currentDimensionA = m_gradationDimensionA->currentData().toDouble(); - const QList dimensions = m_m->Dimensions().values(); - if (dimensions.size() > 1) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.size() > 1) { MeasurementDimension_p dimension = dimensions.at(1); InitDimensionGradation(1, dimension, m_gradationDimensionB); @@ -1929,9 +1903,7 @@ void TMainWindow::DimensionBBaseChanged() { m_currentDimensionB = m_gradationDimensionB->currentData().toDouble(); - const QList dimensions = m_m->Dimensions().values(); - - if (dimensions.size() > 2) + if (const QList dimensions = m_m->Dimensions().values(); dimensions.size() > 2) { const MeasurementDimension_p &dimension = dimensions.at(2); InitDimensionGradation(2, dimension, m_gradationDimensionC); @@ -2282,8 +2254,7 @@ void TMainWindow::SaveMValue() QString const text = ui->plainTextEditFormula->toPlainText(); - QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula); - if (formulaField->text() == text) + if (QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula); formulaField->text() == text) { QTableWidgetItem *result = ui->tableWidget->item(row, ColumnCalcValue); const QString postfix = UnitsToStr(m_mUnit); // Show unit in dialog lable (cm, mm or inch) @@ -2625,8 +2596,7 @@ void TMainWindow::ExportToIndividual() } QString const suffix = QStringLiteral("vit"); - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; } @@ -2790,8 +2760,7 @@ void TMainWindow::AskDefaultSettings() if (settings->IsAskCollectStatistic() || settings->IsAskSendCrashReport()) { - DialogAskCollectStatistic dialog(this); - if (dialog.exec() == QDialog::Accepted) + if (DialogAskCollectStatistic dialog(this); dialog.exec() == QDialog::Accepted) { settings->SetCollectStatistic(dialog.CollectStatistic()); #if defined(CRASH_REPORTING) @@ -2809,9 +2778,8 @@ void TMainWindow::AskDefaultSettings() auto *statistic = VGAnalytics::Instance(); statistic->SetGUILanguage(settings->GetLocale()); - QString clientID = settings->GetClientID(); bool freshID = false; - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -3142,8 +3110,7 @@ void TMainWindow::InitMenu() separator->setSeparator(true); ui->menuMeasurements->insertAction(ui->actionUseFullCircumference, separator); - const QList dimensions = m_m->Dimensions().values(); - if (not dimensions.empty()) + if (const QList dimensions = m_m->Dimensions().values(); not dimensions.empty()) { ui->actionRestrictFirstDimension->setVisible(true); ui->actionRestrictFirstDimension->setEnabled(true); @@ -3398,8 +3365,7 @@ void TMainWindow::ShowHeaderUnits(QTableWidget *table, int column, const QString SCASSERT(table != nullptr) QString header = table->horizontalHeaderItem(column)->text(); - const auto index = header.indexOf('('_L1); - if (index != -1) + if (const auto index = header.indexOf('('_L1); index != -1) { header.remove(index - 1, 100); } @@ -3491,9 +3457,8 @@ auto TMainWindow::MaybeSave() -> bool messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setFixedSize(300, 85); - const auto ret = static_cast(messageBox->exec()); - switch (ret) + switch (static_cast(messageBox->exec())) { case QMessageBox::Yes: if (m_mIsReadOnly) @@ -3815,8 +3780,7 @@ void TMainWindow::UpdateWindowTitle() } else { - auto index = MApplication::VApp()->MainTapeWindows().indexOf(this); - if (index != -1) + if (auto index = MApplication::VApp()->MainTapeWindows().indexOf(this); index != -1) { showName = tr("untitled %1").arg(index + 1); } @@ -3923,8 +3887,7 @@ void TMainWindow::SyncKnownMeasurements() auto TMainWindow::ClearCustomName(const QString &name) -> QString { QString clear = name; - const auto index = clear.indexOf(CustomMSign); - if (index == 0) + if (const auto index = clear.indexOf(CustomMSign); index == 0) { clear.remove(0, 1); } @@ -4122,9 +4085,9 @@ auto TMainWindow::LoadFromExistingFile(const QString &path) -> bool // Check if file already opened const QList list = MApplication::VApp()->MainTapeWindows(); - auto w = - std::find_if(list.begin(), list.end(), [path](TMainWindow *window) { return window->CurrentFile() == path; }); - if (w != list.end()) + if (auto w = std::find_if(list.begin(), list.end(), + [path](TMainWindow *window) { return window->CurrentFile() == path; }); + w != list.end()) { (*w)->activateWindow(); close(); @@ -4234,8 +4197,7 @@ void TMainWindow::CreateWindowMenu(QMenu *menu) TMainWindow *window = windows.at(i); QString title = QStringLiteral("%1. %2").arg(i + 1).arg(window->windowTitle()); - const auto index = title.lastIndexOf("[*]"_L1); - if (index != -1) + if (const auto index = title.lastIndexOf("[*]"_L1); index != -1) { window->isWindowModified() ? title.replace(index, 3, '*'_L1) : title.replace(index, 3, QString()); } @@ -4308,8 +4270,7 @@ auto TMainWindow::CheckMName(const QString &name, const QSet &importedN throw VException(tr("Imported file must not contain the same name twice.")); } - QRegularExpression const rx(NameRegExp()); - if (not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp()); not rx.match(name).hasMatch()) { throw VException(tr("Measurement '%1' doesn't match regex pattern.").arg(name)); } @@ -4433,9 +4394,7 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVe //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector &map, bool withHeader) { - const int columns = csv.columnCount(); - - if (columns < 4) + if (const int columns = csv.columnCount(); columns < 4) { ShowError(tr("Multisize measurements require at least 4 columns.")); return; @@ -4576,8 +4535,7 @@ void TMainWindow::SetCurrentPatternUnit() if (m_comboBoxUnits) { m_comboBoxUnits->blockSignals(true); - const qint32 indexUnit = m_comboBoxUnits->findData(static_cast(m_pUnit)); - if (indexUnit != -1) + if (const qint32 indexUnit = m_comboBoxUnits->findData(static_cast(m_pUnit)); indexUnit != -1) { m_comboBoxUnits->setCurrentIndex(indexUnit); } @@ -4796,8 +4754,7 @@ void TMainWindow::InitKnownMeasurements(QComboBox *combo) return; } - QUuid const kmId = m_m->KnownMeasurements(); - if (!kmId.isNull() && !known.contains(kmId)) + if (QUuid const kmId = m_m->KnownMeasurements(); !kmId.isNull() && !known.contains(kmId)) { combo->addItem(tr("Invalid link"), kmId); } @@ -5124,8 +5081,7 @@ void TMainWindow::InitMeasurementUnits() ui->comboBoxMUnits->addItem(units, QVariant(static_cast(MUnits::Table))); ui->comboBoxMUnits->addItem(tr("Degrees"), QVariant(static_cast(MUnits::Degrees))); - int const i = ui->comboBoxMUnits->findData(current); - if (i != -1) + if (int const i = ui->comboBoxMUnits->findData(current); i != -1) { ui->comboBoxMUnits->setCurrentIndex(i); } @@ -5161,8 +5117,7 @@ void TMainWindow::InitMeasurementDimension() ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::W), QVariant(static_cast(IMD::W))); ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::Z), QVariant(static_cast(IMD::Z))); - int const i = ui->comboBoxDimension->findData(current); - if (i != -1) + if (int const i = ui->comboBoxDimension->findData(current); i != -1) { ui->comboBoxDimension->setCurrentIndex(i); } diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index e6cb7797d..e8db5ecf6 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -105,9 +105,9 @@ auto AppFilePath(const QString &appName) -> QString #if defined(APPIMAGE) && defined(Q_OS_LINUX) return AppImageRoot() + BINDIR + '/'_L1 + appName; #else - QFileInfo const canonicalFile( - QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), appName + executableSuffix)); - if (canonicalFile.exists()) + if (QFileInfo const canonicalFile( + QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), appName + executableSuffix)); + canonicalFile.exists()) { return canonicalFile.absoluteFilePath(); } @@ -730,11 +730,9 @@ auto VApplication::event(QEvent *e) -> bool case QEvent::FileOpen: { auto *fileOpenEvent = dynamic_cast(e); - const QString macFileOpen = fileOpenEvent->file(); - if (not macFileOpen.isEmpty()) + if (const QString macFileOpen = fileOpenEvent->file(); not macFileOpen.isEmpty()) { - auto *window = qobject_cast(mainWindow); - if (window) + if (auto *window = qobject_cast(mainWindow); window != nullptr) { window->LoadPattern(macFileOpen); // open file in existing window } diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 836ee8653..dee1f850e 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -483,8 +483,7 @@ auto VCommandLine::OptDimensionA() const -> int const QString value = OptionValue(LONG_OPTION_DIMENSION_A); bool ok = false; - int const dimensionAValue = value.toInt(&ok); - if (ok && dimensionAValue > 0) + if (int const dimensionAValue = value.toInt(&ok); ok && dimensionAValue > 0) { return dimensionAValue; } @@ -499,8 +498,7 @@ auto VCommandLine::OptDimensionB() const -> int const QString value = OptionValue(LONG_OPTION_DIMENSION_B); bool ok = false; - int const dimensionBValue = value.toInt(&ok); - if (ok && dimensionBValue > 0) + if (int const dimensionBValue = value.toInt(&ok); ok && dimensionBValue > 0) { return dimensionBValue; } @@ -515,8 +513,7 @@ auto VCommandLine::OptDimensionC() const -> int const QString value = OptionValue(LONG_OPTION_DIMENSION_C); bool ok = false; - int const dimensionCValue = value.toInt(&ok); - if (ok && dimensionCValue > 0) + if (int const dimensionCValue = value.toInt(&ok); ok && dimensionCValue > 0) { return dimensionCValue; } @@ -535,8 +532,8 @@ auto VCommandLine::TiledPageMargins() const -> QMarginsF if (IsOptionSet(LONG_OPTION_SHIFTUNITS)) { const QString value = OptionValue(LONG_OPTION_SHIFTUNITS); - const QStringList supportedUnits = QStringList() << unitMM << unitCM << unitINCH; - if (not supportedUnits.contains(value)) + if (const QStringList supportedUnits = QStringList() << unitMM << unitCM << unitINCH; + not supportedUnits.contains(value)) { qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n"; const_cast(this)->parser.showHelp(V_EX_USAGE); diff --git a/src/app/valentina/core/vformulaproperty.cpp b/src/app/valentina/core/vformulaproperty.cpp index c9b26e1db..175958aa3 100644 --- a/src/app/valentina/core/vformulaproperty.cpp +++ b/src/app/valentina/core/vformulaproperty.cpp @@ -29,24 +29,24 @@ #include "vformulaproperty.h" #include "vformulapropertyeditor.h" -#include "../vpropertyexplorer/vproperty_p.h" -#include "../vpropertyexplorer/plugins/vstringproperty.h" -#include "vformulapropertyeditor.h" -#include "../vpatterndb/vformula.h" #include "../vmisc/vabstractapplication.h" +#include "../vpatterndb/vformula.h" +#include "../vpropertyexplorer/plugins/vstringproperty.h" +#include "../vpropertyexplorer/vproperty_p.h" +#include "vformulapropertyeditor.h" //--------------------------------------------------------------------------------------------------------------------- VFormulaProperty::VFormulaProperty(const QString &name) - : VProperty(name, + : VProperty(name, #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - static_cast(VFormula::FormulaTypeId())) + static_cast(VFormula::FormulaTypeId())) #else - static_cast(VFormula::FormulaTypeId())) + static_cast(VFormula::FormulaTypeId())) #endif { d_ptr->type = VPE::Property::Complex; - auto* tmpFormula = new VPE::VStringProperty(tr("Formula")); + auto *tmpFormula = new VPE::VStringProperty(tr("Formula")); addChild(tmpFormula); tmpFormula->setClearButtonEnable(true); tmpFormula->setUpdateBehaviour(true, false); @@ -58,7 +58,7 @@ VFormulaProperty::VFormulaProperty(const QString &name) //--------------------------------------------------------------------------------------------------------------------- //! Get the data how it should be displayed -auto VFormulaProperty::data (int column, int role) const -> QVariant +auto VFormulaProperty::data(int column, int role) const -> QVariant { if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) { @@ -81,14 +81,14 @@ auto VFormulaProperty::flags(int column) const -> Qt::ItemFlags //--------------------------------------------------------------------------------------------------------------------- //! Returns an editor widget, or NULL if it doesn't supply one -auto VFormulaProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, - const QAbstractItemDelegate* delegate) -> QWidget* +auto VFormulaProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options, + const QAbstractItemDelegate *delegate) -> QWidget * { Q_UNUSED(options) Q_UNUSED(delegate) auto formula = VProperty::d_ptr->VariantValue.value(); - auto* tmpEditor = new VFormulaPropertyEditor(parent); + auto *tmpEditor = new VFormulaPropertyEditor(parent); tmpEditor->setLocale(parent->locale()); tmpEditor->SetFormula(formula); VProperty::d_ptr->editor = tmpEditor; @@ -97,10 +97,9 @@ auto VFormulaProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& //--------------------------------------------------------------------------------------------------------------------- //! Sets the property's data to the editor (returns false, if the standard delegate should do that) -auto VFormulaProperty::setEditorData(QWidget* editor) -> bool +auto VFormulaProperty::setEditorData(QWidget *editor) -> bool { - auto* tmpWidget = qobject_cast(editor); - if (tmpWidget) + if (auto *tmpWidget = qobject_cast(editor); tmpWidget != nullptr) { auto formula = VProperty::d_ptr->VariantValue.value(); tmpWidget->SetFormula(formula); @@ -117,8 +116,7 @@ auto VFormulaProperty::setEditorData(QWidget* editor) -> bool //! Gets the data from the widget auto VFormulaProperty::getEditorData(const QWidget *editor) const -> QVariant { - const auto* tmpWidget = qobject_cast(editor); - if (tmpWidget) + if (const auto *tmpWidget = qobject_cast(editor); tmpWidget != nullptr) { QVariant value; value.setValue(tmpWidget->GetFormula()); @@ -143,7 +141,7 @@ auto VFormulaProperty::clone(bool include_children, VProperty *container) const if (!include_children) { - const QList tmpChildren = container->getChildren(); + const QList tmpChildren = container->getChildren(); for (auto *tmpChild : tmpChildren) { container->removeChild(tmpChild); @@ -152,8 +150,7 @@ auto VFormulaProperty::clone(bool include_children, VProperty *container) const } } - return VProperty::clone(false, container); // Child - + return VProperty::clone(false, container); // Child } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 73c74b00d..a1a6be289 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -904,8 +904,8 @@ template void VToolOptionsPropertyBrowser::SetPointName(VPE::VPrope return; } - QRegularExpression const rx(NameRegExp()); - if (name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp()); + name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) { m_idToProperty[AttrName]->setValue(i->name()); } @@ -931,8 +931,8 @@ template void VToolOptionsPropertyBrowser::SetPointName1(VPE::VProp return; } - QRegularExpression const rx(NameRegExp()); - if (name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp()); + name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) { m_idToProperty[AttrName1]->setValue(i->nameP1()); } @@ -958,8 +958,8 @@ template void VToolOptionsPropertyBrowser::SetPointName2(VPE::VProp return; } - QRegularExpression const rx(NameRegExp()); - if (name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp()); + name.isEmpty() || not VContainer::IsUnique(name, valentinaNamespace) || not rx.match(name).hasMatch()) { m_idToProperty[AttrName2]->setValue(i->nameP2()); } @@ -1075,8 +1075,7 @@ template void VToolOptionsPropertyBrowser::SetHCrossCurvesPoint(VPE if (auto *i = qgraphicsitem_cast(m_currentItem)) { const QVariant value = property->data(VPE::VProperty::DPC_Data, Qt::EditRole); - auto type = GetCrossPoint(value); - if (type == i->GetHCrossPoint()) + if (auto type = GetCrossPoint(value); type == i->GetHCrossPoint()) { return; } diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 940260dff..7599599b6 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -80,8 +80,9 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) //----------------------- Unit setup // set default unit - const qint32 indexUnit = ui->unitCombo->findData(VAbstractValApplication::VApp()->ValentinaSettings()->GetUnit()); - if (indexUnit != -1) + if (const qint32 indexUnit = + ui->unitCombo->findData(VAbstractValApplication::VApp()->ValentinaSettings()->GetUnit()); + indexUnit != -1) { ui->unitCombo->setCurrentIndex(indexUnit); } @@ -217,8 +218,8 @@ auto PreferencesConfigurationPage::Apply() -> QStringList settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); settings->SetToolboxIconSizeSmall(ui->radioButtonToolboxIconSizeSmall->isChecked()); - auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); - if (settings->GetThemeMode() != themeMode) + if (auto themeMode = static_cast(ui->comboBoxThemeMode->currentData().toInt()); + settings->GetThemeMode() != themeMode) { QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 265e388d0..ca7297376 100644 --- a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -139,8 +139,7 @@ void PreferencesPathPage::EditPath() } bool usedNotExistedDir = false; - QDir const directory(path); - if (not directory.exists()) + if (QDir const directory(path); not directory.exists()) { usedNotExistedDir = directory.mkpath(QChar('.')); } diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index aebd16ac2..d89d891da 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -99,8 +99,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) //----------------------- Unit setup // set default unit const Unit defUnit = QLocale().measurementSystem() == QLocale::MetricSystem ? Unit::Mm : Unit::Inch; - const qint32 indexUnit = ui->comboBoxLineWidthUnit->findData(static_cast(defUnit)); - if (indexUnit != -1) + if (const qint32 indexUnit = ui->comboBoxLineWidthUnit->findData(static_cast(defUnit)); indexUnit != -1) { ui->comboBoxLineWidthUnit->setCurrentIndex(indexUnit); } @@ -140,15 +139,13 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) ui->fontComboBoxLabelFont->setCurrentFont(labelFont); InitLabelFontSizes(); - const qint32 indexSize = ui->comboBoxLabelFontSize->findData(pointSize); - if (indexSize != -1) + if (const qint32 indexSize = ui->comboBoxLabelFontSize->findData(pointSize); indexSize != -1) { ui->comboBoxLabelFontSize->setCurrentIndex(indexSize); } InitSingleLineFonts(); - const qint32 indexFont = ui->comboBoxSingleLineFont->findData(settings->GetLabelSVGFont()); - if (indexFont != -1) + if (const qint32 indexFont = ui->comboBoxSingleLineFont->findData(settings->GetLabelSVGFont()); indexFont != -1) { ui->comboBoxSingleLineFont->setCurrentIndex(indexFont); } diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index 1f6f056e2..70ddec630 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -207,8 +207,7 @@ void DialogFinalMeasurements::showEvent(QShowEvent *event) } // do your init stuff here - const QSize sz = VAbstractApplication::VApp()->Settings()->GetFinalMeasurementsDialogSize(); - if (not sz.isEmpty()) + if (const QSize sz = VAbstractApplication::VApp()->Settings()->GetFinalMeasurementsDialogSize(); not sz.isEmpty()) { resize(sz); } @@ -390,8 +389,7 @@ void DialogFinalMeasurements::SaveFormula() // Replace line return character with spaces for calc if exist QString const text = ui->plainTextEditFormula->toPlainText(); - QTableWidgetItem *formulaField = ui->tableWidget->item(row, 2); - if (formulaField->text() == text) + if (QTableWidgetItem *formulaField = ui->tableWidget->item(row, 2); formulaField->text() == text) { QTableWidgetItem *result = ui->tableWidget->item(row, 1); // Show unit in dialog lable (cm, mm or inch) diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 1cc3e7e59..7a5627ee2 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -118,8 +118,7 @@ DialogHistory::~DialogHistory() */ void DialogHistory::DialogAccepted() { - QTableWidgetItem *item = ui->tableWidget->item(m_cursorToolRecordRow, 0); - if (item != nullptr) + if (QTableWidgetItem *item = ui->tableWidget->item(m_cursorToolRecordRow, 0); item != nullptr) { auto id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, false); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 77aaa5ef9..1e3b758d7 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -329,9 +329,9 @@ void DialogPatternProperties::ValidatePassmarkLength() const QPalette palette = ui->lineEditPassmarkLength->palette(); const QPalette::ColorRole foregroundRole = ui->lineEditPassmarkLength->foregroundRole(); - QRegularExpression const rx(NameRegExp()); if (not text.isEmpty()) { + QRegularExpression const rx(NameRegExp()); palette.setColor(foregroundRole, rx.match(text).hasMatch() && m_variables.contains(text) ? palette.color(QPalette::Text) : Qt::red); @@ -351,9 +351,9 @@ void DialogPatternProperties::ValidatePassmarkWidth() const QPalette palette = ui->lineEditPassmarkWidth->palette(); const QPalette::ColorRole foregroundRole = ui->lineEditPassmarkWidth->foregroundRole(); - QRegularExpression const rx(NameRegExp()); if (not text.isEmpty()) { + QRegularExpression const rx(NameRegExp()); palette.setColor(foregroundRole, rx.match(text).hasMatch() && m_variables.contains(text) ? palette.color(QPalette::Text) : Qt::red); @@ -468,8 +468,7 @@ void DialogPatternProperties::SaveImage() QMimeType const mime = image.MimeTypeFromData(); QString path = settings->GetPathCustomImage() + QDir::separator() + tr("untitled"); - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { path += '.'_L1 + suffixes.at(0); } @@ -510,8 +509,7 @@ void DialogPatternProperties::ShowImage() QMimeType const mime = image.MimeTypeFromData(); QString name = QDir::tempPath() + QDir::separator() + QStringLiteral("image.XXXXXX"); - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { name += '.'_L1 + suffixes.at(0); } diff --git a/src/app/valentina/dialogs/dialogpreferences.cpp b/src/app/valentina/dialogs/dialogpreferences.cpp index ef22f4e34..55fe6ae5b 100644 --- a/src/app/valentina/dialogs/dialogpreferences.cpp +++ b/src/app/valentina/dialogs/dialogpreferences.cpp @@ -93,8 +93,7 @@ void DialogPreferences::showEvent(QShowEvent *event) } // do your init stuff here - QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); - if (not sz.isEmpty()) + if (QSize const sz = VAbstractApplication::VApp()->Settings()->GetPreferenceDialogSize(); not sz.isEmpty()) { resize(sz); } diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 35d7c65ea..e5cc545da 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -429,11 +429,11 @@ void DialogSaveLayout::Save() Path() + '/' + FileName() + QString::number(i + 1) + VLayoutExporter::ExportFormatSuffix(Format()); if (QFile::exists(name)) { - QMessageBox::StandardButton const res = QMessageBox::question( - this, tr("Name conflict"), - tr("Folder already contain file with name %1. Rewrite all conflict file names?").arg(name), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (res == QMessageBox::No) + if (QMessageBox::StandardButton const res = QMessageBox::question( + this, tr("Name conflict"), + tr("Folder already contain file with name %1. Rewrite all conflict file names?").arg(name), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + res == QMessageBox::No) { reject(); return; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index e43ac7a2e..045b26af9 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -251,8 +251,7 @@ void LogPatternToolUsed(bool checked, const QString &toolName) { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -4932,8 +4931,7 @@ void MainWindow::AskDefaultSettings() if (settings->IsAskCollectStatistic() || settings->IsAskSendCrashReport()) { - DialogAskCollectStatistic dialog(this); - if (dialog.exec() == QDialog::Accepted) + if (DialogAskCollectStatistic dialog(this); dialog.exec() == QDialog::Accepted) { settings->SetCollectStatistic(dialog.CollectStatistic()); #if defined(CRASH_REPORTING) @@ -4951,9 +4949,8 @@ void MainWindow::AskDefaultSettings() auto *statistic = VGAnalytics::Instance(); statistic->SetGUILanguage(settings->GetLocale()); - QString clientID = settings->GetClientID(); bool freshID = false; - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -5030,8 +5027,7 @@ void MainWindow::SaveBackgroundImage(const QUuid &id) if (mime.isValid()) { - QStringList const suffixes = mime.suffixes(); - if (not suffixes.isEmpty()) + if (QStringList const suffixes = mime.suffixes(); not suffixes.isEmpty()) { path += '.'_L1 + suffixes.at(0); } @@ -5771,9 +5767,8 @@ auto MainWindow::MaybeSave() -> bool messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setFixedSize(300, 85); - const auto ret = static_cast(messageBox->exec()); - switch (ret) + switch (static_cast(messageBox->exec())) { case QMessageBox::Yes: if (m_patternReadOnly) @@ -6470,8 +6465,7 @@ auto MainWindow::LoadPattern(QString fileName, const QString &customMeasureFile) { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -7077,8 +7071,7 @@ auto MainWindow::CheckPathToMeasurements(const QString &patternPath, const QStri { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -7101,8 +7094,7 @@ auto MainWindow::CheckPathToMeasurements(const QString &patternPath, const QStri { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 7085b958d..7f0fafef3 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1317,8 +1317,7 @@ auto MainWindowsNoGUI::OpenMeasurementFile(const QString &path) const -> QShared { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); @@ -1341,8 +1340,7 @@ auto MainWindowsNoGUI::OpenMeasurementFile(const QString &path) const -> QShared { auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) + if (QString clientID = settings->GetClientID(); clientID.isEmpty()) { clientID = QUuid::createUuid().toString(); settings->SetClientID(clientID); diff --git a/src/libs/vlayout/dialogs/watermarkwindow.cpp b/src/libs/vlayout/dialogs/watermarkwindow.cpp index ff0570c22..e63ac1d63 100644 --- a/src/libs/vlayout/dialogs/watermarkwindow.cpp +++ b/src/libs/vlayout/dialogs/watermarkwindow.cpp @@ -510,9 +510,8 @@ auto WatermarkWindow::MaybeSave() -> bool messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setFixedSize(300, 85); - const auto ret = static_cast(messageBox->exec()); - switch (ret) + switch (static_cast(messageBox->exec())) { case QMessageBox::Yes: return m_curFile.isEmpty() ? on_actionSaveAs_triggered() : on_actionSave_triggered(); diff --git a/src/libs/vmisc/crashhandler/crashhandler.cpp b/src/libs/vmisc/crashhandler/crashhandler.cpp index 9f25e305c..7091dd540 100644 --- a/src/libs/vmisc/crashhandler/crashhandler.cpp +++ b/src/libs/vmisc/crashhandler/crashhandler.cpp @@ -178,8 +178,7 @@ auto InitializeCrashpad(const QString &appName) -> bool auto MakeDir = [](const QString &path) { - QDir const directory(path); - if (not directory.exists()) + if (QDir const directory(path); not directory.exists()) { directory.mkpath(QChar('.')); } diff --git a/src/libs/vtools/dialogs/dialogtoolbox.cpp b/src/libs/vtools/dialogs/dialogtoolbox.cpp index bf237ac73..5b4f89821 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.cpp +++ b/src/libs/vtools/dialogs/dialogtoolbox.cpp @@ -370,8 +370,8 @@ void CheckPointLabel(QDialog *dialog, QLineEdit *edit, QLabel *labelEditNamePoin SCASSERT(labelEditNamePoint != nullptr) const QString name = edit->text(); - QRegularExpression const rx(NameRegExp()); - if (name.isEmpty() || (pointName != name && not data->IsUnique(name)) || not rx.match(name).hasMatch()) + if (QRegularExpression const rx(NameRegExp()); + name.isEmpty() || (pointName != name && not data->IsUnique(name)) || not rx.match(name).hasMatch()) { flag = false; ChangeColor(labelEditNamePoint, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index 710e6ba7d..b7ccce813 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -451,10 +451,10 @@ void DialogArc::changeEvent(QEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogArc::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not GetAliasSuffix().isEmpty() && (not rx.match(arc.GetAlias()).hasMatch() || (m_originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 754f5cb29..2b253795c 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -495,10 +495,10 @@ void DialogArcWithLength::changeEvent(QEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not GetAliasSuffix().isEmpty() && (not rx.match(arc.GetAlias()).hasMatch() || (m_originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index 48475cdf2..a9b63ff17 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -264,10 +264,10 @@ void DialogCubicBezier::SaveData() //--------------------------------------------------------------------------------------------------------------------- void DialogCubicBezier::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); VCubicBezier spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not ui->lineEditAlias->text().isEmpty() && (not rx.match(spline.GetAlias()).hasMatch() || (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index fc45bd763..9b5591f70 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -277,10 +277,10 @@ void DialogCubicBezierPath::currentPointChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void DialogCubicBezierPath::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); VCubicBezierPath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not ui->lineEditAlias->text().isEmpty() && (not rx.match(tempPath.GetAlias()).hasMatch() || (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 3b38df43b..383c09d4c 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -758,10 +758,10 @@ void DialogEllipticalArc::changeEvent(QEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogEllipticalArc::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); VEllipticalArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not GetAliasSuffix().isEmpty() && (not rx.match(arc.GetAlias()).hasMatch() || (m_originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 2a16efa7a..c72000fe8 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -437,12 +437,11 @@ void DialogSpline::EvalLength2() //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); - VSpline spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not ui->lineEditAlias->text().isEmpty() && (not rx.match(spline.GetAlias()).hasMatch() || (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index e14c8f357..d169de9dd 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -543,12 +543,11 @@ void DialogSplinePath::FXLength2() //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::ValidateAlias() { - QRegularExpression const rx(NameRegExp()); - VSplinePath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && + if (QRegularExpression const rx(NameRegExp()); + not ui->lineEditAlias->text().isEmpty() && (not rx.match(tempPath.GetAlias()).hasMatch() || (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias())))) { diff --git a/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp index 456d11008..c973c580a 100644 --- a/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp @@ -407,8 +407,8 @@ void DialogTrueDarts::CheckName(QLineEdit *edit, QLabel *labelEditNamePoint, con const QString name = edit->text(); const QString secondName = secondPointName->text(); - QRegularExpression const rx(NameRegExp()); - if (name.isEmpty() || secondName == name || + if (QRegularExpression const rx(NameRegExp()); + name.isEmpty() || secondName == name || (pointD1Name != name && pointD2Name != name && data->IsUnique(name) == false) || rx.match(name).hasMatch() == false) { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 3011f1198..0af5b5d6b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -476,9 +476,8 @@ void VAbstractSpline::SetAliasSuffix(QString alias) alias = alias.simplified().replace(QChar(QChar::Space), '_'_L1); curve->SetAliasSuffix(alias); - QRegularExpression const rx(NameRegExp()); - - if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) + if (QRegularExpression const rx(NameRegExp()); + alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) { QSharedPointer obj = qSharedPointerCast(curve); SaveOption(obj); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index 2a80f9138..af4fb4d35 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -122,9 +122,8 @@ void VToolCut::SetAliasSuffix1(QString alias) alias = alias.simplified().replace(QChar(QChar::Space), '_'_L1); curve->SetAliasSuffix(alias); - QRegularExpression const rx(NameRegExp()); - - if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) + if (QRegularExpression const rx(NameRegExp()); + alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) { m_aliasSuffix1 = alias; QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); @@ -151,9 +150,8 @@ void VToolCut::SetAliasSuffix2(QString alias) alias = alias.simplified().replace(QChar(QChar::Space), '_'_L1); curve->SetAliasSuffix(alias); - QRegularExpression const rx(NameRegExp()); - - if (alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) + if (QRegularExpression const rx(NameRegExp()); + alias.isEmpty() || (rx.match(curve->GetAlias()).hasMatch() && VAbstractTool::data.IsUnique(curve->GetAlias()))) { m_aliasSuffix2 = alias; QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); diff --git a/src/libs/vtools/tools/toolsdef.cpp b/src/libs/vtools/tools/toolsdef.cpp index 398b65725..479a8802e 100644 --- a/src/libs/vtools/tools/toolsdef.cpp +++ b/src/libs/vtools/tools/toolsdef.cpp @@ -65,8 +65,6 @@ auto SourceAliasValid(const SourceItem &item, const QSharedPointer &ob { SCASSERT(data != nullptr) - QRegularExpression const rx(NameRegExp()); - QString alias; if (obj->getType() == GOType::Point) @@ -81,7 +79,8 @@ auto SourceAliasValid(const SourceItem &item, const QSharedPointer &ob obj->SetAliasSuffix(oldAlias); } - if (not alias.isEmpty() && originAlias != alias && (not rx.match(alias).hasMatch() || not data->IsUnique(alias))) + if (QRegularExpression const rx(NameRegExp()); + not alias.isEmpty() && originAlias != alias && (not rx.match(alias).hasMatch() || not data->IsUnique(alias))) { return false; } diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index 458f87a32..779c97345 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -213,8 +213,7 @@ auto VAbstractMainWindow::CSVFilePath() -> QString return fileName; } - QFileInfo const f(fileName); - if (f.suffix().isEmpty() && f.suffix() != suffix) + if (QFileInfo const f(fileName); f.suffix().isEmpty() && f.suffix() != suffix) { fileName += '.'_L1 + suffix; }