//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;
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;
+ }
}
/*!
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 );
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-
// File: QtxComboBox.cxx
// Author: Sergey TELKOV
-//
+
#include "QtxComboBox.h"
#include <QStandardItemModel>
};
/*!
- \brief Constructor
+ \brief Constructor.
\internal
\param parent parent object
*/
}
/*!
- \brief Destructor
+ \brief Destructor.
\internal
*/
QtxComboBox::Model::~Model()
}
/*!
- \brief Set 'cleared' state
+ \brief Set 'cleared' state.
\param isClear new 'cleared' state
\internal
*/
\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
/*!
\class QtxComboBox::ClearEvent
\brief Custom event, used to process 'cleared' state of the combo box
- in the editable mode.
+ in editable mode.
\internal
*/
};
/*!
- \brief Constructor
+ \brief Constructor.
\internal
*/
QtxComboBox::ClearEvent::ClearEvent() : QEvent( CLEAR_EVENT )
/*!
\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
{
}
/*!
- \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 );
}
/*!
}
/*!
- \brief Customize child addition/removal event
+ \brief Customize child addition/removal event.
\param e child event
*/
void QtxComboBox::childEvent( QChildEvent* 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 )
{
}
/*!
- \brief Reset "cleared" state and update the combo box.
+ \brief Reset "cleared" state and update combo box.
*/
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
*/
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 );
\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 ) )
\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("") );
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 ) );
+ }
}
/*!
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++ )
{
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" )
{
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() );
}
/*!
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();