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