+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::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
+{
+ QStringList l = index.data( Qt::UserRole ).toStringList();
+ if ( !l.isEmpty() ) {
+ QComboBox* cb = new QComboBox( parent );
+ cb->setFrame( false );
+ cb->addItems( l );
+ return cb;
+ }
+ return QItemDelegate::createEditor( parent, option, index );
+}
+
+void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
+ const QModelIndex& index ) const
+{
+ QString value = index.model()->data( index, Qt::DisplayRole ).toString();
+ QComboBox* cb = dynamic_cast<QComboBox*>( editor );
+ bool bOk = false;
+ if ( cb ) {
+ int i = cb->findText( value );
+ if ( i >= 0 ) {
+ cb->setCurrentIndex( i );
+ bOk = true;
+ }
+ }
+ if ( !bOk ) QItemDelegate::setEditorData( editor, index );
+}
+
+void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
+ QAbstractItemModel* model,
+ const QModelIndex& index) const
+{
+ QComboBox* cb = dynamic_cast<QComboBox*>( editor );
+ if ( cb ) model->setData( index, cb->currentText(), 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 );
+}