From 6d1b7a921225b4a45b2ff946869128dbc583e52d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 20 Feb 2020 19:18:19 +0200 Subject: [PATCH] Call Piece Options and Delete Piece from the piece list context menu. --- ChangeLog.txt | 1 + src/app/valentina/dialogs/vwidgetdetails.cpp | 55 ++++++++++++++++++-- src/libs/vtools/tools/vtoolseamallowance.h | 4 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 513185130..be4bed741 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -39,6 +39,7 @@ - [#984] Issue with up to date list of unique names. - Tracking changes/prevent "OK" recalculation after "Apply". - Change behavior for menu Pattern piece -> Show main path. Now it has an influence on export as well. +- Call Piece Options and Delete Piece from the piece list context menu. # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. diff --git a/src/app/valentina/dialogs/vwidgetdetails.cpp b/src/app/valentina/dialogs/vwidgetdetails.cpp index 2145c6407..084ababfa 100644 --- a/src/app/valentina/dialogs/vwidgetdetails.cpp +++ b/src/app/valentina/dialogs/vwidgetdetails.cpp @@ -263,12 +263,44 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos) QAction *actionSelectAll = menu->addAction(tr("Select all")); QAction *actionSelectNone = menu->addAction(tr("Select none")); - QAction *actionSeparator = new QAction(this); - actionSeparator->setSeparator(true); - menu->addAction(actionSeparator); + menu->addSeparator(); QAction *actionInvertSelection = menu->addAction(tr("Invert selection")); + bool pieceMode = false; + QAction *actionPieceOptions = nullptr; + QAction *actionDeletePiece = nullptr; + VToolSeamAllowance *toolPiece = nullptr; + + QTableWidgetItem *selectedItem = ui->tableWidget->itemAt(pos); + if (selectedItem) + { + QTableWidgetItem *item = ui->tableWidget->item(selectedItem->row(), PieceColumn::InLayout); + const quint32 id = item->data(Qt::UserRole).toUInt(); + + try + { + toolPiece = qobject_cast(VAbstractPattern::getTool(id)); + if (toolPiece) + { + pieceMode = true; + menu->addSeparator(); + + actionPieceOptions = menu->addAction(QIcon::fromTheme(QStringLiteral("preferences-other")), + tr("Piece options")); + + actionDeletePiece = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), + tr("Delete piece")); + actionDeletePiece->setDisabled(toolPiece->referens() > 0); + } + } + catch (const VExceptionBadId &) + { + const QString errorMsg = tr("Cannot find piece by id '%1'").arg(id); + qWarning() << VAbstractApplication::patternMessageSignature + errorMsg; + } + } + const QHash *allDetails = m_data->DataPieces(); if (allDetails->count() == 0) { @@ -333,6 +365,23 @@ void VWidgetDetails::ShowContextMenu(const QPoint &pos) qApp->getUndoStack()->endMacro(); } + else if (pieceMode && selectedAction == actionPieceOptions) + { + toolPiece->ShowOptions(); + } + else if (pieceMode && selectedAction == actionDeletePiece) + { + try + { + toolPiece->DeleteFromMenu(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + //Leave this method immediately after call!!! + } } //------------------------------------------------------------------------------------------------------------------ diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index c2e256f99..9de9c5d8b 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -133,6 +133,8 @@ public slots: void Highlight(quint32 id); void UpdateDetailLabel(); void UpdatePatternInfo(); + void ShowOptions(); + void DeleteFromMenu(); protected slots: void UpdateGrainline(); void SaveMoveDetail(const QPointF &ptPos); @@ -161,11 +163,9 @@ protected: virtual void SaveDialogChange(const QString &undoText = QString()) final; private slots: - void ShowOptions(); void ToggleInLayout(bool checked); void ToggleForbidFlipping(bool checked); void ToggleForceFlipping(bool checked); - void DeleteFromMenu(); void ToggleExcludeState(quint32 id); void ToggleNodePointAngleType(quint32 id, PieceNodeAngle type); void ToggleNodePointPassmark(quint32 id, bool toggle);