From 27c824c4f5a761d2359c60b3304081c38842ff0f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:16:38 +0200 Subject: [PATCH] Cleanup use of slider tools --- .../cafPdmUiDoubleSliderEditor.cpp | 74 +------------------ .../cafPdmUiDoubleSliderEditor.h | 7 +- 2 files changed, 4 insertions(+), 77 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp index f3dd01e153..890e8a7005 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp @@ -44,36 +44,6 @@ #include #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class PdmDoubleValidator : public QDoubleValidator -{ -public: - explicit PdmDoubleValidator( QObject* parent = nullptr ) - : QDoubleValidator( parent ) - { - } - - PdmDoubleValidator( double bottom, double top, int decimals, QObject* parent ) - : QDoubleValidator( bottom, top, decimals, parent ) - { - } - - ~PdmDoubleValidator() override {} - - //-------------------------------------------------------------------------------------------------- - /// - //-------------------------------------------------------------------------------------------------- - void fixup( QString& stringValue ) const override - { - double doubleValue = stringValue.toDouble(); - doubleValue = qBound( bottom(), doubleValue, top() ); - - stringValue = QString::number( doubleValue, 'g', decimals() ); - } -}; - namespace caf { CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT( PdmUiDoubleSliderEditor ); @@ -126,7 +96,7 @@ void PdmUiDoubleSliderEditor::configureAndUpdateUi( const QString& uiConfigName m_lineEdit->setText( textValue ); m_sliderValue = doubleValue; - updateSliderPosition( doubleValue ); + PdmUiSliderTools::updateSliderPosition( m_slider, doubleValue, m_attributes ); } //-------------------------------------------------------------------------------------------------- @@ -182,7 +152,7 @@ void PdmUiDoubleSliderEditor::slotEditingFinished() //-------------------------------------------------------------------------------------------------- void PdmUiDoubleSliderEditor::slotSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( value ); + double newDoubleValue = PdmUiSliderTools::convertFromSliderValue( m_slider, value, m_attributes ); m_sliderValue = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -203,20 +173,6 @@ void PdmUiDoubleSliderEditor::slotSliderReleased() writeValueToField( m_sliderValue ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void PdmUiDoubleSliderEditor::updateSliderPosition( double value ) -{ - int newSliderPosition = convertToSliderValue( value ); - if ( m_slider->value() != newSliderPosition ) - { - m_slider->blockSignals( true ); - m_slider->setValue( newSliderPosition ); - m_slider->blockSignals( false ); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -226,30 +182,4 @@ void PdmUiDoubleSliderEditor::writeValueToField( double value ) this->setValueToField( v ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int PdmUiDoubleSliderEditor::convertToSliderValue( double value ) -{ - double exactSliderValue = - m_slider->maximum() * ( value - m_attributes.m_minimum ) / ( m_attributes.m_maximum - m_attributes.m_minimum ); - - int sliderValue = static_cast( exactSliderValue + 0.5 ); - sliderValue = qBound( m_slider->minimum(), sliderValue, m_slider->maximum() ); - - return sliderValue; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double PdmUiDoubleSliderEditor::convertFromSliderValue( int sliderValue ) -{ - double newDoubleValue = m_attributes.m_minimum + - sliderValue * ( m_attributes.m_maximum - m_attributes.m_minimum ) / m_slider->maximum(); - newDoubleValue = qBound( m_attributes.m_minimum, newDoubleValue, m_attributes.m_maximum ); - - return newDoubleValue; -} - } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h index 661b7fc601..34c73c5b6b 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h @@ -44,7 +44,8 @@ #include #include #include -#include + +class QWidget; namespace caf { @@ -72,12 +73,8 @@ protected slots: void slotSliderReleased(); private: - void updateSliderPosition( double value ); void writeValueToField( double value ); - int convertToSliderValue( double value ); - double convertFromSliderValue( int sliderValue ); - private: QPointer m_lineEdit; QPointer m_slider;