Salome HOME
Show language name in Preferences dialog box.
authorvsr <vsr@opencascade.com>
Tue, 21 Jun 2016 13:05:13 +0000 (16:05 +0300)
committervsr <vsr@opencascade.com>
Tue, 21 Jun 2016 13:05:13 +0000 (16:05 +0300)
src/LightApp/LightApp_Application.cxx
src/Qtx/QtxComboBox.cxx
src/Qtx/QtxComboBox.h
src/Qtx/QtxPagePrefMgr.cxx
src/Qtx/QtxPagePrefMgr.h

index b9ec2df18862eca635d6850ef4aa2598fcb71148..47671d41a1723265e675edcfc56d6713bf803786 100644 (file)
@@ -245,21 +245,23 @@ int LightApp_Application::lastStudyId = 0;
 //since the 'toolbar marker' is not unique, find index of first occurrence of the
 //'toolbar marker' in the array and check that next string is name of the toolbar
 
-int getToolbarMarkerIndex(QByteArray input, const QStringList& aFlags) {
-  int aResult = -1,tmp = 0;
-  int inputLen = input.length();
-  QDataStream anInputData(&input, QIODevice::ReadOnly);
-  while(tmp < inputLen) {
-      tmp = input.indexOf(QToolBarMarker, tmp + 1);
-      if(tmp < 0 )
+namespace
+{
+  int getToolbarMarkerIndex( QByteArray input, const QStringList& aFlags ) {
+    int aResult = -1,tmp = 0;
+    int inputLen = input.length();
+    QDataStream anInputData( &input, QIODevice::ReadOnly );
+    while ( tmp < inputLen ) {
+      tmp = input.indexOf( QToolBarMarker, tmp + 1 );
+      if ( tmp < 0 )
        break;
-      anInputData.device()->seek(tmp);
+      anInputData.device()->seek( tmp );
       uchar mark;
-      anInputData>>mark;
+      anInputData >> mark;
       int lines;
       anInputData >> lines;
 
-      if(lines == 0 && anInputData.atEnd()){
+      if ( lines == 0 && anInputData.atEnd() ) {
        //Case then array doesn't contain information about toolbars,
        aResult = tmp;
        break;
@@ -270,13 +272,26 @@ int getToolbarMarkerIndex(QByteArray input, const QStringList& aFlags) {
       int cnt;
       anInputData >> cnt;
       QString str;
-      anInputData>>str;
-      if(aFlags.contains(str)) {
+      anInputData >> str;
+      if ( aFlags.contains( str ) ) {
        aResult = tmp;
        break;
       }
     }        
-  return aResult;
+    return aResult;
+  }
+
+  QString langToName( const QString& lang )
+  {
+    // special processing for English language to avoid such result as "American English"
+    // as Qt cannot just say "English"
+    QString result;
+    if ( lang == "en" )
+      result = "English";
+    else
+      result = QLocale( lang ).nativeLanguageName();
+    return result;
+  }
 }
 
 /*!
@@ -2219,10 +2234,15 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
                                           LightApp_Preferences::Selector, "language", "language" );
   QStringList aLangs = SUIT_Session::session()->resourceMgr()->stringValue( "language", "languages", "en" ).split( "," );
   QList<QVariant> aIcons;
+  QList<QVariant> aNumbers;
+  QStringList aTitles;
   foreach ( QString aLang, aLangs ) {
     aIcons << QPixmap( QString( ":/images/%1" ).arg( aLang ) );
+    aNumbers << aLang;
+    aTitles << langToName( aLang );
   }
-  pref->setItemProperty( "strings", aLangs, curLang );
+  pref->setItemProperty( "strings", aTitles, curLang );
+  pref->setItemProperty( "ids",     aNumbers, curLang );
   pref->setItemProperty( "icons",   aIcons, curLang );
   pref->setItemProperty( "restart",  true, curLang );
 
index a0b3b09a824382686c8ab2768be43c9509a78b43..c9da713acbe8177eb9b7dd6f7ac84ab5b077c23a 100755 (executable)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-
 // File:      QtxComboBox.cxx
 // Author:    Sergey TELKOV
-//
+
 #include "QtxComboBox.h"
 
 #include <QStandardItemModel>
@@ -49,7 +48,7 @@ private:
 };
 
 /*!
-  \brief Constructor
+  \brief Constructor.
   \internal
   \param parent parent object
 */
@@ -60,7 +59,7 @@ QtxComboBox::Model::Model( QObject* parent )
 }
 
 /*!
-  \brief Destructor
+  \brief Destructor.
   \internal
 */
 QtxComboBox::Model::~Model()
@@ -68,7 +67,7 @@ QtxComboBox::Model::~Model()
 }
 
 /*!
-  \brief Set 'cleared' state
+  \brief Set 'cleared' state.
   \param isClear new 'cleared' state
   \internal
 */
@@ -84,7 +83,7 @@ void QtxComboBox::Model::setCleared( const bool isClear )
   \brief Get model data.
   \param index model index
   \param role data role
-  \return data of role \a role for the \a index
+  \return data of \a role for given \a index
   \internal
 */
 QVariant QtxComboBox::Model::data( const QModelIndex& index, int role ) const
@@ -96,7 +95,7 @@ QVariant QtxComboBox::Model::data( const QModelIndex& index, int role ) const
 /*!
   \class QtxComboBox::ClearEvent
   \brief Custom event, used to process 'cleared' state of the combo box
-  in the editable mode.
+  in editable mode.
   \internal
 */
 
@@ -109,7 +108,7 @@ public:
 };
 
 /*!
-  \brief Constructor
+  \brief Constructor.
   \internal
 */
 QtxComboBox::ClearEvent::ClearEvent() : QEvent( CLEAR_EVENT )
@@ -140,16 +139,14 @@ QtxComboBox::QtxComboBox( QWidget* parent )
 
 /*!
   \brief Destructor.
-
-  Does nothing currently.
 */
 QtxComboBox::~QtxComboBox()
 {
 }
 
 /*!
-  \brief Check if the combo box is in the "cleared" state.
-  \return \c true if combobox is in the "cleared" state
+  \brief Check if combo box is in "cleared" state.
+  \return \c true if combo box is in "cleared" state or \c false otherwise
 */
 bool QtxComboBox::isCleared() const
 {
@@ -174,31 +171,31 @@ void QtxComboBox::setCleared( const bool isClear )
 }
 
 /*!
-  \brief Get current item ID.
-  \return item id
+  \brief Get current item's identifier.
+  \return current item's identifier
 */
-int QtxComboBox::currentId() const
+QVariant QtxComboBox::currentId() const
 {
   return id( currentIndex() );
 }
 
 /*!
-  \brief Set current item by ID.
-  \param num item ID
+  \brief Set current item by identifier.
+  \param ident item's identifier
 */
-void QtxComboBox::setCurrentId( int num )
+void QtxComboBox::setCurrentId( const QVariant& ident )
 {
-  setCurrentIndex( index( num ) );
+  setCurrentIndex( index( ident ) );
 }
 
 /*!
-  \brief Set the identifier to specified item.
-  \param index - index of the item
-  \param id - identifier of the item
+  \brief Assign identifier to specified item.
+  \param idx item's index
+  \param ident item's identifier
 */
-void QtxComboBox::setId( const int index, const int id )
+void QtxComboBox::setId( const int idx, const QVariant& ident )
 {
-  setItemData( index, QVariant( id ), (Qt::ItemDataRole)IdRole );
+  setItemData( idx, ident, (Qt::ItemDataRole)IdRole );
 }
 
 /*!
@@ -216,7 +213,7 @@ void QtxComboBox::paintEvent( QPaintEvent* e )
 }
 
 /*!
-  \brief Customize child addition/removal event
+  \brief Customize child addition/removal event.
   \param e child event
 */
 void QtxComboBox::childEvent( QChildEvent* e )
@@ -236,8 +233,8 @@ void QtxComboBox::customEvent( QEvent* e )
 }
 
 /*!
-  \brief Called when current item is chaned (by the user or programmatically).
-  \param idx item being set current
+  \brief Called when current item is changed (by user or programmatically).
+  \param idx index of item being set current
 */
 void QtxComboBox::onCurrentChanged( int idx )
 {
@@ -249,7 +246,7 @@ void QtxComboBox::onCurrentChanged( int idx )
 }
 
 /*!
-  \brief Reset "cleared" state and update the combo box.
+  \brief Reset "cleared" state and update combo box.
 */
 void QtxComboBox::resetClear()
 {
@@ -261,47 +258,40 @@ void QtxComboBox::resetClear()
 }
 
 /*!
-  \brief Get item ID by the index.
-  \param idx item index
-  \return item ID or -1 if index is invalid.
+  \brief Get item's identifier by index.
+  \param idx item's index
+  \return item's identifier or invalid QVariant if index is out of range
+  or identifier is not assigned to item
 */
-int QtxComboBox::id( const int idx ) const
+QVariant QtxComboBox::id( const int idx ) const
 {
-  int id = -1;
-  QVariant v = itemData( idx, (Qt::ItemDataRole)IdRole );
-  if ( v.canConvert( QVariant::Int ) )
-    id = v.toInt();
-  return id;
+  return itemData( idx, (Qt::ItemDataRole)IdRole );
 }
 
 /*!
-  \brief Get item index by the ID.
-  \param id item ID
-  \return item index or -1 if ID is invalid.
+  \brief Get item index by identifier.
+  \param ident item's identifier
+  \return item's index or -1 if \a ident is invalid of if item is not found
 */
-int QtxComboBox::index( const int ident ) const
+int QtxComboBox::index( const QVariant& ident ) const
 {
-  int idx = -1;
-  for ( int i = 0; i < (int)count() && idx == -1; i++ )
-  {
-    if ( id( i ) == ident )
-      idx = i;
-  }
-  return idx;
+  if ( !ident.isValid() ) return -1;
+  return findData( ident, (Qt::ItemDataRole)IdRole );
 }
 
 /*!
-  \brief Returns true if the item with index has ID.
-  \param idx item index
+  \brief Check if item has assigned identifier.
+  \param idx item's index
+  \return \c true if item with given index has identifier of \c false otherwise
 */
 bool QtxComboBox::hasId( const int idx ) const
 {
   QVariant v = itemData( idx, (Qt::ItemDataRole)IdRole );
-  return v.canConvert( QVariant::Int );
+  return !v.isNull();
 }
 
 /*!
-  \fn void QtxComboBox::activatedId( int id )
-  \brief Emitted when the item with identificator \a id is activated.
-  \param id item ID
+  \fn void QtxComboBox::activatedId( int ident )
+  \brief Emitted when item with identificator \a ident is activated.
+  \param ident item's identifier
 */
index 5bffead0058e0c7c429dc88decb8294c89972732..45cad6740af77b61fb2e44e7634fe673665cc98d 100755 (executable)
@@ -49,17 +49,17 @@ public:
   bool         isCleared() const;
   void         setCleared( const bool );
 
-  int          currentId() const;
-  void         setCurrentId( int );
+  QVariant     currentId() const;
+  void         setCurrentId( const QVariant& );
 
-  int          id( const int ) const;
-  int          index( const int ) const;
+  QVariant     id( const int ) const;
+  int          index( const QVariant& ) const;
 
   bool         hasId( const int ) const;
-  void         setId( const int, const int );
+  void         setId( const int, const QVariant& );
 
 signals:
-  void         activatedId( int );
+  void         activatedId( QVariant );
 
 private slots:
   void         onCurrentChanged( int );
index e4e5138a7f0d903ecebbf506a8a6c9554e63bb57..b6eac24c7129134fa6f272b397c9f4389cc2c1c2 100644 (file)
@@ -2735,9 +2735,9 @@ QStringList QtxPagePrefSelectItem::strings() const
   \return list of values IDs
   \sa strings(), icons(), setNumbers()
 */
-QList<int> QtxPagePrefSelectItem::numbers() const
+QList<QVariant> QtxPagePrefSelectItem::numbers() const
 {
-  QList<int> res;
+  QList<QVariant> res;
   for ( int i = 0; i < mySelector->count(); i++ )
   {
     if ( mySelector->hasId( i ) )
@@ -2775,10 +2775,10 @@ void QtxPagePrefSelectItem::setStrings( const QStringList& lst )
   \param ids new list of values IDs
   \sa numbers(), setStrings(), setIcons()
 */
-void QtxPagePrefSelectItem::setNumbers( const QList<int>& ids )
+void QtxPagePrefSelectItem::setNumbers( const QList<QVariant>& ids )
 {
   int i = 0;
-  for ( QList<int>::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) {
+  for ( QList<QVariant>::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) {
     if ( i >= mySelector->count() )
       mySelector->addItem(QString("") );
     
@@ -2812,10 +2812,16 @@ void QtxPagePrefSelectItem::store()
 
   int idx = mySelector->currentIndex();
 
-  if ( mySelector->hasId( idx ) )
-    setInteger( mySelector->id( idx ) );
-  else if ( idx >= 0 )
+  if ( mySelector->hasId( idx ) ) {
+    QVariant id = mySelector->id( idx );
+    if ( id.type() == QVariant::Int )
+      setInteger( id.toInt() );
+    else if ( id.type() == QVariant::String )
+      setString( id.toString() );
+  }
+  else if ( idx >= 0 ) {
     setString( mySelector->itemText( idx ) );
+  }
 }
 
 /*!
@@ -2825,14 +2831,10 @@ void QtxPagePrefSelectItem::store()
 void QtxPagePrefSelectItem::retrieve()
 {
   QString txt = getString();
-
-  int idx = -1;
-
-  bool ok = false;
-  int num = txt.toInt( &ok );
-  if ( ok )
-    idx = mySelector->index( num );
-  else
+  
+  // try to find via the id
+  int idx = mySelector->index( txt );
+  if ( idx < 0 )
   {
     for ( int i = 0; i < mySelector->count() && idx == -1; i++ )
     {
@@ -2872,11 +2874,7 @@ QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const
     return strings();
   else if ( name == "numbers" || name == "ids" || name == "indexes" )
   {
-    QList<QVariant> lst;
-    QList<int> nums = numbers();
-    for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
-      lst.append( *it );
-    return lst;
+    return numbers();
   }
   else if ( name == "icons" || name == "pixmaps" )
   {
@@ -2935,14 +2933,7 @@ void QtxPagePrefSelectItem::setNumbers( const QVariant& var )
   if ( var.type() != QVariant::List )
     return;
 
-  QList<int> lst;
-  QList<QVariant> varList = var.toList();
-  for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
-  {
-    if ( (*it).canConvert( QVariant::Int ) )
-      lst.append( (*it).toInt() );
-  }
-  setNumbers( lst );
+  setNumbers( var.toList() );
 }
 
 /*!
index aaa3a56b026b1dd8cc072e5488fd0e56085015d5..43e6961aced180464c3540474f326a68871b0c46 100644 (file)
@@ -487,11 +487,11 @@ public:
   void             setInputType( const int );
 
   QStringList      strings() const;
-  QList<int>       numbers() const;
+  QList<QVariant>  numbers() const;
   QList<QIcon>     icons() const;
 
   void             setStrings( const QStringList& );
-  void             setNumbers( const QList<int>& );
+  void             setNumbers( const QList<QVariant>& );
   void             setIcons( const QList<QIcon>& );
 
   virtual void     store();