From 176e24c3f6e64278d951a24a86d613f27aedbffd Mon Sep 17 00:00:00 2001 From: Konstantin Leontev Date: Mon, 29 Apr 2024 21:57:00 +0100 Subject: [PATCH] [bos #40650][CEA 33012] Beta Law distribution (SMESH). Updated DoubleSpinBox for more flexible using as a parent: show tooltip on validation moved into virtual method, check range now is virtual. --- src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 78 +++++++++++++---------- src/SalomeApp/SalomeApp_DoubleSpinBox.h | 4 +- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index c9d8b6351..dcdc6c1fa 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -258,42 +258,9 @@ QValidator::State SalomeApp_DoubleSpinBox::validate( QString& str, int& pos ) co // Show tooltip in case of invalid manual input if ( isShowTipOnValidate() && lineEdit()->hasFocus() ){ - if ( res != QValidator::Acceptable ){ // san: do we need to warn the user in Intermediate state??? - SalomeApp_DoubleSpinBox* that = const_cast( this ); - QPoint pos( size().width(), 0. ); - QPoint globalPos = mapToGlobal( pos ); - QString minVal = textFromValue( minimum() ); - QString maxVal = textFromValue( maximum() ); - - // Same stuff as in QtxDoubleSpinBox::textFromValue() - int digits = getPrecision(); - - // For 'g' format, max. number of digits after the decimal point is getPrecision() - 1 - // See also QtxDoubleSpinBox::validate() - if ( digits < 0 ) - digits = qAbs( digits ) - 1; - - QString templ( isAcceptNames() ? tr( "VALID_RANGE_VAR_MSG" ) : tr( "VALID_RANGE_NOVAR_MSG" ) ); - QString msg( templ.arg( minVal ).arg( maxVal ).arg( digits ) ); - - // Add extra hints to the message (if any passed through dynamic properties) - QVariant propVal = property( "validity_tune_hint" ); - if ( propVal.isValid() ){ - QString extraInfo = propVal.toString(); - if ( !extraInfo.isEmpty() ){ - msg += "\n"; - msg += extraInfo; - } - } - - QToolTip::showText( globalPos, - msg, - that ); - } - else - QToolTip::hideText(); + showValidationToolTip(res); } - + return res; } @@ -459,6 +426,47 @@ SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( cons return NotFound; } +void SalomeApp_DoubleSpinBox::showValidationToolTip(const QValidator::State state) const +{ + // san: do we need to warn the user in Intermediate state??? + if ( state == QValidator::Acceptable ) + { + QToolTip::hideText(); + return; + } + + SalomeApp_DoubleSpinBox* that = const_cast( this ); + QPoint pos( size().width(), 0. ); + QPoint globalPos = mapToGlobal( pos ); + QString minVal = textFromValue( minimum() ); + QString maxVal = textFromValue( maximum() ); + + // Same stuff as in QtxDoubleSpinBox::textFromValue() + int digits = getPrecision(); + + // For 'g' format, max. number of digits after the decimal point is getPrecision() - 1 + // See also QtxDoubleSpinBox::validate() + if ( digits < 0 ) + digits = qAbs( digits ) - 1; + + QString templ( isAcceptNames() ? tr( "VALID_RANGE_VAR_MSG" ) : tr( "VALID_RANGE_NOVAR_MSG" ) ); + QString msg( templ.arg( minVal ).arg( maxVal ).arg( digits ) ); + + // Add extra hints to the message (if any passed through dynamic properties) + QVariant propVal = property( "validity_tune_hint" ); + if ( propVal.isValid() ){ + QString extraInfo = propVal.toString(); + if ( !extraInfo.isEmpty() ){ + msg += "\n"; + msg += extraInfo; + } + } + + QToolTip::showText( globalPos, + msg, + that ); +} + /*! \brief This function is called when the spinbox recieves key press event. */ diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h index b40cab664..7a9889360 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.h +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -71,10 +71,12 @@ protected: State isValid( const QString&, double& ) const; double defaultValue() const; - bool checkRange( const double ) const; + virtual bool checkRange( const double ) const; SearchState findVariable( const QString&, double& ) const; + virtual void showValidationToolTip(const QValidator::State state) const; + protected: virtual void keyPressEvent( QKeyEvent* ); virtual void showEvent( QShowEvent* ); -- 2.39.2