Skip to content

Commit

Permalink
Eliminating GLWidget::***Pressed bool values
Browse files Browse the repository at this point in the history
Fix for issue ElmerCSC#441 (ElmerGUI: unable to select multiple surfaces ElmerCSC#411) by leveraging MouseEvent::modifiers() instead of these bool variables.
  • Loading branch information
t7saeki committed Jul 22, 2023
1 parent fdd6c58 commit f032fb2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 59 deletions.
28 changes: 4 additions & 24 deletions ElmerGUI/Application/src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ GLWidget::GLWidget(QWidget *parent)
helpers = new Helpers;
meshutils = new Meshutils;

ctrlPressed = false;
shiftPressed = false;
altPressed = false;

// Coordinate axis:
quadric_axis = gluNewQuadric();

Expand Down Expand Up @@ -641,15 +637,7 @@ void GLWidget::focusInEvent(QFocusEvent *event)
//-----------------------------------------------------------------------------
void GLWidget::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
ctrlPressed = true;

if(event->key() == Qt::Key_Shift)
shiftPressed = true;

if((event->key() == Qt::Key_Alt) || (event->key() == Qt::Key_AltGr))
altPressed = true;

if(event->key() == Qt::Key_Escape)
emit(escPressed());
}
Expand All @@ -659,14 +647,6 @@ void GLWidget::keyPressEvent(QKeyEvent *event)
//-----------------------------------------------------------------------------
void GLWidget::keyReleaseEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
ctrlPressed = false;

if(event->key() == Qt::Key_Shift)
shiftPressed = false;

if(event->key() == Qt::Key_Alt)
altPressed = false;
}


Expand Down Expand Up @@ -895,7 +875,7 @@ void GLWidget::mouseDoubleClickEvent(QMouseEvent *event)
l = getList(l->getParent());

