From 5e56f30fb119b45d17b9c075ae1c8b750a9272d4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 2 May 2024 12:03:22 +0300 Subject: [PATCH] Refactoring. Replace declarations by a structured binding declaration. --- .../puzzle/dialogs/dialogsavemanuallayout.cpp | 4 ++-- src/app/puzzle/vptilefactory.cpp | 6 +++--- .../valentina/dialogs/dialogincrements.cpp | 10 +++++----- .../valentina/dialogs/dialogsavelayout.cpp | 4 ++-- src/libs/ifc/xml/vabstractpattern.cpp | 6 +++--- .../vdxf/libdxfrw/intern/drw_textcodec.cpp | 8 ++++---- src/libs/vgeometry/vabstractcurve.cpp | 8 ++++---- src/libs/vlayout/vprintlayout.cpp | 6 +++--- .../tools/dialogcurveintersectaxis.cpp | 10 +++++----- .../tools/dialogpointofintersectioncurves.cpp | 20 +++++++++---------- .../tools/piece/dialogseamallowance.cpp | 4 ++-- src/libs/vtools/tools/vtooluniondetails.cpp | 16 +++++++-------- src/libs/vtools/undocommands/deltool.cpp | 4 ++-- .../tst_tslocaletranslation.cpp | 7 +++---- 14 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp index ff040cf6a..21ebcb29b 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp @@ -101,9 +101,9 @@ DialogSaveManualLayout::DialogSaveManualLayout(vsizetype count, bool consoleExpo } } - for (auto &v : InitFormats()) + for (auto &[first, second] : InitFormats()) { - ui->comboBoxFormat->addItem(v.first, QVariant(static_cast(v.second))); + ui->comboBoxFormat->addItem(first, QVariant(static_cast(second))); } #ifdef V_NO_ASSERT // Temporarily unavailable RemoveFormatFromList(LayoutExportFormats::OBJ); diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 60aec260c..b67bd74b4 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -244,8 +244,8 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet painter->save(); - const QPair scale = VPrintLayout::PrinterScaleDiff(printer); - painter->scale(scale.first, scale.second); + const auto [xscale, yscale] = VPrintLayout::PrinterScaleDiff(printer); + painter->scale(xscale, yscale); if (row > 0) { @@ -290,7 +290,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet DrawSolidBottomLine(painter, col, nbCol); } - DrawRuler(painter, scale.first); + DrawRuler(painter, xscale); DrawWatermark(painter); if (col < nbCol - 1) diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index ca2087278..a60f3fddb 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -715,11 +715,11 @@ auto DialogIncrements::IncrementUsed(const QString &name) const -> bool //--------------------------------------------------------------------------------------------------------------------- void DialogIncrements::CacheRename(const QString &name, const QString &newName) { - for (auto &i : m_renameList) + for (auto &[first, second] : m_renameList) { - if (i.second == name) + if (second == name) { - i.second = newName; + second = newName; return; } } @@ -1354,9 +1354,9 @@ void DialogIncrements::RefreshPattern() if (m_hasChanges) { QVector expressions = m_doc->ListExpressions(); - for (auto &item : m_renameList) + for (auto &[first, second] : m_renameList) { - m_doc->ReplaceNameInFormula(expressions, item.first, item.second); + m_doc->ReplaceNameInFormula(expressions, first, second); } m_renameList.clear(); diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 4d8b436e7..8b11db5b2 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -105,9 +105,9 @@ DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName } } - for (auto &v : InitFormats()) + for (auto &[first, second] : InitFormats()) { - ui->comboBoxFormat->addItem(v.first, QVariant(static_cast(v.second))); + ui->comboBoxFormat->addItem(first, QVariant(static_cast(second))); } #ifdef V_NO_ASSERT // Temporarily unavailable RemoveFormatFromList(LayoutExportFormats::OBJ); diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 083e1df80..46bbab718 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -500,8 +500,8 @@ void VAbstractPattern::ParseGroups(const QDomElement &domElement) { VContainer::UpdateId(GetParametrUInt(domElement, AttrId, NULL_ID_STR), valentinaNamespace); - const QPair> groupData = ParseItemElement(domElement); - const QMap group = groupData.second; + const auto [groupDataFirst, groupDataSecond] = ParseItemElement(domElement); + const QMap group = groupDataSecond; auto i = group.constBegin(); while (i != group.constEnd()) { @@ -511,7 +511,7 @@ void VAbstractPattern::ParseGroups(const QDomElement &domElement) } const bool previous = itemVisibility.value(i.key(), false); - itemVisibility.insert(i.key(), previous || groupData.first); + itemVisibility.insert(i.key(), previous || groupDataFirst); ++i; } } diff --git a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp index 6374ad20d..2ebe880c6 100644 --- a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp +++ b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp @@ -81,12 +81,12 @@ void DRW_TextCodec::setVersion(DRW::Version v, bool dxfFormat) void DRW_TextCodec::setVersion(const std::string &v, bool dxfFormat) { version = DRW::UNKNOWNV; - for (auto dwgVersionString : DRW::dwgVersionStrings) + for (auto [first, second] : DRW::dwgVersionStrings) { - if (std::strcmp(v.c_str(), dwgVersionString.first) == 0) + if (std::strcmp(v.c_str(), first) == 0) { - version = dwgVersionString.second; - setVersion(dwgVersionString.second, dxfFormat); + version = second; + setVersion(second, dxfFormat); break; } } diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index b4572d282..e451d63cf 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -611,18 +611,18 @@ auto VAbstractCurve::ShowDirection(const QVector &arrows, qreal { QPainterPath path; - for (const auto &arrow : arrows) + for (const auto &[first, second] : arrows) { - if (not arrow.first.isNull() && not arrow.second.isNull()) + if (not first.isNull() && not second.isNull()) { QPainterPath arrowPath; - QLineF line = arrow.first; + QLineF line = first; line.setLength(width); arrowPath.moveTo(line.p1()); arrowPath.lineTo(line.p2()); - line = arrow.second; + line = second; line.setLength(width); arrowPath.moveTo(line.p1()); arrowPath.lineTo(line.p2()); diff --git a/src/libs/vlayout/vprintlayout.cpp b/src/libs/vlayout/vprintlayout.cpp index 722f2dc5f..8fd4f90de 100644 --- a/src/libs/vlayout/vprintlayout.cpp +++ b/src/libs/vlayout/vprintlayout.cpp @@ -758,9 +758,9 @@ auto VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source) -> Q y = 0; } - QPair const scaleDiff = PrinterScaleDiff(printer); - const double xscale = scaleDiff.first; - const double yscale = scaleDiff.second; + auto const [scaleDiffFirst, scaleDiffSecond] = PrinterScaleDiff(printer); + const double xscale = scaleDiffFirst; + const double yscale = scaleDiffSecond; return {x * xscale, y * yscale, source.width() * xscale, source.height() * yscale}; } diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index ef92f9c10..c83d351e8 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -381,11 +381,11 @@ void DialogCurveIntersectAxis::ValidateAlias() QRegularExpression const rx(NameRegExp()); const QSharedPointer curve = data->GeometricObject(getCurveId()); - QPair const alias = SegmentAliases(curve->getType(), GetAliasSuffix1(), GetAliasSuffix2()); + auto const [aliasFirst, aliasSecond] = SegmentAliases(curve->getType(), GetAliasSuffix1(), GetAliasSuffix2()); if (not GetAliasSuffix1().isEmpty() && - (not rx.match(alias.first).hasMatch() || - (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(alias.first)) || alias.first == alias.second)) + (not rx.match(aliasFirst).hasMatch() || + (originAliasSuffix1 != GetAliasSuffix1() && not data->IsUnique(aliasFirst)) || aliasFirst == aliasSecond)) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); @@ -397,8 +397,8 @@ void DialogCurveIntersectAxis::ValidateAlias() } if (not GetAliasSuffix2().isEmpty() && - (not rx.match(alias.second).hasMatch() || - (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(alias.second)) || alias.first == alias.second)) + (not rx.match(aliasSecond).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(aliasSecond)) || aliasFirst == aliasSecond)) { flagAlias2 = false; ChangeColor(ui->labelAlias2, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp index a60b02898..c3e79c11a 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp @@ -255,11 +255,11 @@ void DialogPointOfIntersectionCurves::ValidateAlias() QRegularExpression const rx(NameRegExp()); const QSharedPointer curve1 = data->GeometricObject(GetFirstCurveId()); - QPair const curve1Alias = + auto const [curve1AliasFirst, curve1AliasSecond] = SegmentAliases(curve1->getType(), GetCurve1AliasSuffix1(), GetCurve1AliasSuffix2()); const QSharedPointer curve2 = data->GeometricObject(GetSecondCurveId()); - QPair const curve2Alias = + auto const [curve2AliasFirst, curve2AliasSecond] = SegmentAliases(curve2->getType(), GetCurve2AliasSuffix1(), GetCurve2AliasSuffix2()); QSet uniqueAliases; @@ -274,10 +274,10 @@ void DialogPointOfIntersectionCurves::ValidateAlias() } }; - CountUniqueAliases(curve1Alias.first); - CountUniqueAliases(curve1Alias.second); - CountUniqueAliases(curve2Alias.first); - CountUniqueAliases(curve2Alias.second); + CountUniqueAliases(curve1AliasFirst); + CountUniqueAliases(curve1AliasSecond); + CountUniqueAliases(curve2AliasFirst); + CountUniqueAliases(curve2AliasSecond); auto Validate = [countAliases, uniqueAliases, rx, this](const QString &originalSuffix, const QString &suffix, const QString &alias, bool &flagAlias, QLabel *label) @@ -296,13 +296,13 @@ void DialogPointOfIntersectionCurves::ValidateAlias() } }; - Validate(originCurve1AliasSuffix1, GetCurve1AliasSuffix1(), curve1Alias.first, flagCurve1Alias1, + Validate(originCurve1AliasSuffix1, GetCurve1AliasSuffix1(), curve1AliasFirst, flagCurve1Alias1, ui->labelCurve1Alias1); - Validate(originCurve1AliasSuffix2, GetCurve1AliasSuffix2(), curve1Alias.second, flagCurve1Alias2, + Validate(originCurve1AliasSuffix2, GetCurve1AliasSuffix2(), curve1AliasSecond, flagCurve1Alias2, ui->labelCurve1Alias2); - Validate(originCurve2AliasSuffix1, GetCurve2AliasSuffix1(), curve2Alias.first, flagCurve2Alias1, + Validate(originCurve2AliasSuffix1, GetCurve2AliasSuffix1(), curve2AliasFirst, flagCurve2Alias1, ui->labelCurve2Alias1); - Validate(originCurve2AliasSuffix2, GetCurve2AliasSuffix2(), curve2Alias.second, flagCurve2Alias2, + Validate(originCurve2AliasSuffix2, GetCurve2AliasSuffix2(), curve2AliasSecond, flagCurve2Alias2, ui->labelCurve2Alias2); CheckState(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 9ca9c2ba1..fcc4e8535 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -4974,8 +4974,8 @@ void DialogSeamAllowance::InitGradationPlaceholdersMenu() auto i = m_gradationPlaceholders.constBegin(); while (i != m_gradationPlaceholders.constEnd()) { - auto value = i.value(); - QAction *action = m_placeholdersMenu->addAction(value.first); + auto [first, second] = i.value(); + QAction *action = m_placeholdersMenu->addAction(first); action->setData(per + i.key() + per); connect(action, &QAction::triggered, this, &DialogSeamAllowance::InsertGradationPlaceholder); ++i; diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 09c762629..1be2c299c 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -1120,15 +1120,15 @@ void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, co QVector children; VPiecePath newPath; - for (const auto &path : unitedPath) + for (const auto &[first, second] : unitedPath) { - if (path.first) + if (first) { // first piece - AddNodeToNewPath(initData, newPath, path.second, children, drawName); + AddNodeToNewPath(initData, newPath, second, children, drawName); } else { // second piece - AddNodeToNewPath(initData, newPath, path.second, children, drawName, dx, dy, pRotate, angle); + AddNodeToNewPath(initData, newPath, second, children, drawName, dx, dy, pRotate, angle); } } @@ -1325,15 +1325,15 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea { const auto unitedPath = VToolUnionDetails::CalcUnitedPath(d1REPath, d2REPath, initData.indexD2, pRotate); - for (const auto &path : unitedPath) + for (const auto &[first, second] : unitedPath) { - if (path.first) + if (first) { // first piece - UpdatePathNode(initData.data, path.second, children); + UpdatePathNode(initData.data, second, children); } else { // second piece - UpdatePathNode(initData.data, path.second, children, dx, dy, pRotate, angle); + UpdatePathNode(initData.data, second, children, dx, dy, pRotate, angle); } } } diff --git a/src/libs/vtools/undocommands/deltool.cpp b/src/libs/vtools/undocommands/deltool.cpp index 303e8cc1f..0b35f37cc 100644 --- a/src/libs/vtools/undocommands/deltool.cpp +++ b/src/libs/vtools/undocommands/deltool.cpp @@ -145,9 +145,9 @@ void DelTool::UpdateGroups(const QMap &groups) const while (i != groups.constEnd()) { QMap groupMap; - for (auto record : i.value().items) + for (auto [first, second] : i.value().items) { - groupMap.insert(record.first, record.second); + groupMap.insert(first, second); } QDomElement group = doc->CreateGroup(i.key(), i.value().name, i.value().tags, groupMap, i.value().tool); diff --git a/src/test/TranslationsTest/tst_tslocaletranslation.cpp b/src/test/TranslationsTest/tst_tslocaletranslation.cpp index e5746b755..f85de616a 100644 --- a/src/test/TranslationsTest/tst_tslocaletranslation.cpp +++ b/src/test/TranslationsTest/tst_tslocaletranslation.cpp @@ -322,12 +322,11 @@ void TST_TSLocaleTranslation::TestHTMLTags() std::make_pair(QRegularExpression(QStringLiteral(""), patternOption), QRegularExpression(QStringLiteral(""), patternOption))}; - for (const auto ®ex : regexes) + for (const auto &[start, end] : regexes) { - if (source.contains(regex.first) && - (not translation.contains(regex.second) || translation.count(regex.second) != source.count(regex.first))) + if (source.contains(start) && (not translation.contains(end) || translation.count(end) != source.count(start))) { - const QString message = u"Tag mismatch. Pattern: '<%1>'. "_s.arg(regex.first.pattern()) + + const QString message = u"Tag mismatch. Pattern: '<%1>'. "_s.arg(start.pattern()) + u"Original name:'%1'"_s.arg(source) + u", translated name:'%1'"_s.arg(translation); QFAIL(qUtf8Printable(message)); }