1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SalomeApp_ListView.cxx
22 // Author : Vadim SANDLER
26 #include "SalomeApp_ListView.h"
27 #include "SalomeApp_Application.h"
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
33 #include <qvalidator.h>
34 #include <qapplication.h>
35 #include <qtoolbutton.h>
37 #include <TColStd_ListIteratorOfListOfInteger.hxx>
38 #include <TColStd_ListIteratorOfListOfReal.hxx>
40 #include "utilities.h"
45 Used for resizing editing widget
47 void computeEditGeometry(SalomeApp_ListViewItem* theItem,
48 SalomeApp_EntityEdit* theWidget)
52 QListView* aListView = theItem->listView();
53 int anEditColumn = theItem->getEditedColumn();
57 int aX = 0, aY = 0, aW = 0, aH = 0;
59 QRect aRect = aListView->itemRect(theItem);
60 aListView->contentsToViewport(aListView->header()->sectionPos(anEditColumn), 0, aX, aY);
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 : QtxListView( parent )
79 myMouseEnabled = true;
80 myEditingEnabled = false;
81 setSelectionMode(Single);
83 setRootIsDecorated(false);
84 setAllColumnsShowFocus(false);
85 // header()->setClickEnabled(false);
86 header()->setMovingEnabled(false);
91 viewport()->installEventFilter(this);
93 connect(this, SIGNAL(selectionChanged()),
94 this, SLOT(onSelectionChanged()));
95 connect(header(), SIGNAL(sizeChange(int, int, int)),
96 this, SLOT(onHeaderSizeChange(int, int, int)));
102 SalomeApp_ListView::~SalomeApp_ListView()
112 Updates all data viewer
114 void SalomeApp_ListView::updateViewer()
116 // temporary disconnecting selection changed SIGNAL
118 SalomeApp_ListViewItem* aRoot = (SalomeApp_ListViewItem*)firstChild();
120 aRoot->updateAllLevels();
122 // connecting again selection changed SIGNAL
124 emit selectionChanged();
128 Updates currently selected item(s)
130 void SalomeApp_ListView::updateSelected()
132 // temporary disconnecting selection changed SIGNAL
134 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)selectedItem();
136 aChild->updateAllLevels();
138 // connecting again selection changed SIGNAL
140 emit selectionChanged();
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( QPopupMenu* aPopup )
164 void SalomeApp_ListView::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 QListView::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()) {
251 // editing is allowed in Single Selection Mode only
252 if (selectionMode() != Single || !isEnableEditing())
254 SalomeApp_ListViewItem* anItem = (SalomeApp_ListViewItem*)selectedItem();
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 QListView::resizeEvent(e);
275 int aW = columnWidth(columns()-1);
276 int aX = header()->sectionPos(columns()-1);
277 if (aW < width() - frameWidth() * 2 - aX - 1)
278 setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
283 Slot, called when columns sizes are changed
285 void SalomeApp_ListView::onHeaderSizeChange(int, int, int)
287 int aW = columnWidth(columns()-1);
288 int aX = header()->sectionPos(columns()-1);
289 if (aW < width() - frameWidth() * 2 - aX - 1)
290 setColumnWidth(columns()-1, width() - frameWidth() * 2 - aX - 1);
294 Handler for paint event
296 void SalomeApp_ListView::viewportPaintEvent(QPaintEvent* e)
298 QListView::viewportPaintEvent(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 < columns(); 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 QListViewItem( parent )
431 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
432 SalomeApp_ListViewItem* after) :
433 QListViewItem( parent, after )
441 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
442 const QString& theName,
443 const bool theEditable) :
444 QListViewItem(parent, theName)
447 setEditable(theEditable);
453 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
454 const QString& theName,
455 const QString& theValue,
456 const bool theEditable) :
457 QListViewItem(parent, theName, theValue)
460 setEditable(theEditable);
466 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
467 const QString& theName,
468 const bool theEditable) :
469 QListViewItem(parent, theName)
472 setEditable(theEditable);
478 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
479 SalomeApp_ListViewItem* after,
480 const QString& theName,
481 const bool theEditable) :
482 QListViewItem(parent, after, theName)
485 setEditable(theEditable);
491 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
492 SalomeApp_ListViewItem* after,
493 const QString& theName,
494 const bool theEditable) :
495 QListViewItem(parent, after, theName)
498 setEditable(theEditable);
505 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
506 const QString& theName,
507 const QString& theValue,
508 const bool theEditable) :
509 QListViewItem(parent, theName, theValue)
512 setEditable(theEditable);
519 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListViewItem* parent,
520 SalomeApp_ListViewItem* after,
521 const QString& theName,
522 const QString& theValue,
523 const bool theEditable) :
524 QListViewItem(parent, after, theName, theValue)
527 setEditable(theEditable);
533 SalomeApp_ListViewItem::SalomeApp_ListViewItem(SalomeApp_ListView* parent,
534 SalomeApp_ListViewItem* after,
535 const QString& theName,
536 const QString& theValue,
537 const bool theEditable) :
538 QListViewItem(parent, after, theName, theValue)
541 setEditable(theEditable);
547 SalomeApp_ListViewItem::~SalomeApp_ListViewItem()
554 void SalomeApp_ListViewItem::init()
558 myEditingType = (int)SalomeApp_EntityEdit::etLineEdit;
559 myValueType = (int)SalomeApp_EntityEdit::vtString;
565 \return text in the first column
567 QString SalomeApp_ListViewItem::getName() const
569 return ( listView()->columns() > 0 ) ? text(0) : QString("");
573 Sets text in the first column
575 UpdateType SalomeApp_ListViewItem::setName(const QString& theName)
577 UpdateType aNeedsUpdate = utCancel;
578 if (listView()->columns() > 0) {
580 aNeedsUpdate = utNone;
586 \return text in the second column
588 QString SalomeApp_ListViewItem::getValue() const
590 return ( listView()->columns() > 1 ) ? text(1) : QString("");
594 Sets text in the second column
596 UpdateType SalomeApp_ListViewItem::setValue(const QString& theValue)
598 UpdateType aNeedsUpdate = utCancel;
599 if (listView()->columns() > 1) {
600 setText(1, theValue);
601 aNeedsUpdate = utNone;
607 \return full path to the entity from the root
609 QString SalomeApp_ListViewItem::fullName()
611 QString aFullName = getName();
612 SalomeApp_ListViewItem* aParent = (SalomeApp_ListViewItem*)parent();
613 while(aParent != NULL) {
614 aFullName = aParent->getName() + QString(".") + aFullName;
615 aParent = (SalomeApp_ListViewItem*)(aParent->parent());
621 expands all entities beginning from this level
623 void SalomeApp_ListViewItem::openAllLevels()
626 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
628 aChild->openAllLevels();
629 aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
634 update all entites beginning from this level
636 void SalomeApp_ListViewItem::updateAllLevels()
638 SalomeApp_ListViewItem* aChild = (SalomeApp_ListViewItem*)firstChild();
640 aChild->updateAllLevels();
641 aChild = (SalomeApp_ListViewItem*)(aChild->nextSibling());
646 \return true if entity is editable
648 bool SalomeApp_ListViewItem::isEditable() const
654 Sets editable flag fo the entity
656 void SalomeApp_ListViewItem::setEditable(bool theEditable)
658 myEditable = theEditable;
662 \return true if entitiy is accepted after editing
664 bool SalomeApp_ListViewItem::isAccepted() const
670 Sets entitiy accepted or not after editing
672 void SalomeApp_ListViewItem::setAccepted(bool theAccepted)
674 myAccepted = theAccepted;
678 \retval type of edit control (default is edit box)
681 \li 2 - editable combo box
683 int SalomeApp_ListViewItem::getEditingType()
685 return myEditingType;
689 \retval type of edit control (negative value means none)
692 \li 2 - editable combo box
694 void SalomeApp_ListViewItem::setEditingType(const int type)
696 myEditingType = type;
699 /*! \retval edited column, default is last column
700 negative value means there are no editable columns
702 int SalomeApp_ListViewItem::getEditedColumn()
704 return listView()->columns()-1;
708 \retval type of edited value (string, int, double)
711 int SalomeApp_ListViewItem::getValueType()
717 Sets type of edited value
719 void SalomeApp_ListViewItem::setValueType(const int valueType)
721 myValueType = valueType;
725 Sets type of edited value
727 int SalomeApp_ListViewItem::getUserType()
733 Sets type of edited value
735 void SalomeApp_ListViewItem::setUserType(const int userType)
737 myUserType = userType;
741 \return buttons for editing widget (Apply (V), Cancel (X))
742 default is both buttons
744 int SalomeApp_ListViewItem::getButtons()
750 Sets buttons for editing widget (Apply (V), Cancel (X))
752 void SalomeApp_ListViewItem::setButtons(const int buttons)
758 Creates control for editing and fills it with values
760 SalomeApp_EntityEdit* SalomeApp_ListViewItem::startEditing()
762 SalomeApp_EntityEdit* aWidget = 0;
763 QListView* aListView = listView();
767 int anEditType = getEditingType();
768 int aValueType = getValueType();
769 int aButtons = getButtons();
770 int anEditColumn = getEditedColumn();
771 if (anEditColumn < 0 || anEditType < 0)
773 aWidget = new SalomeApp_EntityEdit(aListView->viewport(),
776 aButtons & SalomeApp_EntityEdit::btApply,
777 aButtons & SalomeApp_EntityEdit::btCancel);
778 computeEditGeometry(this, aWidget);
780 fillWidgetWithValues(aWidget);
786 Fills widget with initial values (list or single value)
788 void SalomeApp_ListViewItem::fillWidgetWithValues(SalomeApp_EntityEdit* theWidget)
790 int anEditColumn = getEditedColumn();
791 if (theWidget && anEditColumn >= 0 && !text(anEditColumn).isEmpty())
792 theWidget->insertItem(text(anEditColumn), true);
796 Finishes editing of entity
798 UpdateType SalomeApp_ListViewItem::finishEditing(SalomeApp_EntityEdit* theWidget)
800 UpdateType aNeedsUpdate = utCancel;
803 int anEditColumn = getEditedColumn();
804 switch (anEditColumn) {
806 aNeedsUpdate = setName(theWidget->getText());
809 aNeedsUpdate = setValue(theWidget->getText());
817 MESSAGE( "System error has been caught - SalomeApp_ListViewItem::finishEditing" )
823 Calculates rectangle which should contain item's tip
825 QRect SalomeApp_ListViewItem::tipRect()
827 QRect aRect = QRect(-1, -1, -1, -1);
828 QRect aItemRect = listView()->itemRect(this);
829 if ( !aItemRect.isValid() )
832 QString aTip = tipText();
833 if (!aTip.isEmpty()) {
834 QRect aRect0 = textRect(0);
835 QFont aFont(listView()->font());
836 QFontMetrics fm(aFont);
837 int iw = fm.width(aTip);
838 aRect = QRect(QPoint(aRect0.x() < 0 ? 0 : aRect0.x(),
847 \return text for tooltip
849 QString SalomeApp_ListViewItem::tipText()
851 QString aText = getName();
852 if (!getValue().isEmpty())
853 aText += QString(" : ") + getValue();
858 Calculates rect of item text in viewport coordinates
860 QRect SalomeApp_ListViewItem::textRect(const int column) const
862 QRect aItemRect = listView()->itemRect( this );
863 if ( !aItemRect.isValid() )
866 QFont aFont(listView()->font());
867 QFontMetrics fm(aFont);
869 int decorWidth = ( listView()->rootIsDecorated() ) ?
870 ( listView()->treeStepSize() * (depth() + 1) ) :
871 ( listView()->treeStepSize() * depth() );
872 int pixmapWidth = ( pixmap(column) ) ?
873 pixmap(column)->width() + listView()->itemMargin() * 2 :
874 listView()->itemMargin();
876 for (int i = 0; i < column; i++)
877 prevWidth += listView()->header()->sectionSize(i);
880 ((column == 0) ? decorWidth : 0);
881 int iy = aItemRect.y();
882 int iw = fm.width(text(column));
883 int ih = aItemRect.height();
884 if (pixmap(column)) {
885 iy += listView()->itemMargin();
886 ih -= listView()->itemMargin() * 2;
888 ix -= listView()->contentsX();
890 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
895 Calculates rect of item data in viewport coordinates
897 QRect SalomeApp_ListViewItem::itemRect(const int column) const
899 QRect aItemRect = listView()->itemRect( this );
900 if ( !aItemRect.isValid() )
903 QFont aFont(listView()->font());
904 QFontMetrics fm(aFont);
906 int decorWidth = ( listView()->rootIsDecorated() ) ?
907 ( listView()->treeStepSize() * (depth() + 1) ) :
908 ( listView()->treeStepSize() * depth() );
909 int pixmapWidth = ( pixmap(column) ) ?
910 pixmap(column)->width() + listView()->itemMargin() * 2 :
913 for (int i = 0; i < column; i++)
914 prevWidth += listView()->header()->sectionSize(i);
916 int iy = aItemRect.y();
917 int iw = pixmapWidth +
918 listView()->itemMargin() * 2 +
919 ((column == 0) ? decorWidth : 0) +
920 fm.width(text(column));
921 int ih = aItemRect.height();
922 ix -= listView()->contentsX();
924 QRect theResult(QPoint(ix, iy), QSize(iw, ih));
931 SalomeApp_EditBox::SalomeApp_EditBox(QWidget* parent) :
937 Event filter for key pressing
939 void SalomeApp_EditBox::keyPressEvent( QKeyEvent *e )
941 if ( e->key() == Key_Escape )
942 emit escapePressed();
944 QLineEdit::keyPressEvent( e );
952 SalomeApp_ComboBox::SalomeApp_ComboBox(bool rw, QWidget* parent, const char* name) :
953 QComboBox(rw, parent, 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 (text(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(theValue, theIndex);
979 Adds list of items in combo box
981 void SalomeApp_ComboBox::insertList(const QStringList& theList)
983 for (unsigned 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 = text(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 = text(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->setInsertionPolicy(QComboBox::NoInsertion);
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( "STD", tr( "ICON_APPLY" ), false );
1115 myApplyBtn->setPixmap(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( "STD", tr( "ICON_CANCEL" ), false );
1129 myCancelBtn->setPixmap(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->setCurrentItem(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->currentItem();
1200 else if (theOrder == atAfterCurrent &&
1201 myCombo->count() > 0 &&
1202 myCombo->currentItem() < myCombo->count()-1)
1203 aIndexAt = myCombo->currentItem() + 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 == i) {
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 == i) {
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->editable()) {
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() == Key_Enter ||
1329 e->key() == Key_Return ) )
1331 else if (e->key() == 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);