1 // Copyright (C) 2007-2019 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 : BLSURFPluginGUI_Dlg.cxx
22 // Authors : Gilles DAVID (OCC)
26 #include "BLSURFPluginGUI_Dlg.h"
28 #include <QFileDialog>
34 enum { EDITABLE_ROLE = Qt::UserRole + 1, PARAM_NAME,
35 NAME_COL = 0, VALUE_COL };
37 class ItemDelegate: public QItemDelegate {
39 ItemDelegate(QObject* parent=0): QItemDelegate(parent) {}
40 QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
42 bool editable = index.data( EDITABLE_ROLE ).toInt();
43 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
48 //////////////////////////////////////////
49 // BLSURFPluginGUI_AdvWidget
50 //////////////////////////////////////////
52 BLSURFPluginGUI_AdvWidget::BLSURFPluginGUI_AdvWidget( QWidget* parent, Qt::WindowFlags f )
53 : QWidget( parent, f )
56 myOptionTable->topLevelItem( 2 )->setHidden( true ); // hide CUSTOM options
57 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
58 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
60 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
63 BLSURFPluginGUI_AdvWidget::~BLSURFPluginGUI_AdvWidget()
67 void BLSURFPluginGUI_AdvWidget::onChooseGMFFile()
69 QString fileName = QFileDialog::getSaveFileName(0, tr("BLSURF_GMF_FILE_DIALOG"), myGMFFileName->text(), tr("BLSURF_GMF_FILE_FORMAT"));
70 if ( !fileName.isEmpty() ) {
71 if (!fileName.endsWith(".mesh") && !fileName.endsWith(".meshb"))
72 fileName.append(".mesh");
73 myGMFFileName->setText(fileName);
77 void BLSURFPluginGUI_AdvWidget::AddOption( int iTable, const char* option )
79 if ( iTable < 0 || iTable > 2 ) return;
81 QTreeWidgetItem * table = myOptionTable->topLevelItem( iTable );
82 table->setExpanded( true );
84 QTreeWidgetItem * row = new QTreeWidgetItem( table );
85 row->setData( NAME_COL, EDITABLE_ROLE, int( iTable == 2 && !option ));
86 row->setFlags( row->flags() | Qt::ItemIsEditable );
89 bool isDefault = false;
92 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
93 if ( name_value_type.size() > 0 )
94 name = name_value_type[0];
95 if ( name_value_type.size() > 1 )
96 value = name_value_type[1];
97 if ( name_value_type.size() > 2 )
98 isDefault = !name_value_type[2].toInt();
100 row->setText( 0, tr( name.toLatin1().constData() ));
101 row->setText( 1, tr( value.toLatin1().constData() ));
102 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
103 row->setData( NAME_COL, PARAM_NAME, name );
107 table->setHidden( false );
110 myOptionTable->scrollToItem( row );
111 myOptionTable->setCurrentItem( row );
112 myOptionTable->editItem( row, NAME_COL );
117 void BLSURFPluginGUI_AdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
122 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
123 value = tblRow->text( VALUE_COL );
124 isDefault = ! tblRow->checkState( NAME_COL );
128 void BLSURFPluginGUI_AdvWidget::itemChanged(QTreeWidgetItem * tblRow, int column)
132 myOptionTable->blockSignals( true );
134 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
136 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
137 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
139 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
141 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
144 myOptionTable->blockSignals( false );