From ad3a26a272004b77c5c21f756f2bf24672db56b0 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Thu, 21 Apr 2022 13:33:22 +0200 Subject: [PATCH] fixed bug #50 JKQtPlotter::clearAllRegisteredMouseDoubleClickActions(), JKQtPlotter::clearAllMouseWheelActions(), JKQtPlotter::clearAllRegisteredMouseDragActions() didn't really deactivate all actions --- lib/jkqtplotter/jkqtplotter.cpp | 57 ++++++++++++++++++--------------- lib/jkqtplotter/jkqtplotter.h | 4 +-- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/lib/jkqtplotter/jkqtplotter.cpp b/lib/jkqtplotter/jkqtplotter.cpp index cc4e8aba24..5822d06280 100644 --- a/lib/jkqtplotter/jkqtplotter.cpp +++ b/lib/jkqtplotter/jkqtplotter.cpp @@ -880,9 +880,9 @@ void JKQTPlotter::resetCurrentMouseDragAction () { } void JKQTPlotter::mouseDoubleClickEvent ( QMouseEvent * event ){ - - auto itAction=findMatchingMouseDoubleClickAction(event->button(), event->modifiers()); - if (itAction!=plotterStyle.registeredMouseDoubleClickActions.end()) { + bool foundIT=false; + JKQTPMouseDoubleClickActionsHashMapIterator itAction=findMatchingMouseDoubleClickAction(event->button(), event->modifiers(), &foundIT); + if (foundIT) { // we found an action to perform on this double-click if (itAction.value()==JKQTPMouseDoubleClickActions::jkqtpdcaClickOpensContextMenu) { openStandardContextMenu(event->x(), event->y()); @@ -957,11 +957,12 @@ void JKQTPlotter::wheelEvent ( QWheelEvent * event ) { #endif //qDebug()<<"wheelEvent("<modifiers()<<"): plotterStyle.registeredMouseWheelActions="<modifiers()); + bool foundIT=false; + auto itAction=findMatchingMouseWheelAction(event->modifiers(), &foundIT); //qDebug()<<"wheelEvent("<modifiers()<<"): plotterStyle.registeredMouseWheelActions="<modifiers()<<"): itAction="<modifiers()<<"):ZoomByWheel"; @@ -1682,40 +1683,44 @@ void JKQTPlotter::openStandardAndSpecialContextMenu(int x, int y) JKQTPMouseDragActionsHashMapIterator JKQTPlotter::findMatchingMouseDragAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers, bool* found) const { - JKQTPMouseDragActionsHashMapIterator it=registeredOverrideMouseDragActionModes.begin(); - while (it!=registeredOverrideMouseDragActionModes.end() ) { - if (it.key()==qMakePair(button, modifiers)) { - if (found) *found=true; - return it; - } - ++it; - } - it=plotterStyle.registeredMouseDragActionModes.begin(); - while (it!=plotterStyle.registeredMouseDragActionModes.end() ) { - if (it.key()==qMakePair(button, modifiers)) { - if (found) *found=true; - return it; - } - ++it; - } if (found) *found=false; - return plotterStyle.registeredMouseDragActionModes.end(); + JKQTPMouseDragActionsHashMapIterator it=registeredOverrideMouseDragActionModes.cbegin(); + while (it!=registeredOverrideMouseDragActionModes.cend() ) { + if (it.key()==qMakePair(button, modifiers)) { + if (found) *found=true; + return it; + } + ++it; + } + it=plotterStyle.registeredMouseDragActionModes.cbegin(); + while (it!=plotterStyle.registeredMouseDragActionModes.cend() ) { + if (it.key()==qMakePair(button, modifiers)) { + if (found) *found=true; + return it; + } + ++it; + } + return plotterStyle.registeredMouseDragActionModes.cend(); } -JKQTPMouseDoubleClickActionsHashMapIterator JKQTPlotter::findMatchingMouseDoubleClickAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers) const +JKQTPMouseDoubleClickActionsHashMapIterator JKQTPlotter::findMatchingMouseDoubleClickAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers, bool*found) const { - for (JKQTPMouseDoubleClickActionsHashMapIterator it=plotterStyle.registeredMouseDoubleClickActions.begin(); it!=plotterStyle.registeredMouseDoubleClickActions.end(); ++it) { + if (found) *found=false; + for (JKQTPMouseDoubleClickActionsHashMapIterator it=plotterStyle.registeredMouseDoubleClickActions.cbegin(); it!=plotterStyle.registeredMouseDoubleClickActions.cend(); ++it) { if (it.key()==qMakePair(button, modifiers)) { + if (found) *found=true; return it; } } - return plotterStyle.registeredMouseDoubleClickActions.end(); + return plotterStyle.registeredMouseDoubleClickActions.cend(); } -JKQTPMouseWheelActionsHashMapIterator JKQTPlotter::findMatchingMouseWheelAction(Qt::KeyboardModifiers modifiers) const +JKQTPMouseWheelActionsHashMapIterator JKQTPlotter::findMatchingMouseWheelAction(Qt::KeyboardModifiers modifiers, bool *found) const { + if (found) *found=false; for (JKQTPMouseWheelActionsHashMapIterator it=plotterStyle.registeredMouseWheelActions.begin(); it!=plotterStyle.registeredMouseWheelActions.end(); ++it) { if (it.key()==modifiers) { + if (found) *found=true; return it; } } diff --git a/lib/jkqtplotter/jkqtplotter.h b/lib/jkqtplotter/jkqtplotter.h index 1025eaaee9..d926d44121 100644 --- a/lib/jkqtplotter/jkqtplotter.h +++ b/lib/jkqtplotter/jkqtplotter.h @@ -1419,10 +1419,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPlotter: public QWidget { JKQTPMouseDragActionsHashMapIterator findMatchingMouseDragAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers, bool *found=nullptr) const; /** \brief searches JKQTPlotterStyle::registeredMouseWheelActions for a matching action */ - JKQTPMouseWheelActionsHashMapIterator findMatchingMouseWheelAction(Qt::KeyboardModifiers modifiers) const; + JKQTPMouseWheelActionsHashMapIterator findMatchingMouseWheelAction(Qt::KeyboardModifiers modifiers, bool *found=nullptr) const; /** \brief searches JKQTPlotterStyle::registeredMouseDoubleClickActions for a matching action */ - JKQTPMouseDoubleClickActionsHashMapIterator findMatchingMouseDoubleClickAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers) const; + JKQTPMouseDoubleClickActionsHashMapIterator findMatchingMouseDoubleClickAction(Qt::MouseButton button, Qt::KeyboardModifiers modifiers, bool *found=nullptr) const; /** \brief you may overwrite this method to modify the given context menu before it is displayed. *