+int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
+{
+ QMap<int,int>::const_iterator it;
+ for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
+ if ( it.value() == idx ) return it.key();
+ return -1;
+}
+
+int SMESHGUI_FilterTable::ComboItem::index( int i ) const
+{
+ return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
+}
+/*
+ Class : SMESHGUI_FilterTable::CheckItem
+ Description : Check table item.
+*/
+
+class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
+{
+public:
+ static int Type();
+
+ CheckItem( bool = false );
+ CheckItem( const QString&, bool = false );
+ ~CheckItem();
+
+ void setChecked( bool );
+ bool checked() const;
+};
+
+int SMESHGUI_FilterTable::CheckItem::Type()
+{
+ return QTableWidgetItem::UserType + 2;
+}
+
+SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
+ : QTableWidgetItem( Type() )
+{
+ Qt::ItemFlags f = flags();
+ f = f | Qt::ItemIsUserCheckable;
+ f = f & ~Qt::ItemIsTristate;
+ f = f & ~Qt::ItemIsEditable;
+ setFlags( f );
+ setChecked(value);
+}
+
+SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
+ : QTableWidgetItem( Type() )
+{
+ Qt::ItemFlags f = flags();
+ f = f | Qt::ItemIsUserCheckable;
+ f = f & ~Qt::ItemIsTristate;
+ f = f & ~Qt::ItemIsEditable;
+ setFlags( f );
+ setChecked( value );
+ setText( text );
+}
+
+SMESHGUI_FilterTable::CheckItem::~CheckItem()
+{
+}
+
+void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
+{
+ setCheckState( value ? Qt::Checked : Qt::Unchecked );
+}
+
+bool SMESHGUI_FilterTable::CheckItem::checked() const
+{
+ return checkState() == Qt::Checked;
+}
+
+/*
+ Class : SMESHGUI_FilterTable::IntSpinItem
+ Description : Integer spin table item.
+*/
+
+class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
+{
+public:
+ static int Type();
+
+ IntSpinItem( const int theValue );
+
+ int value() const;
+ void setValue( const int theValue );
+
+ void clear();
+};
+
+int SMESHGUI_FilterTable::IntSpinItem::Type()
+{
+ return QTableWidgetItem::UserType + 3;
+}
+
+SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
+ : QTableWidgetItem( Type() )
+{
+ setValue( theValue );
+}
+
+int SMESHGUI_FilterTable::IntSpinItem::value() const
+{
+ bool ok = false;
+ int value = data( Qt::UserRole ).toInt( &ok );
+ return ok ? value : 0;
+}
+
+void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
+{
+ setData( Qt::UserRole, theValue );
+ setText( QString::number( theValue ) );
+}
+
+void SMESHGUI_FilterTable::IntSpinItem::clear()
+{
+ setText( "" );
+}
+
+/*
+ Class : SMESHGUI_FilterTable::DoubleSpinItem
+ Description : Double spin table item.
+*/
+
+class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
+{
+public:
+ static int Type();
+
+ DoubleSpinItem( const double theValue );
+
+ double value() const;
+ void setValue( const double theValue );
+
+ int precision() const;
+ void setPrecision( const int thePrecision );
+
+ void clear();
+};
+
+int SMESHGUI_FilterTable::DoubleSpinItem::Type()
+{
+ return QTableWidgetItem::UserType + 4;
+}
+
+SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
+ : QTableWidgetItem( Type() )
+{
+ setValue( theValue );
+}
+
+double SMESHGUI_FilterTable::DoubleSpinItem::value() const
+{
+ bool ok = false;
+ double value = data( Qt::UserRole ).toDouble( &ok );
+ return ok ? value : 0;
+}
+
+void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
+{
+ setData( Qt::UserRole, theValue );
+ setText( QString::number( theValue ) );
+}
+
+int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
+{
+ bool ok = false;
+ int precision = data( Qt::UserRole + 1 ).toInt( &ok );
+ return ok ? precision : 0;
+}
+
+void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
+{
+ setData( Qt::UserRole + 1, thePrecision );
+}
+
+void SMESHGUI_FilterTable::DoubleSpinItem::clear()
+{
+ setText( "" );
+}
+
+/*
+ Class : SMESHGUI_FilterTable::ComboDelegate
+ Description : Table used by this widget
+*/
+
+class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
+{
+public:
+ 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:
+ QTableWidget* myTable;
+};
+
+SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
+ : QItemDelegate( parent ),
+ myTable( qobject_cast<QTableWidget*>( parent ) )
+{
+}
+
+SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
+{
+}
+
+QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index ) const
+{
+ 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
+{
+ 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
+{
+ 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
+{
+ editor->setGeometry( option.rect );
+}