1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SalomeApp_ListView.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "SalomeApp_ListView.h"
26 #include "SalomeApp_Application.h"
28 #include "SUIT_ResourceMgr.h"
29 #include "SUIT_Session.h"
32 #include <QToolButton>
34 #include <QHeaderView>
37 #include <TColStd_ListOfInteger.hxx>
38 #include <TColStd_ListOfReal.hxx>
40 #include <TColStd_ListIteratorOfListOfInteger.hxx>
41 #include <TColStd_ListIteratorOfListOfReal.hxx>
44 Used for resizing editing widget
46 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
47 SalomeApp_EntityEdit* theWidget)
51 QTreeWidget* aListView = theItem->treeWidget();
52 int anEditColumn = theItem->getEditedColumn();
56 int aX = 0, aY = 0, aW = 0, aH = 0;
58 QRect aRect = aListView->visualItemRect(theItem);
59 aX = aListView->header()->sectionViewportPosition(anEditColumn);
61 aX = 0; // THIS CAN BE REMOVED
62 QSize aSize = theWidget->getControl()->sizeHint();
63 aH = qMax(aSize.height() , aRect.height() );
64 aY = aRect.y() - ((aH - aRect.height()) / 2);
65 //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
66 aW = aListView->viewport()->width() - aX;
69 theWidget->setGeometry(aX, aY, aW, aH);
75 SalomeApp_ListView::SalomeApp_ListView( QWidget* parent )
76 : QTreeWidget/*QtxListView*/( parent )
78 myMouseEnabled = true;
79 myEditingEnabled = false;
80 setSelectionMode(QAbstractItemView::SingleSelection);
81 setRootIsDecorated(false);
82 setAllColumnsShowFocus(false);
83 // header()->setClickEnabled(false);
84 header()->setMovable(false);
89 viewport()->installEventFilter(this);
91 connect(this, SIGNAL(itemSelectionChanged()),
92 this, SLOT(onSelectionChanged()));
93 connect(header(), SIGNAL(sizeChange(int, int, int)),
94 this, SLOT(onHeaderSizeChange(int, int, int)));
100 SalomeApp_ListView::~SalomeApp_ListView()
110 Updates all data viewer
112 void SalomeApp_ListView::updateViewer()
114 // temporary disconnecting selection changed SIGNAL
116 QTreeWidgetItemIterator it( this );
117 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)(*it);
119 aRoot->updateAllLevels();
120 update( contentsRect() );//updateContents();
121 // connecting again selection changed SIGNAL
123 emit itemSelectionChanged();
127 Updates currently selected item(s)
129 void SalomeApp_ListView::updateSelected()
131 // temporary disconnecting selection changed SIGNAL
133 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(selectedItems().first());
135 aChild->updateAllLevels();
136 update( contentsRect() );//updateContents();
137 // connecting again selection changed SIGNAL
139 emit itemSelectionChanged();
143 Returns popup client type
145 QString SalomeApp_ListView::popupClientType() const
147 return "SalomeApp_ListView";
151 Fills popup menu with items
153 void SalomeApp_ListView::contextMenuPopup( QMenu* aPopup )
163 void SalomeApp_ListView::clear()
170 QTreeWidget::clear();
174 \return true if mouse events are enabled
176 bool SalomeApp_ListView::isMouseEnabled()
178 return myMouseEnabled;
182 Enables/disables mouse events (excluding MouseMove)
184 void SalomeApp_ListView::enableMouse(bool enable)
186 myMouseEnabled = enable;
192 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
194 if (object == viewport() &&
195 (event->type() == QEvent::MouseButtonPress ||
196 event->type() == QEvent::MouseButtonRelease ||
197 event->type() == QEvent::MouseButtonDblClick) &&
201 return QTreeWidget::eventFilter(object, event);
205 Setting editing of items availbale/not available
207 void SalomeApp_ListView::enableEditing(bool theFlag)
209 myEditingEnabled = theFlag;
210 if (!myEditingEnabled) {
220 Says if editing is enabled
222 bool SalomeApp_ListView::isEnableEditing()
224 return myEditingEnabled;
228 Calls finishEditing(true)...
230 void SalomeApp_ListView::accept()
236 Slot, called when selection changed in List Viewer
238 void SalomeApp_ListView::onSelectionChanged()
244 if (myEditedItem && !myEditedItem->isAccepted()) {
246 update( contentsRect() );//updateContents();
250 // editing is allowed in Single Selection Mode only
251 if (selectionMode() != QAbstractItemView::SingleSelection || !isEnableEditing())
253 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)(selectedItems().first());
255 if (!anItem->isEditable())
257 myEdit = anItem->startEditing();
259 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
260 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
261 myEditedItem = anItem;
269 Called when Data Viewer is resized
271 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
273 QTreeWidget::resizeEvent(e);
274 int aW = columnWidth(columnCount()-1);
275 int aX = header()->sectionPosition(columnCount()-1);
276 if (aW < width() - frameWidth() * 2 - aX - 1)
277 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
278 update( contentsRect() );//updateContents();
282 Slot, called when columns sizes are changed
284 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
286 int aW = columnWidth(columnCount()-1);
287 int aX = header()->sectionPosition(columnCount()-1);
288 if (aW < width() - frameWidth() * 2 - aX - 1)
289 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
293 Handler for paint event
295 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
297 QTreeWidget::paintEvent(e);
298 if (myEditedItem && myEdit) {
299 computeEditGeometry(myEditedItem, myEdit);
304 Called when user finishes in editing of item
306 void SalomeApp_ListView::onEditOk()
312 Called when user cancels item editing
314 void SalomeApp_ListView::onEditCancel()
316 finishEditing(false);
320 Finishes editing of entity
322 UpdateType SalomeApp_ListView::finishEditing(bool ok)
324 UpdateType aNeedsUpdate = utCancel;
325 if (myEditedItem && myEdit)
327 disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
328 disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
329 myEditedItem->setAccepted(true);
331 aNeedsUpdate = myEditedItem->finishEditing(myEdit);
332 if (aNeedsUpdate == utCancel) {
333 // something to do here on Cancel...
336 // something to do here on OK...
339 switch (aNeedsUpdate) {
343 myEditedItem->updateAllLevels();
349 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
351 aParent->updateAllLevels();
353 myEditedItem->updateAllLevels();
364 // doing the same as for utUpdateViewer here
365 // descendants can add extra processing
375 // hide <myEdit> widget
384 \return current tooltip for list view
385 \retval valid rect in success
387 QRect SalomeApp_ListView::tip(QPoint aPos,
392 QRect result( -1, -1, -1, -1 );
393 SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
395 for (int i = 0; i < columnCount(); i++) {
396 QRect aItemRect = aItem->itemRect(i);
397 QRect aTextRect = aItem->textRect(i);
398 if ( !aItem->text(i).isEmpty() &&
399 ( aItemRect.width() > header()->sectionSize(i) ||
400 aTextRect.left() < 0 ||
401 aTextRect.top() < 0 ||
402 aTextRect.right() > viewport()->width() ||
403 aTextRect.bottom() > viewport()->height() ) ) {
404 // calculating tip data
405 aText = aItem->tipText();
406 dspRect = aItem->tipRect();
408 if (dspRect.isValid()) {
409 result = QRect(QPoint(0, aItemRect.top()),
410 QSize(viewport()->width(), aItemRect.height()));
421 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
422 QTreeWidgetItem( parent )
430 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
431 SalomeApp_ListViewItem* after) :
432 QTreeWidgetItem( parent, after )
440 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
441 const QStringList& theStrings,
442 const bool theEditable) :
443 QTreeWidgetItem(parent, theStrings)
446 setEditable(theEditable);
452 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
453 const QStringList& theString,
454 const bool theEditable) :
455 QTreeWidgetItem(parent, theString)
458 setEditable(theEditable);
464 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
465 SalomeApp_ListViewItem* after,
466 const QString& theName,
467 const bool theEditable) :
468 QTreeWidgetItem(parent, after)
470 setData(0,Qt::DisplayRole,QVariant(theName));
472 setEditable(theEditable);
478 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
479 SalomeApp_ListViewItem* after,
480 const QString& theName,
481 const bool theEditable) :
482 QTreeWidgetItem(parent, after)
484 setData(0,Qt::DisplayRole,QVariant(theName));
486 setEditable(theEditable);
492 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
493 SalomeApp_ListViewItem* after,
494 const QString& theName,
495 const QString& theValue,
496 const bool theEditable) :
497 QTreeWidgetItem(parent, after)
499 setData(0,Qt::DisplayRole,QVariant(theName));
500 setData(1,Qt::DisplayRole,QVariant(theValue));
502 setEditable(theEditable);
508 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
509 SalomeApp_ListViewItem* after,
510 const QString& theName,
511 const QString& theValue,
512 const bool theEditable) :
513 QTreeWidgetItem(parent, after)
515 setData(0,Qt::DisplayRole,QVariant(theName));
516 setData(1,Qt::DisplayRole,QVariant(theValue));
518 setEditable(theEditable);
524 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
531 void SalomeApp_ListViewItem::init()
535 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
536 myValueType = (int)SalomeApp_EntityEdit::vtString;
542 Returns the depth of this item
544 int SalomeApp_ListViewItem::depth() const
547 QTreeWidgetItem* aParent = parent();
549 aParent = aParent->parent();
556 \return text in the first column
558 QString SalomeApp_ListViewItem::getName() const
560 return ( treeWidget()->columnCount() > 0 ) ? text(0) : QString("");
564 Sets text in the first column
566 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
568 UpdateType aNeedsUpdate = utCancel;
569 if (treeWidget()->columnCount() > 0) {
571 aNeedsUpdate = utNone;
577 \return text in the second column
579 QString SalomeApp_ListViewItem::getValue() const
581 return ( treeWidget()->columnCount() > 1 ) ? text(1) : QString("");
585 Sets text in the second column
587 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
589 UpdateType aNeedsUpdate = utCancel;
590 if (treeWidget()->columnCount() > 1) {
591 setText(1, theValue);
592 aNeedsUpdate = utNone;
598 \return full path to the entity from the root
600 QString SalomeApp_ListViewItem::fullName()
602 QString aFullName = getName();
603 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
604 while(aParent != NULL) {
605 aFullName = aParent->getName() + QString(".") + aFullName;
606 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
612 expands all entities beginning from this level
614 void SalomeApp_ListViewItem::openAllLevels()
617 QTreeWidgetItemIterator it( this );
618 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
620 aChild->openAllLevels();
622 aChild = (SalomeApp_ListViewItem*)(*it);
627 update all entites beginning from this level
629 void SalomeApp_ListViewItem::updateAllLevels()
631 QTreeWidgetItemIterator it( this );
632 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
634 aChild->updateAllLevels();
636 aChild = (SalomeApp_ListViewItem*)(*it);
641 \return true if entity is editable
643 bool SalomeApp_ListViewItem::isEditable() const
649 Sets editable flag fo the entity
651 void SalomeApp_ListViewItem::setEditable(bool theEditable)
653 myEditable = theEditable;
657 \return true if entitiy is accepted after editing
659 bool SalomeApp_ListViewItem::isAccepted() const
665 Sets entitiy accepted or not after editing
667 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
669 myAccepted = theAccepted;
673 \retval type of edit control (default is edit box)
676 \li 2 - editable combo box
678 int SalomeApp_ListViewItem::getEditingType()
680 return myEditingType;
684 \retval type of edit control (negative value means none)
687 \li 2 - editable combo box
689 void SalomeApp_ListViewItem::setEditingType(const int type)
691 myEditingType = type;
694 /*! \retval edited column, default is last column
695 negative value means there are no editable columns
697 int SalomeApp_ListViewItem::getEditedColumn()
699 return treeWidget()->columnCount()-1;
703 \retval type of edited value (string, int, double)
706 int SalomeApp_ListViewItem::getValueType()
712 Sets type of edited value
714 void SalomeApp_ListViewItem::setValueType(const int valueType)
716 myValueType = valueType;
720 Sets type of edited value
722 int SalomeApp_ListViewItem::getUserType()
728 Sets type of edited value
730 void SalomeApp_ListViewItem::setUserType(const int userType)
732 myUserType = userType;
736 \return buttons for editing widget (Apply (V), Cancel (X))
737 default is both buttons
739 int SalomeApp_ListViewItem::getButtons()
745 Sets buttons for editing widget (Apply (V), Cancel (X))
747 void SalomeApp_ListViewItem::setButtons(const int buttons)
753 Creates control for editing and fills it with values
755 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
757 SalomeApp_EntityEdit* aWidget = 0;
758 QTreeWidget* aListView = treeWidget();
762 int anEditType = getEditingType();
763 int aValueType = getValueType();
764 int aButtons = getButtons();
765 int anEditColumn = getEditedColumn();
766 if (anEditColumn < 0 || anEditType < 0)
768 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
771 aButtons & SalomeApp_EntityEdit::btApply,
772 aButtons & SalomeApp_EntityEdit::btCancel);
773 computeEditGeometry(this, aWidget);
775 fillWidgetWithValues(aWidget);
781 Fills widget with initial values (list or single value)
783 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
785 int anEditColumn = getEditedColumn();
786 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
787 theWidget->insertItem(text(anEditColumn), true);
791 Finishes editing of entity
793 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
795 UpdateType aNeedsUpdate = utCancel;
798 int anEditColumn = getEditedColumn();
799 switch (anEditColumn) {
801 aNeedsUpdate = setName(theWidget->getText());
804 aNeedsUpdate = setValue(theWidget->getText());
812 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
818 Calculates rectangle which should contain item's tip
820 QRect SalomeApp_ListViewItem::tipRect()
822 QRect aRect = QRect(-1, -1, -1, -1);
823 QRect aItemRect = treeWidget()->visualItemRect(this);
824 if ( !aItemRect.isValid() )
827 QString aTip = tipText();
828 if (!aTip.isEmpty()) {
829 QRect aRect0 = textRect(0);
830 QFont aFont(treeWidget()->font());
831 QFontMetrics fm(aFont);
832 int iw = fm.width(aTip);
833 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
842 \return text for tooltip
844 QString SalomeApp_ListViewItem::tipText()
846 QString aText = getName();
847 if (!getValue().isEmpty())
848 aText += QString(" : ") + getValue();
853 Calculates rect of item text in viewport coordinates
855 QRect SalomeApp_ListViewItem::textRect(const int column) const
857 QRect aItemRect = treeWidget()->visualItemRect( this );
858 if ( !aItemRect.isValid() )
861 QFont aFont(treeWidget()->font());
862 QFontMetrics fm(aFont);
864 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
865 ( treeWidget()->indentation() * (depth() + 1) ) :
866 ( treeWidget()->indentation() * depth() );
867 int pixmapWidth = ( !icon(column).isNull() ) ?
868 treeWidget()->iconSize().width() + 2 :
871 for (int i = 0; i < column; i++)
872 prevWidth += treeWidget()->header()->sectionSize(i);
875 ((column == 0) ? decorWidth : 0);
876 int iy = aItemRect.y();
877 int iw = fm.width(text(column));
878 int ih = aItemRect.height();
879 if (!icon(column).isNull()) {
883 ix -= treeWidget()->contentsRect().left();
885 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
890 Calculates rect of item data in viewport coordinates
892 QRect SalomeApp_ListViewItem::itemRect(const int column) const
894 QRect aItemRect = treeWidget()->visualItemRect( this );
895 if ( !aItemRect.isValid() )
898 QFont aFont(treeWidget()->font());
899 QFontMetrics fm(aFont);
901 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
902 ( treeWidget()->indentation() * (depth() + 1) ) :
903 ( treeWidget()->indentation() * depth() );
904 int pixmapWidth = ( !icon(column).isNull() ) ?
905 treeWidget()->iconSize().width() + 2 :
908 for (int i = 0; i < column; i++)
909 prevWidth += treeWidget()->header()->sectionSize(i);
911 int iy = aItemRect.y();
912 int iw = pixmapWidth +
914 ((column == 0) ? decorWidth : 0) +
915 fm.width(text(column));
916 int ih = aItemRect.height();
917 ix -= treeWidget()->contentsRect().left();
919 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
926 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
932 Event filter for key pressing
934 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
936 if ( e->key() == Qt::Key_Escape )
937 emit escapePressed();
939 QLineEdit::keyPressEvent( e );
947 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
951 setObjectName( name );
955 Searches item in list and returns its index
957 int SalomeApp_ComboBox::findItem(const QString& theText)
959 for (int i = 0; i < count(); i++)
960 if (itemText(i) == theText)
966 Adds item in combo box
968 void SalomeApp_ComboBox::insertItem(const QString& theValue,
971 if (duplicatesEnabled() || findItem(theValue) < 0)
972 QComboBox::insertItem(theIndex, theValue);
976 Adds list of items in combo box
978 void SalomeApp_ComboBox::insertList(const QStringList& theList)
980 for (unsigned i = 0; i < theList.count(); i++)
981 insertItem(theList[i]);
985 Adds item in combo box
987 void SalomeApp_ComboBox::insertItem(const int theValue)
991 for (int i = 0; i < count(); i++) {
992 aNum = itemText(i).toInt(&bOk);
994 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
995 insertItem(QString::number(theValue),i);
1000 insertItem(QString::number(theValue));
1004 Adds list of items in combo box
1006 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
1008 for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1009 insertItem(aIter.Value());
1013 Adds item in combo box
1015 void SalomeApp_ComboBox::insertItem(const double theValue)
1019 for (int i = 0; i < count(); i++) {
1020 aNum = itemText(i).toDouble(&bOk);
1022 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1023 insertItem(QString::number(theValue), i);
1028 insertItem(QString::number(theValue));
1032 Adds list of items in combo box
1034 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1036 for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1037 insertItem(aIter.Value());
1040 #include <qlayout.h>
1042 #define MIN_COMBO_WIDTH 1
1043 #define MIN_EDIT_WIDTH 1
1048 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1059 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1060 SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1062 QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1063 aTopLayout->setAlignment( Qt::AlignTop );
1064 aTopLayout->setSpacing( 0 );
1065 aTopLayout->setMargin( 1 );
1066 if (controlType != etLineEdit &&
1067 controlType != etComboBox &&
1068 controlType != etComboEdit)
1069 controlType = etLineEdit;
1070 if (controlType == etComboBox || controlType == etComboEdit) {
1071 // this is an editable combo box
1072 myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1073 myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1074 myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1075 QSizePolicy::Fixed));
1077 myCombo->setInsertPolicy(QComboBox::NoInsert);
1078 // no duplicates enabled by default
1079 myCombo->setDuplicatesEnabled(false);
1080 aTopLayout->addWidget(myCombo);
1082 connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1083 connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1086 // and this is an edit box
1087 myEdit = new SalomeApp_EditBox(this);
1088 myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1089 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1090 QSizePolicy::Fixed));
1091 aTopLayout->addWidget(myEdit);
1092 connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1093 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1094 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1096 if (valueType != vtString &&
1097 valueType != vtInteger &&
1098 valueType != vtDouble)
1099 valueType = vtString;
1100 if (valueType == vtInteger)
1101 setValidator(new QIntValidator(this));
1102 else if (valueType == vtDouble)
1103 setValidator(new QDoubleValidator(this));
1106 myApplyBtn = new QToolButton(this);
1110 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_APPLY" ), false );
1112 myApplyBtn->setIcon(anIcon);
1113 myApplyBtn->setEnabled(false);
1114 myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1115 myApplyBtn->setMinimumSize(16, 16);
1116 myApplyBtn->setMaximumSize(16, 20);
1117 aTopLayout->addWidget(myApplyBtn);
1118 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1121 // Cancel button (X)
1122 myCancelBtn = new QToolButton(this);
1125 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_CANCEL" ), false );
1126 myCancelBtn->setIcon(anIcon);
1127 myCancelBtn->setEnabled(false);
1128 myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1129 myCancelBtn->setMinimumSize(16, 16);
1130 myCancelBtn->setMaximumSize(16, 20);
1131 aTopLayout->addWidget(myCancelBtn);
1132 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1139 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1144 Clears edit/combo box
1146 void SalomeApp_EntityEdit::clear()
1155 \return current text in edit box or combo box
1157 QString SalomeApp_EntityEdit::getText()
1160 return myEdit->text();
1162 return myCombo->currentText();
1170 void SalomeApp_EntityEdit::setText(const QString& theText)
1174 myEdit->setText(theText);
1176 int aFound = myCombo->findItem(theText);
1178 myCombo->setCurrentIndex(aFound);
1179 onTextChanged(theText);
1185 Adds item in combo box, sets it current if theSetCurrent is true
1187 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1193 if (theOrder == atTop)
1195 else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1196 aIndexAt = myCombo->currentIndex();
1197 else if (theOrder == atAfterCurrent &&
1198 myCombo->count() > 0 &&
1199 myCombo->currentIndex() < myCombo->count()-1)
1200 aIndexAt = myCombo->currentIndex() + 1;
1201 myCombo->insertItem(theValue, aIndexAt);
1208 Adds items in combo box, sets item theCurrent as current
1210 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1211 const int theCurrent)
1214 myCombo->insertList(theList);
1215 if (theCurrent >= 0 && theCurrent < (int)theList.count())
1216 setText(theList[theCurrent]);
1220 Adds item in combo box, sets it current if theSetCurrent is true
1222 void SalomeApp_EntityEdit::insertItem(const int theValue,
1226 myCombo->insertItem(theValue);
1229 setText(QString::number(theValue));
1233 Adds items in combo box, sets item theCurrent as current
1235 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1236 const int theCurrent)
1239 myCombo->insertList(theList);
1241 TColStd_ListIteratorOfListOfInteger aIter(theList);
1242 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1243 if (theCurrent == i) {
1244 setText(QString::number(aIter.Value()));
1251 Adds item in combo box, sets it current if theSetCurrent is true
1253 void SalomeApp_EntityEdit::insertItem(const double theValue,
1257 myCombo->insertItem(theValue);
1260 setText(QString::number(theValue));
1264 Adds items in combo box, sets item theCurrent as current
1266 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1267 const int theCurrent)
1270 myCombo->insertList(theList);
1272 TColStd_ListIteratorOfListOfReal aIter(theList);
1273 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1274 if (theCurrent == i) {
1275 setText(QString::number(aIter.Value()));
1282 \return actual widget
1284 QWidget* SalomeApp_EntityEdit::getControl()
1295 redirect focus to corresponding widget
1297 void SalomeApp_EntityEdit::setFocus()
1301 //myEdit->selectAll();
1303 else if (myCombo && myCombo->isEditable()) {
1304 myCombo->setFocus();
1305 //myCombo->lineEdit()->selectAll();
1310 Sets validator for the control
1312 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1315 myEdit->setValidator(theValidator);
1317 myCombo->setValidator(theValidator);
1321 Event filter for KeyPress event
1323 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1325 if ( (e->key() == Qt::Key_Enter ||
1326 e->key() == Qt::Key_Return ) )
1328 else if (e->key() == Qt::Key_Escape)
1333 Called when item activated in combo box
1335 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1337 onTextChanged(theText);
1341 Slot, called when text changed in line edit
1343 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1346 myApplyBtn->setEnabled(!(theText == myString));
1348 myCancelBtn->setEnabled(!(theText == myString));
1352 Slot, called when user presses Cancel button
1354 void SalomeApp_EntityEdit::onCancel()
1358 myApplyBtn->setEnabled(false);
1360 myCancelBtn->setEnabled(false);
1361 emit escapePressed();
1365 Slot, called when user presses Apply button
1367 void SalomeApp_EntityEdit::onApply()
1369 myString = getText();
1371 myApplyBtn->setEnabled(false);
1373 myCancelBtn->setEnabled(false);
1374 emit returnPressed();
1380 void SalomeApp_EntityEdit::showButtons(bool show)
1383 show ? myApplyBtn->show() : myApplyBtn->hide();
1385 show ? myCancelBtn->show() : myCancelBtn->hide();
1389 Enables/disables data duplication (for combo box)
1391 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1394 myCombo->setDuplicatesEnabled(enabled);