[FEM] add shortcut to delete constraints from list in dialog

see https://forum.freecadweb.org/viewtopic.php?f=18&t=43402
This commit is contained in:
donovaly
2020-02-18 01:22:20 +01:00
committed by wmayer
parent d4d4998f74
commit 97de09ad6f
22 changed files with 176 additions and 75 deletions

View File

@@ -27,7 +27,9 @@
#ifndef _PreComp_
# include <sstream>
# include <QAction>
# include <QKeyEvent>
# include <QListWidget>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
@@ -183,6 +185,45 @@ const QString TaskFemConstraint::makeRefText(const App::DocumentObject* obj, con
return QString::fromUtf8((std::string(obj->getNameInDocument()) + ":" + subName).c_str());
}
void TaskFemConstraint::createDeleteAction(QListWidget* parentList)
{
// creates a context menu, a shortcutt for it and connects it to e slot function
deleteAction = new QAction(tr("Delete"), this);
deleteAction->setShortcut(QKeySequence::Delete);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// display shortcut behind the context menu entry
deleteAction->setShortcutVisibleInContextMenu(true);
#endif
parentList->addAction(deleteAction);
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 (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->isEnabled())
deleteAction->trigger();
return true;
}
}
return TaskFemConstraint::event(e);
}
//**************************************************************************
//**************************************************************************
// TaskDialog

View File

@@ -31,6 +31,9 @@
#include "ViewProviderFemConstraint.h"
class QAction;
class QListWidget;
namespace FemGui {
class TaskFemConstraint : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
@@ -56,12 +59,15 @@ protected:
virtual void changeEvent(QEvent *e) { TaskBox::changeEvent(e); }
const QString makeRefText(const App::DocumentObject* obj, const std::string& subName) const;
virtual void keyPressEvent(QKeyEvent * ke);
void createDeleteAction(QListWidget* parentList);
bool KeyEvent(QEvent *e);
private:
virtual void onSelectionChanged(const Gui::SelectionChanges&) {}
protected:
QWidget* proxy;
QAction* deleteAction;
ViewProviderFemConstraint *ConstraintView;
enum {seldir, selref, selloc, selnone} selectionMode;

View File

@@ -27,10 +27,11 @@
#ifndef _PreComp_
# include <sstream>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
# include <QAction>
# include <Precision.hxx>
# include <TopoDS.hxx>
@@ -76,12 +77,9 @@ TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint *Co
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
// Create a context menu for the listview of the references
QAction* action = new QAction(tr("Delete"), ui->listReferences);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onReferenceDeleted()));
ui->listReferences->addAction(action);
ui->listReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->listReferences);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->spinDistance, SIGNAL(valueChanged(double)),
this, SLOT(onDistanceChanged(double)));
@@ -302,6 +300,11 @@ TaskFemConstraintBearing::~TaskFemConstraintBearing()
delete ui;
}
bool TaskFemConstraintBearing::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintBearing::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);

View File

@@ -32,6 +32,8 @@
#include "TaskFemConstraint.h"
#include "ViewProviderFemConstraintBearing.h"
#include <QKeyEvent>
class Ui_TaskFemConstraintBearing;
namespace App {
@@ -66,6 +68,7 @@ private Q_SLOTS:
void onCheckAxial(bool);
protected:
bool event(QEvent *e);
virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);

View File

