diff --git a/ChangeLog.txt b/ChangeLog.txt index 4337bc124..422978267 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -46,6 +46,7 @@ - New piece option Follow grainline. - Validate sheet and layout names before proposing file name. - Puzzle app. Fix piece position move when update layout data. +- Puzzle app. Fix losing selection by piece. # Valentina 0.7.52 September 12, 2022 - Fix crash when default locale is ru. diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index c1791b4e0..822661c0f 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -102,21 +102,32 @@ void VPSheetSceneData::RefreshPieces() } VPSheetPtr sheet = layout->GetSheet(m_sheetUuid); - if (not sheet.isNull()) + if (sheet.isNull()) { - QList pieces = sheet->GetPieces(); - m_graphicsPieces.reserve(pieces.size()); + return; + } - for (const auto &piece : pieces) + QList pieces = sheet->GetPieces(); + m_graphicsPieces.reserve(pieces.size()); + + for (const auto &piece : pieces) + { + if (piece.isNull()) { - if (not piece.isNull()) - { - auto *graphicsPiece = new VPGraphicsPiece(piece); - m_graphicsPieces.append(graphicsPiece); - m_scene->addItem(graphicsPiece); - ConnectPiece(graphicsPiece); - } + continue; } + + auto *graphicsPiece = new VPGraphicsPiece(piece); + m_graphicsPieces.append(graphicsPiece); + m_scene->addItem(graphicsPiece); + + // Restore selection state + if (piece->IsSelected()) + { + graphicsPiece->setSelected(piece->IsSelected()); + } + + ConnectPiece(graphicsPiece); } } @@ -315,7 +326,7 @@ void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) QObject::connect(layout.data(), &VPLayout::PieceTransformationChanged, piece, &VPGraphicsPiece::on_RefreshPiece); QObject::connect(layout.data(), &VPLayout::PieceZValueChanged, piece, &VPGraphicsPiece::PieceZValueChanged); QObject::connect(layout.data(), &VPLayout::PieceSelectionChanged, m_rotationControls, - &VPGraphicsPieceControls::on_UpdateControls); + &VPGraphicsPieceControls::on_UpdateControls, Qt::UniqueConnection); QObject::connect(layout.data(), &VPLayout::PiecePositionValidityChanged, piece, &VPGraphicsPiece::on_RefreshPiece); QObject::connect(piece, &VPGraphicsPiece::PieceTransformationChanged, m_rotationControls, &VPGraphicsPieceControls::on_UpdateControls);