From b9e26f0b3fc127c43bea1a022bdc6b7d8ec0f15f Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 14:24:07 +0100 Subject: [PATCH] Add a trash list and delete context menu function --- src/app/puzzle/vpcarrouselpiecelist.cpp | 12 ++++++++---- src/app/puzzle/vpcarrouselpiecelist.h | 1 - src/app/puzzle/vplayout.cpp | 10 +++++++++- src/app/puzzle/vplayout.h | 16 +++++++++------- src/app/puzzle/vpmaingraphicsview.cpp | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index c782bfeb7..a6bea85ba 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -197,10 +197,16 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) { VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); - QVariant data = QVariant::fromValue(sheetPieces); - moveAction->setData(data); + QVariant moveData = QVariant::fromValue(sheetPieces); + moveAction->setData(moveData); + + VPPieceList* trashPieceList = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetTrashPieceList(); + QAction *deleteAction = contextMenu.addAction(tr("Delete")); + QVariant deleteData = QVariant::fromValue(trashPieceList); + deleteAction->setData(deleteData); connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + connect(deleteAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); } // remove from piece list action @@ -235,8 +241,6 @@ void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() } } - - //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) { diff --git a/src/app/puzzle/vpcarrouselpiecelist.h b/src/app/puzzle/vpcarrouselpiecelist.h index 48d8cf5ce..26f65d957 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.h +++ b/src/app/puzzle/vpcarrouselpiecelist.h @@ -108,7 +108,6 @@ private slots: * @brief on_ActionPieceMovedToPieceList when a piece is moved to another piece list via a context menu */ void on_ActionPieceMovedToPieceList(); - }; #endif // VPCARROUSELPIECELIST_H diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index ef81a0694..539bc9e0c 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -38,6 +38,7 @@ Q_LOGGING_CATEGORY(pLayout, "p.layout") //--------------------------------------------------------------------------------------------------------------------- VPLayout::VPLayout() : m_unplacedPieceList(new VPPieceList(this)), + m_trashPieceList(new VPPieceList(this)), m_sheets(QList()) { m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); @@ -48,6 +49,7 @@ VPLayout::~VPLayout() { qDeleteAll(m_sheets); delete m_unplacedPieceList; + delete m_trashPieceList; } //--------------------------------------------------------------------------------------------------------------------- @@ -56,6 +58,12 @@ VPPieceList* VPLayout::GetUnplacedPieceList() return m_unplacedPieceList; } +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPLayout::GetTrashPieceList() +{ + return m_trashPieceList; +} + //--------------------------------------------------------------------------------------------------------------------- VPSheet* VPLayout::AddSheet() { @@ -208,7 +216,7 @@ void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) pieceList->AddPiece(piece); // signal, that a piece was moved - emit PieceMovedToPieceList(piece, pieceListBefore,pieceList); + emit PieceMovedToPieceList(piece, pieceListBefore, pieceList); } diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index e8ca4d933..f8ff3a7ee 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -50,6 +50,12 @@ public: */ VPPieceList* GetUnplacedPieceList(); + /** + * @brief GetTrashPieceList Returns the piece list of the trash + * @return the pieces list of trashed pieces. + */ + VPPieceList* GetTrashPieceList(); + VPSheet* AddSheet(); VPSheet* AddSheet(VPSheet *sheet); QList GetSheets(); @@ -265,16 +271,12 @@ private: VPPieceList *m_unplacedPieceList; - QList m_sheets; - /** - TODO : To be replaced by m_focusedSheet - * @brief m_focusedPieceList pointer the the focused piece list, to which pieces will be - * added via drag and drop, or if no piece list is defined. + * @brief m_trashPieceList Holds the pieces that were deleted */ - VPPieceList *m_focusedPieceList{nullptr}; - + VPPieceList *m_trashPieceList; + QList m_sheets; VPSheet *m_focusedSheet{nullptr}; // format diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 4c4c3d1a0..17a246d96 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -213,7 +213,7 @@ void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *p scene()->removeItem(_graphicsPiece); m_graphicsPieces.removeAll(_graphicsPiece); } - else if(pieceListAfter != m_layout->GetUnplacedPieceList()) + else if(pieceListAfter != m_layout->GetUnplacedPieceList() && pieceListAfter != m_layout->GetTrashPieceList()) { if(_graphicsPiece == nullptr) {