@@ -31,10 +31,13 @@
# include <Geom_Line.hxx>
# include <Geom_Plane.hxx>
# include <Precision.hxx>
# include <QMessageBox>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <TopoDS.hxx>
# include <gp_Ax1.hxx>
# include <gp_Lin.hxx>
@@ -67,10 +70,9 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement(ViewProviderFemCons
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -575,6 +577,11 @@ bool TaskFemConstraintDisplacement::get_rotyfree() const{return ui->rotyfree->is
bool TaskFemConstraintDisplacement::get_rotzfix() const{return ui->rotzfix->isChecked();}
bool TaskFemConstraintDisplacement::get_rotzfree() const{return ui->rotzfree->isChecked();}
bool TaskFemConstraintDisplacement::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintDisplacement::changeEvent(QEvent *)
{
// TaskBox::changeEvent(e);

View File

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintDisplacement;
@@ -48,7 +49,7 @@ class TaskFemConstraintDisplacement : public TaskFemConstraint
Q_OBJECT
public:
TaskFemConstraintDisplacement(ViewProviderFemConstraintDisplacement *ConstraintView,QWidget *parent = 0);
TaskFemConstraintDisplacement(ViewProviderFemConstraintDisplacement *ConstraintView, QWidget *parent = 0);
~TaskFemConstraintDisplacement();
const std::string getReferences() const;
double get_spinxDisplacement()const;
@@ -96,10 +97,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintDisplacement* ui;

View File

@@ -29,10 +29,13 @@
# include <Geom_Line.hxx>
# include <Geom_Plane.hxx>
# include <Precision.hxx>
# include <QMessageBox>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <TopoDS.hxx>
# include <gp_Ax1.hxx>
# include <gp_Lin.hxx>
@@ -45,9 +48,6 @@
#include "ui_TaskFemConstraintFixed.h"
#include <App/Application.h>
#include <Gui/Command.h>
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
@@ -65,10 +65,9 @@ TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed *C
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -261,6 +260,10 @@ 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

@@ -58,10 +58,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintFixed* ui;

View File

@@ -28,10 +28,11 @@
#ifndef _PreComp_
# include <sstream>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
# include <QAction>
# include <Precision.hxx>
# include <TopoDS.hxx>
@@ -139,12 +140,9 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
// Create a context menu for the listview of the references
QAction* action = new QAction(tr("Delete"), ui->listReferences);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onReferenceDeleted()));
ui->listReferences->addAction(action);
ui->listReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->listReferences);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->comboBoundaryType, SIGNAL(currentIndexChanged(int)),
this, SLOT(onBoundaryTypeChanged(void)));
@@ -800,6 +798,11 @@ TaskFemConstraintFluidBoundary::~TaskFemConstraintFluidBoundary()
delete ui;
}
bool TaskFemConstraintFluidBoundary::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintFluidBoundary::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);

View File

@@ -33,6 +33,8 @@
#include "TaskFemConstraint.h"
#include "ViewProviderFemConstraintFluidBoundary.h"
#include <QKeyEvent>
class Ui_TaskFemConstraintFluidBoundary;
namespace App {
@@ -86,6 +88,7 @@ private Q_SLOTS:
void onCheckReverse(bool); // consider removing this slot as the UI is hidden
protected:
bool event(QEvent *e);
virtual void changeEvent(QEvent *e);
private:

View File

@@ -27,10 +27,11 @@
#ifndef _PreComp_
# include <sstream>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
# include <QAction>
# include <Precision.hxx>
# include <TopoDS.hxx>
@@ -75,12 +76,9 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce *C
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
// Create a context menu for the listview of the references
QAction* action = new QAction(tr("Delete"), ui->listReferences);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onReferenceDeleted()));
ui->listReferences->addAction(action);
ui->listReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->listReferences);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->spinForce, SIGNAL(valueChanged(double)),
this, SLOT(onForceChanged(double)));
@@ -314,6 +312,11 @@ TaskFemConstraintForce::~TaskFemConstraintForce()
delete ui;
}
bool TaskFemConstraintForce::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintForce::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);

View File

@@ -32,6 +32,8 @@
#include "TaskFemConstraint.h"
#include "ViewProviderFemConstraintForce.h"
#include <QKeyEvent>
class Ui_TaskFemConstraintForce;
namespace App {
@@ -65,6 +67,7 @@ private Q_SLOTS:
void onCheckReverse(bool);
protected:
bool event(QEvent *e);
virtual void changeEvent(QEvent *e);
private:

View File

@@ -36,8 +36,9 @@
# include <gp_Lin.hxx>
# include <gp_Pln.hxx>
# include <QMessageBox>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
@@ -63,10 +64,9 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHe
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->rb_convection, SIGNAL(clicked(bool)), this, SLOT(Conv()));
connect(ui->rb_dflux, SIGNAL(clicked(bool)), this, SLOT(Flux()));
@@ -388,6 +388,11 @@ std::string TaskFemConstraintHeatflux::get_constraint_type(void) const {
return type;
}
bool TaskFemConstraintHeatflux::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintHeatflux::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);

