1 #include "QDS_RadioBox.h"
3 #include <DDS_Dictionary.h>
5 #include <TCollection_AsciiString.hxx>
6 #include <TColStd_HArray1OfInteger.hxx>
7 #include <TColStd_HArray1OfExtendedString.hxx>
9 #include <qobjectlist.h>
10 #include <qbuttongroup.h>
11 #include <qradiobutton.h>
16 QDS_RadioBox::QDS_RadioBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
17 : QDS_Datum( id, parent, flags & ~( Label | Units ), comp )
24 QDS_RadioBox::~QDS_RadioBox()
29 Returns number of items in ComboBox. If total is 'false' then only
30 visible items are taken into account otherwise all items.
32 int QDS_RadioBox::count( bool total ) const
35 return myValue.count();
38 QPtrList<QRadioButton> bList;
45 Returns list of ids. If total is 'false' then only visible items
46 are taken into account otherwise all items.
48 void QDS_RadioBox::values( QValueList<int>& ids, bool total ) const
51 for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it )
52 if ( total || ( myState.contains( *it ) && myState[*it] ) )
57 Returns visible state of identificator.
59 bool QDS_RadioBox::state( const int id ) const
62 if ( myState.contains( id ) )
68 Sets the visible state of identificator. If 'id' is -1 then specified
69 state will be set to all ids.
71 void QDS_RadioBox::setState( const bool on, const int id, const bool append )
76 for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it )
77 lst.append( it.key() );
82 setState( on, lst, append );
86 Sets the visible state of identificator from the specified list.
88 void QDS_RadioBox::setState( const bool on, const QValueList<int>& ids, const bool append )
90 if ( ids.isEmpty() && append )
96 for ( uint i = 0; i < ids.count(); i++ )
97 aMap.insert( *ids.at( i ), 0 );
99 for ( IdStateMap::Iterator it = myState.begin(); it != myState.end(); ++it )
101 if ( aMap.contains( it.key() ) )
103 if ( it.data() != on )
109 else if ( !append && it.data() == on )
120 Sets the user items into the combo box.
122 void QDS_RadioBox::setValues( const QValueList<int>& ids, const QStringList& names )
124 if ( ids.count() != names.count() )
132 This is an overloaded member function, provided for convenience.
133 It behaves essentially like the above function. It creates
134 QValueList (0, 1, 2 ... ) and call previous method
136 void QDS_RadioBox::setValues( const QStringList& names )
138 QValueList< int > ids;
139 for ( int i = 0, n = names.count(); i < n; i++ )
141 setValues( ids, names );
145 Returns string from control.
147 QString QDS_RadioBox::getString() const
150 QButtonGroup* bg = buttonGroup();
153 int id = bg->selectedId();
155 res = QString::number( id );
161 Sets the string into control.
163 void QDS_RadioBox::setString( const QString& txt )
165 QButtonGroup* bg = buttonGroup();
169 int oldId = bg->selectedId();
173 QPtrList<QRadioButton> bList;
175 for ( QPtrListIterator<QRadioButton> it( bList ); it.current(); ++it )
176 it.current()->setChecked( false );
181 int id = txt.toInt( &ok );
185 bool block = signalsBlocked();
186 blockSignals( true );
188 blockSignals( block );
191 int newId = bg->selectedId();
193 if ( oldId != newId )
196 QString str = getString();
197 emit activated( newId );
199 emit paramChanged( str );
204 Returns pointer to QButtonGroup widget.
206 QButtonGroup* QDS_RadioBox::buttonGroup() const
208 return ::qt_cast<QButtonGroup*>( controlWidget() );
212 Create QComboBox widget as control subwidget.
214 QWidget* QDS_RadioBox::createControl( QWidget* parent )
216 QButtonGroup* bg = new QButtonGroup( 1, Qt::Vertical, "", parent );
217 bg->setExclusive( true );
218 bg->setRadioButtonExclusive( true );
222 void QDS_RadioBox::unitSystemChanged( const QString& system )
224 QDS_Datum::unitSystemChanged( system );
226 Handle(TColStd_HArray1OfInteger) anIds;
227 Handle(TColStd_HArray1OfExtendedString) aValues, anIcons;
229 Handle(DDS_DicItem) aDicItem = dicItem();
230 if ( !aDicItem.IsNull() )
231 aDicItem->GetListOfValues( aValues, anIds, anIcons );
236 QMap<int, QString> userMap;
237 QIntList::iterator iIt = myUserIds.begin();
238 QStringList::iterator sIt = myUserNames.begin();
239 for ( ; iIt != myUserIds.end() && sIt != myUserNames.end(); ++iIt, ++sIt )
240 userMap.insert( *iIt, *sIt );
242 if ( !anIds.IsNull() && !aValues.IsNull() &&
243 anIds->Length() == aValues->Length() )
245 for ( int i = anIds->Lower(); i <= anIds->Upper(); i++ )
248 int id = anIds->Value( i );
249 if ( userMap.contains( id ) )
250 aValue = userMap[id];
252 aValue = toQString( aValues->Value( i ) );
254 myDataIds.append( id );
255 myValue.insert( id, aValue );
256 myState.insert( id, true );
260 for ( iIt = myUserIds.begin(); iIt != myUserIds.end(); ++iIt )
263 if ( !myValue.contains( id ) )
265 myDataIds.append( id );
266 myValue.insert( id, userMap[id] );
271 for ( IdStateMap::Iterator it1 = myState.begin(); it1 != myState.end(); ++it1 )
272 if ( !myValue.contains( it1.key() ) )
273 del.append( it1.key() );
275 for ( IdValueMap::Iterator it2 = myValue.begin(); it2 != myValue.end(); ++it2 )
276 if ( !myState.contains( it2.key() ) )
277 add.append( it2.key() );
279 for ( QIntList::iterator iter1 = del.begin(); iter1 != del.end(); ++iter1 )
280 myState.remove( *iter1 );
282 for ( QIntList::iterator iter2 = add.begin(); iter2 != add.end(); ++iter2 )
283 myState.insert( *iter2, true );
285 QButtonGroup* bg = buttonGroup();
287 bg->setTitle( label() );
293 Notify about state changed in line edit of RadioBox.
295 void QDS_RadioBox::onToggled( bool on )
302 QString str = getString();
303 emit paramChanged( str );
307 Updates RadioBox after have change of visible state or items have been inserted / removed.
309 void QDS_RadioBox::updateRadioBox()
311 QButtonGroup* bg = buttonGroup();
315 int curId = bg->selectedId();
317 QPtrList<QRadioButton> bList;
319 for ( QPtrListIterator<QRadioButton> itr( bList ); itr.current(); ++itr )
320 delete itr.current();
322 for ( QIntList::const_iterator it = myDataIds.begin(); it != myDataIds.end(); ++it )
325 if ( !myValue.contains( id ) || !myState.contains( id ) || !myState[id] )
328 QRadioButton* rb = new QRadioButton( myValue[id], bg );
329 bg->insert( rb, id );
331 connect( rb, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
337 if ( !bg->find( id ) )
339 QPtrList<QRadioButton> bList;
341 if ( !bList.isEmpty() )
342 id = bg->id( bList.getFirst() );
345 bool block = signalsBlocked();
346 blockSignals( true );
348 blockSignals( block );
351 if ( curId != bg->selectedId() )
355 emit paramChanged( getString() );
359 void QDS_RadioBox::buttons( QPtrList<QRadioButton>& lst ) const
361 lst.setAutoDelete( false );
364 QButtonGroup* bg = buttonGroup();
368 QObjectList* objs = bg->queryList( "QRadioButton" );
371 for ( QObjectListIt it( *objs ); it.current(); ++it )
373 QRadioButton* rb = ::qt_cast<QRadioButton*>( it.current() );