Salome HOME
[bos #40650][CEA 33012] Beta Law distribution (SMESH). Updated DoubleSpinBox for... kleontev/40650_Beta_Law_distribution 27/head
authorKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Mon, 29 Apr 2024 20:57:00 +0000 (21:57 +0100)
committerKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Mon, 13 May 2024 13:50:55 +0000 (14:50 +0100)
src/SalomeApp/SalomeApp_DoubleSpinBox.cxx
src/SalomeApp/SalomeApp_DoubleSpinBox.h

index c9d8b6351b3df312470c28d8f8a79e72d80c5254..dcdc6c1fa0624ec53faf2e7fe2a2206bbe502459 100644 (file)
@@ -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<SalomeApp_DoubleSpinBox*>( 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<SalomeApp_DoubleSpinBox*>( 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.
 */
index b40cab6642bbabc511c486a5bd0b761b35e76e77..7a9889360d046722b8db2c26df3d0896aa851795 100644 (file)
@@ -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* );