Sketcher: Do not allow mouse interruption while entering dimension (#20925)

* Sketcher: Do not allow mouse interruption while entering dimensions

So, currently user has an option to enter dimensions to different
Sketcher elements like circle, line, or hexagon, whatever else. But, if
they move mouse during entering of those parameters, they are gone.

This is because we are currently allowing for constant
`QAbstractSpinBox` value change during mouse move, it stops changing
ONLY AFTER value is being set (user enters number and presses ENTER
or TAB).

So, this patch introduces one more state for `EditableDatumLabel` which
is `hasFinishedEditing` which is being triggered by ENTER or TAB key,
and still keeping old `isSet` state, which disallows mouse movement
disruption and dynamically updates the edited element on viewport.
This means, that all objects now wait for `hasFinishedEditing` state to
actually finish editing.

* Sketcher: Avoid out of boundary access by checking onViewParameters size

* Sketcher: Add missing Qt headers for CI

* Sketcher: Allow using TAB to switch between labels without accepting

* Sketcher: Change to or statement, so enter will accept both labels

* Sketcher: Apply review comments

* used casting directly in if statement and auto to keep linter happy
* added comments for flags used for describing EditableDatumLabel states
This commit is contained in:
tetektoza
2025-06-02 22:18:42 +02:00
committed by GitHub
parent 997d485124
commit 9b40afea7a
17 changed files with 81 additions and 54 deletions

View File

@@ -31,6 +31,9 @@
# include <Inventor/nodes/SoSwitch.h>
#endif // _PreComp_
#include <QEvent>
#include <QKeyEvent>
#include <Gui/Application.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
@@ -52,6 +55,7 @@ EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view,
bool autoDistance,
bool avoidMouseCursor)
: isSet(false)
, hasFinishedEditing(false)
, autoDistance(autoDistance)
, autoDistanceReverse(false)
, avoidMouseCursor(avoidMouseCursor)
@@ -158,7 +162,8 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool
spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
spinBox->setFocusPolicy(Qt::ClickFocus); // prevent passing focus with tab.
spinBox->setAutoNormalize(false);
spinBox->setKeyboardTracking(false);
spinBox->setKeyboardTracking(true);
spinBox->installEventFilter(this);
if (eventFilteringObj) {
spinBox->installEventFilter(eventFilteringObj);
@@ -190,6 +195,23 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool
connect(spinBox, qOverload<double>(&QuantitySpinBox::valueChanged), this, validateAndFinish);
}
bool EditableDatumLabel::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
auto* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
if (auto* spinBox = qobject_cast<QAbstractSpinBox*>(watched)) {
this->hasFinishedEditing = true;
Q_EMIT this->valueChanged(this->value);
return false;
}
}
}
return QObject::eventFilter(watched, event);
}
void EditableDatumLabel::stopEdit()
{
if (spinBox) {