Back to index

salome-gui  6.5.0
Public Types | Signals | Public Member Functions | Protected Member Functions | Private Slots | Private Attributes
SalomeApp_EntityEdit Class Reference

#include <SalomeApp_ListView.h>

Collaboration diagram for SalomeApp_EntityEdit:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { etLineEdit, etComboBox, etComboEdit }
enum  { vtString, vtInteger, vtDouble }
enum  { atBottom, atTop, atBeforeCurrent, atAfterCurrent }
enum  { btApply = 0x0001, btCancel = 0x0002 }

Signals

void returnPressed ()
void escapePressed ()

Public Member Functions

 SalomeApp_EntityEdit (QWidget *parent, int controlType=etLineEdit, int valueType=vtString, bool butApply=false, bool butCancel=false)
 Constructor.
 ~SalomeApp_EntityEdit ()
 Destructor.
void finishEditing ()
void clear ()
 Clears edit/combo box.
QString getText ()
void setText (const QString &theText)
 Sets text.
void insertItem (const QString &theValue, bool theSetCurrent=false, int theOrder=atBottom)
 Adds item in combo box, sets it current if theSetCurrent is true.
void insertList (const QStringList &theList, const int theCurrent=-1)
 Adds items in combo box, sets item theCurrent as current.
void insertItem (const int theValue, bool theSetCurrent=false)
 Adds item in combo box, sets it current if theSetCurrent is true.
void insertList (const TColStd_ListOfInteger &theList, const int theCurrent=-1)
 Adds items in combo box, sets item theCurrent as current.
void insertItem (const double theValue, bool theSetCurrent=false)
 Adds item in combo box, sets it current if theSetCurrent is true.
void insertList (const TColStd_ListOfReal &theList, const int theCurrent=-1)
 Adds items in combo box, sets item theCurrent as current.
QWidget * getControl ()
void setFocus ()
 redirect focus to corresponding widget
void setValidator (const QValidator *)
 Sets validator for the control.
void showButtons (bool show)
 Shows/hides buttons.
void setDuplicatesEnabled (bool enabled)
 Enables/disables data duplication (for combo box)

Protected Member Functions

void keyPressEvent (QKeyEvent *e)
 Event filter for KeyPress event.

Private Slots

void onComboActivated (const QString &)
 Called when item activated in combo box.
void onTextChanged (const QString &)
 Slot, called when text changed in line edit.
void onApply ()
 Slot, called when user presses Apply button.
void onCancel ()
 Slot, called when user presses Cancel button.

Private Attributes

SalomeApp_EditBoxmyEdit
SalomeApp_ComboBoxmyCombo
QToolButton * myApplyBtn
QToolButton * myCancelBtn
QString myString

Detailed Description

Definition at line 158 of file SalomeApp_ListView.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
etLineEdit 
etComboBox 
etComboEdit 

Definition at line 164 of file SalomeApp_ListView.h.

       {
    etLineEdit,           // simple edit box
    etComboBox,           // non-editable combo box
    etComboEdit           // editable combo box
  };
anonymous enum
Enumerator:
vtString 
vtInteger 
vtDouble 

Definition at line 170 of file SalomeApp_ListView.h.

       {
    vtString,             // string
    vtInteger,            // integer value
    vtDouble              // double value
  };
anonymous enum
Enumerator:
atBottom 
atTop 
atBeforeCurrent 
atAfterCurrent 

Definition at line 176 of file SalomeApp_ListView.h.

anonymous enum
Enumerator:
btApply 
btCancel 

Definition at line 183 of file SalomeApp_ListView.h.

       {
    btApply  = 0x0001,
    btCancel = 0x0002
  };

Constructor & Destructor Documentation

SalomeApp_EntityEdit::SalomeApp_EntityEdit ( QWidget *  parent,
int  controlType = etLineEdit,
int  valueType = vtString,
bool  butApply = false,
bool  butCancel = false 
)

Constructor.

Definition at line 1049 of file SalomeApp_ListView.cxx.

                                                   :
