Salome HOME
Copyright update 2022
[modules/gui.git] / src / QDS / QDS.cxx
index fb1cdae2448ec31ca1181cfee38d4c587d2517d2..ef75b071b6444eae30b6da662831ea83ca5c7d6e 100644 (file)
@@ -1,11 +1,14 @@
-// Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
+// 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.
+// 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
+// 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.
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "QDS.h"
 
 #include "QDS_Datum.h"
 
-#include <qtextcodec.h>
+#include <QTextCodec>
 
 #include <DDS_DicItem.h>
 #include <DDS_Dictionary.h>
 
-#include <TCollection_HAsciiString.hxx>
-#include <TCollection_HExtendedString.hxx>
+QList<QDS_Datum*> QDS::_datumList;
 
-QValueList<QDS_Datum*> QDS::_datumList;
+/*!
+  \class QDS
+  \brief A set of usefull static functions.
+*/
 
 /*!
-  Convert the OpenCascade ascii string to Qt string.
+  \brief Convert the OpenCascade ASCII string to Qt string.
+  \param src OCC ASCII string
+  \return Qt string
 */
 QString QDS::toQString( const TCollection_AsciiString& src )
 {
@@ -44,7 +52,9 @@ QString QDS::toQString( const TCollection_AsciiString& src )
 }
 
 /*!
-  Convert the OpenCascade unicode string to Qt string.
+  \brief Convert the OpenCascade Unicode string to Qt string.
+  \param src OCC Unicode string
+  \return Qt string
 */
 QString QDS::toQString( const TCollection_ExtendedString& src )
 {
@@ -55,50 +65,57 @@ QString QDS::toQString( const TCollection_ExtendedString& src )
 }
 
 /*!
-  Convert the OpenCascade ascii string to Qt string.
+  \brief Convert the OpenCascade ASCII string to Qt string.
+  \param src handle to OCC ASCII string
+  \return Qt string
 */
 QString QDS::toQString( const Handle(TCollection_HAsciiString)& src )
 {
   if ( src.IsNull() )
-    return QString::null;
+    return QString();
   else
     return toQString( src->String() );
 }
 
 /*!
-  Convert the OpenCascade unicode string to Qt string.
+  \brief Convert the OpenCascade Unicode string to Qt string.
+  \param src handle to OCC Unicode string
+  \return Qt string
 */
 QString QDS::toQString( const Handle(TCollection_HExtendedString)& src )
 {
   if ( src.IsNull() )
-    return QString::null;
+    return QString();
   else
     return toQString( src->String() );
 }
 
 /*!
-  Convert the Qt string to OpenCascade ascii string.
+  \brief Convert the Qt string to OpenCascade ASCII string.
+  \param src Qt string
+  \return OCC ASCII string
 */
 TCollection_AsciiString QDS::toAsciiString( const QString& src )
 {
   TCollection_AsciiString res;
-  if ( src.latin1() )
+  if ( src.toLatin1().constData() )
   {
     QTextCodec* codec = QTextCodec::codecForLocale();
     if ( codec )
     {
-      int len = -1;
-      QCString str = codec->fromUnicode( src, len );
-      res = TCollection_AsciiString( (Standard_CString)(const char*)str, len );
+      QByteArray str = codec->fromUnicode( src );
+      res = TCollection_AsciiString( (Standard_CString)(const char*)str, str.size() );
     }
     else
-      res = TCollection_AsciiString( (char*)src.latin1() );
+      res = TCollection_AsciiString( (char*)src.toLatin1().constData() );
   }
   return res;
 }
 
 /*!
-  Convert the OpenCascade unicode string to OpenCascade ascii string.
+  \brief Convert the OpenCascade Unicode string to OpenCascade ASCII string.
+  \param src OCC Unicode string
+  \return OCC ASCII string
 */
 TCollection_AsciiString QDS::toAsciiString( const TCollection_ExtendedString& src )
 {
@@ -106,7 +123,9 @@ TCollection_AsciiString QDS::toAsciiString( const TCollection_ExtendedString& sr
 }
 
 /*!
-  Convert the OpenCascade unicode string to OpenCascade ascii string.
+  \brief Convert the OpenCascade Unicode string to OpenCascade ASCII string.
+  \param src handle to OCC Unicode string
+  \return OCC ASCII string
 */
 TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedString)& src )
 {
@@ -117,7 +136,9 @@ TCollection_AsciiString QDS::toAsciiString( const Handle(TCollection_HExtendedSt
 }
 
 /*!
-  Convert the Qt string to OpenCascade unicode string.
+  \brief Convert the Qt string to OpenCascade Unicode string.
+  \param src Qt string
+  \return OCC Unicode string
 */
 TCollection_ExtendedString QDS::toExtString( const QString& src )
 {
@@ -125,7 +146,7 @@ TCollection_ExtendedString QDS::toExtString( const QString& src )
     return TCollection_ExtendedString();
 
   Standard_Integer len = src.length();
-  Standard_ExtString extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
+  Standard_ExtCharacter* extStr = new Standard_ExtCharacter[( len + 1 ) * 2];
   memcpy( extStr, src.unicode(), len * 2 );
   extStr[len] = 0;
 
@@ -137,7 +158,9 @@ TCollection_ExtendedString QDS::toExtString( const QString& src )
 }
 
 /*!
-  Convert the OpenCascade ascii string to OpenCascade unicode string.
+  \brief Convert the OpenCascade ASCII string to OpenCascade Unicode string.
+  \param src OCC ASCII string
+  \return OCC Unicode string
 */
 TCollection_ExtendedString QDS::toExtString( const TCollection_AsciiString& src )
 {
@@ -145,8 +168,8 @@ TCollection_ExtendedString QDS::toExtString( const TCollection_AsciiString& src
 }
 
 /*!
-  Load datum definitions in the dictionary from XML file \adictPath.
-  Returns true if load successed or false otherwise.
+  \brief Load datum definitions from XML file \a dictPath to the dictionary.
+  \return \c true if loading is successed or \c false otherwise.
 */
 bool QDS::load( const QString& dictPath )
 {
@@ -157,9 +180,15 @@ bool QDS::load( const QString& dictPath )
 }
 
 /*!
-  Returns the label of unit system \asys. If component \acomp specified and not empty then
-  function find the given unit system in the given component otherwise all components will be searched.
-  If unit system not found then empty string returned.
+  \brief Get the label of unit system \a sys.
+
+  If component \a comp is specified and not empty then the function 
+  searches the given unit system in the specified component, otherwise 
+  all components will be searched.
+
+  \param sys unit system
+  \param comp component
+  \return unit system lavel or empty string if unit system is not found
 */
 QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
 {
@@ -173,9 +202,16 @@ QString QDS::unitSystemLabel( const QString& sys, const QString& comp )
 }
 
 /*!
-  Gets the name of active unit system from the specified component \acomp.
-  If component not specified or component is empty string then first got component will be used.
-  If component exist then active unit system name returned or empty string otherwise.
+  \brief Get the name of active unit system from the specified component \a comp.
+
+  If component is not specified or empty string, then the first found 
+  component will be used.
+  
+  If component exists, then active unit system name is returned. Otherwise, 
+  empty string is returned.
+  
+  \param comp component
+  \return name of the active unit system
 */
 QString QDS::activeUnitSystem( const QString& comp )
 {
@@ -188,11 +224,18 @@ QString QDS::activeUnitSystem( const QString& comp )
 }
 
 /*!
-  Sets the active unit system named \asys. If not empty component name \acomp specified then
-  unit system will be activated in the given component otherwise all components will be processed.
+  \brief Set the active unit system.
+
+  If not empty component name \a comp is specified, then the unit system
+  will be activated in the given component, otherwise all components 
+  will be processed.
+
+  After the changing of active unit system function notifies about it all
+  registered datums from processed components using method 
+  QDS_Datum::unitSystemChanged()
 
-  After the changing of active unit system function notify about it to all registered datums
-  from processed components using method QDS_Datum::unitSystemChanged();
+  \param unit system to be set active
+  \param comp component
 */
 void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
 {
@@ -209,7 +252,7 @@ void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
     return;
 
   TCollection_AsciiString aComp = toAsciiString( comp );
-  for ( QValueList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
+  for ( QList<QDS_Datum*>::iterator it = _datumList.begin(); it != _datumList.end(); ++it )
   {
     QDS_Datum* datum = *it;
     if ( !datum )
@@ -228,8 +271,11 @@ void QDS::setActiveUnitSystem( const QString& sys, const QString& comp )
 }
 
 /*!
-  Register given datum \adatum in the static list.
-  This function invoked by QDS_Datum constructor.
+  \brief Register given datum \a datum in the global list.
+  
+  This function is invoked automatically by QDS_Datum constructor.
+  
+  \param datum datum being registered
 */
 void QDS::insertDatum( QDS_Datum* datum )
 {
@@ -240,13 +286,16 @@ void QDS::insertDatum( QDS_Datum* datum )
 }
 
 /*!
-  Remove given datum \adatum from the static list.
-  This function invoked by QDS_Datum destructor.
+  \brief Remove given datum \a datum from the global list.
+
+  This function is invoked automatically by QDS_Datum destructor.
+
+  \param datum datum being unregistered
 */
 void QDS::removeDatum( QDS_Datum* datum )
 {
   if ( !datum )
     return;
 
-  _datumList.remove( datum );
+  _datumList.removeAt( _datumList.indexOf(datum) );
 }