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