QWidget(parent),
myEdit(0),
myCombo(0),
myApplyBtn(0),
myCancelBtn(0)
{
  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
  SUIT_ResourceMgr* mgr = app ? app->resourceMgr() : NULL;

  QHBoxLayout* aTopLayout = new QHBoxLayout(this);
  aTopLayout->setAlignment( Qt::AlignTop );
  aTopLayout->setSpacing( 0 );
  aTopLayout->setMargin( 1 );
  if (controlType != etLineEdit &&
      controlType != etComboBox &&
      controlType != etComboEdit)
    controlType = etLineEdit;
  if (controlType == etComboBox || controlType == etComboEdit) {
    // this is an editable combo box
    myCombo = new SalomeApp_ComboBox(controlType == etComboEdit, this);
    myCombo->setMinimumSize(MIN_COMBO_WIDTH, 0);
    myCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
                                       QSizePolicy::Fixed));
    // no insertions
    myCombo->setInsertPolicy(QComboBox::NoInsert);
    // no duplicates enabled by default
    myCombo->setDuplicatesEnabled(false);
    aTopLayout->addWidget(myCombo);
    // connect signals
    connect(myCombo, SIGNAL(activated(const QString&)), this, SLOT(onComboActivated(const QString&)));
    connect(myCombo, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
  }
  else {
    // and this is an edit box
    myEdit = new SalomeApp_EditBox(this);
    myEdit->setMinimumSize(MIN_EDIT_WIDTH, 0);
    myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
                                      QSizePolicy::Fixed));
    aTopLayout->addWidget(myEdit);
    connect(myEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
    connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onApply()));
    connect(myEdit, SIGNAL(escapePressed()), this, SLOT(onCancel()));
  }
  if (valueType != vtString &&
      valueType != vtInteger &&
      valueType != vtDouble)
    valueType = vtString;
  if (valueType == vtInteger)
    setValidator(new QIntValidator(this));
  else if (valueType == vtDouble)
    setValidator(new QDoubleValidator(this));
  if (butApply) {
    // Apply button (V)
    myApplyBtn = new QToolButton(this);

    QPixmap anIcon;
    if( mgr )
      anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_APPLY" ), false );

    myApplyBtn->setIcon(anIcon);
    myApplyBtn->setEnabled(false);
    myApplyBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    myApplyBtn->setMinimumSize(16, 16);
    myApplyBtn->setMaximumSize(16, 20);
    aTopLayout->addWidget(myApplyBtn);
    connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
  }
  if (butCancel) {
    // Cancel button (X)
    myCancelBtn = new QToolButton(this);
    QPixmap anIcon;
    if( mgr )
      anIcon = mgr->loadPixmap( "SalomeApp", tr( "ICON_CANCEL" ), false );
    myCancelBtn->setIcon(anIcon);
    myCancelBtn->setEnabled(false);
    myCancelBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    myCancelBtn->setMinimumSize(16, 16);
    myCancelBtn->setMaximumSize(16, 20);
    aTopLayout->addWidget(myCancelBtn);
    connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(onCancel()));
  }
}

Here is the call graph for this function:

Destructor.

Definition at line 1140 of file SalomeApp_ListView.cxx.

{
}

Member Function Documentation

Clears edit/combo box.

Definition at line 1147 of file SalomeApp_ListView.cxx.

{
  if (myEdit)
    myEdit->clear();
  if (myCombo)
    myCombo->clear();
}

Here is the caller graph for this function:

Returns:
actual widget

Definition at line 1285 of file SalomeApp_ListView.cxx.

{
  if (myEdit)
    return myEdit;
  else if (myCombo)
    return myCombo;
  else
    return 0;
}

Here is the caller graph for this function:

Returns:
current text in edit box or combo box

Definition at line 1158 of file SalomeApp_ListView.cxx.

{
  if (myEdit)
    return myEdit->text();
  else if (myCombo)
    return myCombo->currentText();
  else
    return "";
}

Here is the caller graph for this function:

void SalomeApp_EntityEdit::insertItem ( const QString &  theValue,
bool  theSetCurrent = false,
int  theOrder = atBottom 
)

Adds item in combo box, sets it current if theSetCurrent is true.

Definition at line 1188 of file SalomeApp_ListView.cxx.

