1 // Copyright (C) 2007-2023 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HYBRIDPluginGUI_Dlg.cxx
22 // Authors : Renaud NEDELEC (OCC)
26 #include "HYBRIDPluginGUI_Dlg.h"
28 #include <QFileDialog>
31 #include <HYBRIDPlugin_Hypothesis.hxx>
35 enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,
36 NAME_COL = 0, VALUE_COL };
38 class ItemDelegate: public QItemDelegate {
40 ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}
41 QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
43 bool editable = index.data( EDITABLE_ROLE ).toInt();
44 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
49 //////////////////////////////////////////
50 // HYBRIDPluginGUI_AdvWidget
51 //////////////////////////////////////////
53 HYBRIDPluginGUI_AdvWidget::HYBRIDPluginGUI_AdvWidget( QWidget* parent, Qt::WindowFlags f )
54 : QWidget( parent, f )
57 //myOptionTable->layout()->setMargin( 0 );
58 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
59 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
61 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
64 HYBRIDPluginGUI_AdvWidget::~HYBRIDPluginGUI_AdvWidget()
68 void HYBRIDPluginGUI_AdvWidget::AddOption( const char* option, bool isCustom )
70 QTreeWidget * table = myOptionTable;
71 //table->setExpanded( true );
73 QTreeWidgetItem * row = new QTreeWidgetItem( table );
74 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
75 row->setFlags( row->flags() | Qt::ItemIsEditable );
78 bool isDefault = false;
81 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
82 if ( name_value_type.size() > 0 )
83 name = name_value_type[0];
84 if ( name_value_type.size() > 1 )
85 value = name_value_type[1];
86 if ( name_value_type.size() > 2 )
87 isDefault = !name_value_type[2].toInt();
89 // if ( value == HYBRIDPlugin_Hypothesis::NoValue() )
92 row->setText( 0, tr( name.toLatin1().constData() ));
93 row->setText( 1, tr( value.toLatin1().constData() ));
94 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
95 row->setData( NAME_COL, PARAM_NAME, name );
99 myOptionTable->scrollToItem( row );
100 myOptionTable->setCurrentItem( row );
101 myOptionTable->editItem( row, NAME_COL );
105 void HYBRIDPluginGUI_AdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
110 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
111 value = tblRow->text( VALUE_COL );
112 isDefault = ! tblRow->checkState( NAME_COL );
114 // if ( value.isEmpty() )
115 // value = HYBRIDPlugin_Hypothesis::NoValue();
119 void HYBRIDPluginGUI_AdvWidget::itemChanged(QTreeWidgetItem * tblRow, int column)
123 myOptionTable->blockSignals( true );
125 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
127 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
128 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
130 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
132 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
135 myOptionTable->blockSignals( false );