Salome HOME
IPAL9008
[modules/gui.git] / src / SalomeApp / SalomeApp_ListView.cxx
1 //  SALOME SalomeApp 
2 //
3 //  Copyright (C) 2005  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SalomeApp_ListView.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #include "SalomeApp_ListView.h"
13 #include "SalomeApp_Application.h"
14
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_Session.h"
17
18 #include <qheader.h>
19 #include <qvalidator.h>
20 #include <qapplication.h>
21 #include <qtoolbutton.h>
22
23 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <TColStd_ListIteratorOfListOfReal.hxx>
25
26 #include "utilities.h"
27
28 using namespace std;
29
30 //////////////////////////////////////////////////////////////////////
31 // SalomeApp_ListView class implementation
32 //////////////////////////////////////////////////////////////////////
33
34 //================================================================
35 // Function : computeEditGeometry
36 // Purpose  : static function - used for resizing editing widget
37 //================================================================
38 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
39                          SalomeApp_EntityEdit*   theWidget)  
40 {
41   if (!theItem)
42     return;
43   QListView* aListView = theItem->listView();
44   int anEditColumn = theItem->getEditedColumn();
45   if (anEditColumn < 0)
46     return;
47   
48   int aX = 0, aY = 0, aW = 0, aH = 0;
49
50   QRect aRect = aListView->itemRect(theItem);
51   aListView->contentsToViewport(aListView->header()->sectionPos(anEditColumn), 0, aX, aY);
52   if (aX < 0)
53     aX = 0; // THIS CAN BE REMOVED
54   QSize aSize = theWidget->getControl()->sizeHint();
55   aH = QMAX(aSize.height() , aRect.height() );
56   aY = aRect.y() - ((aH - aRect.height()) / 2);
57   //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
58   aW = aListView->viewport()->width() - aX;
59   if (aW < 0)
60     aW = 0;
61   theWidget->setGeometry(aX, aY, aW, aH);
62 }
63
64 //================================================================
65 // Function : SalomeApp_ListView::SalomeApp_ListView
66 // Purpose  : constructor
67 //================================================================
68 SalomeApp_ListView::SalomeApp_ListView(QWidget *parent) :
69 QListView(parent) 
70 {
71   myMouseEnabled = true;
72   myEditingEnabled = false;
73   setSelectionMode(Single);
74   setSorting(-1);
75   setRootIsDecorated(false);
76   setAllColumnsShowFocus(false);
77 //  header()->setClickEnabled(false);
78   header()->setMovingEnabled(false);
79
80   myEditedItem = 0;
81   myEdit = 0;
82
83   viewport()->installEventFilter(this);
84
85   connect(this, SIGNAL(selectionChanged()), 
86           this, SLOT(onSelectionChanged()));
87   connect(header(), SIGNAL(sizeChange(int, int, int)), 
88           this,     SLOT(onHeaderSizeChange(int, int, int)));
89 }
90
91 //================================================================
92 // Function : SalomeApp_ListView::~SalomeApp_ListView
93 // Purpose  : destructor
94 //================================================================
95 SalomeApp_ListView::~SalomeApp_ListView() 
96 {
97   if (myEdit) {
98     delete myEdit;
99   }
100   myEdit = 0;
101   myEditedItem = 0;
102 }
103
104 //================================================================
105 // Function : SalomeApp_ListView::updateViewer
106 // Purpose  : updates all data viewer
107 //================================================================
108 void SalomeApp_ListView::updateViewer() 
109 {
110   // temporary disconnecting selection changed SIGNAL
111   blockSignals(true);
112   SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)firstChild();
113   if (aRoot)
114     aRoot->updateAllLevels();
115   updateContents();
116   // connecting again selection changed SIGNAL
117   blockSignals(false);
118   emit selectionChanged();
119 }
120
121 //================================================================
122 // Function : SalomeApp_ListView::updateSelected
123 // Purpose  : updates currently selected item(s)
124 //================================================================
125 void SalomeApp_ListView::updateSelected() 
126 {
127   // temporary disconnecting selection changed SIGNAL
128   blockSignals(true);
129   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)selectedItem();
130   if (aChild)
131     aChild->updateAllLevels();
132   updateContents();
133   // connecting again selection changed SIGNAL
134   blockSignals(false);
135   emit selectionChanged();
136 }
137
138 //================================================================
139 // Function : SalomeApp_ListView::popupClientType
140 // Purpose  : returns popup client type
141 //================================================================
142 QString SalomeApp_ListView::popupClientType() const
143 {
144   return "SalomeApp_ListView";
145 }
146
147 //================================================================
148 // Function : SalomeApp_ListView::contextMenuPopup
149 // Purpose  : fills popup menu with items
150 //================================================================
151 void SalomeApp_ListView::contextMenuPopup( QPopupMenu* aPopup ) 
152 {
153   if (aPopup) {
154     // add items here...
155   }
156 }
157
158 //================================================================
159 // Function : SalomeApp_ListView::clear
160 // Purpose  : clears view
161 //================================================================
162 void SalomeApp_ListView::clear() 
163 {
164   if (myEdit) {
165     delete myEdit;
166     myEdit = 0;
167     myEditedItem = 0;
168   }
169   QListView::clear();
170 }
171
172 //================================================================
173 // Function : SalomeApp_ListView::isMouseEnabled
174 // Purpose  : returms true if mouse events are enabled
175 //================================================================
176 bool SalomeApp_ListView::isMouseEnabled() 
177 {
178   return myMouseEnabled;
179 }
180
181 //================================================================
182 // Function : SalomeApp_ListView::enableMouse
183 // Purpose  : enabled/disables mouse events (excluding MouseMove)
184 //================================================================
185 void SalomeApp_ListView::enableMouse(bool enable) 
186 {
187   myMouseEnabled = enable;
188 }
189
190 //================================================================
191 // Function : SalomeApp_ListView::eventFilter
192 // Purpose  : event filter
193 //================================================================
194 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event) 
195 {
196   if (object == viewport() &&
197        (event->type() == QEvent::MouseButtonPress   ||
198         event->type() == QEvent::MouseButtonRelease ||
199         event->type() == QEvent::MouseButtonDblClick)  &&
200       !isMouseEnabled())
201     return true;
202   else
203     return QListView::eventFilter(object, event);
204 }
205
206 //================================================================
207 // Function : SalomeApp_ListView::enableEditing
208 // Purpose  : setting editing of items availbale/not available
209 //================================================================
210 void SalomeApp_ListView::enableEditing(bool theFlag) 
211 {
212   myEditingEnabled = theFlag;
213   if (!myEditingEnabled) {
214     if (myEdit) {
215       delete myEdit;
216       myEdit = 0;
217       myEditedItem = 0;
218     }
219   }
220 }
221
222 //================================================================
223 // Function : SalomeApp_ListView::isEnableEditing
224 // Purpose  : says if editing is enabled
225 //================================================================
226 bool SalomeApp_ListView::isEnableEditing() 
227 {
228   return myEditingEnabled;
229 }
230
231 //================================================================
232 // Function : SalomeApp_ListView::accept
233 // Purpose  : calls finishEditing(true)...
234 //================================================================
235 void SalomeApp_ListView::accept() 
236 {
237   finishEditing(true);
238 }
239
240 //================================================================
241 // Function : QAD_ListView::onSelectionChanged
242 // Purpose  : slot, called when selection changed in List Viewer
243 //================================================================
244 void SalomeApp_ListView::onSelectionChanged() 
245 {
246   if (myEdit) {
247     finishEditing(true);
248     delete myEdit;
249     myEdit = 0;
250     if (myEditedItem && !myEditedItem->isAccepted()) {
251       delete myEditedItem;
252       updateContents();
253     }
254     myEditedItem = 0;
255   } 
256   // editing is allowed in Single Selection Mode only
257   if (selectionMode() != Single || !isEnableEditing())
258     return;
259   SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)selectedItem();
260   if (anItem) {
261     if (!anItem->isEditable())
262       return;
263     myEdit = anItem->startEditing();
264     if (myEdit) {
265       connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
266       connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
267       myEditedItem = anItem;
268       myEdit->show();
269       myEdit->setFocus();
270     }
271   }
272 }
273
274 //================================================================
275 // Function : SalomeApp_ListView::resizeEvent
276 // Purpose  : called when Data Viewer is resized
277 //================================================================
278 void SalomeApp_ListView::resizeEvent( QResizeEvent * e) 
279 {
280   QListView::resizeEvent(e);
281   int aW = columnWidth(columns()-1);
282   int aX = header()->sectionPos(columns()-1);
283   if (aW < width() - frameWidth() * 2 - aX - 1)
284     setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
285   updateContents();
286 }
287
288 //================================================================
289 // Function : SalomeApp_ListView::onHeaderSizeChange
290 // Purpose  : slot, called when columns sizes are changed
291 //================================================================
292 void SalomeApp_ListView::onHeaderSizeChange(int, int, int) 
293 {
294   int aW = columnWidth(columns()-1);
295   int aX = header()->sectionPos(columns()-1);
296   if (aW < width() - frameWidth() * 2 - aX - 1)
297     setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
298 }
299
300 //================================================================
301 // Function : SalomeApp_ListView::viewportPaintEvent
302 // Purpose  : handler for paint event
303 //================================================================
304 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e) 
305 {
306   QListView::viewportPaintEvent(e);
307   if (myEditedItem && myEdit) {
308     computeEditGeometry(myEditedItem, myEdit);
309   }
310 }
311
312 //================================================================
313 // Function : SalomeApp_ListView::onEditOk
314 // Purpose  : called when user finishes in editing of item
315 //================================================================
316 void SalomeApp_ListView::onEditOk() 
317 {
318   finishEditing(true);
319 }
320   
321 //================================================================
322 // Function : SalomeApp_ListView::onEditCancel
323 // Purpose  : called when user cancels item editing
324 //================================================================
325 void SalomeApp_ListView::onEditCancel() 
326 {
327   finishEditing(false);
328 }
329
330 //================================================================
331 // Function : SalomeApp_ListView::finishEditing
332 // Purpose  : finishes editing of entity
333 //================================================================
334 UpdateType SalomeApp_ListView::finishEditing(bool ok) 
335 {
336   UpdateType aNeedsUpdate = utCancel;
337   if (myEditedItem && myEdit)
338   {
339     disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
340     disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
341     myEditedItem->setAccepted(true);
342     if (ok) {
343       aNeedsUpdate = myEditedItem->finishEditing(myEdit);
344       if (aNeedsUpdate == utCancel) {
345         // something to do here on Cancel...
346       }
347       else {
348         // something to do here on OK...
349       }
350       // updating contents
351       switch (aNeedsUpdate) {
352       case utUpdateItem:
353         {
354           if (myEditedItem)
355             myEditedItem->updateAllLevels();
356           break;
357         }
358       case utUpdateParent:
359         {
360           if (myEditedItem) {
361             SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
362             if (aParent)
363               aParent->updateAllLevels();
364             else 
365               myEditedItem->updateAllLevels();
366           }
367           break;
368         }
369       case utUpdateViewer:
370         {
371           updateViewer();
372           break;
373         }
374       case utUpdateAll:
375         {
376           // doing the same as for utUpdateViewer here
377           // descendants can add extra processing
378           updateViewer();
379           break;
380         }
381       default:
382         break;
383       }
384     }
385   }
386
387   // hide <myEdit> widget
388   if (myEdit) {
389     myEdit->hide();
390   }
391
392   return aNeedsUpdate;
393 }
394
395 //================================================================
396 // Function : SalomeApp_ListView::tip
397 // Purpose  : gets current tooltip for list view
398 //            returns valid rect in success
399 //================================================================
400 QRect SalomeApp_ListView::tip(QPoint aPos, 
401                         QString& aText, 
402                         QRect& dspRect, 
403                         QFont& dspFnt) const 
404 {
405   QRect result( -1, -1, -1, -1 );
406   SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
407   if ( aItem ) {
408     for (int i = 0; i < columns(); i++) {
409       QRect aItemRect = aItem->itemRect(i);
410       QRect aTextRect = aItem->textRect(i);
411       if ( !aItem->text(i).isEmpty() &&
412            ( aItemRect.width()  > header()->sectionSize(i) ||
413              aTextRect.left()   < 0 || 
414              aTextRect.top()    < 0 ||
415              aTextRect.right()  > viewport()->width() ||
416              aTextRect.bottom() > viewport()->height() ) ) {
417         // calculating tip data
418         aText   = aItem->tipText();
419         dspRect = aItem->tipRect();
420         dspFnt  = font();
421         if (dspRect.isValid()) {
422           result  = QRect(QPoint(0, aItemRect.top()), 
423                           QSize(viewport()->width(), aItemRect.height()));
424         }
425       }
426     }
427   }
428   return result;
429 }
430
431 //////////////////////////////////////////////////////////////////////
432 // SalomeApp_ListViewItem Class Implementation
433 //////////////////////////////////////////////////////////////////////
434
435 //================================================================
436 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
437 // Purpose  : constructor
438 //================================================================
439 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
440 QListViewItem( parent ) 
441 {
442   init();
443 }
444
445 //================================================================
446 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
447 // Purpose  : constructor
448 //================================================================
449 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent, 
450                                    SalomeApp_ListViewItem* after) :
451 QListViewItem( parent, after ) 
452 {
453   init();
454 }
455
456 //================================================================
457 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
458 // Purpose  : constructor
459 //================================================================
460 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent, 
461                                    const QString&    theName,
462                                    const bool        theEditable) :
463 QListViewItem(parent, theName) 
464 {
465   init();
466   setEditable(theEditable);
467 }
468
469 //================================================================
470 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
471 // Purpose  : constructor
472 //================================================================
473 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent, 
474                                    const QString&    theName,
475                                    const QString&    theValue,
476                                    const bool        theEditable) :
477 QListViewItem(parent, theName, theValue) 
478 {
479   init();
480   setEditable(theEditable);
481 }
482
483 //================================================================
484 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
485 // Purpose  : constructor
486 //================================================================
487 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent, 
488                                    const QString&    theName,
489                                    const bool        theEditable) :
490 QListViewItem(parent, theName)
491 {
492   init();
493   setEditable(theEditable);
494 }
495
496 //================================================================
497 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
498 // Purpose  : constructor
499 //================================================================
500 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent, 
501                                    SalomeApp_ListViewItem* after, 
502                                    const QString&    theName,
503                                    const bool        theEditable) :
504 QListViewItem(parent, after, theName)
505 {
506   init();
507   setEditable(theEditable);
508 }
509
510 //================================================================
511 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
512 // Purpose  : constructor
513 //================================================================
514 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent, 
515                                    SalomeApp_ListViewItem* after, 
516                                    const QString&    theName,
517                                    const bool        theEditable) :
518 QListViewItem(parent, after, theName)
519 {
520   init();
521   setEditable(theEditable);
522 }
523
524
525 //================================================================
526 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
527 // Purpose  : constructor
528 //================================================================
529 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent, 
530                                    const QString&    theName,
531                                    const QString&    theValue,
532                                    const bool        theEditable) :
533 QListViewItem(parent, theName, theValue)
534 {
535   init();
536   setEditable(theEditable);
537 }
538
539
540 //================================================================
541 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
542 // Purpose  : constructor
543 //================================================================
544 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent, 
545                                    SalomeApp_ListViewItem* after, 
546                                    const QString&    theName,
547                                    const QString&    theValue,
548                                    const bool        theEditable) :
549 QListViewItem(parent, after, theName, theValue)
550 {
551   init();
552   setEditable(theEditable);
553 }
554
555 //================================================================
556 // Function : SalomeApp_ListViewItem::SalomeApp_ListViewItem
557 // Purpose  : constructor
558 //================================================================
559 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView*     parent, 
560                                    SalomeApp_ListViewItem* after, 
561                                    const QString&    theName,
562                                    const QString&    theValue,
563                                    const bool        theEditable) :
564 QListViewItem(parent, after, theName, theValue)
565 {
566   init();
567   setEditable(theEditable);
568 }
569
570 //================================================================
571 // Function : SalomeApp_ListViewItem::~SalomeApp_ListViewItem
572 // Purpose  : destructor
573 //================================================================
574 SalomeApp_ListViewItem::~SalomeApp_ListViewItem() 
575 {
576 }
577
578 //================================================================
579 // Function : SalomeApp_ListViewItem::init
580 // Purpose  : initialization
581 //================================================================
582 void SalomeApp_ListViewItem::init() 
583 {
584   myEditable    = false;
585   myAccepted    = true;
586   myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
587   myValueType   = (int)SalomeApp_EntityEdit::vtString;
588   myButtons     = 0;
589   myUserType    = -1;
590 }
591
592 //================================================================
593 // Function : SalomeApp_ListViewItem::getName
594 // Purpose  : as default returns text in the first column
595 //================================================================
596 QString SalomeApp_ListViewItem::getName() const 
597 {
598   return ( listView()->columns() > 0 ) ? text(0) : QString("");
599 }
600
601 //================================================================
602 // Function : SalomeApp_ListViewItem::setName
603 // Purpose  : as default sets text in the first column
604 //================================================================
605 UpdateType SalomeApp_ListViewItem::setName(const QString& theName) 
606 {
607   UpdateType aNeedsUpdate = utCancel;
608   if (listView()->columns() > 0) {
609     setText(0, theName);
610     aNeedsUpdate = utNone;
611   }
612   return aNeedsUpdate;
613 }
614
615 //================================================================
616 // Function : SalomeApp_ListViewItem::getValue
617 // Purpose  : as default returns text in the second column
618 //================================================================
619 QString SalomeApp_ListViewItem::getValue() const 
620 {
621   return ( listView()->columns() > 1 ) ? text(1) : QString("");
622 }
623
624 //================================================================
625 // Function : SalomeApp_ListViewItem::setValue
626 // Purpose  : as default sets text in the second column
627 //================================================================
628 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue) 
629 {
630   UpdateType aNeedsUpdate = utCancel;
631   if (listView()->columns() > 1) {
632     setText(1, theValue);
633     aNeedsUpdate = utNone;
634   }
635   return aNeedsUpdate;
636 }
637
638 //================================================================
639 // Function : SalomeApp_ListViewItem::fullName
640 // Purpose  : returns full path to the entity from the root
641 //================================================================
642 QString SalomeApp_ListViewItem::fullName() 
643 {
644   QString aFullName = getName();
645   SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
646   while(aParent != NULL) {
647     aFullName = aParent->getName() + QString(".") + aFullName;
648     aParent = (SalomeApp_ListViewItem*)(aParent->parent());
649   }
650   return aFullName;
651 }
652
653 //================================================================
654 // Function : SalomeApp_ListViewItem::openAllLevels
655 // Purpose  : expands all entities beginning from this level
656 //================================================================
657 void SalomeApp_ListViewItem::openAllLevels() 
658 {
659   setOpen(true);
660   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
661   while( aChild ) {
662     aChild->openAllLevels();
663     aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
664   }
665 }
666
667 //================================================================
668 // Function : SalomeApp_ListViewItem::updateAllLevels
669 // Purpose  : update all entites beginning from this level
670 //================================================================
671 void SalomeApp_ListViewItem::updateAllLevels() 
672 {
673   SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
674   while( aChild ) {
675     aChild->updateAllLevels();
676     aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
677   }
678 }
679
680 //================================================================
681 // Function : SalomeApp_EditBox::isEditable
682 // Purpose  : return true if entity is editable
683 //================================================================
684 bool SalomeApp_ListViewItem::isEditable() const 
685 {
686   return myEditable;
687 }
688
689 //================================================================
690 // Function : SalomeApp_ListViewItem::setEditable
691 // Purpose  : sets editable flag fo the entity
692 //================================================================
693 void SalomeApp_ListViewItem::setEditable(bool theEditable) 
694 {
695   myEditable = theEditable;
696 }
697
698 //================================================================
699 // Function : SalomeApp_ListViewItem::isAccepted
700 // Purpose  : returns true if entitiy is accepted after editing
701 //================================================================
702 bool SalomeApp_ListViewItem::isAccepted() const 
703 {
704   return myAccepted;
705 }
706
707 //================================================================
708 // Function : SalomeApp_ListViewItem::setAccepted
709 // Purpose  : set entitiy accepted or not after editing
710 //================================================================
711 void SalomeApp_ListViewItem::setAccepted(bool theAccepted) 
712 {
713   myAccepted = theAccepted;
714 }
715
716 //================================================================
717 // Function : SalomeApp_ListViewItem::getEditingType
718 // Purpose  : returns type of edit control (0 - edit box, 1 - combo box, 
719 //            2 - editable combo box),  default is edit box
720 //================================================================
721 int SalomeApp_ListViewItem::getEditingType() 
722 {
723   return myEditingType;
724 }
725
726 //================================================================
727 // Function : SalomeApp_ListViewItem::setEditingType
728 // Purpose  : sets type of edit control (0 - edit box, 1 - combo box, 
729 //            2 - editable combo box), negative value means none
730 //================================================================
731 void SalomeApp_ListViewItem::setEditingType(const int type) 
732 {
733   myEditingType = type;
734 }
735
736 //================================================================
737 // Function : SalomeApp_ListViewItem::getEditedColumn
738 // Purpose  : returns edited column, default is last column
739 //            negative value means there are no editable columns
740 //================================================================
741 int SalomeApp_ListViewItem::getEditedColumn() 
742 {
743   return listView()->columns()-1;
744 }
745
746 //================================================================
747 // Function : SalomeApp_ListViewItem::getValueType
748 // Purpose  : returns type of edited value (string, int, double)
749 //            default is string
750 //================================================================
751 int SalomeApp_ListViewItem::getValueType() 
752 {
753   return myValueType;
754 }
755
756 //================================================================
757 // Function : SalomeApp_ListViewItem::setValueType
758 // Purpose  : sets type of edited value
759 //================================================================
760 void SalomeApp_ListViewItem::setValueType(const int valueType) 
761 {
762   myValueType = valueType;
763 }
764
765 //================================================================
766 // Function : SalomeApp_ListViewItem::getUserType
767 // Purpose  : sets type of edited value
768 //================================================================
769 int SalomeApp_ListViewItem::getUserType() 
770 {
771   return myUserType;
772 }
773
774 //================================================================
775 // Function : SalomeApp_ListViewItem::setUserType
776 // Purpose  : sets type of edited value
777 //================================================================
778 void SalomeApp_ListViewItem::setUserType(const int userType) 
779 {
780   myUserType = userType;
781 }
782
783 //================================================================
784 // Function : SalomeApp_ListViewItem::getButtons
785 // Purpose  : returns buttons for editing widget (Apply (V), Cancel (X))
786 //            default is both buttons
787 //================================================================
788 int SalomeApp_ListViewItem::getButtons() 
789 {
790   return myButtons;
791 }
792
793 //================================================================
794 // Function : SalomeApp_ListViewItem::getButtons
795 // Purpose  : sets buttons for editing widget (Apply (V), Cancel (X))
796 //================================================================
797 void SalomeApp_ListViewItem::setButtons(const int buttons) 
798 {
799   myButtons = buttons;
800 }
801
802 //================================================================
803 // Function : SalomeApp_ListViewItem::startEditing
804 // Purpose  : creates control for editing and fills it with values
805 //================================================================
806 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing() 
807 {
808   SalomeApp_EntityEdit* aWidget = 0;
809   QListView* aListView = listView();
810   if (aListView) {
811     if (!isEditable())
812       return 0;
813     int anEditType   = getEditingType();
814     int aValueType   = getValueType();
815     int aButtons     = getButtons();
816     int anEditColumn = getEditedColumn();
817     if (anEditColumn < 0 || anEditType < 0)
818       return 0;
819     aWidget = new SalomeApp_EntityEdit(aListView->viewport(), 
820                                  anEditType, 
821                                  aValueType, 
822                                  aButtons & SalomeApp_EntityEdit::btApply,
823                                  aButtons & SalomeApp_EntityEdit::btCancel);
824     computeEditGeometry(this, aWidget);
825
826     fillWidgetWithValues(aWidget);
827   }
828   return aWidget;
829 }
830
831 //================================================================
832 // Function : SalomeApp_ListViewItem::fillWidgetWithValues
833 // Purpose  : fills widget with initial values (list or single value)
834 //================================================================
835 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget) 
836 {
837   int anEditColumn = getEditedColumn();
838   if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
839     theWidget->insertItem(text(anEditColumn), true);
840 }
841
842 //================================================================
843 // Function : SalomeApp_ListViewItem::finishEditing
844 // Purpose  : finishes editing of entity
845 //================================================================
846 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget) 
847 {
848   UpdateType aNeedsUpdate = utCancel;
849   try {
850     if (theWidget) {
851       int anEditColumn = getEditedColumn();
852       switch (anEditColumn) {
853       case 0:
854         aNeedsUpdate = setName(theWidget->getText());
855         break;
856       case 1:
857         aNeedsUpdate = setValue(theWidget->getText());
858         break;
859       default: 
860         break;
861       }
862     } 
863   }
864   catch (...) {
865     MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
866   }
867   return aNeedsUpdate;
868 }
869
870 //================================================================
871 // Function : SalomeApp_ListViewItem::tipRect
872 // Purpose  : calculates rectangle which should contain item's tip
873 //================================================================
874 QRect SalomeApp_ListViewItem::tipRect() 
875 {
876   QRect aRect = QRect(-1, -1, -1, -1);
877   QRect aItemRect = listView()->itemRect(this);
878   if ( !aItemRect.isValid() )
879     return aItemRect;
880
881   QString aTip = tipText();
882   if (!aTip.isEmpty()) {
883     QRect aRect0 = textRect(0);
884     QFont aFont(listView()->font());
885     QFontMetrics fm(aFont);
886     int iw = fm.width(aTip);
887     aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(), 
888                          aRect0.y()), 
889                   QSize (iw,         
890                          aRect0.height()));
891   }
892   return aRect;
893 }
894
895 //================================================================
896 // Function : SalomeApp_ListViewItem::tipText
897 // Purpose  : returns text for tooltip
898 //================================================================
899 QString SalomeApp_ListViewItem::tipText() 
900 {
901   QString aText = getName();
902   if (!getValue().isEmpty())
903     aText += QString(" : ") + getValue();
904   return aText;
905 }
906
907 //================================================================
908 // Function : SalomeApp_ListViewItem::textRect
909 // Purpose  : calculates rect of item text in viewport coordinates
910 //================================================================
911 QRect SalomeApp_ListViewItem::textRect(const int column) const
912 {
913   QRect aItemRect = listView()->itemRect( this );
914   if ( !aItemRect.isValid() )
915     return aItemRect;
916   
917   QFont aFont(listView()->font());
918   QFontMetrics fm(aFont);
919   
920   int decorWidth  = ( listView()->rootIsDecorated() ) ? 
921                     ( listView()->treeStepSize() * (depth() + 1) ) :
922                     ( listView()->treeStepSize() *  depth() );
923   int pixmapWidth = ( pixmap(column) ) ? 
924                       pixmap(column)->width() +  listView()->itemMargin() * 2 : 
925                       listView()->itemMargin();
926   int prevWidth = 0;
927   for (int i = 0; i < column; i++)
928     prevWidth += listView()->header()->sectionSize(i);
929   int ix = prevWidth   +
930            pixmapWidth + 
931            ((column == 0) ? decorWidth : 0);
932   int iy = aItemRect.y();
933   int iw = fm.width(text(column));
934   int ih = aItemRect.height();
935   if (pixmap(column)) {
936     iy += listView()->itemMargin();
937     ih -= listView()->itemMargin() * 2;
938   }
939   ix -= listView()->contentsX();
940
941   QRect theResult(QPoint(ix, iy), QSize(iw, ih));
942   return theResult;
943 }
944
945 //================================================================
946 // Function : SalomeApp_ListViewItem::itemRect
947 // Purpose  : calculates rect of item data in viewport coordinates
948 //================================================================
949 QRect SalomeApp_ListViewItem::itemRect(const int column) const
950 {
951   QRect aItemRect = listView()->itemRect( this );
952   if ( !aItemRect.isValid() )
953     return aItemRect;
954   
955   QFont aFont(listView()->font());
956   QFontMetrics fm(aFont);
957   
958   int decorWidth  = ( listView()->rootIsDecorated() ) ? 
959                     ( listView()->treeStepSize() * (depth() + 1) ) :
960                     ( listView()->treeStepSize() *  depth() );
961   int pixmapWidth = ( pixmap(column) ) ? 
962                       pixmap(column)->width() +  listView()->itemMargin() * 2 : 
963                       0;
964   int prevWidth = 0;
965   for (int i = 0; i < column; i++)
966     prevWidth += listView()->header()->sectionSize(i);
967   int ix = prevWidth;
968   int iy = aItemRect.y();
969   int iw = pixmapWidth + 
970            listView()->itemMargin() * 2 + 
971            ((column == 0) ? decorWidth : 0) + 
972            fm.width(text(column));
973   int ih = aItemRect.height();
974   ix -= listView()->contentsX();
975
976   QRect theResult(QPoint(ix, iy), QSize(iw, ih));
977   return theResult;
978 }
979
980 //////////////////////////////////////////////////////////////////////
981 // SalomeApp_EditBox class implementation
982 //////////////////////////////////////////////////////////////////////
983
984 //================================================================
985 // Function : SalomeApp_EditBox::SalomeApp_EditBox
986 // Purpose  : constructor
987 //================================================================
988 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
989 QLineEdit(parent) 
990 {
991 }
992
993 //================================================================
994 // Function : SalomeApp_EditBox::keyPressEvent
995 // Purpose  : event filter for key pressing
996 //================================================================
997 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e ) 
998 {
999   if ( e->key() == Key_Escape )
1000     emit escapePressed();
1001   else
1002     QLineEdit::keyPressEvent( e );
1003   e->accept();
1004 }
1005
1006 //////////////////////////////////////////////////////////////////////
1007 // SalomeApp_ComboBox class implementation
1008 //////////////////////////////////////////////////////////////////////
1009
1010 //================================================================
1011 // Function : SalomeApp_ComboBox::SalomeApp_ComboBox
1012 // Purpose  : constructor
1013 //================================================================
1014 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
1015 QComboBox(rw, parent, name) 
1016 {
1017 }
1018
1019 //================================================================
1020 // Function : SalomeApp_ComboBox::findItem
1021 // Purpose  : searches item in list and returns its index
1022 //================================================================
1023 int SalomeApp_ComboBox::findItem(const QString& theText) 
1024 {
1025   for (int i = 0; i < count(); i++) 
1026     if (text(i) == theText)
1027       return i;
1028   return -1;
1029 }
1030
1031 //================================================================
1032 // Function : SalomeApp_ComboBox::insertItem
1033 // Purpose  : adds item in combo box
1034 //================================================================
1035 void SalomeApp_ComboBox::insertItem(const QString& theValue,
1036                               int            theIndex) 
1037 {
1038   if (duplicatesEnabled() || findItem(theValue) < 0)
1039     QComboBox::insertItem(theValue, theIndex);
1040 }
1041
1042 //================================================================
1043 // Function : SalomeApp_ComboBox::insertList
1044 // Purpose  : adds list of items in combo box
1045 //================================================================
1046 void SalomeApp_ComboBox::insertList(const QStringList& theList) 
1047 {
1048   for (unsigned i = 0; i < theList.count(); i++)
1049     insertItem(theList[i]);
1050 }
1051
1052 //================================================================
1053 // Function : SalomeApp_ComboBox::insertItem
1054 // Purpose  : adds item in combo box
1055 //================================================================
1056 void SalomeApp_ComboBox::insertItem(const int theValue) 
1057 {
1058   int aNum;
1059   bool bOk;
1060   for (int i = 0; i < count(); i++) {
1061     aNum = text(i).toInt(&bOk);
1062     if (bOk) {
1063       if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1064         insertItem(QString::number(theValue), i);
1065         return;
1066       }
1067     }
1068   }
1069   insertItem(QString::number(theValue));
1070 }
1071
1072 //================================================================
1073 // Function : SalomeApp_ComboBox::insertList
1074 // Purpose  : adds list of items in combo box
1075 //================================================================
1076 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList) 
1077 {
1078   for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1079     insertItem(aIter.Value());
1080 }
1081
1082 //================================================================
1083 // Function : SalomeApp_ComboBox::insertItem
1084 // Purpose  : adds item in combo box
1085 //================================================================
1086 void SalomeApp_ComboBox::insertItem(const double theValue) 
1087 {
1088   double aNum;
1089   bool bOk;
1090   for (int i = 0; i < count(); i++) {
1091     aNum = text(i).toDouble(&bOk);
1092     if (bOk) {
1093       if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1094         insertItem(QString::number(theValue), i);
1095         return;
1096       }
1097     }
1098   }
1099   insertItem(QString::number(theValue));
1100 }
1101
1102 //================================================================
1103 // Function : SalomeApp_ComboBox::insertList
1104 // Purpose  : adds list of items in combo box
1105 //================================================================
1106 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList) 
1107 {
1108   for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1109     insertItem(aIter.Value());
1110 }
1111
1112 //////////////////////////////////////////////////////////////////////
1113 // SalomeApp_EntityEdit class implementation
1114 //////////////////////////////////////////////////////////////////////
1115
1116 #include <qlayout.h>
1117
1118 #define MIN_COMBO_WIDTH     1
1119 #define MIN_EDIT_WIDTH      1
1120
1121 //================================================================
1122 // Function : SalomeApp_EntityEdit::SalomeApp_EntityEdit
1123 // Purpose  : constructor
1124 //================================================================
1125 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent, 
1126                                int      controlType,
1127                                int      valueType,
1128                                bool     butApply, 
1129                                bool     butCancel) :
1130 QWidget(parent),
1131 myEdit(0),
1132 myCombo(0),
1133 myApplyBtn(0),
1134 myCancelBtn(0) 
1135 {
1136   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1137   SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1138
1139   QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1140   aTopLayout->setAlignment( Qt::AlignTop );
1141   aTopLayout->setSpacing( 0 );
1142   aTopLayout->setMargin( 1 );
1143   if (controlType != etLineEdit && 
1144       controlType != etComboBox && 
1145       controlType != etComboEdit)
1146     controlType = etLineEdit;
1147   if (controlType == etComboBox || controlType == etComboEdit) {
1148     // this is an editable combo box
1149     myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1150     myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1151     myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1152                                        QSizePolicy::Fixed));
1153     // no insertions
1154     myCombo->setInsertionPolicy(QComboBox::NoInsertion);
1155     // no duplicates enabled by default
1156     myCombo->setDuplicatesEnabled(false);
1157     aTopLayout->addWidget(myCombo);
1158     // connect signals
1159     connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1160     connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1161   }
1162   else {
1163     // and this is an edit box
1164     myEdit = new SalomeApp_EditBox(this);
1165     myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1166     myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1167                                       QSizePolicy::Fixed));
1168     aTopLayout->addWidget(myEdit);
1169     connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1170     connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1171     connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1172   }
1173   if (valueType != vtString && 
1174       valueType != vtInteger && 
1175       valueType != vtDouble)
1176     valueType = vtString;
1177   if (valueType == vtInteger)
1178     setValidator(new QIntValidator(this));
1179   else if (valueType == vtDouble)
1180     setValidator(new QDoubleValidator(this));
1181   if (butApply) {
1182     // Apply button (V)
1183     myApplyBtn = new QToolButton(this);
1184     
1185     QPixmap anIcon;
1186     if( mgr )
1187       anIcon = mgr->loadPixmap( "STD", tr( "ICON_APPLY" ) );
1188
1189     myApplyBtn->setPixmap(anIcon);
1190     myApplyBtn->setEnabled(false);
1191     myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1192     myApplyBtn->setMinimumSize(16, 16);
1193     myApplyBtn->setMaximumSize(16, 20);
1194     aTopLayout->addWidget(myApplyBtn);
1195     connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1196   }
1197   if (butCancel) {
1198     // Cancel button (X)
1199     myCancelBtn = new QToolButton(this);
1200     QPixmap anIcon;
1201     if( mgr )
1202       anIcon = mgr->loadPixmap( "STD", tr( "ICON_CANCEL" ) );
1203     myCancelBtn->setPixmap(anIcon);
1204     myCancelBtn->setEnabled(false);
1205     myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1206     myCancelBtn->setMinimumSize(16, 16);
1207     myCancelBtn->setMaximumSize(16, 20);
1208     aTopLayout->addWidget(myCancelBtn);
1209     connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1210   }
1211 }
1212
1213 //================================================================
1214 // Function : SalomeApp_EntityEdit::~SalomeApp_EntityEdit
1215 // Purpose  : destructor
1216 //================================================================
1217 SalomeApp_EntityEdit::~SalomeApp_EntityEdit() 
1218 {
1219 }
1220
1221 //================================================================
1222 // Function : SalomeApp_EntityEdit::clear
1223 // Purpose  : clears edit/combo box
1224 //================================================================
1225 void SalomeApp_EntityEdit::clear() 
1226 {
1227   if (myEdit)
1228     myEdit->clear();
1229   if (myCombo)
1230     myCombo->clear();
1231 }
1232
1233 //================================================================
1234 // Function : SalomeApp_EntityEdit::getText
1235 // Purpose  : returns current text in edit box or combo box
1236 //================================================================
1237 QString SalomeApp_EntityEdit::getText() 
1238 {
1239   if (myEdit)
1240     return myEdit->text();
1241   else if (myCombo)
1242     return myCombo->currentText();
1243   else
1244     return "";
1245 }
1246
1247 //================================================================
1248 // Function : SalomeApp_EntityEdit::setText
1249 // Purpose  : sets text
1250 //================================================================
1251 void SalomeApp_EntityEdit::setText(const QString& theText) 
1252 {
1253   myString = theText;
1254   if (myEdit)
1255     myEdit->setText(theText);
1256   if (myCombo) {
1257     int aFound = myCombo->findItem(theText);
1258     if (aFound >= 0) {
1259       myCombo->setCurrentItem(aFound);
1260       onTextChanged(theText);
1261     }
1262   }
1263 }
1264
1265 //================================================================
1266 // Function : SalomeApp_EntityEdit::insertItem
1267 // Purpose  : adds item in combo box, 
1268 //            sets it current if theSetCurrent is true
1269 //================================================================
1270 void SalomeApp_EntityEdit::insertItem(const QString& theValue, 
1271                                 bool           theSetCurrent,
1272                                 int            theOrder) 
1273 {
1274   if (myCombo) {
1275     int aIndexAt = -1;
1276     if (theOrder == atTop)
1277       aIndexAt = 0;
1278     else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1279       aIndexAt = myCombo->currentItem();
1280     else if (theOrder == atAfterCurrent && 
1281              myCombo->count() > 0 && 
1282              myCombo->currentItem() < myCombo->count()-1)
1283       aIndexAt = myCombo->currentItem() + 1;
1284     myCombo->insertItem(theValue, aIndexAt);
1285   }
1286   if (theSetCurrent)
1287     setText(theValue);
1288 }
1289
1290 //================================================================
1291 // Function : SalomeApp_EntityEdit::insertList
1292 // Purpose  : adds items in combo box, 
1293 //            sets item theCurrent as current
1294 //================================================================
1295 void SalomeApp_EntityEdit::insertList(const QStringList& theList, 
1296                                 const int          theCurrent) 
1297 {
1298   if (myCombo)
1299     myCombo->insertList(theList);
1300   if (theCurrent >= 0 && theCurrent < (int)theList.count())
1301     setText(theList[theCurrent]);
1302 }
1303
1304 //================================================================
1305 // Function : SalomeApp_EntityEdit::insertItem
1306 // Purpose  : adds item in combo box, 
1307 //            sets it current if theSetCurrent is true
1308 //================================================================
1309 void SalomeApp_EntityEdit::insertItem(const int theValue, 
1310                                 bool      theSetCurrent) 
1311 {
1312   if (myCombo) {
1313     myCombo->insertItem(theValue);
1314   }
1315   if (theSetCurrent)
1316     setText(QString::number(theValue));
1317 }
1318
1319 //================================================================
1320 // Function : SalomeApp_EntityEdit::insertList
1321 // Purpose  : adds items in combo box, 
1322 //            sets item theCurrent as current
1323 //================================================================
1324 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList, 
1325                                 const int                    theCurrent) 
1326 {
1327   if (myCombo)
1328     myCombo->insertList(theList);
1329
1330   TColStd_ListIteratorOfListOfInteger aIter(theList);
1331   for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1332     if (theCurrent == i) {
1333       setText(QString::number(aIter.Value()));
1334       break;
1335     }
1336   }
1337 }
1338
1339 //================================================================
1340 // Function : SalomeApp_EntityEdit::insertItem
1341 // Purpose  : adds item in combo box, 
1342 //            sets it current if theSetCurrent is true
1343 //================================================================
1344 void SalomeApp_EntityEdit::insertItem(const double theValue, 
1345                                 bool         theSetCurrent) 
1346 {
1347   if (myCombo) {
1348     myCombo->insertItem(theValue);
1349   }
1350   if (theSetCurrent)
1351     setText(QString::number(theValue));
1352 }
1353
1354 //================================================================
1355 // Function : SalomeApp_EntityEdit::insertList
1356 // Purpose  : adds items in combo box, 
1357 //            sets item theCurrent as current
1358 //================================================================
1359 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList, 
1360                                 const int                 theCurrent) 
1361 {
1362   if (myCombo)
1363     myCombo->insertList(theList);
1364   
1365   TColStd_ListIteratorOfListOfReal aIter(theList);
1366   for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1367     if (theCurrent == i) {
1368       setText(QString::number(aIter.Value()));
1369       break;
1370     }
1371   }
1372 }
1373
1374 //================================================================
1375 // Function : SalomeApp_EntityEdit::getControl
1376 // Purpose  : gets actual widget
1377 //================================================================
1378 QWidget* SalomeApp_EntityEdit::getControl() 
1379 {
1380   if (myEdit)
1381     return myEdit;
1382   else if (myCombo)
1383     return myCombo;
1384   else
1385     return 0;
1386 }
1387
1388 //================================================================
1389 // Function : SalomeApp_EntityEdit::setFocus
1390 // Purpose  : redirect focus to corresponding widget
1391 //================================================================
1392 void SalomeApp_EntityEdit::setFocus() 
1393 {
1394   if (myEdit) {
1395     myEdit->setFocus();
1396     //myEdit->selectAll();
1397   }
1398   else if (myCombo && myCombo->editable()) {
1399     myCombo->setFocus();
1400     //myCombo->lineEdit()->selectAll();
1401   }
1402 }
1403
1404 //================================================================
1405 // Function : SalomeApp_EntityEdit::setValidator
1406 // Purpose  : sets validator for the control
1407 //================================================================
1408 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator) 
1409 {
1410   if (myEdit)
1411     myEdit->setValidator(theValidator);
1412   if (myCombo)
1413     myCombo->setValidator(theValidator);
1414 }
1415
1416 //================================================================
1417 // Function : SalomeApp_EntityEdit::keyPressEvent
1418 // Purpose  : event filter for KeyPress event
1419 //================================================================
1420 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e) 
1421 {
1422   if ( (e->key() == Key_Enter ||
1423         e->key() == Key_Return ) )
1424     onApply();
1425   else if (e->key() == Key_Escape)
1426     onCancel();
1427 }
1428
1429 //================================================================
1430 // Function : SalomeApp_EntityEdit::onComboActivated
1431 // Purpose  : called when item activated in combo box
1432 //================================================================
1433 void SalomeApp_EntityEdit::onComboActivated(const QString& theText) 
1434 {
1435   onTextChanged(theText);
1436 }
1437
1438 //================================================================
1439 // Function : SalomeApp_EntityEdit::onTextChanged
1440 // Purpose  : slot, called when text changed in line edit
1441 //================================================================
1442 void SalomeApp_EntityEdit::onTextChanged(const QString& theText) 
1443 {
1444   if (myApplyBtn)
1445     myApplyBtn->setEnabled(!(theText == myString));
1446   if (myCancelBtn)
1447     myCancelBtn->setEnabled(!(theText == myString));
1448 }
1449
1450 //================================================================
1451 // Function : SalomeApp_EntityEdit::onCancel
1452 // Purpose  : slot, called when user presses Cancel button
1453 //================================================================
1454 void SalomeApp_EntityEdit::onCancel() 
1455 {
1456   setText(myString);
1457   if (myApplyBtn)
1458     myApplyBtn->setEnabled(false);
1459   if (myCancelBtn)
1460     myCancelBtn->setEnabled(false);
1461   emit escapePressed();
1462 }
1463
1464 //================================================================
1465 // Function : SalomeApp_EntityEdit::onApply
1466 // Purpose  : slot, called when user presses Apply button
1467 //================================================================
1468 void SalomeApp_EntityEdit::onApply() 
1469 {
1470   myString = getText();
1471   if (myApplyBtn)
1472     myApplyBtn->setEnabled(false);
1473   if (myCancelBtn)
1474     myCancelBtn->setEnabled(false);
1475   emit returnPressed();
1476 }
1477
1478 //================================================================
1479 // Function : SalomeApp_EntityEdit::showButtons
1480 // Purpose  : shows/hides buttons
1481 //================================================================
1482 void SalomeApp_EntityEdit::showButtons(bool show) 
1483 {
1484   if (myApplyBtn)
1485     show ? myApplyBtn->show()  : myApplyBtn->hide();
1486   if (myCancelBtn)
1487     show ? myCancelBtn->show() : myCancelBtn->hide();
1488 }
1489
1490 //================================================================
1491 // Function : SalomeApp_EntityEdit::setDuplicatesEnabled
1492 // Purpose  : enables/disables data duplication (for combo box)
1493 //================================================================
1494 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1495 {
1496   if (myCombo)
1497     myCombo->setDuplicatesEnabled(enabled);
1498 }