1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
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 : HexoticPluginGUI_Dlg.cxx
22 // Authors : Renaud NEDELEC (OCC)
26 #include "HexoticPluginGUI_Dlg.h"
28 #include <QFileDialog>
29 #include <QItemDelegate>
32 #include <HexoticPlugin_Hypothesis.hxx>
33 #include <SUIT_FileDlg.h>
37 enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,
38 NAME_COL = 0, VALUE_COL };
40 class ItemDelegate: public QItemDelegate {
42 ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}
43 QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
45 bool editable = index.data( EDITABLE_ROLE ).toInt();
46 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
51 //////////////////////////////////////////
52 // HexoticPluginGUI_AdvWidget
53 //////////////////////////////////////////
55 HexoticPluginGUI_AdvWidget::HexoticPluginGUI_AdvWidget( QWidget* parent, Qt::WindowFlags f )
56 : QWidget( parent, f )
59 //myOptionTable->layout()->setMargin( 0 );
60 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
61 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
63 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
66 HexoticPluginGUI_AdvWidget::~HexoticPluginGUI_AdvWidget()
70 void HexoticPluginGUI_AdvWidget::AddOption( const char* option, bool isCustom )
72 QTreeWidget * table = myOptionTable;
73 //table->setExpanded( true );
75 QTreeWidgetItem * row = new QTreeWidgetItem( table );
76 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
77 row->setFlags( row->flags() | Qt::ItemIsEditable );
80 bool isDefault = false;
83 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
84 if ( name_value_type.size() > 0 )
85 name = name_value_type[0];
86 if ( name_value_type.size() > 1 )
87 value = name_value_type[1];
88 if ( name_value_type.size() > 2 )
89 isDefault = !name_value_type[2].toInt();
91 // if ( value == HexoticPlugin_Hypothesis::NoValue() )
94 row->setText( 0, tr( name.toLatin1().constData() ));
95 row->setText( 1, tr( value.toLatin1().constData() ));
96 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
97 row->setData( NAME_COL, PARAM_NAME, name );
101 myOptionTable->scrollToItem( row );
102 myOptionTable->setCurrentItem( row );
103 myOptionTable->editItem( row, NAME_COL );
107 void HexoticPluginGUI_AdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
112 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
113 value = tblRow->text( VALUE_COL );
114 isDefault = ! tblRow->checkState( NAME_COL );
116 // if ( value.isEmpty() )
117 // value = HexoticPlugin_Hypothesis::NoValue();
121 void HexoticPluginGUI_AdvWidget::itemChanged(QTreeWidgetItem * tblRow, int column)
125 myOptionTable->blockSignals( true );
127 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
129 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
130 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
132 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
134 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
137 myOptionTable->blockSignals( false );
142 void HexoticPluginGUI_AdvWidget::onDirBtnClicked()
144 QString dir = SUIT_FileDlg::getExistingDirectory( this, myHexoticWorkingDir->text(), QString() );
145 if ( !dir.isEmpty() )
146 myHexoticWorkingDir->setText( dir );