1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
32 #include "utilities.h"
35 #include <QToolButton>
37 #include <QHeaderView>
40 #include <TColStd_ListOfInteger.hxx>
41 #include <TColStd_ListOfReal.hxx>
43 #include <TColStd_ListIteratorOfListOfInteger.hxx>
44 #include <TColStd_ListIteratorOfListOfReal.hxx>
47 Used for resizing editing widget
49 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
50 SalomeApp_EntityEdit* theWidget)
54 QTreeWidget* aListView = theItem->treeWidget();
55 int anEditColumn = theItem->getEditedColumn();
59 int aX = 0, aY = 0, aW = 0, aH = 0;
61 QRect aRect = aListView->visualItemRect(theItem);
62 aX = aListView->header()->sectionViewportPosition(anEditColumn);
64 aX = 0; // THIS CAN BE REMOVED
65 QSize aSize = theWidget->getControl()->sizeHint();
66 aH = qMax(aSize.height() , aRect.height() );
67 aY = aRect.y() - ((aH - aRect.height()) / 2);
68 //aW = aListView->columnWidth(anEditColumn); // CAN SUBSTITUTE NEXT 3 ROWS
69 aW = aListView->viewport()->width() - aX;
72 theWidget->setGeometry(aX, aY, aW, aH);
78 SalomeApp_ListView::SalomeApp_ListView( QWidget* parent )
79 : QTreeWidget/*QtxListView*/( parent )
81 myMouseEnabled = true;
82 myEditingEnabled = false;
83 setSelectionMode(QAbstractItemView::SingleSelection);
84 setRootIsDecorated(false);
85 setAllColumnsShowFocus(false);
86 // header()->setClickEnabled(false);
87 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
88 header()->setMovable(false);
90 header()->setSectionsMovable(false);
96 viewport()->installEventFilter(this);
98 connect(this, SIGNAL(itemSelectionChanged()),
99 this, SLOT(onSelectionChanged()));
100 connect(header(), SIGNAL(sizeChange(int, int, int)),
101 this, SLOT(onHeaderSizeChange(int, int, int)));
107 SalomeApp_ListView::~SalomeApp_ListView()
117 Updates all data viewer
119 void SalomeApp_ListView::updateViewer()
121 // temporary disconnecting selection changed SIGNAL
123 QTreeWidgetItemIterator it( this );
124 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)(*it);
126 aRoot->updateAllLevels();
127 update( contentsRect() );//updateContents();
128 // connecting again selection changed SIGNAL
130 emit itemSelectionChanged();
134 Updates currently selected item(s)
136 void SalomeApp_ListView::updateSelected()
138 // temporary disconnecting selection changed SIGNAL
140 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(selectedItems().first());
142 aChild->updateAllLevels();
143 update( contentsRect() );//updateContents();
144 // connecting again selection changed SIGNAL
146 emit itemSelectionChanged();
150 Returns popup client type
152 QString SalomeApp_ListView::popupClientType() const
154 return "SalomeApp_ListView";
158 Fills popup menu with items
160 void SalomeApp_ListView::contextMenuPopup( QMenu* aPopup )
170 void SalomeApp_ListView::clear()
177 QTreeWidget::clear();
181 \return true if mouse events are enabled
183 bool SalomeApp_ListView::isMouseEnabled()
185 return myMouseEnabled;
189 Enables/disables mouse events (excluding MouseMove)
191 void SalomeApp_ListView::enableMouse(bool enable)
193 myMouseEnabled = enable;
199 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
201 if (object == viewport() &&
202 (event->type() == QEvent::MouseButtonPress ||
203 event->type() == QEvent::MouseButtonRelease ||
204 event->type() == QEvent::MouseButtonDblClick) &&
208 return QTreeWidget::eventFilter(object, event);
212 Setting editing of items availbale/not available
214 void SalomeApp_ListView::enableEditing(bool theFlag)
216 myEditingEnabled = theFlag;
217 if (!myEditingEnabled) {
227 Says if editing is enabled
229 bool SalomeApp_ListView::isEnableEditing()
231 return myEditingEnabled;
235 Calls finishEditing(true)...
237 void SalomeApp_ListView::accept()
243 Slot, called when selection changed in List Viewer
245 void SalomeApp_ListView::onSelectionChanged()
251 if (myEditedItem && !myEditedItem->isAccepted()) {
253 update( contentsRect() );//updateContents();
257 // editing is allowed in Single Selection Mode only
258 if (selectionMode() != QAbstractItemView::SingleSelection || !isEnableEditing())
260 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)(selectedItems().first());
262 if (!anItem->isEditable())
264 myEdit = anItem->startEditing();
266 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
267 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
268 myEditedItem = anItem;
276 Called when Data Viewer is resized
278 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
280 QTreeWidget::resizeEvent(e);
281 int aW = columnWidth(columnCount()-1);
282 int aX = header()->sectionPosition(columnCount()-1);
283 if (aW < width() - frameWidth() * 2 - aX - 1)
284 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
285 update( contentsRect() );//updateContents();
289 Slot, called when columns sizes are changed
291 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
293 int aW = columnWidth(columnCount()-1);
294 int aX = header()->sectionPosition(columnCount()-1);
295 if (aW < width() - frameWidth() * 2 - aX - 1)
296 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
300 Handler for paint event
302 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
304 QTreeWidget::paintEvent(e);
305 if (myEditedItem && myEdit) {
306 computeEditGeometry(myEditedItem, myEdit);
311 Called when user finishes in editing of item
313 void SalomeApp_ListView::onEditOk()
319 Called when user cancels item editing
321 void SalomeApp_ListView::onEditCancel()
323 finishEditing(false);
327 Finishes editing of entity
329 UpdateType SalomeApp_ListView::finishEditing(bool ok)
331 UpdateType aNeedsUpdate = utCancel;
332 if (myEditedItem && myEdit)
334 disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
335 disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
336 myEditedItem->setAccepted(true);
338 aNeedsUpdate = myEditedItem->finishEditing(myEdit);
339 if (aNeedsUpdate == utCancel) {
340 // something to do here on Cancel...
343 // something to do here on OK...
346 switch (aNeedsUpdate) {
350 myEditedItem->updateAllLevels();
356 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
358 aParent->updateAllLevels();
360 myEditedItem->updateAllLevels();
371 // doing the same as for utUpdateViewer here
372 // descendants can add extra processing
382 // hide <myEdit> widget
391 \return current tooltip for list view
392 \retval valid rect in success
394 QRect SalomeApp_ListView::tip(QPoint aPos,
399 QRect result( -1, -1, -1, -1 );
400 SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
402 for (int i = 0; i < columnCount(); i++) {
403 QRect aItemRect = aItem->itemRect(i);
404 QRect aTextRect = aItem->textRect(i);
405 if ( !aItem->text(i).isEmpty() &&
406 ( aItemRect.width() > header()->sectionSize(i) ||
407 aTextRect.left() < 0 ||
408 aTextRect.top() < 0 ||
409 aTextRect.right() > viewport()->width() ||
410 aTextRect.bottom() > viewport()->height() ) ) {
411 // calculating tip data
412 aText = aItem->tipText();
413 dspRect = aItem->tipRect();
415 if (dspRect.isValid()) {
416 result = QRect(QPoint(0, aItemRect.top()),
417 QSize(viewport()->width(), aItemRect.height()));
428 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
429 QTreeWidgetItem( parent )
437 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
438 SalomeApp_ListViewItem* after) :
439 QTreeWidgetItem( parent, after )
447 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
448 const QStringList& theStrings,
449 const bool theEditable) :
450 QTreeWidgetItem(parent, theStrings)
453 setEditable(theEditable);
459 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
460 const QStringList& theString,
461 const bool theEditable) :
462 QTreeWidgetItem(parent, theString)
465 setEditable(theEditable);
471 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
472 SalomeApp_ListViewItem* after,
473 const QString& theName,
474 const bool theEditable) :
475 QTreeWidgetItem(parent, after)
477 setData(0,Qt::DisplayRole,QVariant(theName));
479 setEditable(theEditable);
485 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
486 SalomeApp_ListViewItem* after,
487 const QString& theName,
488 const bool theEditable) :
489 QTreeWidgetItem(parent, after)
491 setData(0,Qt::DisplayRole,QVariant(theName));
493 setEditable(theEditable);
499 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
500 SalomeApp_ListViewItem* after,
501 const QString& theName,
502 const QString& theValue,
503 const bool theEditable) :
504 QTreeWidgetItem(parent, after)
506 setData(0,Qt::DisplayRole,QVariant(theName));
507 setData(1,Qt::DisplayRole,QVariant(theValue));
509 setEditable(theEditable);
515 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
516 SalomeApp_ListViewItem* after,
517 const QString& theName,
518 const QString& theValue,
519 const bool theEditable) :
520 QTreeWidgetItem(parent, after)
522 setData(0,Qt::DisplayRole,QVariant(theName));
523 setData(1,Qt::DisplayRole,QVariant(theValue));
525 setEditable(theEditable);
531 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
538 void SalomeApp_ListViewItem::init()
542 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
543 myValueType = (int)SalomeApp_EntityEdit::vtString;
549 Returns the depth of this item
551 int SalomeApp_ListViewItem::depth() const
554 QTreeWidgetItem* aParent = parent();
556 aParent = aParent->parent();
563 \return text in the first column
565 QString SalomeApp_ListViewItem::getName() const
567 return ( treeWidget()->columnCount() > 0 ) ? text(0) : QString("");
571 Sets text in the first column
573 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
575 UpdateType aNeedsUpdate = utCancel;
576 if (treeWidget()->columnCount() > 0) {
578 aNeedsUpdate = utNone;
584 \return text in the second column
586 QString SalomeApp_ListViewItem::getValue() const
588 return ( treeWidget()->columnCount() > 1 ) ? text(1) : QString("");
592 Sets text in the second column
594 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
596 UpdateType aNeedsUpdate = utCancel;
597 if (treeWidget()->columnCount() > 1) {
598 setText(1, theValue);
599 aNeedsUpdate = utNone;
605 \return full path to the entity from the root
607 QString SalomeApp_ListViewItem::fullName()
609 QString aFullName = getName();
610 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
611 while(aParent != NULL) {
612 aFullName = aParent->getName() + QString(".") + aFullName;
613 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
619 expands all entities beginning from this level
621 void SalomeApp_ListViewItem::openAllLevels()
624 QTreeWidgetItemIterator it( this );
625 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
627 aChild->openAllLevels();
629 aChild = (SalomeApp_ListViewItem*)(*it);
634 update all entites beginning from this level
636 void SalomeApp_ListViewItem::updateAllLevels()
638 QTreeWidgetItemIterator it( this );
639 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
641 aChild->updateAllLevels();
643 aChild = (SalomeApp_ListViewItem*)(*it);
648 \return true if entity is editable
650 bool SalomeApp_ListViewItem::isEditable() const
656 Sets editable flag fo the entity
658 void SalomeApp_ListViewItem::setEditable(bool theEditable)
660 myEditable = theEditable;
664 \return true if entitiy is accepted after editing
666 bool SalomeApp_ListViewItem::isAccepted() const
672 Sets entitiy accepted or not after editing
674 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
676 myAccepted = theAccepted;
680 \retval type of edit control (default is edit box)
683 \li 2 - editable combo box
685 int SalomeApp_ListViewItem::getEditingType()
687 return myEditingType;
691 \retval type of edit control (negative value means none)
694 \li 2 - editable combo box
696 void SalomeApp_ListViewItem::setEditingType(const int type)
698 myEditingType = type;
701 /*! \retval edited column, default is last column
702 negative value means there are no editable columns
704 int SalomeApp_ListViewItem::getEditedColumn()
706 return treeWidget()->columnCount()-1;
710 \retval type of edited value (string, int, double)
713 int SalomeApp_ListViewItem::getValueType()
719 Sets type of edited value
721 void SalomeApp_ListViewItem::setValueType(const int valueType)
723 myValueType = valueType;
727 Sets type of edited value
729 int SalomeApp_ListViewItem::getUserType()
735 Sets type of edited value
737 void SalomeApp_ListViewItem::setUserType(const int userType)
739 myUserType = userType;
743 \return buttons for editing widget (Apply (V), Cancel (X))
744 default is both buttons
746 int SalomeApp_ListViewItem::getButtons()
752 Sets buttons for editing widget (Apply (V), Cancel (X))
754 void SalomeApp_ListViewItem::setButtons(const int buttons)
760 Creates control for editing and fills it with values
762 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
764 SalomeApp_EntityEdit* aWidget = 0;
765 QTreeWidget* aListView = treeWidget();
769 int anEditType = getEditingType();
770 int aValueType = getValueType();
771 int aButtons = getButtons();
772 int anEditColumn = getEditedColumn();
773 if (anEditColumn < 0 || anEditType < 0)
775 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
778 aButtons & SalomeApp_EntityEdit::btApply,
779 aButtons & SalomeApp_EntityEdit::btCancel);
780 computeEditGeometry(this, aWidget);
782 fillWidgetWithValues(aWidget);
788 Fills widget with initial values (list or single value)
790 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
792 int anEditColumn = getEditedColumn();
793 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
794 theWidget->insertItem(text(anEditColumn), true);
798 Finishes editing of entity
800 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
802 UpdateType aNeedsUpdate = utCancel;
805 int anEditColumn = getEditedColumn();
806 switch (anEditColumn) {
808 aNeedsUpdate = setName(theWidget->getText());
811 aNeedsUpdate = setValue(theWidget->getText());
819 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
825 Calculates rectangle which should contain item's tip
827 QRect SalomeApp_ListViewItem::tipRect()
829 QRect aRect = QRect(-1, -1, -1, -1);
830 QRect aItemRect = treeWidget()->visualItemRect(this);
831 if ( !aItemRect.isValid() )
834 QString aTip = tipText();
835 if (!aTip.isEmpty()) {
836 QRect aRect0 = textRect(0);
837 QFont aFont(treeWidget()->font());
838 QFontMetrics fm(aFont);
839 int iw = fm.width(aTip);
840 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
849 \return text for tooltip
851 QString SalomeApp_ListViewItem::tipText()
853 QString aText = getName();
854 if (!getValue().isEmpty())
855 aText += QString(" : ") + getValue();
860 Calculates rect of item text in viewport coordinates
862 QRect SalomeApp_ListViewItem::textRect(const int column) const
864 QRect aItemRect = treeWidget()->visualItemRect( this );
865 if ( !aItemRect.isValid() )
868 QFont aFont(treeWidget()->font());
869 QFontMetrics fm(aFont);
871 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
872 ( treeWidget()->indentation() * (depth() + 1) ) :
873 ( treeWidget()->indentation() * depth() );
874 int pixmapWidth = ( !icon(column).isNull() ) ?
875 treeWidget()->iconSize().width() + 2 :
878 for (int i = 0; i < column; i++)
879 prevWidth += treeWidget()->header()->sectionSize(i);
882 ((column == 0) ? decorWidth : 0);
883 int iy = aItemRect.y();
884 int iw = fm.width(text(column));
885 int ih = aItemRect.height();
886 if (!icon(column).isNull()) {
890 ix -= treeWidget()->contentsRect().left();
892 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
897 Calculates rect of item data in viewport coordinates
899 QRect SalomeApp_ListViewItem::itemRect(const int column) const
901 QRect aItemRect = treeWidget()->visualItemRect( this );
902 if ( !aItemRect.isValid() )
905 QFont aFont(treeWidget()->font());
906 QFontMetrics fm(aFont);
908 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
909 ( treeWidget()->indentation() * (depth() + 1) ) :
910 ( treeWidget()->indentation() * depth() );
911 int pixmapWidth = ( !icon(column).isNull() ) ?
912 treeWidget()->iconSize().width() + 2 :
915 for (int i = 0; i < column; i++)
916 prevWidth += treeWidget()->header()->sectionSize(i);
918 int iy = aItemRect.y();
919 int iw = pixmapWidth +
921 ((column == 0) ? decorWidth : 0) +
922 fm.width(text(column));
923 int ih = aItemRect.height();
924 ix -= treeWidget()->contentsRect().left();
926 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
933 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
939 Event filter for key pressing
941 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
943 if ( e->key() == Qt::Key_Escape )
944 emit escapePressed();
946 QLineEdit::keyPressEvent( e );
954 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
958 setObjectName( name );
962 Searches item in list and returns its index
964 int SalomeApp_ComboBox::findItem(const QString& theText)
966 for (int i = 0; i < count(); i++)
967 if (itemText(i) == theText)
973 Adds item in combo box
975 void SalomeApp_ComboBox::insertItem(const QString& theValue,
978 if (duplicatesEnabled() || findItem(theValue) < 0)
979 QComboBox::insertItem(theIndex, theValue);
983 Adds list of items in combo box
985 void SalomeApp_ComboBox::insertList(const QStringList& theList)
987 for (unsigned i = 0; i < theList.count(); i++)
988 insertItem(theList[i]);
992 Adds item in combo box
994 void SalomeApp_ComboBox::insertItem(const int theValue)
998 for (int i = 0; i < count(); i++) {
999 aNum = itemText(i).toInt(&bOk);
1001 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1002 insertItem(QString::number(theValue),i);
1007 insertItem(QString::number(theValue));
1011 Adds list of items in combo box
1013 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
1015 for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1016 insertItem(aIter.Value());
1020 Adds item in combo box
1022 void SalomeApp_ComboBox::insertItem(const double theValue)
1026 for (int i = 0; i < count(); i++) {
1027 aNum = itemText(i).toDouble(&bOk);
1029 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1030 insertItem(QString::number(theValue), i);
1035 insertItem(QString::number(theValue));
1039 Adds list of items in combo box
1041 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1043 for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1044 insertItem(aIter.Value());
1047 #include <qlayout.h>
1049 #define MIN_COMBO_WIDTH 1
1050 #define MIN_EDIT_WIDTH 1
1055 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1066 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1067 SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1069 QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1070 aTopLayout->setAlignment( Qt::AlignTop );
1071 aTopLayout->setSpacing( 0 );
1072 aTopLayout->setMargin( 1 );
1073 if (controlType != etLineEdit &&
1074 controlType != etComboBox &&
1075 controlType != etComboEdit)
1076 controlType = etLineEdit;
1077 if (controlType == etComboBox || controlType == etComboEdit) {
1078 // this is an editable combo box
1079 myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1080 myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1081 myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1082 QSizePolicy::Fixed));
1084 myCombo->setInsertPolicy(QComboBox::NoInsert);
1085 // no duplicates enabled by default
1086 myCombo->setDuplicatesEnabled(false);
1087 aTopLayout->addWidget(myCombo);
1089 connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1090 connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1093 // and this is an edit box
1094 myEdit = new SalomeApp_EditBox(this);
1095 myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1096 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1097 QSizePolicy::Fixed));
1098 aTopLayout->addWidget(myEdit);
1099 connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1100 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1101 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1103 if (valueType != vtString &&
1104 valueType != vtInteger &&
1105 valueType != vtDouble)
1106 valueType = vtString;
1107 if (valueType == vtInteger)
1108 setValidator(new QIntValidator(this));
1109 else if (valueType == vtDouble)
1110 setValidator(new QDoubleValidator(this));
1113 myApplyBtn = new QToolButton(this);
1117 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_APPLY" ), false );
1119 myApplyBtn->setIcon(anIcon);
1120 myApplyBtn->setEnabled(false);
1121 myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1122 myApplyBtn->setMinimumSize(16, 16);
1123 myApplyBtn->setMaximumSize(16, 20);
1124 aTopLayout->addWidget(myApplyBtn);
1125 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1128 // Cancel button (X)
1129 myCancelBtn = new QToolButton(this);
1132 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_CANCEL" ), false );
1133 myCancelBtn->setIcon(anIcon);
1134 myCancelBtn->setEnabled(false);
1135 myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1136 myCancelBtn->setMinimumSize(16, 16);
1137 myCancelBtn->setMaximumSize(16, 20);
1138 aTopLayout->addWidget(myCancelBtn);
1139 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1146 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1151 Clears edit/combo box
1153 void SalomeApp_EntityEdit::clear()
1162 \return current text in edit box or combo box
1164 QString SalomeApp_EntityEdit::getText()
1167 return myEdit->text();
1169 return myCombo->currentText();
1177 void SalomeApp_EntityEdit::setText(const QString& theText)
1181 myEdit->setText(theText);
1183 int aFound = myCombo->findItem(theText);
1185 myCombo->setCurrentIndex(aFound);
1186 onTextChanged(theText);
1192 Adds item in combo box, sets it current if theSetCurrent is true
1194 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1200 if (theOrder == atTop)
1202 else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1203 aIndexAt = myCombo->currentIndex();
1204 else if (theOrder == atAfterCurrent &&
1205 myCombo->count() > 0 &&
1206 myCombo->currentIndex() < myCombo->count()-1)
1207 aIndexAt = myCombo->currentIndex() + 1;
1208 myCombo->insertItem(theValue, aIndexAt);
1215 Adds items in combo box, sets item theCurrent as current
1217 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1218 const int theCurrent)
1221 myCombo->insertList(theList);
1222 if (theCurrent >= 0 && theCurrent < (int)theList.count())
1223 setText(theList[theCurrent]);
1227 Adds item in combo box, sets it current if theSetCurrent is true
1229 void SalomeApp_EntityEdit::insertItem(const int theValue,
1233 myCombo->insertItem(theValue);
1236 setText(QString::number(theValue));
1240 Adds items in combo box, sets item theCurrent as current
1242 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1243 const int theCurrent)
1246 myCombo->insertList(theList);
1248 TColStd_ListIteratorOfListOfInteger aIter(theList);
1249 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1250 if (theCurrent == i) {
1251 setText(QString::number(aIter.Value()));
1258 Adds item in combo box, sets it current if theSetCurrent is true
1260 void SalomeApp_EntityEdit::insertItem(const double theValue,
1264 myCombo->insertItem(theValue);
1267 setText(QString::number(theValue));
1271 Adds items in combo box, sets item theCurrent as current
1273 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1274 const int theCurrent)
1277 myCombo->insertList(theList);
1279 TColStd_ListIteratorOfListOfReal aIter(theList);
1280 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1281 if (theCurrent == i) {
1282 setText(QString::number(aIter.Value()));
1289 \return actual widget
1291 QWidget* SalomeApp_EntityEdit::getControl()
1302 redirect focus to corresponding widget
1304 void SalomeApp_EntityEdit::setFocus()
1308 //myEdit->selectAll();
1310 else if (myCombo && myCombo->isEditable()) {
1311 myCombo->setFocus();
1312 //myCombo->lineEdit()->selectAll();
1317 Sets validator for the control
1319 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1322 myEdit->setValidator(theValidator);
1324 myCombo->setValidator(theValidator);
1328 Event filter for KeyPress event
1330 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1332 if ( (e->key() == Qt::Key_Enter ||
1333 e->key() == Qt::Key_Return ) )
1335 else if (e->key() == Qt::Key_Escape)
1340 Called when item activated in combo box
1342 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1344 onTextChanged(theText);
1348 Slot, called when text changed in line edit
1350 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1353 myApplyBtn->setEnabled(!(theText == myString));
1355 myCancelBtn->setEnabled(!(theText == myString));
1359 Slot, called when user presses Cancel button
1361 void SalomeApp_EntityEdit::onCancel()
1365 myApplyBtn->setEnabled(false);
1367 myCancelBtn->setEnabled(false);
1368 emit escapePressed();
1372 Slot, called when user presses Apply button
1374 void SalomeApp_EntityEdit::onApply()
1376 myString = getText();
1378 myApplyBtn->setEnabled(false);
1380 myCancelBtn->setEnabled(false);
1381 emit returnPressed();
1387 void SalomeApp_EntityEdit::showButtons(bool show)
1390 show ? myApplyBtn->show() : myApplyBtn->hide();
1392 show ? myCancelBtn->show() : myCancelBtn->hide();
1396 Enables/disables data duplication (for combo box)
1398 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1401 myCombo->setDuplicatesEnabled(enabled);