{
  if (myCombo) {
    int aIndexAt = -1;
    if (theOrder == atTop)
      aIndexAt = 0;
    else if (theOrder == atBeforeCurrent && myCombo->count() > 0)
      aIndexAt = myCombo->currentIndex();
    else if (theOrder == atAfterCurrent &&
             myCombo->count() > 0 &&
             myCombo->currentIndex() < myCombo->count()-1)
      aIndexAt = myCombo->currentIndex() + 1;
    myCombo->insertItem(theValue, aIndexAt);
  }
  if (theSetCurrent)
    setText(theValue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SalomeApp_EntityEdit::insertItem ( const int  theValue,
bool  theSetCurrent = false 
)

Adds item in combo box, sets it current if theSetCurrent is true.

Definition at line 1223 of file SalomeApp_ListView.cxx.

{
  if (myCombo) {
    myCombo->insertItem(theValue);
  }
  if (theSetCurrent)
    setText(QString::number(theValue));
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::insertItem ( const double  theValue,
bool  theSetCurrent = false 
)

Adds item in combo box, sets it current if theSetCurrent is true.

Definition at line 1254 of file SalomeApp_ListView.cxx.

{
  if (myCombo) {
    myCombo->insertItem(theValue);
  }
  if (theSetCurrent)
    setText(QString::number(theValue));
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::insertList ( const QStringList &  theList,
const int  theCurrent = -1 
)

Adds items in combo box, sets item theCurrent as current.

Definition at line 1211 of file SalomeApp_ListView.cxx.

{
  if (myCombo)
    myCombo->insertList(theList);
  if (theCurrent >= 0 && theCurrent < (int)theList.count())
    setText(theList[theCurrent]);
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::insertList ( const TColStd_ListOfInteger &  theList,
const int  theCurrent = -1 
)

Adds items in combo box, sets item theCurrent as current.

Definition at line 1236 of file SalomeApp_ListView.cxx.

{
  if (myCombo)
    myCombo->insertList(theList);

  TColStd_ListIteratorOfListOfInteger aIter(theList);
  for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
    if (theCurrent == i) {
      setText(QString::number(aIter.Value()));
      break;
    }
  }
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::insertList ( const TColStd_ListOfReal &  theList,
const int  theCurrent = -1 
)

Adds items in combo box, sets item theCurrent as current.

Definition at line 1267 of file SalomeApp_ListView.cxx.

{
  if (myCombo)
    myCombo->insertList(theList);

  TColStd_ListIteratorOfListOfReal aIter(theList);
  for (unsigned i = 0; aIter.More(); aIter.Next(), i++) {
    if (theCurrent == i) {
      setText(QString::number(aIter.Value()));
      break;
    }
  }
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::keyPressEvent ( QKeyEvent *  e) [protected]

Event filter for KeyPress event.

Definition at line 1324 of file SalomeApp_ListView.cxx.

{
  if ( (e->key() == Qt::Key_Enter ||
        e->key() == Qt::Key_Return ) )
    onApply();
  else if (e->key() == Qt::Key_Escape)
    onCancel();
}

Here is the call graph for this function:

void SalomeApp_EntityEdit::onApply ( ) [private, slot]

Slot, called when user presses Apply button.

Definition at line 1368 of file SalomeApp_ListView.cxx.

{
  myString = getText();
  if (myApplyBtn)
    myApplyBtn->setEnabled(false);
  if (myCancelBtn)
    myCancelBtn->setEnabled(false);
  emit returnPressed();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SalomeApp_EntityEdit::onCancel ( ) [private, slot]

Slot, called when user presses Cancel button.

Definition at line 1355 of file SalomeApp_ListView.cxx.

{
  setText(myString);
  if (myApplyBtn)
    myApplyBtn->setEnabled(false);
  if (myCancelBtn)
    myCancelBtn->setEnabled(false);
  emit escapePressed();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SalomeApp_EntityEdit::onComboActivated ( const QString &  theText) [private, slot]

Called when item activated in combo box.

Definition at line 1336 of file SalomeApp_ListView.cxx.

{
  onTextChanged(theText);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SalomeApp_EntityEdit::onTextChanged ( const QString &  theText) [private, slot]

Slot, called when text changed in line edit.

Definition at line 1344 of file SalomeApp_ListView.cxx.

{
  if (myApplyBtn)
    myApplyBtn->setEnabled(!(theText == myString));
  if (myCancelBtn)
    myCancelBtn->setEnabled(!(theText == myString));
}

Here is the caller graph for this function:

Here is the caller graph for this function:

Enables/disables data duplication (for combo box)

Definition at line 1392 of file SalomeApp_ListView.cxx.

{
  if (myCombo)
    myCombo->setDuplicatesEnabled(enabled);
}

redirect focus to corresponding widget

Definition at line 1298 of file SalomeApp_ListView.cxx.

{
  if (myEdit) {
    myEdit->setFocus();
    //myEdit->selectAll();
  }
  else if (myCombo && myCombo->isEditable()) {
    myCombo->setFocus();
    //myCombo->lineEdit()->selectAll();
  }
}

Here is the caller graph for this function:

void SalomeApp_EntityEdit::setText ( const QString &  theText)

Sets text.

Definition at line 1171 of file SalomeApp_ListView.cxx.

{
  myString = theText;
  if (myEdit)
    myEdit->setText(theText);
  if (myCombo) {
    int aFound = myCombo->findItem(theText);
    if (aFound >= 0) {
      myCombo->setCurrentIndex(aFound);
      onTextChanged(theText);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SalomeApp_EntityEdit::setValidator ( const QValidator *  theValidator)

Sets validator for the control.

Definition at line 1313 of file SalomeApp_ListView.cxx.

{
  if (myEdit)
    myEdit->setValidator(theValidator);
  if (myCombo)
    myCombo->setValidator(theValidator);
}

Here is the caller graph for this function:

Shows/hides buttons.

Definition at line 1381 of file SalomeApp_ListView.cxx.

{
  if (myApplyBtn)
    show ? myApplyBtn->show()  : myApplyBtn->hide();
  if (myCancelBtn)
    show ? myCancelBtn->show() : myCancelBtn->hide();
}

Member Data Documentation

QToolButton* SalomeApp_EntityEdit::myApplyBtn [private]

Definition at line 235 of file SalomeApp_ListView.h.

QToolButton* SalomeApp_EntityEdit::myCancelBtn [private]

Definition at line 236 of file SalomeApp_ListView.h.

Definition at line 234 of file SalomeApp_ListView.h.

Definition at line 233 of file SalomeApp_ListView.h.

QString SalomeApp_EntityEdit::myString [private]

Definition at line 237 of file SalomeApp_ListView.h.


The documentation for this class was generated from the following files: