FEM: Fix convoluted event handling of constraint task boxes

and make Delete key working on macOS
This commit is contained in:
wmayer
2024-07-23 08:25:37 +02:00
committed by Chris Hennes
parent 8a1b4b2d05
commit be34f251cd
26 changed files with 23 additions and 100 deletions

View File

@@ -59,12 +59,32 @@ TaskFemConstraint::TaskFemConstraint(ViewProviderFemConstraint* ConstraintView,
, proxy(nullptr)
, deleteAction(nullptr)
, ConstraintView(ConstraintView)
, selectionMode(selref)
{}
bool TaskFemConstraint::event(QEvent* event)
{
selectionMode = selref;
if (event && event->type() == QEvent::ShortcutOverride) {
auto ke = static_cast<QKeyEvent*>(event); // NOLINT
if (deleteAction) {
if (ke->matches(QKeySequence::Delete) || ke->matches(QKeySequence::Backspace)) {
ke->accept();
}
}
}
return TaskBox::event(event);
}
void TaskFemConstraint::keyPressEvent(QKeyEvent* ke)
{
// if we have a Del key, trigger the deleteAction
if (ke->matches(QKeySequence::Delete) || ke->matches(QKeySequence::Backspace)) {
if (deleteAction && deleteAction->isEnabled()) {
ke->accept();
deleteAction->trigger();
}
}
TaskBox::keyPressEvent(ke);
}
@@ -157,32 +177,6 @@ void TaskFemConstraint::createDeleteAction(QListWidget* parentList)
parentList->setContextMenuPolicy(Qt::ActionsContextMenu);
}
bool TaskFemConstraint::KeyEvent(QEvent* e)
{
// in case another instance takes key events, accept the overridden key even
if (e && e->type() == QEvent::ShortcutOverride) {
QKeyEvent* kevent = static_cast<QKeyEvent*>(e);
if (kevent->modifiers() == Qt::NoModifier) {
if (deleteAction && kevent->key() == Qt::Key_Delete) {
kevent->accept();
return true;
}
}
}
// if we have a Del key, trigger the deleteAction
else if (e && e->type() == QEvent::KeyPress) {
QKeyEvent* kevent = static_cast<QKeyEvent*>(e);
if (kevent->key() == Qt::Key_Delete) {
if (deleteAction && deleteAction->isEnabled()) {
deleteAction->trigger();
}
return true;
}
}
return TaskFemConstraint::event(e);
}
//**************************************************************************
//**************************************************************************
// TaskDialog

View File

@@ -62,6 +62,8 @@ protected Q_SLOTS:
void onButtonReference(const bool pressed = true);
void setSelection(QListWidgetItem* item);
bool event(QEvent* event) override;
protected:
void changeEvent(QEvent* e) override
{
@@ -71,7 +73,6 @@ protected:
const QString makeRefText(const App::DocumentObject* obj, const std::string& subName) const;
void keyPressEvent(QKeyEvent* ke) override;
void createDeleteAction(QListWidget* parentList);
bool KeyEvent(QEvent* e);
void onSelectionChanged(const Gui::SelectionChanges&) override
{}

View File

@@ -309,11 +309,6 @@ bool TaskFemConstraintBearing::getAxial() const
TaskFemConstraintBearing::~TaskFemConstraintBearing() = default;
bool TaskFemConstraintBearing::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintBearing::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);

View File

@@ -69,7 +69,6 @@ private Q_SLOTS:
void onCheckAxial(bool);
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void onSelectionChanged(const Gui::SelectionChanges& msg) override;

View File

@@ -477,11 +477,6 @@ bool TaskFemConstraintDisplacement::get_useFlowSurfaceForce() const
return ui->FlowForceCB->isChecked();
}
bool TaskFemConstraintDisplacement::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintDisplacement::changeEvent(QEvent*)
{
// TaskBox::changeEvent(e);

View File

@@ -85,7 +85,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -247,11 +247,6 @@ const std::string TaskFemConstraintFixed::getReferences() const
return TaskFemConstraint::getReferences(items);
}
bool TaskFemConstraintFixed::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintFixed::changeEvent(QEvent*)
{}

View File

@@ -51,7 +51,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -951,11 +951,6 @@ void TaskFemConstraintFluidBoundary::updateUI()
}
}
bool TaskFemConstraintFluidBoundary::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintFluidBoundary::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);

View File

@@ -91,7 +91,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -386,11 +386,6 @@ bool TaskFemConstraintForce::getReverse() const
TaskFemConstraintForce::~TaskFemConstraintForce() = default;
bool TaskFemConstraintForce::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintForce::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);

View File

@@ -69,7 +69,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -458,11 +458,6 @@ std::string TaskFemConstraintHeatflux::get_constraint_type() const
return type;
}
bool TaskFemConstraintHeatflux::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintHeatflux::changeEvent(QEvent* e)
{
TaskBox::changeEvent(e);

View File

@@ -66,7 +66,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -281,11 +281,6 @@ const std::string TaskFemConstraintPlaneRotation::getReferences() const
return TaskFemConstraint::getReferences(items);
}
bool TaskFemConstraintPlaneRotation::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintPlaneRotation::changeEvent(QEvent*)
{}

View File

@@ -53,7 +53,6 @@ private Q_SLOTS:
void removeFromSelection();
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
private:

View File

@@ -262,11 +262,6 @@ bool TaskFemConstraintPressure::getReverse() const
return ui->checkBoxReverse->isChecked();
}
bool TaskFemConstraintPressure::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintPressure::changeEvent(QEvent*)
{}

View File

@@ -56,7 +56,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -619,11 +619,6 @@ std::vector<std::string> TaskFemConstraintRigidBody::getRotationalMode() const
return rotModes;
}
bool TaskFemConstraintRigidBody::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintRigidBody::changeEvent(QEvent*)
{}

View File

@@ -66,7 +66,6 @@ private Q_SLOTS:
void onRefNodeZChanged(double);
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -270,11 +270,6 @@ std::string TaskFemConstraintSpring::getElmerStiffness() const
return Base::Tools::toStdString(ui->ElmerStiffnessCB->currentText());
}
bool TaskFemConstraintSpring::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintSpring::changeEvent(QEvent*)
{}

View File

@@ -54,7 +54,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -319,11 +319,6 @@ std::string TaskFemConstraintTemperature::get_constraint_type() const
return ui->cb_constr_type->currentText().toStdString();
}
bool TaskFemConstraintTemperature::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintTemperature::changeEvent(QEvent*)
{
// TaskBox::changeEvent(e);

View File

@@ -62,7 +62,6 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;

View File

@@ -555,11 +555,6 @@ std::string TaskFemConstraintTransform::get_transform_type() const
return transform;
}
bool TaskFemConstraintTransform::event(QEvent* e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintTransform::changeEvent(QEvent*)
{}

View File

@@ -63,7 +63,6 @@ private Q_SLOTS:
void angleChanged(double a);
protected:
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
const QString makeText(const App::DocumentObject* obj) const;