]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Dialog.cxx
Salome HOME
3aed9fe5d6cdeee4a6987e23fc3ff7343cd2d18c
[modules/gui.git] / src / LightApp / LightApp_Dialog.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_Dialog.cxx
23 // Author:    Alexander SOLOVYOV
24 //
25 #include "LightApp_Dialog.h"
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28
29 #include <QAbstractButton>
30 #include <QToolButton>
31 #include <QLineEdit>
32 #include <QLabel>
33
34 /*!
35   Constructor
36 */
37 LightApp_Dialog::LightApp_Dialog( QWidget* parent, const char* name, bool modal,
38                                   bool allowResize, const int f, Qt::WindowFlags wf )
39 : QtxDialog( parent, modal, allowResize, f, wf ),
40   myIsExclusive( true ),
41   myIsBusy( false )
42 {
43   setObjectName( name );
44   setObjectPixmap( "LightApp", tr( "ICON_SELECT" ) );
45 }
46
47 /*!
48   Destructor
49 */
50 LightApp_Dialog::~LightApp_Dialog()
51 {
52 }
53
54 /*!
55   Show dialog
56 */
57 void LightApp_Dialog::show()
58 {
59   QtxDialog::show();
60 }
61
62 /*!
63   \return isExclusive status of selection buttons
64 */
65 bool LightApp_Dialog::isExclusive() const
66 {
67   return myIsExclusive;
68 }
69
70 /*!
71   Updates "on" state of buttons according to special button
72   \param _id - id of special button (if it is -1, then first selected button will be treated as special)
73 */
74 void LightApp_Dialog::updateButtons( const int _id )
75 {
76   if( !myIsExclusive )
77     return;
78
79   int id = _id;
80
81   ObjectMap::const_iterator anIt = myObjects.begin(),
82                             aLast = myObjects.end();
83   for( ; anIt!=aLast; anIt++ )
84   {
85     QToolButton* but = (QToolButton*)anIt.value().myBtn;
86     if( but && but->isChecked() )
87     {
88       if( id==-1 )
89         id = anIt.key();
90
91       if( anIt.key()!=id )
92         but->setChecked( false );
93     }
94   }
95 }
96
97 /*!
98   Sets isExclusive status of selection buttons
99   \param ex - new value of isExclusive status
100 */
101 void LightApp_Dialog::setExclusive( const bool ex )
102 {
103   myIsExclusive = ex;
104   updateButtons();
105 }
106
107 /*!
108   Shows object selection widget
109   \param id - identificator of object selection widget
110 */
111 void LightApp_Dialog::showObject( const int id )
112 {
113   setObjectShown( id, true );
114 }
115
116 /*!
117   Hides object selection widget
118   \param id - identificator of object selection widget
119 */
120 void LightApp_Dialog::hideObject( const int id )
121 {
122   setObjectShown( id, false );
123 }
124
125 /*!
126   Shows/hides object selection widget
127   \param id - identificator of object selection widget
128   \param shown - if it is true, widget will be shown
129 */
130 void LightApp_Dialog::setObjectShown( const int id, const bool shown )
131 {
132   if( myObjects.contains( id ) && isObjectShown( id )!=shown )
133   {
134     Object& obj = myObjects[ id ];
135     obj.myEdit->setShown( shown );
136     obj.myBtn->setShown( shown );
137     obj.myLabel->setShown( shown );
138     if( !shown )
139       ( ( QToolButton* )obj.myBtn )->setChecked( false );
140   }
141 }
142
143 /*!
144   \return isShown state of object selection widget
145   \param id - identificator of object selection widget
146 */
147 bool LightApp_Dialog::isObjectShown( const int id ) const
148 {
149   return myObjects.contains( id ) &&
150          ( myObjects[ id ].myEdit->isVisible() ||
151            myObjects[ id ].myEdit->isVisibleTo( myObjects[ id ].myEdit->parentWidget() ) );
152 }
153
154 /*!
155   Change enable state of object selection widget
156   \param id - identificator of object selection widget
157   \param en - new value of enable state
158 */
159 void LightApp_Dialog::setObjectEnabled( const int id, const bool en )
160 {
161   if( myObjects.contains( id ) && isObjectEnabled( id )!=en )
162   {
163     Object& obj = myObjects[ id ];
164     obj.myEdit->setEnabled( en );
165     obj.myBtn->setEnabled( en );
166 //    obj.myLabel->setEnabled( en );
167     if( !en )
168       ( ( QToolButton* )obj.myBtn )->setChecked( false );
169   } 
170 }
171
172 /*!
173   \return enable state of object selection widget
174   \param id - identificator of object selection widget
175 */
176 bool LightApp_Dialog::isObjectEnabled( const int id ) const
177 {
178   return myObjects.contains( id ) && myObjects[ id ].myEdit->isEnabled();
179 }
180
181 /*!
182   Passes to all active widgets name, type and id of selected object          
183   \param name - name of selected object
184   \param type - type of selected object
185   \param id - id of selected object
186   \param update - is need to update selection description string
187 */
188 void LightApp_Dialog::selectObject( const QString& name, const int type, const QString& id, const bool update )
189 {
190   QStringList names;   names.append( name );
191   TypesList types;     types.append( type );
192   QStringList ids;     ids.append( id );
193   selectObject( names, types, ids, update );
194 }
195
196 /*!
197   Passes to all active widgets names, types and ids of selected objects
198   \param _names - names of selected objects
199   \param _types - types of selected objects
200   \param _ids - ids of selected objects
201   \param update - is need to update selection description string
202 */
203 void LightApp_Dialog::selectObject( const QStringList& _names,
204                                      const TypesList& _types,
205                                      const QStringList& _ids,
206                                      const bool update )
207 {
208   ObjectMap::iterator anIt = myObjects.begin(),
209                       aLast = myObjects.end();
210   for( ; anIt!=aLast; anIt++ )
211     if( anIt.value().myBtn->isChecked() )
212       selectObject( anIt.key(), _names, _types, _ids, update );
213 }
214
215 /*!
216   \return true if widget has selection
217   \param id - identificator of object selection widget
218 */
219 bool LightApp_Dialog::hasSelection( const int id ) const
220 {
221   return myObjects.contains( id ) && !myObjects[ id ].myIds.isEmpty();
222 }
223
224 /*!
225   Clears selection of widget
226   \param id - identificator of object selection widget
227 */
228 void LightApp_Dialog::clearSelection( const int id )
229 {
230   if( id==-1 )
231   {
232     ObjectMap::const_iterator anIt = myObjects.begin(),
233                               aLast = myObjects.end();
234     for( ; anIt!=aLast; anIt++ )
235       clearSelection( anIt.key() );
236   }
237   
238   else if( myObjects.contains( id ) )
239   {
240     myObjects[ id ].myIds.clear();
241     myObjects[ id ].myTypes.clear();
242     myObjects[ id ].myNames.clear();
243     
244     myObjects[ id ].myEdit->setText( QString() );
245     emit selectionChanged( id );
246   }
247 }
248
249 /*!
250   \return object selection widget 
251   \param theId - identificator of object selection widget
252   \param theWgId may be "Label", "Btn" or "Control"
253 */
254 QWidget* LightApp_Dialog::objectWg( const int theId, const int theWgId ) const
255 {
256   QWidget* aResWg = 0;
257   if( myObjects.contains( theId ) )
258   {
259     if ( theWgId == Label )
260       aResWg = myObjects[ theId ].myLabel;
261     else if ( theWgId == Btn )
262       aResWg = myObjects[ theId ].myBtn;
263     else if ( theWgId == Control )
264       aResWg = myObjects[ theId ].myEdit;
265   }
266   return aResWg;
267 }
268
269 /*!
270   \return object selection widget text
271   \param theId - identificator of object selection widget
272 */
273 QString LightApp_Dialog::objectText( const int theId ) const
274 {
275   return myObjects.contains( theId ) ? myObjects[ theId ].myEdit->text() : "";
276 }
277
278 /*!
279   Sets object selection widget text
280   \param theId - identificator of object selection widget
281   \param theText - new text
282 */
283 void LightApp_Dialog::setObjectText( const int theId, const QString& theText )
284 {
285   if ( myObjects.contains( theId ) )
286     myObjects[ theId ].myEdit->setText( theText );
287 }
288
289 /*!
290   \return objects selected by widget
291   \param id - identificator of object selection widget
292   \param list - list to be filled by selected objects
293 */
294 void LightApp_Dialog::selectedObject( const int id, QStringList& list ) const
295 {
296   if( myObjects.contains( id ) )
297     list = myObjects[ id ].myIds;
298 }
299
300 /*!
301   \return selected object id
302   \param id - identificator of object selection widget
303 */
304 QString LightApp_Dialog::selectedObject( const int id ) const
305 {
306   if ( myObjects.contains( id ) && myObjects[ id ].myIds.count() > 0 )
307     return myObjects[ id ].myIds.first();
308   else
309     return "";
310 }
311
312 /*!
313   \return all selected objects
314   \param objs - map: widget id -> string id to be filled with selected objects
315 */
316 void LightApp_Dialog::objectSelection( SelectedObjects& objs ) const
317 {
318   //objs.clear();
319   ObjectMap::const_iterator anIt = myObjects.begin(),
320                             aLast = myObjects.end();
321   for( ; anIt!=aLast; anIt++ )
322   {
323     QStringList ids;
324     selectedObject( anIt.key(), ids );
325     if( !ids.isEmpty() )
326       objs.insert( anIt.key(), ids );
327   }
328 }
329
330 /*!
331   Creates object selection widget
332   \return id
333   \label - label text
334   \parent - parent object
335   \id - proposed id for widget (if it is less than 0, the free id will be used)
336 */
337 int LightApp_Dialog::createObject( const QString& label, QWidget* parent, const int id )
338 {  
339   int nid = id;
340   if( nid<0 )
341     for( nid=0; myObjects.contains( nid ); nid++ );
342   
343   if( !myObjects.contains( nid ) )
344   {
345     QLabel* lab = new QLabel( label, parent );
346     myObjects[ nid ].myLabel = lab;
347     
348     QToolButton* but = new QToolButton( parent );
349     but->setIcon( QIcon( myPixmap ) );
350     but->setCheckable( true );
351     but->setMaximumWidth( but->height() );
352     but->setMinimumWidth( but->height() );    
353     connect( but, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
354     myObjects[ nid ].myBtn = but;
355
356     QLineEdit* ne = new QLineEdit( parent );
357     ne->setReadOnly( true );
358     ne->setMinimumWidth( 150 );
359     connect( ne, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
360     myObjects[ nid ].myEdit = ne;
361
362     myObjects[ nid ].myNI = OneNameOrCount;
363   }
364   return nid;
365 }
366
367 /*!
368   Changes label of object selection widget
369   \param id - identificator of object selection widget
370   \param label - new text of label
371 */
372 void LightApp_Dialog::renameObject( const int id, const QString& label )
373 {
374   if( myObjects.contains( id ) )
375     myObjects[ id ].myLabel->setText( label );
376 }
377
378 /*!
379   Sets possible types for widget
380   \param id - identificator of object selection widget
381   \param type1,... - type
382 */
383 void LightApp_Dialog::setObjectType( const int id, const int type1, ... )
384 {
385   TypesList types;
386   
387   const int* tt = &type1;
388   while( *tt>=0 )
389   {
390     types.append( *tt );
391     tt++;
392   }
393
394   setObjectType( id, types );
395 }
396
397 /*!
398   Sets possible types for widget
399   \param id - identificator of object selection widget
400   \param list - list of possible types
401 */
402 void LightApp_Dialog::setObjectType( const int id, const TypesList& list )
403 {
404   if( !myObjects.contains( id ) )
405     return;
406
407   TypesList& internal = myObjects[ id ].myPossibleTypes;
408     
409   QMap<int,int> types;
410   TypesList::const_iterator anIt = list.begin(),
411                             aLast = list.end();
412   for( ; anIt!=aLast; anIt++ )
413     types.insert( *anIt, 0 );
414
415
416   internal.clear();
417   QMap<int,int>::const_iterator aMIt = types.begin(),
418                                 aMLast = types.end();
419   for( ; aMIt!=aMLast; aMIt++ )
420     internal.append( aMIt.key() );
421
422   updateObject( id );
423 }
424
425 /*!
426   Adds new possible types to object selection widget
427   \param id - identificator of object selection widget
428   \param type1, ... - new types
429 */
430 void LightApp_Dialog::addObjectType( const int id, const int type1, const int, ... )
431 {
432   TypesList types; objectTypes( id, types );
433
434   const int* tt = &type1;
435   while( *tt>=0 )
436   {
437     types.append( *tt );
438     tt++;
439   }
440
441   setObjectType( id, types );  
442 }
443
444 /*!
445   Adds new possible types to object selection widget
446   \param id - identificator of object selection widget
447   \param list - new types
448 */
449 void LightApp_Dialog::addObjectType( const int id, const TypesList& list )
450 {
451   TypesList types = list; objectTypes( id, types );
452   setObjectType( id, types );
453 }
454
455 /*!
456   Adds new possible type to object selection widget
457   \param id - identificator of object selection widget
458   \param type - new type
459 */
460 void LightApp_Dialog::addObjectType( const int id, const int type )
461 {
462   TypesList types; objectTypes( id, types );
463   types.append( type );
464   setObjectType( id, types );
465 }
466
467 /*!
468   Clears list of possibles types for object selection widget
469   \param id - identificator of object selection widget
470 */
471 void LightApp_Dialog::removeObjectType( const int id )
472 {
473   TypesList types;
474   setObjectType( id, types );
475 }
476
477 /*!
478   Removes types from list of possibles for object selection widget
479   \param id - identificator of object selection widget
480   \param list - list of types to be removed
481 */
482 void LightApp_Dialog::removeObjectType( const int id, const TypesList& list )
483 {
484   if( !myObjects.contains( id ) )
485     return;
486
487   TypesList& internal = myObjects[ id ].myPossibleTypes;
488
489   QMap<int,int> types;
490   TypesList::const_iterator anIt = internal.begin(),
491                             aLast = internal.end();
492   for( ; anIt!=aLast; anIt++ )
493     types.insert( *anIt, 0 );
494   anIt = list.begin(); aLast = list.end();
495   for( ; anIt!=aLast; anIt++ )
496     types.remove( *anIt );
497
498
499   internal.clear();
500   QMap<int,int>::const_iterator aMIt = types.begin(),
501                                 aMLast = types.end();
502   for( ; aMIt!=aMLast; aMIt++ )
503     internal.append( aMIt.key() );
504
505   updateObject( id );
506 }
507
508 /*!
509   Removes type from list of possibles for object selection widget
510   \param id - identificator of object selection widget
511   \param type - type to be removed
512 */
513 void LightApp_Dialog::removeObjectType( const int id, const int type )
514 {
515   TypesList list; list.append( type );
516   removeObjectType( id, list );
517 }
518
519 /*!
520   \return true if widget has such type
521   \param id - identificator of object selection widget
522   \param type - type to be checked
523 */
524 bool LightApp_Dialog::hasObjectType( const int id, const int type ) const
525 {
526   if( myObjects.contains( id ) )
527     return myObjects[ id ].myPossibleTypes.contains( type );
528   else
529     return false;
530 }
531
532 /*!
533   Returns list of possible types for widget
534   \param id - identificator of object selection widget
535   \param list - list to be filled with possible types
536 */
537 void LightApp_Dialog::objectTypes( const int id, TypesList& list ) const
538 {
539   if( myObjects.contains( id ) )
540   {
541     TypesList::const_iterator anIt = myObjects[ id ].myPossibleTypes.begin(),
542                               aLast = myObjects[ id ].myPossibleTypes.end();
543     for( ; anIt!=aLast; anIt++ )
544       list.append( *anIt );
545   }  
546 }
547
548 /*!
549   SLOT: called if selection button is clicked
550 */
551 void LightApp_Dialog::onToggled( bool on )
552 {
553   QAbstractButton* but = ( QAbstractButton* )sender();
554   int id = -1;
555
556   if( !but )
557     return;
558     
559   ObjectMap::const_iterator anIt = myObjects.begin(),
560                             aLast = myObjects.end();
561   for( ; anIt!=aLast && id==-1; anIt++ )
562     if( anIt.value().myBtn==but )
563       id = anIt.key();
564
565   if( id!=-1 )
566     if( on )
567     {
568       updateButtons( id );
569       emit objectActivated( id );
570     }
571     else
572       emit objectDeactivated( id );
573 }
574
575 /*!
576   Updates selection description of widget
577   \param id - identificator of object selection widget
578   \param emit_signal - if it is true, the signal "selection changed" is emitted
579 */
580 void LightApp_Dialog::updateObject( const int id, bool emit_signal )
581 {
582   if( hasSelection( id ) )
583   {
584     Object& obj = myObjects[ id ];
585     filterTypes( id, obj.myNames, obj.myTypes, obj.myIds );
586     obj.myEdit->setText( selectionDescription( obj.myNames, obj.myTypes, obj.myNI ) );
587     if( emit_signal )
588       emit selectionChanged( id );
589   }
590 }
591
592 /*!
593   Finds in list possible types
594   \param id - identificator of object selection widget
595   \param names - list of selected objects names
596   \param types - list of selected objects types
597   \param ids - list of selected objects ids
598 */
599 void LightApp_Dialog::filterTypes( const int id, QStringList& names, TypesList& types, QStringList& ids ) const
600 {
601   if( !myObjects.contains( id ) )
602     return;
603
604   const Object& obj = myObjects[ id ];
605   if( obj.myPossibleTypes.isEmpty() )
606     return;
607
608   QStringList new_names, new_ids;
609   TypesList new_types;
610   
611   TypesList::const_iterator anIt1 = types.begin(),
612                             aLast = types.end();
613   QStringList::const_iterator anIt2 = names.begin(),
614                               anIt3 = ids.begin();
615   for( ; anIt1!=aLast; anIt1++, anIt2++, anIt3++ )
616     if( obj.myPossibleTypes.contains( *anIt1 ) )
617     {
618       if( new_types.count()==1 && !multipleSelection( id ) )
619         break;
620         
621       new_names.append( *anIt2 );
622       new_types.append( *anIt1 );
623       new_ids.append( *anIt3 );       
624     }
625   names = new_names;
626   types = new_types;
627   ids = new_ids;
628 }
629
630 /*!
631   \return global resource manager
632 */
633 SUIT_ResourceMgr* LightApp_Dialog::resMgr() const
634 {
635   return SUIT_Session::session()->resourceMgr();
636 }
637
638 /*!
639   Sets pixmap for all object selection button
640   \param p - image
641 */
642 void LightApp_Dialog::setObjectPixmap( const QPixmap& p )
643 {
644   myPixmap = p;
645   ObjectMap::const_iterator anIt = myObjects.begin(),
646                             aLast = myObjects.end();
647   for( ; anIt!=aLast; anIt++ )
648     ( ( QToolButton* )anIt.value().myBtn )->setIcon( p );
649 }                        
650
651 /*!
652   Sets pixmap all for object selection button
653   \param section - name of section of resource manager
654   \param file - name of file
655 */
656 void LightApp_Dialog::setObjectPixmap( const QString& section, const QString& file )
657 {
658   SUIT_ResourceMgr* mgr = resMgr();
659   if( mgr )
660     setObjectPixmap( mgr->loadPixmap( section, file ) );
661 }
662
663 /*!
664   \return true, if it is enable multiple selection
665   \param id - identificator of object selection widget
666 */
667 bool LightApp_Dialog::multipleSelection( const int id ) const
668 {
669   return nameIndication( id )!=OneName;  
670 }
671
672 /*!
673   \return type of name indication
674   \param id - identificator of object selection widget
675 */
676 LightApp_Dialog::NameIndication LightApp_Dialog::nameIndication( const int id ) const
677 {
678   if( myObjects.contains( id ) )
679     return myObjects[ id ].myNI;
680   else
681     return OneNameOrCount;
682 }
683
684 /*!
685   Sets type of name indication
686   \param id - identificator of object selection widget
687   \param ni - new type of name indication
688 */
689 void LightApp_Dialog::setNameIndication( const int id, const NameIndication ni )
690 {
691   if( id==-1 )
692   {
693     ObjectMap::iterator anIt = myObjects.begin(),
694                         aNext,
695                         aLast = myObjects.end();
696     for( ; anIt!=aLast; anIt++ )
697     {
698       anIt.value().myNI = ni;
699       setReadOnly( anIt.key(), isReadOnly( anIt.key() ) );
700       aNext = anIt; aNext++;
701       updateObject( anIt.key(), aNext==aLast );
702     }
703   }
704   else if( myObjects.contains( id ) )
705   {
706     myObjects[ id ].myNI = ni;
707     setReadOnly( id, isReadOnly( id ) );
708     updateObject( id, true );
709   }
710 }
711
712 /*!
713   \return string representation of selection by selection data
714   \param names - list of selected objects names
715   \param types - list of selected objects types
716   \param ni - type of name indication
717 */
718 QString LightApp_Dialog::selectionDescription( const QStringList& names, const TypesList& types, const NameIndication ni ) const
719 {
720   if( names.count()!=types.count() )
721     return "LightApp_Dialog::selectionDescription(): Error!!!";
722     
723   if( names.isEmpty() )
724     return QString();
725     
726   switch( ni )
727   {
728     case OneName:
729       return names.first();
730       break;
731       
732     case OneNameOrCount:
733       if( names.count()==1 )
734         return names.first();
735       else
736         return countOfTypes( types );
737       break;
738       
739     case ListOfNames:
740       return names.join( " " );
741       break;
742       
743     case Count:
744       return countOfTypes( types );
745       break;
746   };
747   return QString();
748 }
749
750 /*!
751   \return string representation of count of types
752   \param types - list of types
753 */
754 QString LightApp_Dialog::countOfTypes( const TypesList& types ) const
755 {
756   QMap<int, int> typesCount;
757   QStringList typeCount;
758   
759   TypesList::const_iterator anIt = types.begin(),
760                             aLast = types.end();
761   for( ; anIt!=aLast; anIt++ )
762     if( typesCount.contains( *anIt ) )
763       typesCount[ *anIt ]++;
764     else
765       typesCount[ *anIt ] = 1;
766
767   QMap<int,int>::const_iterator aMIt = typesCount.begin(),
768                                 aMLast = typesCount.end();
769   for( ; aMIt!=aMLast; aMIt++ )
770     typeCount.append( QString( "%1 %2" ).arg( aMIt.value() ).arg( typeName( aMIt.key() ) ) );
771
772   return typeCount.join( ", " );
773 }
774
775 /*!
776   \return reference to type name
777   \param type - integer id of type
778 */
779 QString& LightApp_Dialog::typeName( const int type )
780 {
781   return myTypeNames[ type ];
782 }
783
784 /*!
785   \return const reference to type name
786   \param type - integer id of type
787 */
788 const QString LightApp_Dialog::typeName( const int type ) const
789 {
790   return myTypeNames[ type ];
791 }
792
793
794 /*!
795   Activates object selection widget
796   \param id - identificator of object selection widget
797 */
798 void LightApp_Dialog::activateObject( const int theId )
799 {
800   if ( myObjects.contains( theId ) && !myObjects[ theId ].myBtn->isChecked() )
801     myObjects[ theId ].myBtn->toggle();
802 }
803
804 /*!
805   Deactivates all object selection widgets
806 */
807 void LightApp_Dialog::deactivateAll()
808 {
809   ObjectMap::iterator anIt = myObjects.begin(),
810                       aLast = myObjects.end();
811   for( ; anIt!=aLast; anIt++ )
812   {
813     QToolButton* btn = ( QToolButton* )anIt.value().myBtn;
814     btn->setChecked( false );
815   }
816 }
817
818 /*!
819   Passes to widget name, type and id of selected object
820   \param id - identificator of object selection widget
821   \param name - name of selected object
822   \param type - type of selected object
823   \param selid - id of selected object
824   \param update - is need to update selection description string
825 */
826 void LightApp_Dialog::selectObject( const int id, const QString& name, const int type, const QString& selid, const bool update )
827 {
828   QStringList names;   names.append( name );
829   TypesList types;     types.append( type );
830   QStringList ids;     ids.append( selid );
831   selectObject( id, names, types, ids, update );
832 }
833
834 /*!
835   Passes to widget names, types and ids of selected objects
836   \param id - identificator of object selection widget
837   \param _names - names of selected object
838   \param _types - types of selected object
839   \param _ids - ids of selected object
840   \param update - is need to update selection description string
841 */
842 void LightApp_Dialog::selectObject( const int id, const QStringList& _names, const TypesList& _types,
843                                      const QStringList& _ids, const bool update )
844 {
845   if( !myObjects.contains( id ) )
846     return;
847     
848   QStringList names = _names, ids = _ids;
849   TypesList types = _types;
850
851   filterTypes( id, names, types, ids );
852
853   Object& obj = myObjects[ id ];
854   if( update )
855     obj.myEdit->setText( selectionDescription( names, types, obj.myNI ) );
856   obj.myTypes = types;
857   obj.myIds = ids;
858   obj.myNames = names;
859
860   emit selectionChanged( id );
861 }
862
863 /*!
864   Sets read only state of object selection line edit
865   \param id - identificator of object selection widget
866   \param ro - new read only state
867 */
868 void LightApp_Dialog::setReadOnly( const int id, const bool ro )
869 {
870   if( myObjects.contains( id ) )
871     myObjects[ id ].myEdit->setReadOnly( nameIndication( id )==ListOfNames || nameIndication( id )==OneName ? ro : true );
872 }
873
874 /*!
875   \return read only state of object selection line edit
876   \param id - identificator of object selection widget
877 */
878 bool LightApp_Dialog::isReadOnly( const int id ) const
879 {
880   if( myObjects.contains( id ) )
881     return myObjects[ id ].myEdit->isReadOnly();
882   else
883     return true;
884 }
885
886 /*!
887   SLOT: called if text of object selection line edit is changed
888 */
889 void LightApp_Dialog::onTextChanged( const QString& text )
890 {
891   if( myIsBusy )
892     return;
893
894   myIsBusy = true;
895
896   if( sender() && sender()->inherits( "QLineEdit" ) )
897   {
898     QLineEdit* edit = ( QLineEdit* )sender();
899     int id = -1;
900     ObjectMap::const_iterator anIt = myObjects.begin(),
901                               aLast = myObjects.end();
902     for( ; anIt!=aLast; anIt++ )
903       if( anIt.value().myEdit == edit )
904         id = anIt.key();
905
906     if( id>=0 && !isReadOnly( id ) )
907     {
908       QStringList list = text.split( " ", QString::SkipEmptyParts );
909       emit objectChanged( id, list );
910     }
911   }
912
913   myIsBusy = false;
914 }