Partial homogenization of FEM dialogs for constraints (#21538)

* FEM: Add context menu entry for clearing the reference list in constraints

See #6085

* FEM: Add 'Remove' button to python based dialogs for adding geometry references

See #6085
This commit is contained in:
Ralf Habacker
2025-06-09 17:51:36 +02:00
committed by GitHub
parent a46d84aa2e
commit 719ee20ba4
15 changed files with 50 additions and 13 deletions

View File

@@ -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<Fem::Constraint>();
@@ -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

View File

@@ -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<ViewProviderFemConstraint> ConstraintView;
enum

View File

@@ -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);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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
)