diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 61ed52167c..39346b47d6 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include +# include # include # include # include @@ -90,6 +91,17 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj connect(ui->buttonSpineBase, SIGNAL(toggled(bool)), this, SLOT(onBaseButton(bool))); + // Create context menu + QAction* remove = new QAction(tr("Remove"), this); + remove->setShortcut(QKeySequence::Delete); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + // display shortcut behind the context menu entry + remove->setShortcutVisibleInContextMenu(true); +#endif + ui->listWidgetReferences->addAction(remove); + connect(remove, SIGNAL(triggered()), this, SLOT(onDeleteEdge())); + ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); + this->groupLayout()->addWidget(proxy); PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); @@ -110,8 +122,13 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj ui->spineBaseEdit->setText(QString::fromUtf8(pipe->Spine.getValue()->Label.getValue())); std::vector strings = pipe->Spine.getSubValues(); - for (std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) - ui->listWidgetReferences->addItem(QString::fromStdString(*it)); + for (std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) { + QString label = QString::fromStdString(*it); + QListWidgetItem* item = new QListWidgetItem(); + item->setText(label); + item->setData(Qt::UserRole, QByteArray(label.toUtf8())); + ui->listWidgetReferences->addItem(item); + } if (!strings.empty()) { PipeView->makeTemporaryVisible(true); @@ -288,6 +305,30 @@ void TaskPipeParameters::removeFromListWidget(QListWidget* widget, QString items } } +void TaskPipeParameters::onDeleteEdge() +{ + // Delete the selected path edge + int row = ui->listWidgetReferences->currentRow(); + QListWidgetItem* item = ui->listWidgetReferences->item(row); + if (item) { + QByteArray data = item->data(Qt::UserRole).toByteArray(); + ui->listWidgetReferences->takeItem(row); + delete item; + // search inside the list of spines + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + std::vector refs = pipe->Spine.getSubValues(); + std::string obj = data.toStdString(); + std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + // if something was found, delte it and update the spine list + if (f != refs.end()) { + refs.erase(f); + pipe->Spine.setValue(pipe->Spine.getValue(), refs); + clearButtons(); + recomputeFeature(); + } + } +} + bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const { if (msg.Type == Gui::SelectionChanges::AddSelection && selectionMode != none) { @@ -401,6 +442,17 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO connect(ui->doubleSpinBoxZ, SIGNAL(valueChanged(double)), this, SLOT(onBinormalChanged(double))); + // Create context menu + QAction* remove = new QAction(tr("Remove"), this); + remove->setShortcut(QKeySequence::Delete); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + // display shortcut behind the context menu entry + remove->setShortcutVisibleInContextMenu(true); +#endif + ui->listWidgetReferences->addAction(remove); + connect(remove, SIGNAL(triggered()), this, SLOT(onDeleteItem())); + ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); + this->groupLayout()->addWidget(proxy); PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); @@ -419,8 +471,13 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO ui->profileBaseEdit->setText(QString::fromUtf8(pipe->AuxillerySpine.getValue()->Label.getValue())); std::vector strings = pipe->AuxillerySpine.getSubValues(); - for (std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) - ui->listWidgetReferences->addItem(QString::fromStdString(*it)); + for (std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) { + QString label = QString::fromStdString(*it); + QListWidgetItem* item = new QListWidgetItem(); + item->setText(label); + item->setData(Qt::UserRole, QByteArray(label.toUtf8())); + ui->listWidgetReferences->addItem(item); + } ui->comboBoxMode->setCurrentIndex(pipe->Mode.getValue()); ui->curvelinear->setChecked(pipe->AuxilleryCurvelinear.getValue()); @@ -615,6 +672,30 @@ void TaskPipeOrientation::removeFromListWidget(QListWidget* widget, QString name } } +void TaskPipeOrientation::onDeleteItem() +{ + // Delete the selected spine + int row = ui->listWidgetReferences->currentRow(); + QListWidgetItem* item = ui->listWidgetReferences->item(row); + if (item) { + QByteArray data = item->data(Qt::UserRole).toByteArray(); + ui->listWidgetReferences->takeItem(row); + delete item; + // search inside the list of spines + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + std::vector refs = pipe->AuxillerySpine.getSubValues(); + std::string obj = data.toStdString(); + std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + // if something was found, delte it and update the spine list + if (f != refs.end()) { + refs.erase(f); + pipe->AuxillerySpine.setValue(pipe->AuxillerySpine.getValue(), refs); + clearButtons(); + recomputeFeature(); + } + } +} + void TaskPipeOrientation::updateUI(int idx) { //make sure we resize to the size of the current page @@ -648,13 +729,27 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(updateUI(int))); + // Create context menu + QAction* remove = new QAction(tr("Remove"), this); + remove->setShortcut(QKeySequence::Delete); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + // display shortcut behind the context menu entry + remove->setShortcutVisibleInContextMenu(true); +#endif + ui->listWidgetReferences->addAction(remove); + ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); + connect(remove, SIGNAL(triggered()), this, SLOT(onDeleteSection())); + this->groupLayout()->addWidget(proxy); PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); - const std::vector& sections = pipe->Sections.getValues(); - for (auto it : sections) { - QString label = QString::fromUtf8(it->Label.getValue()); - ui->listWidgetReferences->addItem(label); + for (auto obj : pipe->Sections.getValues()) { + Gui::Application::Instance->showViewProvider(obj); + QString label = QString::fromUtf8(obj->Label.getValue()); + QListWidgetItem* item = new QListWidgetItem(); + item->setText(label); + item->setData(Qt::UserRole, QByteArray(obj->getNameInDocument())); + ui->listWidgetReferences->addItem(item); } ui->comboBoxScaling->setCurrentIndex(pipe->Transformation.getValue()); @@ -784,6 +879,30 @@ void TaskPipeScaling::removeFromListWidget(QListWidget* widget, QString name) { } } +void TaskPipeScaling::onDeleteSection() +{ + // Delete the selected profile + int row = ui->listWidgetReferences->currentRow(); + QListWidgetItem* item = ui->listWidgetReferences->item(row); + if (item) { + QByteArray data = item->data(Qt::UserRole).toByteArray(); + ui->listWidgetReferences->takeItem(row); + delete item; + // search inside the list of sections + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + std::vector refs = pipe->Sections.getValues(); + App::DocumentObject* obj = pipe->getDocument()->getObject(data.constData()); + std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + // if something was found, delte it and update the section list + if (f != refs.end()) { + refs.erase(f); + pipe->Sections.setValues(refs); + clearButtons(); + recomputeFeature(); + } + } +} + void TaskPipeScaling::updateUI(int idx) { //make sure we resize to the size of the current page diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.h b/src/Mod/PartDesign/Gui/TaskPipeParameters.h index c391bdaa42..3c474c2533 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.h @@ -65,6 +65,7 @@ private Q_SLOTS: void onButtonRefRemove(bool checked); void onBaseButton(bool checked); void onProfileButton(bool checked); + void onDeleteEdge(); protected: enum selectionModes { none, refAdd, refRemove, refObjAdd, refProfile }; @@ -103,6 +104,7 @@ private Q_SLOTS: void onBaseButton(bool checked); void onCurvelinearChanged(bool checked); void onBinormalChanged(double); + void onDeleteItem(); protected: enum selectionModes { none, refAdd, refRemove, refObjAdd }; @@ -138,6 +140,7 @@ private Q_SLOTS: void onButtonRefAdd(bool checked); void onButtonRefRemove(bool checked); void updateUI(int idx); + void onDeleteSection(); protected: enum selectionModes { none, refAdd, refRemove };