// if not ctrl pressed, rebuild all selected lists except this one:
if(!ctrlPressed) {
if(!(event->modifiers() & Qt::ControlModifier)) {
for(i = 0; i < getLists(); i++) {
list_t *l2 = getList(i);
if(l2->isSelected() && (l2->getIndex() != l->getIndex())) {
Expand Down Expand Up @@ -953,7 +933,7 @@ void GLWidget::mouseDoubleClickEvent(QMouseEvent *event)
// body selection:
//----------------
currentlySelectedBody = -1;
if(shiftPressed || bodyEditActive) {
if( (event->modifiers() & Qt::ShiftModifier) || bodyEditActive) {

// determine the max bulk index
int MAX_BULK_INDEX = -1;
Expand Down Expand Up @@ -1057,15 +1037,15 @@ void GLWidget::mouseDoubleClickEvent(QMouseEvent *event)
body_selection_finished:

// Emit result to mainwindow:
emit(signalBoundarySelected(l));
emit(signalBoundarySelected(l, event->modifiers()));

} else {

// Emit "nothing selected":
dummylist.setNature(-1);
dummylist.setType(-1);
dummylist.setIndex(-1);
emit(signalBoundarySelected(&dummylist));
emit(signalBoundarySelected(&dummylist, event->modifiers()));

}

Expand Down
5 changes: 1 addition & 4 deletions ElmerGUI/Application/src/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ class GLWidget : public QGLWidget
bool stateDrawBodyIndex;
bool stateBcColors;
bool stateBodyColors;
bool ctrlPressed;
bool shiftPressed;
bool altPressed;
bool bodyEditActive;
bool stateUseBgImage;
bool stateStretchBgImage;
Expand All @@ -182,7 +179,7 @@ class GLWidget : public QGLWidget
public slots:

signals:
void signalBoundarySelected(list_t*);
void signalBoundarySelected(list_t*, Qt::KeyboardModifiers);
void escPressed();

protected:
Expand Down
22 changes: 6 additions & 16 deletions ElmerGUI/Application/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ MainWindow::MainWindow() {
SLOT(menuBarTriggeredSlot(QAction *)));

// glWidget emits (list_t*) when a boundary is selected by double clicking:
connect(glWidget, SIGNAL(signalBoundarySelected(list_t *)), this,
SLOT(boundarySelectedSlot(list_t *)));
connect(glWidget, SIGNAL(signalBoundarySelected(list_t *, Qt::KeyboardModifiers)), this,
SLOT(boundarySelectedSlot(list_t *, Qt::KeyboardModifiers)));

// glWidget emits (void) when esc has been pressed:
connect(glWidget, SIGNAL(escPressed()), this, SLOT(viewNormalModeSlot()));
Expand Down Expand Up @@ -6099,7 +6099,7 @@ void MainWindow::generateSifSlot() {

// Boundary selected by double clicking (signaled by glWidget::select):
//-----------------------------------------------------------------------------
void MainWindow::boundarySelectedSlot(list_t *l) {
void MainWindow::boundarySelectedSlot(list_t *l, Qt::KeyboardModifiers modifiers) {
QString qs;

if (l->getIndex() < 0) {
Expand Down Expand Up @@ -6131,10 +6131,7 @@ void MainWindow::boundarySelectedSlot(list_t *l) {

// Open bc property sheet for selected boundary:
//-----------------------------------------------
if (l->isSelected() && (glWidget->altPressed || bcEditActive)) {
glWidget->ctrlPressed = false;
glWidget->shiftPressed = false;
glWidget->altPressed = false;
if (l->isSelected() && ((modifiers & Qt::AltModifier) || bcEditActive)) {

if (l->getNature() != PDE_BOUNDARY) {
/*Ignore when double clicking a body of 2D geometry under boundary
Expand Down Expand Up @@ -6186,7 +6183,7 @@ void MainWindow::boundarySelectedSlot(list_t *l) {

// boundary as a body treatment
// ----------------------------
if (l->isSelected() && glWidget->ctrlPressed) {
if (l->isSelected() && (modifiers & Qt::ControlModifier)) {

// renumbering:
int n = glWidget->boundaryMap.value(l->getIndex());
Expand All @@ -6206,9 +6203,6 @@ void MainWindow::boundarySelectedSlot(list_t *l) {
bodyEdit = boundaryEdit->bodyProperties;

if (bodyEdit) {
glWidget->ctrlPressed = false;
glWidget->shiftPressed = false;
glWidget->altPressed = false;

bodyEdit->setWindowTitle("Properties for body " +
QString::number(current));
Expand All @@ -6224,11 +6218,7 @@ void MainWindow::boundarySelectedSlot(list_t *l) {
// Open body property sheet for selected body:
//---------------------------------------------
if ((glWidget->currentlySelectedBody >= 0) &&
(glWidget->shiftPressed || bodyEditActive)) {

glWidget->ctrlPressed = false;
glWidget->shiftPressed = false;
glWidget->altPressed = false;
( (modifiers & Qt::ShiftModifier) || bodyEditActive)) {

current = glWidget->currentlySelectedBody;

Expand Down
2 changes: 1 addition & 1 deletion ElmerGUI/Application/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private slots:
void meshingTerminatedSlot(); // signal emitted by meshingThread
void meshingFinishedSlot(); // signal emitted by meshingThread

void boundarySelectedSlot(list_t *); // signal emitted by glWidget
void boundarySelectedSlot(list_t *, Qt::KeyboardModifiers); // signal emitted by glWidget
void doDivideSurfaceSlot(double); // signal emitted by boundaryDivide
void doDivideEdgeSlot(double); // signal emitted by boundaryDivide

Expand Down
24 changes: 11 additions & 13 deletions ElmerGUI/Application/src/objectbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ ObjectBrowser::ObjectBrowser(QMainWindow *parent, Qt::WindowFlags flags)
connect(mainwindow->edgeUnifyAct, SIGNAL(triggered()), this,
SLOT(boundaryUnifiedSlot()));

connect(mainwindow->glWidget, SIGNAL(signalBoundarySelected(list_t *)), this,
SLOT(boundarySelectedSlot(list_t *)));
connect(mainwindow->glWidget, SIGNAL(signalBoundarySelected(list_t *, Qt::KeyboardModifiers)), this,
SLOT(boundarySelectedSlot(list_t *, Qt::KeyboardModifiers)));

connect(mainwindow->meshingThread, SIGNAL(started()), this,
SLOT(meshingStartedSlot()));
Expand Down Expand Up @@ -407,7 +407,7 @@ void ObjectBrowser::treeItemDoubleClickedSlot(QTreeWidgetItem *item,
mainwindow->glWidget->bodyEditActive = false;
mainwindow->bcEditAct->setChecked(true);
mainwindow->bodyEditAct->setChecked(false);
mainwindow->boundarySelectedSlot(l);
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
// mainwindow->bcEditActive = bcEditActive;
// mainwindow->bodyEditActive = bodyEditActive;
connect1(
Expand Down Expand Up @@ -437,7 +437,7 @@ void ObjectBrowser::treeItemDoubleClickedSlot(QTreeWidgetItem *item,
mainwindow->glWidget->bodyEditActive = false;
mainwindow->bcEditAct->setChecked(true);
mainwindow->bodyEditAct->setChecked(false);
mainwindow->boundarySelectedSlot(l);
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
// mainwindow->bcEditActive = bcEditActive;
// mainwindow->bodyEditActive = bodyEditActive;
connect1(
Expand Down Expand Up @@ -465,7 +465,7 @@ void ObjectBrowser::treeItemDoubleClickedSlot(QTreeWidgetItem *item,
mainwindow->glWidget->bodyEditActive = true;
mainwindow->bcEditAct->setChecked(false);
mainwindow->bodyEditAct->setChecked(true);
mainwindow->boundarySelectedSlot(l);
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
// mainwindow->bcEditActive = bcEditActive;
// mainwindow->bodyEditActive = bodyEditActive;
connect1(pe,
Expand Down Expand Up @@ -503,7 +503,7 @@ void ObjectBrowser::treeItemDoubleClickedSlot(QTreeWidgetItem *item,
mainwindow->glWidget->bodyEditActive = true;
mainwindow->bcEditAct->setChecked(false);
mainwindow->bodyEditAct->setChecked(true);
mainwindow->boundarySelectedSlot(l);
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
// mainwindow->bcEditActive = bcEditActive;
// mainwindow->bodyEditActive = bodyEditActive;
connect1(pe,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ void ObjectBrowser::boundaryDividedSlot(double d) {
boundaryPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
}

void ObjectBrowser::boundarySelectedSlot(list_t *l) {
void ObjectBrowser::boundarySelectedSlot(list_t *l, Qt::KeyboardModifiers modifiers) {

bodyPropertyParentTreeItem->setExpanded(true);
boundaryPropertyParentTreeItem->setExpanded(true);
Expand Down Expand Up @@ -1059,15 +1059,15 @@ void ObjectBrowser::boundarySelectedSlot(list_t *l) {

if (dialog == NULL) {
cout << " could not find selected body/boundary in "
"ObjectBrowser::boundarySelectedSlot(list_t*). list_t:"
"ObjectBrowser::boundarySelectedSlot(list_t*, Qt::KeyboardModifiers). list_t:"
<< (qulonglong)l << endl;
return;
}

for (int i = 0; i < boundaryPropertyParentTreeItem->childCount(); i++) {
QTreeWidgetItem *child = boundaryPropertyParentTreeItem->child(i);
if (child->data(0, Qt::UserRole) == (qulonglong)dialog) {
tree->setCurrentItem(child);
if( !(modifiers & Qt::ControlModifier) )tree->setCurrentItem(child);
BoundaryPropertyEditor *pe = (BoundaryPropertyEditor *)dialog;
connect1(
pe, SIGNAL(BoundaryComboChanged(BoundaryPropertyEditor *, QString)),
Expand All @@ -1083,7 +1083,7 @@ void ObjectBrowser::boundarySelectedSlot(list_t *l) {
for (int i = 0; i < bodyPropertyParentTreeItem->childCount(); i++) {
QTreeWidgetItem *child = bodyPropertyParentTreeItem->child(i);
if (child->data(0, Qt::UserRole) == (qulonglong)dialog) {
tree->setCurrentItem(child);
if( !(modifiers & Qt::ControlModifier)) tree->setCurrentItem(child);
BodyPropertyEditor *pe = (BodyPropertyEditor *)dialog;
connect1(pe,
SIGNAL(BodyMaterialComboChanged(BodyPropertyEditor *, QString)),
Expand Down Expand Up @@ -1747,9 +1747,7 @@ void ObjectBrowser::treeItemSelectionChangedSlot() {
MainWindow *mainwindow = (MainWindow *)mainWindow;
if (mainwindow->glWidget->getMesh() == NULL)
return;
if (mainwindow->glWidget->ctrlPressed)
return; // ignore if selecting multiple surfaces/edges in glWidget to
// maintain the selection at glWidget

QTreeWidgetItem *item = tree->currentItem();

// select boundaries/bodies checked in DyanmicEditor
Expand Down
2 changes: 1 addition & 1 deletion ElmerGUI/Application/src/objectbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private slots:
void boundaryDividedSlot(double);
void boundaryUnifiedSlot();

void boundarySelectedSlot(list_t*);
void boundarySelectedSlot(list_t*, Qt::KeyboardModifiers);

void boundaryComboChanged(BoundaryPropertyEditor *,QString);
void bodyComboChanged(BodyPropertyEditor *,QString);
Expand Down

0 comments on commit f032fb2

Please sign in to comment.