1 // Copyright (C) 2007-2013 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
23 // File : SalomeApp_ListView.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "SalomeApp_ListView.h"
27 #include "SalomeApp_Application.h"
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
33 #include <QToolButton>
35 #include <QHeaderView>
38 #include <TColStd_ListOfInteger.hxx>
39 #include <TColStd_ListOfReal.hxx>
41 #include <TColStd_ListIteratorOfListOfInteger.hxx>
42 #include <TColStd_ListIteratorOfListOfReal.hxx>
45 Used for resizing editing widget
47 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
48 SalomeApp_EntityEdit* theWidget)
52 QTreeWidget* aListView = theItem->treeWidget();
53 int anEditColumn = theItem->getEditedColumn();
57 int aX = 0, aY = 0, aW = 0, aH = 0;
59 QRect aRect = aListView->visualItemRect(theItem);
60 aX = aListView->header()->sectionViewportPosition(anEditColumn);
62 aX = 0; // THIS CAN BE REMOVED
63 QSize aSize = theWidget->getControl()->sizeHint();
64 aH = qMax(aSize.height() , aRect.height() );
65 aY = aRect.y() - ((aH - aRect.height()) / 2);
66 //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
67 aW = aListView->viewport()->width() - aX;
70 theWidget->setGeometry(aX, aY, aW, aH);
76 SalomeApp_ListView::SalomeApp_ListView( QWidget* parent )
77 : QTreeWidget/*QtxListView*/( parent )
79 myMouseEnabled = true;
80 myEditingEnabled = false;
81 setSelectionMode(QAbstractItemView::SingleSelection);
82 setRootIsDecorated(false);
83 setAllColumnsShowFocus(false);
84 // header()->setClickEnabled(false);
85 header()->setMovable(false);
90 viewport()->installEventFilter(this);
92 connect(this, SIGNAL(itemSelectionChanged()),
93 this, SLOT(onSelectionChanged()));
94 connect(header(), SIGNAL(sizeChange(int, int, int)),
95 this, SLOT(onHeaderSizeChange(int, int, int)));
101 SalomeApp_ListView::~SalomeApp_ListView()
111 Updates all data viewer
113 void SalomeApp_ListView::updateViewer()
115 // temporary disconnecting selection changed SIGNAL
117 QTreeWidgetItemIterator it( this );
118 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)(*it);
120 aRoot->updateAllLevels();
121 update( contentsRect() );//updateContents();
122 // connecting again selection changed SIGNAL
124 emit itemSelectionChanged();
128 Updates currently selected item(s)
130 void SalomeApp_ListView::updateSelected()
132 // temporary disconnecting selection changed SIGNAL
134 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(selectedItems().first());
136 aChild->updateAllLevels();
137 update( contentsRect() );//updateContents();
138 // connecting again selection changed SIGNAL
140 emit itemSelectionChanged();
144 Returns popup client type
146 QString SalomeApp_ListView::popupClientType() const
148 return "SalomeApp_ListView";
152 Fills popup menu with items
154 void SalomeApp_ListView::contextMenuPopup( QMenu* aPopup )
164 void SalomeApp_ListView::clear()
171 QTreeWidget::clear();
175 \return true if mouse events are enabled
177 bool SalomeApp_ListView::isMouseEnabled()
179 return myMouseEnabled;
183 Enables/disables mouse events (excluding MouseMove)
185 void SalomeApp_ListView::enableMouse(bool enable)
187 myMouseEnabled = enable;
193 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
195 if (object == viewport() &&
196 (event->type() == QEvent::MouseButtonPress ||
197 event->type() == QEvent::MouseButtonRelease ||
198 event->type() == QEvent::MouseButtonDblClick) &&
202 return QTreeWidget::eventFilter(object, event);
206 Setting editing of items availbale/not available
208 void SalomeApp_ListView::enableEditing(bool theFlag)
210 myEditingEnabled = theFlag;
211 if (!myEditingEnabled) {
221 Says if editing is enabled
223 bool SalomeApp_ListView::isEnableEditing()
225 return myEditingEnabled;
229 Calls finishEditing(true)...
231 void SalomeApp_ListView::accept()
237 Slot, called when selection changed in List Viewer
239 void SalomeApp_ListView::onSelectionChanged()
245 if (myEditedItem && !myEditedItem->isAccepted()) {
247 update( contentsRect() );//updateContents();
251 // editing is allowed in Single Selection Mode only
252 if (selectionMode() != QAbstractItemView::SingleSelection || !isEnableEditing())
254 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)(selectedItems().first());
256 if (!anItem->isEditable())
258 myEdit = anItem->startEditing();
260 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
261 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
262 myEditedItem = anItem;
270 Called when Data Viewer is resized
272 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
274 QTreeWidget::resizeEvent(e);
275 int aW = columnWidth(columnCount()-1);
276 int aX = header()->sectionPosition(columnCount()-1);
277 if (aW < width() - frameWidth() * 2 - aX - 1)
278 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
279 update( contentsRect() );//updateContents();
283 Slot, called when columns sizes are changed
285 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
287 int aW = columnWidth(columnCount()-1);
288 int aX = header()->sectionPosition(columnCount()-1);
289 if (aW < width() - frameWidth() * 2 - aX - 1)
290 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
294 Handler for paint event
296 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
298 QTreeWidget::paintEvent(e);
299 if (myEditedItem && myEdit) {
300 computeEditGeometry(myEditedItem, myEdit);
305 Called when user finishes in editing of item
307 void SalomeApp_ListView::onEditOk()
313 Called when user cancels item editing
315 void SalomeApp_ListView::onEditCancel()
317 finishEditing(false);
321 Finishes editing of entity
323 UpdateType SalomeApp_ListView::finishEditing(bool ok)
325 UpdateType aNeedsUpdate = utCancel;
326 if (myEditedItem && myEdit)
328 disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
329 disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
330 myEditedItem->setAccepted(true);
332 aNeedsUpdate = myEditedItem->finishEditing(myEdit);
333 if (aNeedsUpdate == utCancel) {
334 // something to do here on Cancel...
337 // something to do here on OK...
340 switch (aNeedsUpdate) {
344 myEditedItem->updateAllLevels();
350 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
352 aParent->updateAllLevels();
354 myEditedItem->updateAllLevels();
365 // doing the same as for utUpdateViewer here
366 // descendants can add extra processing
376 // hide <myEdit> widget
385 \return current tooltip for list view
386 \retval valid rect in success
388 QRect SalomeApp_ListView::tip(QPoint aPos,
393 QRect result( -1, -1, -1, -1 );
394 SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
396 for (int i = 0; i < columnCount(); i++) {
397 QRect aItemRect = aItem->itemRect(i);
398 QRect aTextRect = aItem->textRect(i);
399 if ( !aItem->text(i).isEmpty() &&
400 ( aItemRect.width() > header()->sectionSize(i) ||
401 aTextRect.left() < 0 ||
402 aTextRect.top() < 0 ||
403 aTextRect.right() > viewport()->width() ||
404 aTextRect.bottom() > viewport()->height() ) ) {
405 // calculating tip data
406 aText = aItem->tipText();
407 dspRect = aItem->tipRect();
409 if (dspRect.isValid()) {
410 result = QRect(QPoint(0, aItemRect.top()),
411 QSize(viewport()->width(), aItemRect.height()));
422 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
423 QTreeWidgetItem( parent )
431 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
432 SalomeApp_ListViewItem* after) :
433 QTreeWidgetItem( parent, after )
441 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
442 const QStringList& theStrings,
443 const bool theEditable) :
444 QTreeWidgetItem(parent, theStrings)
447 setEditable(theEditable);
453 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
454 const QStringList& theString,
455 const bool theEditable) :
456 QTreeWidgetItem(parent, theString)
459 setEditable(theEditable);
465 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
466 SalomeApp_ListViewItem* after,
467 const QString& theName,
468 const bool theEditable) :
469 QTreeWidgetItem(parent, after)
471 setData(0,Qt::DisplayRole,QVariant(theName));
473 setEditable(theEditable);
479 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
480 SalomeApp_ListViewItem* after,
481 const QString& theName,
482 const bool theEditable) :
483 QTreeWidgetItem(parent, after)
485 setData(0,Qt::DisplayRole,QVariant(theName));
487 setEditable(theEditable);
493 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
494 SalomeApp_ListViewItem* after,
495 const QString& theName,
496 const QString& theValue,
497 const bool theEditable) :
498 QTreeWidgetItem(parent, after)
500 setData(0,Qt::DisplayRole,QVariant(theName));
501 setData(1,Qt::DisplayRole,QVariant(theValue));
503 setEditable(theEditable);
509 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
510 SalomeApp_ListViewItem* after,
511 const QString& theName,
512 const QString& theValue,
513 const bool theEditable) :
514 QTreeWidgetItem(parent, after)
516 setData(0,Qt::DisplayRole,QVariant(theName));
517 setData(1,Qt::DisplayRole,QVariant(theValue));
519 setEditable(theEditable);
525 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
532 void SalomeApp_ListViewItem::init()
536 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
537 myValueType = (int)SalomeApp_EntityEdit::vtString;
543 Returns the depth of this item
545 int SalomeApp_ListViewItem::depth() const
548 QTreeWidgetItem* aParent = parent();
550 aParent = aParent->parent();
557 \return text in the first column
559 QString SalomeApp_ListViewItem::getName() const
561 return ( treeWidget()->columnCount() > 0 ) ? text(0) : QString("");
565 Sets text in the first column
567 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
569 UpdateType aNeedsUpdate = utCancel;
570 if (treeWidget()->columnCount() > 0) {
572 aNeedsUpdate = utNone;
578 \return text in the second column
580 QString SalomeApp_ListViewItem::getValue() const
582 return ( treeWidget()->columnCount() > 1 ) ? text(1) : QString("");
586 Sets text in the second column
588 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
590 UpdateType aNeedsUpdate = utCancel;
591 if (treeWidget()->columnCount() > 1) {
592 setText(1, theValue);
593 aNeedsUpdate = utNone;
599 \return full path to the entity from the root
601 QString SalomeApp_ListViewItem::fullName()
603 QString aFullName = getName();
604 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
605 while(aParent != NULL) {
606 aFullName = aParent->getName() + QString(".") + aFullName;
607 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
613 expands all entities beginning from this level
615 void SalomeApp_ListViewItem::openAllLevels()
618 QTreeWidgetItemIterator it( this );
619 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
621 aChild->openAllLevels();
623 aChild = (SalomeApp_ListViewItem*)(*it);
628 update all entites beginning from this level
630 void SalomeApp_ListViewItem::updateAllLevels()
632 QTreeWidgetItemIterator it( this );
633 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
635 aChild->updateAllLevels();
637 aChild = (SalomeApp_ListViewItem*)(*it);
642 \return true if entity is editable
644 bool SalomeApp_ListViewItem::isEditable() const
650 Sets editable flag fo the entity
652 void SalomeApp_ListViewItem::setEditable(bool theEditable)
654 myEditable = theEditable;
658 \return true if entitiy is accepted after editing
660 bool SalomeApp_ListViewItem::isAccepted() const
666 Sets entitiy accepted or not after editing
668 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
670 myAccepted = theAccepted;
674 \retval type of edit control (default is edit box)
677 \li 2 - editable combo box
679 int SalomeApp_ListViewItem::getEditingType()
681 return myEditingType;
685 \retval type of edit control (negative value means none)
688 \li 2 - editable combo box
690 void SalomeApp_ListViewItem::setEditingType(const int type)
692 myEditingType = type;
695 /*! \retval edited column, default is last column
696 negative value means there are no editable columns
698 int SalomeApp_ListViewItem::getEditedColumn()
700 return treeWidget()->columnCount()-1;
704 \retval type of edited value (string, int, double)
707 int SalomeApp_ListViewItem::getValueType()
713 Sets type of edited value
715 void SalomeApp_ListViewItem::setValueType(const int valueType)
717 myValueType = valueType;
721 Sets type of edited value
723 int SalomeApp_ListViewItem::getUserType()
729 Sets type of edited value
731 void SalomeApp_ListViewItem::setUserType(const int userType)
733 myUserType = userType;
737 \return buttons for editing widget (Apply (V), Cancel (X))
738 default is both buttons
740 int SalomeApp_ListViewItem::getButtons()
746 Sets buttons for editing widget (Apply (V), Cancel (X))
748 void SalomeApp_ListViewItem::setButtons(const int buttons)
754 Creates control for editing and fills it with values
756 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
758 SalomeApp_EntityEdit* aWidget = 0;
759 QTreeWidget* aListView = treeWidget();
763 int anEditType = getEditingType();
764 int aValueType = getValueType();
765 int aButtons = getButtons();
766 int anEditColumn = getEditedColumn();
767 if (anEditColumn < 0 || anEditType < 0)
769 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
772 aButtons & SalomeApp_EntityEdit::btApply,
773 aButtons & SalomeApp_EntityEdit::btCancel);
774 computeEditGeometry(this, aWidget);
776 fillWidgetWithValues(aWidget);
782 Fills widget with initial values (list or single value)
784 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
786 int anEditColumn = getEditedColumn();
787 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
788 theWidget->insertItem(text(anEditColumn), true);
792 Finishes editing of entity
794 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
796 UpdateType aNeedsUpdate = utCancel;
799 int anEditColumn = getEditedColumn();
800 switch (anEditColumn) {
802 aNeedsUpdate = setName(theWidget->getText());
805 aNeedsUpdate = setValue(theWidget->getText());
813 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
819 Calculates rectangle which should contain item's tip
821 QRect SalomeApp_ListViewItem::tipRect()
823 QRect aRect = QRect(-1, -1, -1, -1);
824 QRect aItemRect = treeWidget()->visualItemRect(this);
825 if ( !aItemRect.isValid() )
828 QString aTip = tipText();
829 if (!aTip.isEmpty()) {
830 QRect aRect0 = textRect(0);
831 QFont aFont(treeWidget()->font());
832 QFontMetrics fm(aFont);
833 int iw = fm.width(aTip);
834 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
843 \return text for tooltip
845 QString SalomeApp_ListViewItem::tipText()
847 QString aText = getName();
848 if (!getValue().isEmpty())
849 aText += QString(" : ") + getValue();
854 Calculates rect of item text in viewport coordinates
856 QRect SalomeApp_ListViewItem::textRect(const int column) const
858 QRect aItemRect = treeWidget()->visualItemRect( this );
859 if ( !aItemRect.isValid() )
862 QFont aFont(treeWidget()->font());
863 QFontMetrics fm(aFont);
865 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
866 ( treeWidget()->indentation() * (depth() + 1) ) :
867 ( treeWidget()->indentation() * depth() );
868 int pixmapWidth = ( !icon(column).isNull() ) ?
869 treeWidget()->iconSize().width() + 2 :
872 for (int i = 0; i < column; i++)
873 prevWidth += treeWidget()->header()->sectionSize(i);
876 ((column == 0) ? decorWidth : 0);
877 int iy = aItemRect.y();
878 int iw = fm.width(text(column));
879 int ih = aItemRect.height();
880 if (!icon(column).isNull()) {
884 ix -= treeWidget()->contentsRect().left();
886 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
891 Calculates rect of item data in viewport coordinates
893 QRect SalomeApp_ListViewItem::itemRect(const int column) const
895 QRect aItemRect = treeWidget()->visualItemRect( this );
896 if ( !aItemRect.isValid() )
899 QFont aFont(treeWidget()->font());
900 QFontMetrics fm(aFont);
902 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
903 ( treeWidget()->indentation() * (depth() + 1) ) :
904 ( treeWidget()->indentation() * depth() );
905 int pixmapWidth = ( !icon(column).isNull() ) ?
906 treeWidget()->iconSize().width() + 2 :
909 for (int i = 0; i < column; i++)
910 prevWidth += treeWidget()->header()->sectionSize(i);
912 int iy = aItemRect.y();
913 int iw = pixmapWidth +
915 ((column == 0) ? decorWidth : 0) +
916 fm.width(text(column));
917 int ih = aItemRect.height();
918 ix -= treeWidget()->contentsRect().left();
920 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
927 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
933 Event filter for key pressing
935 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
937 if ( e->key() == Qt::Key_Escape )
938 emit escapePressed();
940 QLineEdit::keyPressEvent( e );
948 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
952 setObjectName( name );
956 Searches item in list and returns its index
958 int SalomeApp_ComboBox::findItem(const QString& theText)
960 for (int i = 0; i < count(); i++)
961 if (itemText(i) == theText)
967 Adds item in combo box
969 void SalomeApp_ComboBox::insertItem(const QString& theValue,
972 if (duplicatesEnabled() || findItem(theValue) < 0)
973 QComboBox::insertItem(theIndex, theValue);
977 Adds list of items in combo box
979 void SalomeApp_ComboBox::insertList(const QStringList& theList)
981 for (unsigned i = 0; i < theList.count(); i++)
982 insertItem(theList[i]);
986 Adds item in combo box
988 void SalomeApp_ComboBox::insertItem(const int theValue)
992 for (int i = 0; i < count(); i++) {
993 aNum = itemText(i).toInt(&bOk);
995 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
996 insertItem(QString::number(theValue),i);
1001 insertItem(QString::number(theValue));
1005 Adds list of items in combo box
1007 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
1009 for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1010 insertItem(aIter.Value());
1014 Adds item in combo box
1016 void SalomeApp_ComboBox::insertItem(const double theValue)
1020 for (int i = 0; i < count(); i++) {
1021 aNum = itemText(i).toDouble(&bOk);
1023 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1024 insertItem(QString::number(theValue), i);
1029 insertItem(QString::number(theValue));
1033 Adds list of items in combo box
1035 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1037 for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1038 insertItem(aIter.Value());
1041 #include <qlayout.h>
1043 #define MIN_COMBO_WIDTH 1
1044 #define MIN_EDIT_WIDTH 1
1049 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1060 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1061 SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1063 QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1064 aTopLayout->setAlignment( Qt::AlignTop );
1065 aTopLayout->setSpacing( 0 );
1066 aTopLayout->setMargin( 1 );
1067 if (controlType != etLineEdit &&
1068 controlType != etComboBox &&
1069 controlType != etComboEdit)
1070 controlType = etLineEdit;
1071 if (controlType == etComboBox || controlType == etComboEdit) {
1072 // this is an editable combo box
1073 myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1074 myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1075 myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1076 QSizePolicy::Fixed));
1078 myCombo->setInsertPolicy(QComboBox::NoInsert);
1079 // no duplicates enabled by default
1080 myCombo->setDuplicatesEnabled(false);
1081 aTopLayout->addWidget(myCombo);
1083 connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1084 connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1087 // and this is an edit box
1088 myEdit = new SalomeApp_EditBox(this);
1089 myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1090 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1091 QSizePolicy::Fixed));
1092 aTopLayout->addWidget(myEdit);
1093 connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1094 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1095 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1097 if (valueType != vtString &&
1098 valueType != vtInteger &&
1099 valueType != vtDouble)
1100 valueType = vtString;
1101 if (valueType == vtInteger)
1102 setValidator(new QIntValidator(this));
1103 else if (valueType == vtDouble)
1104 setValidator(new QDoubleValidator(this));
1107 myApplyBtn = new QToolButton(this);
1111 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_APPLY" ), false );
1113 myApplyBtn->setIcon(anIcon);
1114 myApplyBtn->setEnabled(false);
1115 myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1116 myApplyBtn->setMinimumSize(16, 16);
1117 myApplyBtn->setMaximumSize(16, 20);
1118 aTopLayout->addWidget(myApplyBtn);
1119 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1122 // Cancel button (X)
1123 myCancelBtn = new QToolButton(this);
1126 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_CANCEL" ), false );
1127 myCancelBtn->setIcon(anIcon);
1128 myCancelBtn->setEnabled(false);
1129 myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1130 myCancelBtn->setMinimumSize(16, 16);
1131 myCancelBtn->setMaximumSize(16, 20);
1132 aTopLayout->addWidget(myCancelBtn);
1133 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1140 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1145 Clears edit/combo box
1147 void SalomeApp_EntityEdit::clear()
1156 \return current text in edit box or combo box
1158 QString SalomeApp_EntityEdit::getText()
1161 return myEdit->text();
1163 return myCombo->currentText();
1171 void SalomeApp_EntityEdit::setText(const QString& theText)
1175 myEdit->setText(theText);
1177 int aFound = myCombo->findItem(theText);
1179 myCombo->setCurrentIndex(aFound);
1180 onTextChanged(theText);
1186 Adds item in combo box, sets it current if theSetCurrent is true
1188 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1194 if (theOrder == atTop)
1196 else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1197 aIndexAt = myCombo->currentIndex();
1198 else if (theOrder == atAfterCurrent &&
1199 myCombo->count() > 0 &&
1200 myCombo->currentIndex() < myCombo->count()-1)
1201 aIndexAt = myCombo->currentIndex() + 1;
1202 myCombo->insertItem(theValue, aIndexAt);
1209 Adds items in combo box, sets item theCurrent as current
1211 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1212 const int theCurrent)
1215 myCombo->insertList(theList);
1216 if (theCurrent >= 0 && theCurrent < (int)theList.count())
1217 setText(theList[theCurrent]);
1221 Adds item in combo box, sets it current if theSetCurrent is true
1223 void SalomeApp_EntityEdit::insertItem(const int theValue,
1227 myCombo->insertItem(theValue);
1230 setText(QString::number(theValue));
1234 Adds items in combo box, sets item theCurrent as current
1236 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1237 const int theCurrent)
1240 myCombo->insertList(theList);
1242 TColStd_ListIteratorOfListOfInteger aIter(theList);
1243 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1244 if (theCurrent == i) {
1245 setText(QString::number(aIter.Value()));
1252 Adds item in combo box, sets it current if theSetCurrent is true
1254 void SalomeApp_EntityEdit::insertItem(const double theValue,
1258 myCombo->insertItem(theValue);
1261 setText(QString::number(theValue));
1265 Adds items in combo box, sets item theCurrent as current
1267 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1268 const int theCurrent)
1271 myCombo->insertList(theList);
1273 TColStd_ListIteratorOfListOfReal aIter(theList);
1274 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1275 if (theCurrent == i) {
1276 setText(QString::number(aIter.Value()));
1283 \return actual widget
1285 QWidget* SalomeApp_EntityEdit::getControl()
1296 redirect focus to corresponding widget
1298 void SalomeApp_EntityEdit::setFocus()
1302 //myEdit->selectAll();
1304 else if (myCombo && myCombo->isEditable()) {
1305 myCombo->setFocus();
1306 //myCombo->lineEdit()->selectAll();
1311 Sets validator for the control
1313 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1316 myEdit->setValidator(theValidator);
1318 myCombo->setValidator(theValidator);
1322 Event filter for KeyPress event
1324 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1326 if ( (e->key() == Qt::Key_Enter ||
1327 e->key() == Qt::Key_Return ) )
1329 else if (e->key() == Qt::Key_Escape)
1334 Called when item activated in combo box
1336 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1338 onTextChanged(theText);
1342 Slot, called when text changed in line edit
1344 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1347 myApplyBtn->setEnabled(!(theText == myString));
1349 myCancelBtn->setEnabled(!(theText == myString));
1353 Slot, called when user presses Cancel button
1355 void SalomeApp_EntityEdit::onCancel()
1359 myApplyBtn->setEnabled(false);
1361 myCancelBtn->setEnabled(false);
1362 emit escapePressed();
1366 Slot, called when user presses Apply button
1368 void SalomeApp_EntityEdit::onApply()
1370 myString = getText();
1372 myApplyBtn->setEnabled(false);
1374 myCancelBtn->setEnabled(false);
1375 emit returnPressed();
1381 void SalomeApp_EntityEdit::showButtons(bool show)
1384 show ? myApplyBtn->show() : myApplyBtn->hide();
1386 show ? myCancelBtn->show() : myCancelBtn->hide();
1390 Enables/disables data duplication (for combo box)
1392 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1395 myCombo->setDuplicatesEnabled(enabled);