Salome HOME
Copyright update 2022
[modules/gui.git] / src / QDS / QDS_SpinBox.cxx
index d25322c3f0b29b4af6e51d7cba40f21f17abddb4..5add80db58d23e37897f019f17316e7b8ab46152 100644 (file)
@@ -1,10 +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 <qspinbox.h>
-#include <qvalidator.h>
+#include <QtxIntSpinBox.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 )
@@ -12,60 +54,73 @@ 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
 {
   QString res;
-  QSpinBox* aSpinBox = spinBox();
-  if ( aSpinBox )
+  QtxIntSpinBox* aSpinBox = spinBox();
+  if ( aSpinBox && !aSpinBox->isCleared() )
   {
     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 )
 {
-  if ( spinBox() )
+  if ( !spinBox() )
+    return;
+
+  spinBox()->setCleared( txt.isEmpty() );
+  if ( !txt.isEmpty() )
     spinBox()->setValue( txt.toInt() );
 }
 
 /*!
-  Returns pointer to QSpinBox widget.
+  \brief Get spin box widget.
+  \return internal spin box widget.
 */
-QSpinBox* QDS_SpinBox::spinBox() const
+QtxIntSpinBox* QDS_SpinBox::spinBox() const
 {
-  return ::qt_cast<QSpinBox*>( 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 )
 {
-  QSpinBox* aSpinBox = new QSpinBox( parent );
+  QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
   return aSpinBox;
 }
 
 /*!
-  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 )
 {
@@ -76,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 )
 {
@@ -105,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() );
+
   }
 }