1 // Copyright (C) 2007-2024 CEA, EDF, 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 header()->setSectionsMovable(false);
92 viewport()->installEventFilter(this);
94 connect(this, SIGNAL(itemSelectionChanged()),
95 this, SLOT(onSelectionChanged()));
96 connect(header(), SIGNAL(sizeChange(int, int, int)),
97 this, SLOT(onHeaderSizeChange(int, int, int)));
103 SalomeApp_ListView::~SalomeApp_ListView()
113 Updates all data viewer
115 void SalomeApp_ListView::updateViewer()
117 // temporary disconnecting selection changed SIGNAL
119 QTreeWidgetItemIterator it( this );
120 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)(*it);
122 aRoot->updateAllLevels();
123 update( contentsRect() );//updateContents();
124 // connecting again selection changed SIGNAL
126 emit itemSelectionChanged();
130 Updates currently selected item(s)
132 void SalomeApp_ListView::updateSelected()
134 // temporary disconnecting selection changed SIGNAL
136 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(selectedItems().first());
138 aChild->updateAllLevels();
139 update( contentsRect() );//updateContents();
140 // connecting again selection changed SIGNAL
142 emit itemSelectionChanged();
146 Returns popup client type
148 QString SalomeApp_ListView::popupClientType() const
150 return "SalomeApp_ListView";
154 Fills popup menu with items
156 void SalomeApp_ListView::contextMenuPopup( QMenu* aPopup )
166 void SalomeApp_ListView::clear()
173 QTreeWidget::clear();
177 \return true if mouse events are enabled
179 bool SalomeApp_ListView::isMouseEnabled()
181 return myMouseEnabled;
185 Enables/disables mouse events (excluding MouseMove)
187 void SalomeApp_ListView::enableMouse(bool enable)
189 myMouseEnabled = enable;
195 bool SalomeApp_ListView::eventFilter(QObject* object, QEvent* event)
197 if (object == viewport() &&
198 (event->type() == QEvent::MouseButtonPress ||
199 event->type() == QEvent::MouseButtonRelease ||
200 event->type() == QEvent::MouseButtonDblClick) &&
204 return QTreeWidget::eventFilter(object, event);
208 Setting editing of items availbale/not available
210 void SalomeApp_ListView::enableEditing(bool theFlag)
212 myEditingEnabled = theFlag;
213 if (!myEditingEnabled) {
223 Says if editing is enabled
225 bool SalomeApp_ListView::isEnableEditing()
227 return myEditingEnabled;
231 Calls finishEditing(true)...
233 void SalomeApp_ListView::accept()
239 Slot, called when selection changed in List Viewer
241 void SalomeApp_ListView::onSelectionChanged()
247 if (myEditedItem && !myEditedItem->isAccepted()) {
249 update( contentsRect() );//updateContents();
253 // editing is allowed in Single Selection Mode only
254 if (selectionMode() != QAbstractItemView::SingleSelection || !isEnableEditing())
256 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)(selectedItems().first());
258 if (!anItem->isEditable())
260 myEdit = anItem->startEditing();
262 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
263 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
264 myEditedItem = anItem;
272 Called when Data Viewer is resized
274 void SalomeApp_ListView::resizeEvent( QResizeEvent * e)
276 QTreeWidget::resizeEvent(e);
277 int aW = columnWidth(columnCount()-1);
278 int aX = header()->sectionPosition(columnCount()-1);
279 if (aW < width() - frameWidth() * 2 - aX - 1)
280 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
281 update( contentsRect() );//updateContents();
285 Slot, called when columns sizes are changed
287 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
289 int aW = columnWidth(columnCount()-1);
290 int aX = header()->sectionPosition(columnCount()-1);
291 if (aW < width() - frameWidth() * 2 - aX - 1)
292 setColumnWidth(columnCount()-1, width() - frameWidth() * 2 - aX - 1);
296 Handler for paint event
298 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
300 QTreeWidget::paintEvent(e);
301 if (myEditedItem && myEdit) {
302 computeEditGeometry(myEditedItem, myEdit);
307 Called when user finishes in editing of item
309 void SalomeApp_ListView::onEditOk()
315 Called when user cancels item editing
317 void SalomeApp_ListView::onEditCancel()
319 finishEditing(false);
323 Finishes editing of entity
325 UpdateType SalomeApp_ListView::finishEditing(bool ok)
327 UpdateType aNeedsUpdate = utCancel;
328 if (myEditedItem && myEdit)
330 disconnect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditOk()));
331 disconnect(myEdit, SIGNAL(escapePressed()), this, SLOT(onEditCancel()));
332 myEditedItem->setAccepted(true);
334 aNeedsUpdate = myEditedItem->finishEditing(myEdit);
335 if (aNeedsUpdate == utCancel) {
336 // something to do here on Cancel...
339 // something to do here on OK...
342 switch (aNeedsUpdate) {
346 myEditedItem->updateAllLevels();
352 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)(myEditedItem->parent());
354 aParent->updateAllLevels();
356 myEditedItem->updateAllLevels();
367 // doing the same as for utUpdateViewer here
368 // descendants can add extra processing
378 // hide <myEdit> widget
387 \return current tooltip for list view
388 \retval valid rect in success
390 QRect SalomeApp_ListView::tip(QPoint aPos,
395 QRect result( -1, -1, -1, -1 );
396 SalomeApp_ListViewItem* aItem = (SalomeApp_ListViewItem*)itemAt( aPos );
398 for (int i = 0; i < columnCount(); i++) {
399 QRect aItemRect = aItem->itemRect(i);
400 QRect aTextRect = aItem->textRect(i);
401 if ( !aItem->text(i).isEmpty() &&
402 ( aItemRect.width() > header()->sectionSize(i) ||
403 aTextRect.left() < 0 ||
404 aTextRect.top() < 0 ||
405 aTextRect.right() > viewport()->width() ||
406 aTextRect.bottom() > viewport()->height() ) ) {
407 // calculating tip data
408 aText = aItem->tipText();
409 dspRect = aItem->tipRect();
411 if (dspRect.isValid()) {
412 result = QRect(QPoint(0, aItemRect.top()),
413 QSize(viewport()->width(), aItemRect.height()));
424 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent) :
425 QTreeWidgetItem( parent )
433 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
434 SalomeApp_ListViewItem* after) :
435 QTreeWidgetItem( parent, after )
443 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
444 const QStringList& theStrings,
445 const bool theEditable) :
446 QTreeWidgetItem(parent, theStrings)
449 setEditable(theEditable);
455 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
456 const QStringList& theString,
457 const bool theEditable) :
458 QTreeWidgetItem(parent, theString)
461 setEditable(theEditable);
467 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
468 SalomeApp_ListViewItem* after,
469 const QString& theName,
470 const bool theEditable) :
471 QTreeWidgetItem(parent, after)
473 setData(0,Qt::DisplayRole,QVariant(theName));
475 setEditable(theEditable);
481 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
482 SalomeApp_ListViewItem* after,
483 const QString& theName,
484 const bool theEditable) :
485 QTreeWidgetItem(parent, after)
487 setData(0,Qt::DisplayRole,QVariant(theName));
489 setEditable(theEditable);
495 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
496 SalomeApp_ListViewItem* after,
497 const QString& theName,
498 const QString& theValue,
499 const bool theEditable) :
500 QTreeWidgetItem(parent, after)
502 setData(0,Qt::DisplayRole,QVariant(theName));
503 setData(1,Qt::DisplayRole,QVariant(theValue));
505 setEditable(theEditable);
511 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
512 SalomeApp_ListViewItem* after,
513 const QString& theName,
514 const QString& theValue,
515 const bool theEditable) :
516 QTreeWidgetItem(parent, after)
518 setData(0,Qt::DisplayRole,QVariant(theName));
519 setData(1,Qt::DisplayRole,QVariant(theValue));
521 setEditable(theEditable);
527 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
534 void SalomeApp_ListViewItem::init()
538 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
539 myValueType = (int)SalomeApp_EntityEdit::vtString;
545 Returns the depth of this item
547 int SalomeApp_ListViewItem::depth() const
550 QTreeWidgetItem* aParent = parent();
552 aParent = aParent->parent();
559 \return text in the first column
561 QString SalomeApp_ListViewItem::getName() const
563 return ( treeWidget()->columnCount() > 0 ) ? text(0) : QString("");
567 Sets text in the first column
569 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
571 UpdateType aNeedsUpdate = utCancel;
572 if (treeWidget()->columnCount() > 0) {
574 aNeedsUpdate = utNone;
580 \return text in the second column
582 QString SalomeApp_ListViewItem::getValue() const
584 return ( treeWidget()->columnCount() > 1 ) ? text(1) : QString("");
588 Sets text in the second column
590 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
592 UpdateType aNeedsUpdate = utCancel;
593 if (treeWidget()->columnCount() > 1) {
594 setText(1, theValue);
595 aNeedsUpdate = utNone;
601 \return full path to the entity from the root
603 QString SalomeApp_ListViewItem::fullName()
605 QString aFullName = getName();
606 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
607 while(aParent != NULL) {
608 aFullName = aParent->getName() + QString(".") + aFullName;
609 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
615 expands all entities beginning from this level
617 void SalomeApp_ListViewItem::openAllLevels()
620 QTreeWidgetItemIterator it( this );
621 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
623 aChild->openAllLevels();
625 aChild = (SalomeApp_ListViewItem*)(*it);
630 update all entites beginning from this level
632 void SalomeApp_ListViewItem::updateAllLevels()
634 QTreeWidgetItemIterator it( this );
635 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)(*it);
637 aChild->updateAllLevels();
639 aChild = (SalomeApp_ListViewItem*)(*it);
644 \return true if entity is editable
646 bool SalomeApp_ListViewItem::isEditable() const
652 Sets editable flag fo the entity
654 void SalomeApp_ListViewItem::setEditable(bool theEditable)
656 myEditable = theEditable;
660 \return true if entitiy is accepted after editing
662 bool SalomeApp_ListViewItem::isAccepted() const
668 Sets entitiy accepted or not after editing
670 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
672 myAccepted = theAccepted;
676 \retval type of edit control (default is edit box)
679 \li 2 - editable combo box
681 int SalomeApp_ListViewItem::getEditingType()
683 return myEditingType;
687 \retval type of edit control (negative value means none)
690 \li 2 - editable combo box
692 void SalomeApp_ListViewItem::setEditingType(const int type)
694 myEditingType = type;
697 /*! \retval edited column, default is last column
698 negative value means there are no editable columns
700 int SalomeApp_ListViewItem::getEditedColumn()
702 return treeWidget()->columnCount()-1;
706 \retval type of edited value (string, int, double)
709 int SalomeApp_ListViewItem::getValueType()
715 Sets type of edited value
717 void SalomeApp_ListViewItem::setValueType(const int valueType)
719 myValueType = valueType;
723 Sets type of edited value
725 int SalomeApp_ListViewItem::getUserType()
731 Sets type of edited value
733 void SalomeApp_ListViewItem::setUserType(const int userType)
735 myUserType = userType;
739 \return buttons for editing widget (Apply (V), Cancel (X))
740 default is both buttons
742 int SalomeApp_ListViewItem::getButtons()
748 Sets buttons for editing widget (Apply (V), Cancel (X))
750 void SalomeApp_ListViewItem::setButtons(const int buttons)
756 Creates control for editing and fills it with values
758 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
760 SalomeApp_EntityEdit* aWidget = 0;
761 QTreeWidget* aListView = treeWidget();
765 int anEditType = getEditingType();
766 int aValueType = getValueType();
767 int aButtons = getButtons();
768 int anEditColumn = getEditedColumn();
769 if (anEditColumn < 0 || anEditType < 0)
771 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
774 aButtons & SalomeApp_EntityEdit::btApply,
775 aButtons & SalomeApp_EntityEdit::btCancel);
776 computeEditGeometry(this, aWidget);
778 fillWidgetWithValues(aWidget);
784 Fills widget with initial values (list or single value)
786 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
788 int anEditColumn = getEditedColumn();
789 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
790 theWidget->insertItem(text(anEditColumn), true);
794 Finishes editing of entity
796 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
798 UpdateType aNeedsUpdate = utCancel;
801 int anEditColumn = getEditedColumn();
802 switch (anEditColumn) {
804 aNeedsUpdate = setName(theWidget->getText());
807 aNeedsUpdate = setValue(theWidget->getText());
815 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" );
821 Calculates rectangle which should contain item's tip
823 QRect SalomeApp_ListViewItem::tipRect()
825 QRect aRect = QRect(-1, -1, -1, -1);
826 QRect aItemRect = treeWidget()->visualItemRect(this);
827 if ( !aItemRect.isValid() )
830 QString aTip = tipText();
831 if (!aTip.isEmpty()) {
832 QRect aRect0 = textRect(0);
833 QFont aFont(treeWidget()->font());
834 QFontMetrics fm(aFont);
835 int iw = fm.width(aTip);
836 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
845 \return text for tooltip
847 QString SalomeApp_ListViewItem::tipText()
849 QString aText = getName();
850 if (!getValue().isEmpty())
851 aText += QString(" : ") + getValue();
856 Calculates rect of item text in viewport coordinates
858 QRect SalomeApp_ListViewItem::textRect(const int column) const
860 QRect aItemRect = treeWidget()->visualItemRect( this );
861 if ( !aItemRect.isValid() )
864 QFont aFont(treeWidget()->font());
865 QFontMetrics fm(aFont);
867 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
868 ( treeWidget()->indentation() * (depth() + 1) ) :
869 ( treeWidget()->indentation() * depth() );
870 int pixmapWidth = ( !icon(column).isNull() ) ?
871 treeWidget()->iconSize().width() + 2 :
874 for (int i = 0; i < column; i++)
875 prevWidth += treeWidget()->header()->sectionSize(i);
878 ((column == 0) ? decorWidth : 0);
879 int iy = aItemRect.y();
880 int iw = fm.width(text(column));
881 int ih = aItemRect.height();
882 if (!icon(column).isNull()) {
886 ix -= treeWidget()->contentsRect().left();
888 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
893 Calculates rect of item data in viewport coordinates
895 QRect SalomeApp_ListViewItem::itemRect(const int column) const
897 QRect aItemRect = treeWidget()->visualItemRect( this );
898 if ( !aItemRect.isValid() )
901 QFont aFont(treeWidget()->font());
902 QFontMetrics fm(aFont);
904 int decorWidth = ( treeWidget()->rootIsDecorated() ) ?
905 ( treeWidget()->indentation() * (depth() + 1) ) :
906 ( treeWidget()->indentation() * depth() );
907 int pixmapWidth = ( !icon(column).isNull() ) ?
908 treeWidget()->iconSize().width() + 2 :
911 for (int i = 0; i < column; i++)
912 prevWidth += treeWidget()->header()->sectionSize(i);
914 int iy = aItemRect.y();
915 int iw = pixmapWidth +
917 ((column == 0) ? decorWidth : 0) +
918 fm.width(text(column));
919 int ih = aItemRect.height();
920 ix -= treeWidget()->contentsRect().left();
922 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
929 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
935 Event filter for key pressing
937 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
939 if ( e->key() == Qt::Key_Escape )
940 emit escapePressed();
942 QLineEdit::keyPressEvent( e );
950 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
954 setObjectName( name );
958 Searches item in list and returns its index
960 int SalomeApp_ComboBox::findItem(const QString& theText)
962 for (int i = 0; i < count(); i++)
963 if (itemText(i) == theText)
969 Adds item in combo box
971 void SalomeApp_ComboBox::insertItem(const QString& theValue,
974 if (duplicatesEnabled() || findItem(theValue) < 0)
975 QComboBox::insertItem(theIndex, theValue);
979 Adds list of items in combo box
981 void SalomeApp_ComboBox::insertList(const QStringList& theList)
983 for (int i = 0; i < theList.count(); i++)
984 insertItem(theList[i]);
988 Adds item in combo box
990 void SalomeApp_ComboBox::insertItem(const int theValue)
994 for (int i = 0; i < count(); i++) {
995 aNum = itemText(i).toInt(&bOk);
997 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
998 insertItem(QString::number(theValue),i);
1003 insertItem(QString::number(theValue));
1007 Adds list of items in combo box
1009 void SalomeApp_ComboBox::insertList(const TColStd_ListOfInteger& theList)
1011 for (TColStd_ListIteratorOfListOfInteger aIter(theList); aIter.More(); aIter.Next())
1012 insertItem(aIter.Value());
1016 Adds item in combo box
1018 void SalomeApp_ComboBox::insertItem(const double theValue)
1022 for (int i = 0; i < count(); i++) {
1023 aNum = itemText(i).toDouble(&bOk);
1025 if (aNum > theValue || (aNum == theValue && duplicatesEnabled())) {
1026 insertItem(QString::number(theValue), i);
1031 insertItem(QString::number(theValue));
1035 Adds list of items in combo box
1037 void SalomeApp_ComboBox::insertList(const TColStd_ListOfReal& theList)
1039 for (TColStd_ListIteratorOfListOfReal aIter(theList); aIter.More(); aIter.Next())
1040 insertItem(aIter.Value());
1043 #include <qlayout.h>
1045 #define MIN_COMBO_WIDTH 1
1046 #define MIN_EDIT_WIDTH 1
1051 SalomeApp_EntityEdit::SalomeApp_EntityEdit(QWidget* parent,
1062 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1063 SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;
1065 QHBoxLayout* aTopLayout = new QHBoxLayout(this);
1066 aTopLayout->setAlignment( Qt::AlignTop );
1067 aTopLayout->setSpacing( 0 );
1068 aTopLayout->setMargin( 1 );
1069 if (controlType != etLineEdit &&
1070 controlType != etComboBox &&
1071 controlType != etComboEdit)
1072 controlType = etLineEdit;
1073 if (controlType == etComboBox || controlType == etComboEdit) {
1074 // this is an editable combo box
1075 myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
1076 myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
1077 myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1078 QSizePolicy::Fixed));
1080 myCombo->setInsertPolicy(QComboBox::NoInsert);
1081 // no duplicates enabled by default
1082 myCombo->setDuplicatesEnabled(false);
1083 aTopLayout->addWidget(myCombo);
1085 connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
1086 connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1089 // and this is an edit box
1090 myEdit = new SalomeApp_EditBox(this);
1091 myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
1092 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
1093 QSizePolicy::Fixed));
1094 aTopLayout->addWidget(myEdit);
1095 connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
1096 connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
1097 connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
1099 if (valueType != vtString &&
1100 valueType != vtInteger &&
1101 valueType != vtDouble)
1102 valueType = vtString;
1103 if (valueType == vtInteger)
1104 setValidator(new QIntValidator(this));
1105 else if (valueType == vtDouble)
1106 setValidator(new QDoubleValidator(this));
1109 myApplyBtn = new QToolButton(this);
1113 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_APPLY" ), false );
1115 myApplyBtn->setIcon(anIcon);
1116 myApplyBtn->setEnabled(false);
1117 myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1118 myApplyBtn->setMinimumSize(16, 16);
1119 myApplyBtn->setMaximumSize(16, 20);
1120 aTopLayout->addWidget(myApplyBtn);
1121 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
1124 // Cancel button (X)
1125 myCancelBtn = new QToolButton(this);
1128 anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_CANCEL" ), false );
1129 myCancelBtn->setIcon(anIcon);
1130 myCancelBtn->setEnabled(false);
1131 myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
1132 myCancelBtn->setMinimumSize(16, 16);
1133 myCancelBtn->setMaximumSize(16, 20);
1134 aTopLayout->addWidget(myCancelBtn);
1135 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
1142 SalomeApp_EntityEdit::~SalomeApp_EntityEdit()
1147 Clears edit/combo box
1149 void SalomeApp_EntityEdit::clear()
1158 \return current text in edit box or combo box
1160 QString SalomeApp_EntityEdit::getText()
1163 return myEdit->text();
1165 return myCombo->currentText();
1173 void SalomeApp_EntityEdit::setText(const QString& theText)
1177 myEdit->setText(theText);
1179 int aFound = myCombo->findItem(theText);
1181 myCombo->setCurrentIndex(aFound);
1182 onTextChanged(theText);
1188 Adds item in combo box, sets it current if theSetCurrent is true
1190 void SalomeApp_EntityEdit::insertItem(const QString& theValue,
1196 if (theOrder == atTop)
1198 else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
1199 aIndexAt = myCombo->currentIndex();
1200 else if (theOrder == atAfterCurrent &&
1201 myCombo->count() > 0 &&
1202 myCombo->currentIndex() < myCombo->count()-1)
1203 aIndexAt = myCombo->currentIndex() + 1;
1204 myCombo->insertItem(theValue, aIndexAt);
1211 Adds items in combo box, sets item theCurrent as current
1213 void SalomeApp_EntityEdit::insertList(const QStringList& theList,
1214 const int theCurrent)
1217 myCombo->insertList(theList);
1218 if (theCurrent >= 0 && theCurrent < (int)theList.count())
1219 setText(theList[theCurrent]);
1223 Adds item in combo box, sets it current if theSetCurrent is true
1225 void SalomeApp_EntityEdit::insertItem(const int theValue,
1229 myCombo->insertItem(theValue);
1232 setText(QString::number(theValue));
1236 Adds items in combo box, sets item theCurrent as current
1238 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfInteger& theList,
1239 const int theCurrent)
1242 myCombo->insertList(theList);
1244 TColStd_ListIteratorOfListOfInteger aIter(theList);
1245 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1246 if (theCurrent == (int)i) { //!< TODO: mismatch signed/unsigned
1247 setText(QString::number(aIter.Value()));
1254 Adds item in combo box, sets it current if theSetCurrent is true
1256 void SalomeApp_EntityEdit::insertItem(const double theValue,
1260 myCombo->insertItem(theValue);
1263 setText(QString::number(theValue));
1267 Adds items in combo box, sets item theCurrent as current
1269 void SalomeApp_EntityEdit::insertList(const TColStd_ListOfReal& theList,
1270 const int theCurrent)
1273 myCombo->insertList(theList);
1275 TColStd_ListIteratorOfListOfReal aIter(theList);
1276 for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
1277 if (theCurrent == (int)i) { //!< TODO: mismatch signed/unsigned
1278 setText(QString::number(aIter.Value()));
1285 \return actual widget
1287 QWidget* SalomeApp_EntityEdit::getControl()
1298 redirect focus to corresponding widget
1300 void SalomeApp_EntityEdit::setFocus()
1304 //myEdit->selectAll();
1306 else if (myCombo && myCombo->isEditable()) {
1307 myCombo->setFocus();
1308 //myCombo->lineEdit()->selectAll();
1313 Sets validator for the control
1315 void SalomeApp_EntityEdit::setValidator(const QValidator* theValidator)
1318 myEdit->setValidator(theValidator);
1320 myCombo->setValidator(theValidator);
1324 Event filter for KeyPress event
1326 void SalomeApp_EntityEdit::keyPressEvent( QKeyEvent * e)
1328 if ( (e->key() == Qt::Key_Enter ||
1329 e->key() == Qt::Key_Return ) )
1331 else if (e->key() == Qt::Key_Escape)
1336 Called when item activated in combo box
1338 void SalomeApp_EntityEdit::onComboActivated(const QString& theText)
1340 onTextChanged(theText);
1344 Slot, called when text changed in line edit
1346 void SalomeApp_EntityEdit::onTextChanged(const QString& theText)
1349 myApplyBtn->setEnabled(!(theText == myString));
1351 myCancelBtn->setEnabled(!(theText == myString));
1355 Slot, called when user presses Cancel button
1357 void SalomeApp_EntityEdit::onCancel()
1361 myApplyBtn->setEnabled(false);
1363 myCancelBtn->setEnabled(false);
1364 emit escapePressed();
1368 Slot, called when user presses Apply button
1370 void SalomeApp_EntityEdit::onApply()
1372 myString = getText();
1374 myApplyBtn->setEnabled(false);
1376 myCancelBtn->setEnabled(false);
1377 emit returnPressed();
1383 void SalomeApp_EntityEdit::showButtons(bool show)
1386 show ? myApplyBtn->show() : myApplyBtn->hide();
1388 show ? myCancelBtn->show() : myCancelBtn->hide();
1392 Enables/disables data duplication (for combo box)
1394 void SalomeApp_EntityEdit::setDuplicatesEnabled(bool enabled)
1397 myCombo->setDuplicatesEnabled(enabled);