1 // Copyright (C) 2007-2016 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 std::cout << "fileName: " << fileName.toStdString() << std::endl;
71 if (!fileName.endsWith(".mesh") && !fileName.endsWith(".meshb"))
72 fileName.append(".mesh");
73 myGMFFileName->setText(fileName);
76 void BLSURFPluginGUI_AdvWidget::AddOption( int iTable, const char* option )
78 if ( iTable < 0 || iTable > 2 ) return;
80 QTreeWidgetItem * table = myOptionTable->topLevelItem( iTable );
81 table->setExpanded( true );
83 QTreeWidgetItem * row = new QTreeWidgetItem( table );
84 row->setData( NAME_COL, EDITABLE_ROLE, int( iTable == 2 && !option ));
85 row->setFlags( row->flags() | Qt::ItemIsEditable );
88 bool isDefault = false;
91 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
92 if ( name_value_type.size() > 0 )
93 name = name_value_type[0];
94 if ( name_value_type.size() > 1 )
95 value = name_value_type[1];
96 if ( name_value_type.size() > 2 )
97 isDefault = !name_value_type[2].toInt();
99 row->setText( 0, tr( name.toLatin1().constData() ));
100 row->setText( 1, tr( value.toLatin1().constData() ));
101 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
102 row->setData( NAME_COL, PARAM_NAME, name );
106 table->setHidden( false );
109 myOptionTable->scrollToItem( row );
110 myOptionTable->editItem( row, NAME_COL );
115 void BLSURFPluginGUI_AdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
120 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
121 value = tblRow->text( VALUE_COL );
122 isDefault = ! tblRow->checkState( NAME_COL );
126 void BLSURFPluginGUI_AdvWidget::itemChanged(QTreeWidgetItem * tblRow, int column)
130 myOptionTable->blockSignals( true );
132 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
134 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
135 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
137 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
139 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
142 myOptionTable->blockSignals( false );