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