diff --git a/src/Mod/Fem/Gui/TaskFemConstraint.cpp b/src/Mod/Fem/Gui/TaskFemConstraint.cpp index 566858e8f0..814619a0cc 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraint.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraint.cpp @@ -57,6 +57,8 @@ TaskFemConstraint::TaskFemConstraint(ViewProviderFemConstraint* ConstraintView, true, parent) , proxy(nullptr) + , actionList(nullptr) + , clearListAction(nullptr) , deleteAction(nullptr) , ConstraintView(ConstraintView) , selectionMode(selref) @@ -129,6 +131,12 @@ void TaskFemConstraint::setSelection(QListWidgetItem* item) Gui::Selection().addSelection(docName.c_str(), objName.c_str(), ItemName.c_str(), 0, 0, 0); } +void TaskFemConstraint::onReferenceClearList() +{ + QSignalBlocker block(actionList); + actionList->clear(); +} + void TaskFemConstraint::onReferenceDeleted(const int row) { Fem::Constraint* pcConstraint = ConstraintView->getObject(); @@ -163,6 +171,22 @@ const QString TaskFemConstraint::makeRefText(const App::DocumentObject* obj, return QString::fromUtf8((std::string(obj->getNameInDocument()) + ":" + subName).c_str()); } +void TaskFemConstraint::createActions(QListWidget* parentList) +{ + actionList = parentList; + createDeleteAction(parentList); + createClearListAction(parentList); +} + +void TaskFemConstraint::createClearListAction(QListWidget* parentList) +{ + clearListAction = new QAction(tr("Clear list"), this); + connect(clearListAction, &QAction::triggered, this, &TaskFemConstraint::onReferenceClearList); + + parentList->addAction(clearListAction); + parentList->setContextMenuPolicy(Qt::ActionsContextMenu); +} + void TaskFemConstraint::createDeleteAction(QListWidget* parentList) { // creates a context menu, a shortcut for it and connects it to a slot function diff --git a/src/Mod/Fem/Gui/TaskFemConstraint.h b/src/Mod/Fem/Gui/TaskFemConstraint.h index 4533e0d2f3..3ee90ebd19 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraint.h +++ b/src/Mod/Fem/Gui/TaskFemConstraint.h @@ -60,6 +60,7 @@ public: protected Q_SLOTS: void onReferenceDeleted(const int row); void onButtonReference(const bool pressed = true); + void onReferenceClearList(); void setSelection(QListWidgetItem* item); bool event(QEvent* event) override; @@ -72,12 +73,16 @@ protected: const QString makeRefText(const std::string& objName, const std::string& subName) const; const QString makeRefText(const App::DocumentObject* obj, const std::string& subName) const; void keyPressEvent(QKeyEvent* ke) override; + void createActions(QListWidget* parentList); + void createClearListAction(QListWidget* parentList); void createDeleteAction(QListWidget* parentList); void onSelectionChanged(const Gui::SelectionChanges&) override {} protected: QWidget* proxy; + QListWidget* actionList; + QAction* clearListAction; QAction* deleteAction; Gui::WeakPtrT ConstraintView; enum diff --git a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp index ab6a5811ca..3d7ef0d44b 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp @@ -61,7 +61,7 @@ TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint* Co QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->listReferences); + createActions(ui->listReferences); connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintBearing::onReferenceDeleted); this->groupLayout()->addWidget(proxy); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 86adc128d3..03d60d5a83 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -57,7 +57,7 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index 86899e667a..f18e4ce6f4 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -54,7 +54,7 @@ TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* C QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintFixed::onReferenceDeleted); connect(ui->lw_references, &QListWidget::currentItemChanged, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index cbec0958a9..de5947fd17 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -139,7 +139,7 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->listReferences); + createActions(ui->listReferences); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index ef6e5a3119..861656318d 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -89,7 +89,7 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* C ui->checkReverse->setChecked(reversed); // create a context menu for the listview of the references - createDeleteAction(ui->listReferences); + createActions(ui->listReferences); connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintForce::onReferenceDeleted); connect(ui->buttonDirection, &QToolButton::clicked, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index e9cc6090a9..52dc84abcb 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -57,7 +57,7 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp index 76cbccfc52..a4457735b0 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp @@ -60,7 +60,7 @@ TaskFemConstraintPlaneRotation::TaskFemConstraintPlaneRotation( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index a253f239b4..02c9878444 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -81,7 +81,7 @@ TaskFemConstraintPressure::TaskFemConstraintPressure( } // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp index d3e8a43cf9..67854bd768 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp @@ -56,7 +56,7 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); deleteAction->connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index 413fe39bf9..434dd60c5e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -54,7 +54,7 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintSpring::onReferenceDeleted); connect(ui->lw_references, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 5dfe77200b..789c5f3779 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -100,7 +100,7 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature( } // create a context menu for the listview of the references - createDeleteAction(ui->lw_references); + createActions(ui->lw_references); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index 5d32f8fa7d..c8c006f680 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -60,7 +60,7 @@ TaskFemConstraintTransform::TaskFemConstraintTransform( QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references - createDeleteAction(ui->lw_Rect); + createActions(ui->lw_Rect); connect(deleteAction, &QAction::triggered, this, diff --git a/src/Mod/Fem/femguiutils/selection_widgets.py b/src/Mod/Fem/femguiutils/selection_widgets.py index e92595ee9d..1c8df15e34 100644 --- a/src/Mod/Fem/femguiutils/selection_widgets.py +++ b/src/Mod/Fem/femguiutils/selection_widgets.py @@ -295,6 +295,7 @@ class GeometryElementsSelection(QtGui.QWidget): self.setWindowTitle(self.tr("Geometry reference selector")) # button self.pushButton_Add = QtGui.QPushButton(self.tr("Add")) + self.pushButton_Remove = QtGui.QPushButton(self.tr("Remove")) # list self.list_References = QtGui.QListWidget() # radiobutton down the list @@ -307,9 +308,13 @@ class GeometryElementsSelection(QtGui.QWidget): rbtnLayout.addWidget(self.lb_selmod) rbtnLayout.addWidget(self.rb_standard) rbtnLayout.addWidget(self.rb_solid) + # add/remove button + subLayout = QtGui.QHBoxLayout() + subLayout.addWidget(self.pushButton_Add) + subLayout.addWidget(self.pushButton_Remove) # main layout mainLayout = QtGui.QVBoxLayout() - mainLayout.addWidget(self.pushButton_Add) + mainLayout.addLayout(subLayout) mainLayout.addWidget(self.list_References) tip1 = self.tr( @@ -344,6 +349,9 @@ class GeometryElementsSelection(QtGui.QWidget): self.references_list_right_clicked, ) QtCore.QObject.connect(self.pushButton_Add, QtCore.SIGNAL("clicked()"), self.add_references) + QtCore.QObject.connect( + self.pushButton_Remove, QtCore.SIGNAL("clicked()"), self.remove_selected_reference + ) QtCore.QObject.connect( self.rb_standard, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_standard )