+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 );
+}