Back to index

salome-smesh  6.5.0
Public Member Functions | Private Attributes
SMESHGUI_FilterTable::ComboDelegate Class Reference

List of all members.

Public Member Functions

 ComboDelegate (QObject *=0)
 ~ComboDelegate ()
QWidget * createEditor (QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
void setEditorData (QWidget *, const QModelIndex &) const
void setModelData (QWidget *, QAbstractItemModel *, const QModelIndex &) const
void updateEditorGeometry (QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const

Private Attributes

QTableWidget * myTable

Detailed Description

Definition at line 589 of file SMESHGUI_FilterDlg.cxx.


Constructor & Destructor Documentation

Definition at line 607 of file SMESHGUI_FilterDlg.cxx.

  : QItemDelegate( parent ), 
    myTable( qobject_cast<QTableWidget*>( parent ) )
{
}

Definition at line 613 of file SMESHGUI_FilterDlg.cxx.

{
}

Member Function Documentation

QWidget * SMESHGUI_FilterTable::ComboDelegate::createEditor ( QWidget *  parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const

Definition at line 617 of file SMESHGUI_FilterDlg.cxx.

{
  QVariant aData = index.data( Qt::UserRole );
  QVariant::Type aDataType = aData.type();
  if( aDataType == QVariant::StringList ) {
    QStringList l = aData.toStringList();
    if ( !l.isEmpty() ) {
      QComboBox* cb = new QComboBox( parent );
      cb->setFrame( false );
      cb->addItems( l );
      return cb;
    }
  }
  else if( aDataType == QVariant::Int ) {
    bool ok = false;
    int aValue = aData.toInt( &ok );
    if ( ok ) {
      SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
      intSpin->setFrame( false );
      intSpin->setValue( aValue );
      return intSpin;
    }
  }
  else if( aDataType == QVariant::Double ) {
    bool ok = false;
    double aValue = aData.toDouble( &ok );
    if ( ok ) {
      int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
      if ( !ok )
        aPrecision = 0;

      SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
      dblSpin->setFrame( false );
      dblSpin->setValue( aValue );
      return dblSpin;
    }
  }
  return QItemDelegate::createEditor( parent, option, index );
}
void SMESHGUI_FilterTable::ComboDelegate::setEditorData ( QWidget *  editor,
const QModelIndex &  index 
) const

Definition at line 659 of file SMESHGUI_FilterDlg.cxx.

{
  QVariant data = index.model()->data( index, Qt::DisplayRole );
  QString value = data.toString();
  bool bOk = false;
  if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
    int i = cb->findText( value );
    if ( i >= 0 ) {
      cb->setCurrentIndex( i );
      bOk = true;
    }
  }
  else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
    if( data.type() == QVariant::Double ) {
      double valueDouble = data.toDouble( &bOk );
      if( bOk )
        dblSpin->setValue( valueDouble );
    }
  }
  if ( !bOk ) QItemDelegate::setEditorData( editor, index );
}
void SMESHGUI_FilterTable::ComboDelegate::setModelData ( QWidget *  editor,
QAbstractItemModel *  model,
const QModelIndex &  index 
) const

Definition at line 682 of file SMESHGUI_FilterDlg.cxx.

{
  if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
    model->setData( index, cb->currentText(), Qt::DisplayRole );
  else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
    model->setData( index, intSpin->value(), Qt::DisplayRole );
  else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
    model->setData( index, dblSpin->value(), Qt::DisplayRole );
  else QItemDelegate::setModelData( editor, model, index );
}
void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry ( QWidget *  editor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const

Definition at line 695 of file SMESHGUI_FilterDlg.cxx.

{
  editor->setGeometry( option.rect );
}

Member Data Documentation

Definition at line 604 of file SMESHGUI_FilterDlg.cxx.


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