Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add method to check if double-spinbox value is being edited #1219

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Libs/Widgets/ctkDoubleSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <QStyleOptionSpinBox>
#include <QVariant>

//------------------------------------------------------------------------------
CTK_GET_CPP(ctkDoubleSpinBox, bool, isSettingValue, IsSettingValue)

//-----------------------------------------------------------------------------
// ctkQDoubleSpinBox
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -187,6 +190,7 @@ ctkDoubleSpinBoxPrivate::ctkDoubleSpinBoxPrivate(ctkDoubleSpinBox& object)
this->InputRange[0] = 0.;
this->InputRange[1] = 99.99;
this->ForceInputValueUpdate = false;
this->IsSettingValue = false;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -285,6 +289,8 @@ int ctkDoubleSpinBoxPrivate::decimalsForValue(double value) const
void ctkDoubleSpinBoxPrivate::setValue(double value, int dec)
{
Q_Q(ctkDoubleSpinBox);
bool wasSettingValue = this->IsSettingValue;
this->IsSettingValue = true;
dec = this->boundDecimals(dec);
const bool changeDecimals = dec != q->decimals();
if (changeDecimals)
Expand Down Expand Up @@ -316,6 +322,7 @@ void ctkDoubleSpinBoxPrivate::setValue(double value, int dec)
this->CachedMinimumSizeHint = QSize();
q->updateGeometry();
}
this->IsSettingValue = wasSettingValue;
}

//-----------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions Libs/Widgets/ctkDoubleSpinBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class CTK_WIDGETS_EXPORT ctkDoubleSpinBox : public QWidget
/// SizeHintByMinMax by default
/// SizeHintPolicy, sizeHintPolicy(), setSizeHintPolicy()
Q_PROPERTY(SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
/// This property is true while the spinbox is setting a value.
/// \sa isSettingValue()
Q_PROPERTY(bool isSettingValue READ isSettingValue)

public:

Expand Down Expand Up @@ -319,6 +322,14 @@ public Q_SLOTS:
/// \sa isReadOnly
void setReadOnly(bool readOnly);

/// Return true if the spinbox is in the progress of setting a value.
///
/// Setting of value is performed in two steps: first the value is set in the spinbox
/// and then the valueChanged and decimalsChanged signals are emitted.
/// During this entire time, isSettingValue() returns true, because in some cases
/// it is important to know which of the sibling widgets initiated an update.
bool isSettingValue()const;

Q_SIGNALS:
/// Emitted every time the spinbox value is modified
/// \sa QDoubleSpinBox::valueChanged()
Expand Down
2 changes: 2 additions & 0 deletions Libs/Widgets/ctkDoubleSpinBox_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class ctkDoubleSpinBoxPrivate: public QObject
mutable QSize CachedMinimumSizeHint;
bool ForceInputValueUpdate;

bool IsSettingValue;

QPointer<ctkValueProxy> Proxy;

void init();
Expand Down
7 changes: 7 additions & 0 deletions Libs/Widgets/ctkSliderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,10 @@ void ctkSliderWidget::onValueProxyModified()
d->SpinBox->setValue(d->Slider->value());
Q_ASSERT(d->equal(d->SpinBox->value(),d->Slider->value()));
}

// --------------------------------------------------------------------------
bool ctkSliderWidget::isSettingValueFromSpinBox()const
{
Q_D(const ctkSliderWidget);
return d->SpinBox->isSettingValue();
}
3 changes: 3 additions & 0 deletions Libs/Widgets/ctkSliderWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ class CTK_WIDGETS_EXPORT ctkSliderWidget : public QWidget
virtual void setValueProxy(ctkValueProxy* proxy);
virtual ctkValueProxy* valueProxy() const;

/// Return true if a value is currently being set in the spinbox.
bool isSettingValueFromSpinBox()const;

public Q_SLOTS:
///
/// Reset the slider and spinbox to zero (value and position)
Expand Down
Loading