View File

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintHeatflux;
@@ -69,10 +70,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
virtual void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintHeatflux* ui;
};

View File

@@ -28,10 +28,11 @@
#ifndef _PreComp_
# include <sstream>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
# include <QAction>
# include <Precision.hxx>
# include <TopoDS.hxx>
@@ -76,10 +77,9 @@ TaskFemConstraintPlaneRotation::TaskFemConstraintPlaneRotation(ViewProviderFemCo
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -283,6 +283,10 @@ 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

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintPlaneRotation;
@@ -60,10 +61,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintPlaneRotation* ui;

View File

@@ -33,9 +33,9 @@
# include <gp_Ax1.hxx>
# include <gp_Lin.hxx>
# include <gp_Pln.hxx>
# include <QMessageBox>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
@@ -67,10 +67,9 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPr
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -281,7 +280,11 @@ bool TaskFemConstraintPressure::get_Reverse() const
{
return ui->checkBoxReverse->isChecked();
}
/* */
bool TaskFemConstraintPressure::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintPressure::changeEvent(QEvent *)
{

View File

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintPressure;
@@ -63,10 +64,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintPressure* ui;

View File

@@ -37,9 +37,9 @@
# include <gp_Pln.hxx>
# include <sstream>
# include <QMessageBox>
# include <QAction>
# include <QMessageBox>
# include <QKeyEvent>
# include <QRegExp>
# include <QTextStream>
#endif
@@ -69,10 +69,9 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstr
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -330,6 +329,11 @@ std::string TaskFemConstraintTemperature::get_constraint_type(void) const {
return type;
}
bool TaskFemConstraintTemperature::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintTemperature::changeEvent(QEvent *)
{
// TaskBox::changeEvent(e);

View File

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintTemperature;
@@ -65,10 +66,10 @@ private Q_SLOTS:
void setSelection(QListWidgetItem* item);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintTemperature* ui;

View File

@@ -36,9 +36,9 @@
# include <gp_Ax1.hxx>
# include <gp_Lin.hxx>
# include <gp_Pln.hxx>
# include <QMessageBox>
# include <QAction>
# include <QKeyEvent>
# include <QMessageBox>
# include <QRegExp>
# include <QTextStream>
@@ -73,10 +73,9 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
QAction* actionRect = new QAction(tr("Delete"), ui->lw_Rect);
actionRect->connect(actionRect, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_Rect->addAction(actionRect);
ui->lw_Rect->setContextMenuPolicy(Qt::ActionsContextMenu);
// create a context menu for the listview of the references
createDeleteAction(ui->lw_Rect);
deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
connect(ui->lw_Rect, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
@@ -483,6 +482,11 @@ std::string TaskFemConstraintTransform::get_transform_type(void) const {
return transform;
}
bool TaskFemConstraintTransform::event(QEvent *e)
{
return TaskFemConstraint::KeyEvent(e);
}
void TaskFemConstraintTransform::changeEvent(QEvent *){
}

View File

@@ -38,6 +38,7 @@
#include <QObject>
#include <Base/Console.h>
#include <App/DocumentObject.h>
#include <QKeyEvent>
#include <QListWidgetItem>
class Ui_TaskFemConstraintTransform;
@@ -69,11 +70,11 @@ private Q_SLOTS:
void z_Changed(int z);
protected:
bool event(QEvent *e);
void changeEvent(QEvent *e);
const QString makeText(const App::DocumentObject* obj) const;
private:
//void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI();
Ui_TaskFemConstraintTransform* ui;
};