3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SalomeApp_ListView.cxx
8 // Author : Vadim SANDLER
12 #include "SalomeApp_ListView.h"
13 #include "SalomeApp_Application.h"
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_Session.h"
19 #include <qvalidator.h>
20 #include <qapplication.h>
21 #include <qtoolbutton.h>
23 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <TColStd_ListIteratorOfListOfReal.hxx>
26 #include "utilities.h"
31 Used for resizing editing widget
33 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
34 SalomeApp_EntityEdit* theWidget)
38 QListView* aListView = theItem->listView();
39 int anEditColumn = theItem->getEditedColumn();
43 int aX = 0, aY = 0, aW = 0, aH = 0;
45 QRect aRect = aListView->itemRect(theItem);
46 aListView->contentsToViewport(aListView->header()->sectionPos(anEditColumn), 0, aX, aY);
48 aX = 0; // THIS CAN BE REMOVED
49 QSize aSize = theWidget->getControl()->sizeHint();
50 aH = QMAX(aSize.height() , aRect.height() );
51 aY = aRect.y() - ((aH - aRect.height()) / 2);
52 //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
53 aW = aListView->viewport()->width() - aX;
56 theWidget->setGeometry(aX, aY, aW, aH);
62 SalomeApp_ListView::SalomeApp_ListView( QWidget* parent )
63 : QtxListView( parent )
65 myMouseEnabled = true;
66 myEditingEnabled = false;
67 setSelectionMode(Single);
69 setRootIsDecorated(false);
70 setAllColumnsShowFocus(false);
71 // header()->setClickEnabled(false);
72 header()->setMovingEnabled(false);
77 viewport()->installEventFilter(this);
79 connect(this, SIGNAL(selectionChanged()),
80 this, SLOT(onSelectionChanged()));
81 connect(header(), SIGNAL(sizeChange(int, int, int)),
82 this, SLOT(onHeaderSizeChange(int, int, int)));
88 SalomeApp_ListView::~SalomeApp_ListView()
98 Updates all data viewer
100 void SalomeApp_ListView::updateViewer()
102 // temporary disconnecting selection changed SIGNAL
104 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)firstChild();
106 aRoot->updateAllLevels();
108 // connecting again selection changed SIGNAL
110 emit selectionChanged();
114 Updates currently selected item(s)
116 void SalomeApp_ListView::updateSelected()
118 // temporary disconnecting selection changed SIGNAL
120 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)selectedItem();
122 aChild->updateAllLevels();
124 // connecting again selection changed SIGNAL
126 emit selectionChanged();
130 Returns popup client type
132 QString SalomeApp_ListView::popupClientType() const
134 return "SalomeApp_ListView";
138 Fills popup menu with items
140 void SalomeApp_ListView::contextMenuPopup( QPopupMenu* aPopup )
150 void SalomeApp_ListView::clear()
161 \return true if mouse events are enabled
163 bool SalomeApp_ListView::isMouseEnabled()
165 return myMouseEnabled;
169 Enables/disables mouse events (excluding MouseMove)
171 void SalomeApp_ListView::enableMouse(bool enable)
173 myMouseEnabled = enable;
179 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
181 if (object == viewport() &&
182 (event->type() == QEvent::MouseButtonPress ||
183 event->type() == QEvent::MouseButtonRelease ||
184 event->type() == QEvent::MouseButtonDblClick) &&
188 return QListView::eventFilter(object, event);
192 Setting editing of items availbale/not available
194 void SalomeApp_ListView::enableEditing(bool theFlag)
196 myEditingEnabled = theFlag;
197 if (!myEditingEnabled) {
207 Says if editing is enabled
209 bool SalomeApp_ListView::isEnableEditing()
211 return myEditingEnabled;
215 Calls finishEditing(true)...
217 void SalomeApp_ListView::accept()
223 Slot, called when selection changed in List Viewer
225 void SalomeApp_ListView::onSelectionChanged()
231 if (myEditedItem && !myEditedItem->isAccepted()) {
237 // editing is allowed in Single Selection Mode only
238 if (selectionMode() != Single || !isEnableEditing())
240 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)selectedItem();
242 if (!anItem->isEditable())
244 myEdit = anItem->startEditing();
246 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
247 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
248 myEditedItem = anItem;
256 Called when Data Viewer is resized
258 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
260 QListView::resizeEvent(e);
261 int aW = columnWidth(columns()-1);
262 int aX = header()->sectionPos(columns()-1);
263 if (aW < width() - frameWidth() * 2 - aX - 1)
264 setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
269 Slot, called when columns sizes are changed
271 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
273 int aW = columnWidth(columns()-1);
274 int aX = header()->sectionPos(columns()-1);
275 if (aW < width() - frameWidth() * 2 - aX - 1)
276 setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
280 Handler for paint event
282 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
284 QListView::viewportPaintEvent(e);
285 if (myEditedItem && myEdit) {
286 computeEditGeometry(myEditedItem, myEdit);
291 Called when user finishes in editing of item
293 void SalomeApp_ListView::onEditOk()
299 Called when user cancels item editing
301 void SalomeApp_ListView::onEditCancel()
303 finishEditing(false);
307 Finishes editing of entity
309 UpdateType SalomeApp_ListView::finishEditing(bool ok)
311 UpdateType aNeedsUpdate = utCancel;
312 if (myEditedItem && myEdit)
314 disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
315 disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
316 myEditedItem->setAccepted(true);
318 aNeedsUpdate = myEditedItem->finishEditing(myEdit);
319 if (aNeedsUpdate == utCancel) {
320 // something to do here on Cancel...
323 // something to do here on OK...
326 switch (aNeedsUpdate) {
330 myEditedItem->updateAllLevels();
336 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
338 aParent->updateAllLevels();
340 myEditedItem->updateAllLevels();
351 // doing the same as for utUpdateViewer here
352 // descendants can add extra processing
362 // hide <myEdit> widget
371 \return current tooltip for list view
372 \retval valid rect in success
374 QRect SalomeApp_ListView::tip(QPoint aPos,
379 QRect result( -1, -1, -1, -1 );
380 SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
382 for (int i = 0; i < columns(); i++) {
383 QRect aItemRect = aItem->itemRect(i);
384 QRect aTextRect = aItem->textRect(i);
385 if ( !aItem->text(i).isEmpty() &&
386 ( aItemRect.width() > header()->sectionSize(i) ||
387 aTextRect.left() < 0 ||
388 aTextRect.top() < 0 ||
389 aTextRect.right() > viewport()->width() ||
390 aTextRect.bottom() > viewport()->height() ) ) {
391 // calculating tip data
392 aText = aItem->tipText();
393 dspRect = aItem->tipRect();
395 if (dspRect.isValid()) {
396 result = QRect(QPoint(0, aItemRect.top()),
397 QSize(viewport()->width(), aItemRect.height()));
408 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
409 QListViewItem( parent )
417 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
418 SalomeApp_ListViewItem* after) :
419 QListViewItem( parent, after )
427 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
428 const QString& theName,
429 const bool theEditable) :
430 QListViewItem(parent, theName)
433 setEditable(theEditable);
439 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
440 const QString& theName,
441 const QString& theValue,
442 const bool theEditable) :
443 QListViewItem(parent, theName, theValue)
446 setEditable(theEditable);
452 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
453 const QString& theName,
454 const bool theEditable) :
455 QListViewItem(parent, theName)
458 setEditable(theEditable);
464 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
465 SalomeApp_ListViewItem* after,
466 const QString& theName,
467 const bool theEditable) :
468 QListViewItem(parent, after, theName)
471 setEditable(theEditable);
477 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
478 SalomeApp_ListViewItem* after,
479 const QString& theName,
480 const bool theEditable) :
481 QListViewItem(parent, after, theName)
484 setEditable(theEditable);
491 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
492 const QString& theName,
493 const QString& theValue,
494 const bool theEditable) :
495 QListViewItem(parent, theName, theValue)
498 setEditable(theEditable);
505 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
506 SalomeApp_ListViewItem* after,
507 const QString& theName,
508 const QString& theValue,
509 const bool theEditable) :
510 QListViewItem(parent, after, theName, theValue)
513 setEditable(theEditable);
519 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
520 SalomeApp_ListViewItem* after,
521 const QString& theName,
522 const QString& theValue,
523 const bool theEditable) :
524 QListViewItem(parent, after, theName, theValue)
527 setEditable(theEditable);
533 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
540 void SalomeApp_ListViewItem::init()
544 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
545 myValueType = (int)SalomeApp_EntityEdit::vtString;
551 \return text in the first column
553 QString SalomeApp_ListViewItem::getName() const
555 return ( listView()->columns() > 0 ) ? text(0) : QString("");
559 Sets text in the first column
561 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
563 UpdateType aNeedsUpdate = utCancel;
564 if (listView()->columns() > 0) {
566 aNeedsUpdate = utNone;
572 \return text in the second column
574 QString SalomeApp_ListViewItem::getValue() const
576 return ( listView()->columns() > 1 ) ? text(1) : QString("");
580 Sets text in the second column
582 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
584 UpdateType aNeedsUpdate = utCancel;
585 if (listView()->columns() > 1) {
586 setText(1, theValue);
587 aNeedsUpdate = utNone;
593 \return full path to the entity from the root
595 QString SalomeApp_ListViewItem::fullName()
597 QString aFullName = getName();
598 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
599 while(aParent != NULL) {
600 aFullName = aParent->getName() + QString(".") + aFullName;
601 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
607 expands all entities beginning from this level
609 void SalomeApp_ListViewItem::openAllLevels()
612 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
614 aChild->openAllLevels();
615 aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
620 update all entites beginning from this level
622 void SalomeApp_ListViewItem::updateAllLevels()
624 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
626 aChild->updateAllLevels();
627 aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
632 \return true if entity is editable
634 bool SalomeApp_ListViewItem::isEditable() const
640 Sets editable flag fo the entity
642 void SalomeApp_ListViewItem::setEditable(bool theEditable)
644 myEditable = theEditable;
648 \return true if entitiy is accepted after editing
650 bool SalomeApp_ListViewItem::isAccepted() const
656 Sets entitiy accepted or not after editing
658 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
660 myAccepted = theAccepted;
664 \retval type of edit control (default is edit box)
667 \li 2 - editable combo box
669 int SalomeApp_ListViewItem::getEditingType()
671 return myEditingType;
675 \retval type of edit control (negative value means none)
678 \li 2 - editable combo box
680 void SalomeApp_ListViewItem::setEditingType(const int type)
682 myEditingType = type;
685 /*! \retval edited column, default is last column
686 negative value means there are no editable columns
688 int SalomeApp_ListViewItem::getEditedColumn()
690 return listView()->columns()-1;
694 \retval type of edited value (string, int, double)
697 int SalomeApp_ListViewItem::getValueType()
703 Sets type of edited value
705 void SalomeApp_ListViewItem::setValueType(const int valueType)
707 myValueType = valueType;
711 Sets type of edited value
713 int SalomeApp_ListViewItem::getUserType()
719 Sets type of edited value
721 void SalomeApp_ListViewItem::setUserType(const int userType)
723 myUserType = userType;
727 \return buttons for editing widget (Apply (V), Cancel (X))
728 default is both buttons
730 int SalomeApp_ListViewItem::getButtons()
736 Sets buttons for editing widget (Apply (V), Cancel (X))
738 void SalomeApp_ListViewItem::setButtons(const int buttons)
744 Creates control for editing and fills it with values
746 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
748 SalomeApp_EntityEdit* aWidget = 0;
749 QListView* aListView = listView();
753 int anEditType = getEditingType();
754 int aValueType = getValueType();
755 int aButtons = getButtons();
756 int anEditColumn = getEditedColumn();
757 if (anEditColumn < 0 || anEditType < 0)
759 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
762 aButtons & SalomeApp_EntityEdit::btApply,
763 aButtons & SalomeApp_EntityEdit::btCancel);
764 computeEditGeometry(this, aWidget);
766 fillWidgetWithValues(aWidget);
772 Fills widget with initial values (list or single value)
774 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
776 int anEditColumn = getEditedColumn();
777 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
778 theWidget->insertItem(text(anEditColumn), true);
782 Finishes editing of entity
784 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
786 UpdateType aNeedsUpdate = utCancel;
789 int anEditColumn = getEditedColumn();
790 switch (anEditColumn) {
792 aNeedsUpdate = setName(theWidget->getText());
795 aNeedsUpdate = setValue(theWidget->getText());
803 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
809 Calculates rectangle which should contain item's tip
811 QRect SalomeApp_ListViewItem::tipRect()
813 QRect aRect = QRect(-1, -1, -1, -1);
814 QRect aItemRect = listView()->itemRect(this);
815 if ( !aItemRect.isValid() )
818 QString aTip = tipText();
819 if (!aTip.isEmpty()) {
820 QRect aRect0 = textRect(0);
821 QFont aFont(listView()->font());
822 QFontMetrics fm(aFont);
823 int iw = fm.width(aTip);
824 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
833 \return text for tooltip
835 QString SalomeApp_ListViewItem::tipText()
837 QString aText = getName();
838 if (!getValue().isEmpty())
839 aText += QString(" : ") + getValue();
844 Calculates rect of item text in viewport coordinates
846 QRect SalomeApp_ListViewItem::textRect(const int column) const
848 QRect aItemRect = listView()->itemRect( this );
849 if ( !aItemRect.isValid() )
852 QFont aFont(listView()->font());
853 QFontMetrics fm(aFont);
855 int decorWidth = ( listView()->rootIsDecorated() ) ?
856 ( listView()->treeStepSize() * (depth() + 1) ) :
857 ( listView()->treeStepSize() * depth() );
858 int pixmapWidth = ( pixmap(column) ) ?
859 pixmap(column)->width() + listView()->itemMargin() * 2 :
860 listView()->itemMargin();
862 for (int i = 0; i < column; i++)
863 prevWidth += listView()->header()->sectionSize(i);
866 ((column == 0) ? decorWidth : 0);
867 int iy = aItemRect.y();
868 int iw = fm.width(text(column));
869 int ih = aItemRect.height();
870 if (pixmap(column)) {
871 iy += listView()->itemMargin();
872 ih -= listView()->itemMargin() * 2;
874 ix -= listView()->contentsX();
876 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
881 Calculates rect of item data in viewport coordinates
883 QRect SalomeApp_ListViewItem::itemRect(const int column) const
885 QRect aItemRect = listView()->itemRect( this );
886 if ( !aItemRect.isValid() )
889 QFont aFont(listView()->font());
890 QFontMetrics fm(aFont);
892 int decorWidth = ( listView()->rootIsDecorated() ) ?
893 ( listView()->treeStepSize() * (depth() + 1) ) :
894 ( listView()->treeStepSize() * depth() );
895 int pixmapWidth = ( pixmap(column) ) ?
896 pixmap(column)->width() + listView()->itemMargin() * 2 :
899 for (int i = 0; i < column; i++)
900 prevWidth += listView()->header()->sectionSize(i);
902 int iy = aItemRect.y();
903 int iw = pixmapWidth +
904 listView()->itemMargin() * 2 +
905 ((column == 0) ? decorWidth : 0) +
906 fm.width(text(column));
907 int ih = aItemRect.height();
908 ix -= listView()->contentsX();
910 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
917 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
923 Event filter for key pressing
925 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
927 if ( e->key() == Key_Escape )
928 emit escapePressed();
930 QLineEdit::keyPressEvent( e );
938 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
939 QComboBox(rw, parent, name)
944 Searches item in list and returns its index
946 int SalomeApp_ComboBox::findItem(const QString& theText)
948 for (int i = 0; i < count(); i++)
949 if (text(i) == theText)
955 Adds item in combo box
957 void SalomeApp_ComboBox::insertItem(const QString& theValue,
960 if (duplicatesEnabled() || findItem(theValue) < 0)
961 QComboBox::insertItem(theValue, theIndex);
965 Adds list of items in combo box
967 void SalomeApp_ComboBox::insertList(const QStringList& theList)
969 for (unsigned i = 0; i < theList.count(); i++)
970 insertItem(theList[i]);
974 Adds item in combo box
976 void SalomeApp_ComboBox::insertItem(const int theValue)
980 for (int i = 0; i < count(); i++) {
981 aNum = text(i).toInt(&bOk);
983 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
984 insertItem(QString::number(theValue), i);
989 insertItem(QString::number(theValue));
993 Adds list of items in combo box
995 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
997 for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
998 insertItem(aIter.Value());
1002 Adds item in combo box
1004 void SalomeApp_ComboBox::insertItem(const double theValue)
1008 for (int i = 0; i < count(); i++) {
1009 aNum = text(i).toDouble(&bOk);
1011 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1012 insertItem(QString::number(theValue), i);
1017 insertItem(QString::number(theValue));
1021 Adds list of items in combo box
1023 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1025 for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1026 insertItem(aIter.Value());
1029 #include <qlayout.h>
1031 #define MIN_COMBO_WIDTH 1
1032 #define MIN_EDIT_WIDTH 1
1037 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1048 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1049 SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1051 QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1052 aTopLayout->setAlignment( Qt::AlignTop );
1053 aTopLayout->setSpacing( 0 );
1054 aTopLayout->setMargin( 1 );
1055 if (controlType != etLineEdit &&
1056 controlType != etComboBox &&
1057 controlType != etComboEdit)
1058 controlType = etLineEdit;
1059 if (controlType == etComboBox || controlType == etComboEdit) {
1060 // this is an editable combo box
1061 myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1062 myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1063 myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1064 QSizePolicy::Fixed));
1066 myCombo->setInsertionPolicy(QComboBox::NoInsertion);
1067 // no duplicates enabled by default
1068 myCombo->setDuplicatesEnabled(false);
1069 aTopLayout->addWidget(myCombo);
1071 connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1072 connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1075 // and this is an edit box
1076 myEdit = new SalomeApp_EditBox(this);
1077 myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1078 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1079 QSizePolicy::Fixed));
1080 aTopLayout->addWidget(myEdit);
1081 connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1082 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1083 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1085 if (valueType != vtString &&
1086 valueType != vtInteger &&
1087 valueType != vtDouble)
1088 valueType = vtString;
1089 if (valueType == vtInteger)
1090 setValidator(new QIntValidator(this));
1091 else if (valueType == vtDouble)
1092 setValidator(new QDoubleValidator(this));
1095 myApplyBtn = new QToolButton(this);
1099 anIcon = mgr->loadPixmap( "STD", tr( "ICON_APPLY" ), false );
1101 myApplyBtn->setPixmap(anIcon);
1102 myApplyBtn->setEnabled(false);
1103 myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1104 myApplyBtn->setMinimumSize(16, 16);
1105 myApplyBtn->setMaximumSize(16, 20);
1106 aTopLayout->addWidget(myApplyBtn);
1107 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1110 // Cancel button (X)
1111 myCancelBtn = new QToolButton(this);
1114 anIcon = mgr->loadPixmap( "STD", tr( "ICON_CANCEL" ), false );
1115 myCancelBtn->setPixmap(anIcon);
1116 myCancelBtn->setEnabled(false);
1117 myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1118 myCancelBtn->setMinimumSize(16, 16);
1119 myCancelBtn->setMaximumSize(16, 20);
1120 aTopLayout->addWidget(myCancelBtn);
1121 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1128 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1133 Clears edit/combo box
1135 void SalomeApp_EntityEdit::clear()
1144 \return current text in edit box or combo box
1146 QString SalomeApp_EntityEdit::getText()
1149 return myEdit->text();
1151 return myCombo->currentText();
1159 void SalomeApp_EntityEdit::setText(const QString& theText)
1163 myEdit->setText(theText);
1165 int aFound = myCombo->findItem(theText);
1167 myCombo->setCurrentItem(aFound);
1168 onTextChanged(theText);
1174 Adds item in combo box, sets it current if theSetCurrent is true
1176 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1182 if (theOrder == atTop)
1184 else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1185 aIndexAt = myCombo->currentItem();
1186 else if (theOrder == atAfterCurrent &&
1187 myCombo->count() > 0 &&
1188 myCombo->currentItem() < myCombo->count()-1)
1189 aIndexAt = myCombo->currentItem() + 1;
1190 myCombo->insertItem(theValue, aIndexAt);
1197 Adds items in combo box, sets item theCurrent as current
1199 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1200 const int theCurrent)
1203 myCombo->insertList(theList);
1204 if (theCurrent >= 0 && theCurrent < (int)theList.count())
1205 setText(theList[theCurrent]);
1209 Adds item in combo box, sets it current if theSetCurrent is true
1211 void SalomeApp_EntityEdit::insertItem(const int theValue,
1215 myCombo->insertItem(theValue);
1218 setText(QString::number(theValue));
1222 Adds items in combo box, sets item theCurrent as current
1224 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1225 const int theCurrent)
1228 myCombo->insertList(theList);
1230 TColStd_ListIteratorOfListOfInteger aIter(theList);
1231 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1232 if (theCurrent == i) {
1233 setText(QString::number(aIter.Value()));
1240 Adds item in combo box, sets it current if theSetCurrent is true
1242 void SalomeApp_EntityEdit::insertItem(const double theValue,
1246 myCombo->insertItem(theValue);
1249 setText(QString::number(theValue));
1253 Adds items in combo box, sets item theCurrent as current
1255 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1256 const int theCurrent)
1259 myCombo->insertList(theList);
1261 TColStd_ListIteratorOfListOfReal aIter(theList);
1262 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1263 if (theCurrent == i) {
1264 setText(QString::number(aIter.Value()));
1271 \return actual widget
1273 QWidget* SalomeApp_EntityEdit::getControl()
1284 redirect focus to corresponding widget
1286 void SalomeApp_EntityEdit::setFocus()
1290 //myEdit->selectAll();
1292 else if (myCombo && myCombo->editable()) {
1293 myCombo->setFocus();
1294 //myCombo->lineEdit()->selectAll();
1299 Sets validator for the control
1301 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1304 myEdit->setValidator(theValidator);
1306 myCombo->setValidator(theValidator);
1310 Event filter for KeyPress event
1312 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1314 if ( (e->key() == Key_Enter ||
1315 e->key() == Key_Return ) )
1317 else if (e->key() == Key_Escape)
1322 Called when item activated in combo box
1324 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1326 onTextChanged(theText);
1330 Slot, called when text changed in line edit
1332 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1335 myApplyBtn->setEnabled(!(theText == myString));
1337 myCancelBtn->setEnabled(!(theText == myString));
1341 Slot, called when user presses Cancel button
1343 void SalomeApp_EntityEdit::onCancel()
1347 myApplyBtn->setEnabled(false);
1349 myCancelBtn->setEnabled(false);
1350 emit escapePressed();
1354 Slot, called when user presses Apply button
1356 void SalomeApp_EntityEdit::onApply()
1358 myString = getText();
1360 myApplyBtn->setEnabled(false);
1362 myCancelBtn->setEnabled(false);
1363 emit returnPressed();
1369 void SalomeApp_EntityEdit::showButtons(bool show)
1372 show ? myApplyBtn->show() : myApplyBtn->hide();
1374 show ? myCancelBtn->show() : myCancelBtn->hide();
1378 Enables/disables data duplication (for combo box)
1380 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1383 myCombo->setDuplicatesEnabled(enabled);