Salome HOME
Copyright update 2022
[modules/gui.git] / src / QDS / QDS_SpinBox.cxx
index b77aa8ba0759b8f0e85ad3dcd1d622b05a782ae8..5add80db58d23e37897f019f17316e7b8ab46152 100644 (file)
@@ -1,11 +1,52 @@
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "QDS_SpinBox.h"
 
 #include <QtxIntSpinBox.h>
 
-#include <qvalidator.h>
+/*
+  \class QDS_SpinBox
+  \brief Datum with control corresponding to spin box.
+
+  This control used for integer numbers. User can input data directly in the spin box
+  or can modify current value by clicking arrow (+/-) buttons.
+*/
 
 /*!
-  Constructor.
+  \brief Constructor. 
+
+  Create spin box datum object with datum identifier \a id and parent widget \a parent.
+
+  Parameter \a flags defines behaviour of datum and set of created
+  subwidgets. Default value of this parameter is QDS::All.
+
+  Parameter \a comp specifies the component name which will be used
+  when searching the dictionary item.
+
+  \param id datum identifier
+  \param parent parent widget
+  \param flags datum flags
+  \param comp component
 */
 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
 : QDS_Datum( id, parent, flags, comp )
@@ -13,14 +54,15 @@ QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, c
 }
 
 /*!
-  Destructor.
+  \brief Destructor.
 */
 QDS_SpinBox::~QDS_SpinBox()
 {
 }
 
 /*!
-  Returns string from QSpinBox widget.
+  \brief Get string from the spin box.
+  \return string value
 */
 QString QDS_SpinBox::getString() const
 {
@@ -30,15 +72,16 @@ QString QDS_SpinBox::getString() const
   {
     res = aSpinBox->text();
     if ( !aSpinBox->suffix().isEmpty() )
-      res.remove( res.find( aSpinBox->suffix() ), aSpinBox->suffix().length() );
+      res.remove( res.indexOf( aSpinBox->suffix() ), aSpinBox->suffix().length() );
     if ( !aSpinBox->prefix().isEmpty() )
-      res.remove( res.find( aSpinBox->prefix() ), aSpinBox->prefix().length() );
+      res.remove( res.indexOf( aSpinBox->prefix() ), aSpinBox->prefix().length() );
   }
   return res;
 }
 
 /*!
-  Sets the string into QSpinBox widget.
+  \brief Set the string value to the spin box widget.
+  \param txt string value
 */
 void QDS_SpinBox::setString( const QString& txt )
 {
@@ -51,15 +94,18 @@ void QDS_SpinBox::setString( const QString& txt )
 }
 
 /*!
-  Returns pointer to QSpinBox widget.
+  \brief Get spin box widget.
+  \return internal spin box widget.
 */
 QtxIntSpinBox* QDS_SpinBox::spinBox() const
 {
-  return ::qt_cast<QtxIntSpinBox*>( controlWidget() );
+  return ::qobject_cast<QtxIntSpinBox*>( controlWidget() );
 }
 
 /*!
-  Create QSpinBox widget as control subwidget.
+  \brief Create internal spin box as control widget.
+  \param parent parent widget
+  \return created spin box widget
 */
 QWidget* QDS_SpinBox::createControl( QWidget* parent )
 {
@@ -70,7 +116,11 @@ QWidget* QDS_SpinBox::createControl( QWidget* parent )
 }
 
 /*!
-  Notify about text changing in spin box.
+  \brief Called when value in the spin box is changed.
+
+  Emit signals to notify  about value changing in the spin box.
+
+  \param val current spin box value
 */
 void QDS_SpinBox::onValueChanged( int val )
 {
@@ -81,27 +131,33 @@ void QDS_SpinBox::onValueChanged( int val )
 }
 
 /*!
-  Sets the increment step.
+  \brief Set the spin box increment value.
+  \param step new increment value
 */
 void QDS_SpinBox::setStep( const int step )
 {
   if ( spinBox() )
-    spinBox()->setLineStep( step );
+    spinBox()->setSingleStep( step );
 }
 
 /*!
-  Returns the increment step.
+  \brief Get the spin box increment value.
+  \return current increment value
 */
 int QDS_SpinBox::step() const
 {
   int s = 0;
   if ( spinBox() )
-    s = spinBox()->lineStep();
+    s = spinBox()->singleStep();
   return s;
 }
 
 /*!
-  This method is redefined from ancestor class to perform own initialization ( suffix, prefix, etc ).
+  \brief Process notification about active units system changing.
+
+  Update spin box contents according to the data dictionary item properties: suffix, prefix, minimum, maximum
+  
+  \param system new active units system
 */
 void QDS_SpinBox::unitSystemChanged( const QString& system )
 {
@@ -110,13 +166,16 @@ void QDS_SpinBox::unitSystemChanged( const QString& system )
   QSpinBox* sb = spinBox();
   if ( sb )
   {
-    delete sb->validator();
-    QValidator* valid = validator();
-    sb->setValidator( valid );
+    // not porting this code to qt4, only commented, since from the task context
+    // the new setted validator accepts all integers
+    //delete sb->validator();
+    //QValidator* valid = validator();
+    //sb->setValidator( valid );
 
     sb->setSuffix( suffix() );
     sb->setPrefix( prefix() );
-    sb->setMinValue( minValue().toInt() );
-    sb->setMaxValue( maxValue().toInt() );
+    sb->setMinimum( minValue().isEmpty() ? -INT_MAX : minValue().toInt() );
+    sb->setMaximum( maxValue().isEmpty() ? INT_MAX : maxValue().toInt() );
+
   }
 }