1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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
20 #include "CurveCreator_TableView.h"
22 #include <QTableWidget>
23 #include <QTableWidgetItem>
24 //#include <QDoubleSpinBox>
25 #include <QtxDoubleSpinBox.h>
27 const double DBL_MINIMUM = -10000000.;
28 const double DBL_MAXIMUM = 10000000.;
30 CurveCreator_TableItemDelegate::CurveCreator_TableItemDelegate( QObject* theParent )
31 : QItemDelegate( theParent )
36 * Creates an editor for the cell
38 QWidget* CurveCreator_TableItemDelegate::createEditor( QWidget* theParent,
39 const QStyleOptionViewItem& theOption,
40 const QModelIndex& theIndex ) const
42 QWidget* anEditor = 0;
44 int aColumnId = theIndex.column();
45 if ( aColumnId == 2 || aColumnId == 3 ) {
46 QDoubleSpinBox* aSpin = new QtxDoubleSpinBox( theParent );
47 aSpin->setDecimals( 6 );
48 aSpin->setRange( DBL_MINIMUM, DBL_MAXIMUM );
52 anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex );
57 void CurveCreator_TableItemDelegate::setEditorData( QWidget* theEditor,
58 const QModelIndex& theIndex ) const
60 QTableWidget* aTableWidget = dynamic_cast<QTableWidget*>( parent() );
61 QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
62 ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
63 int aColumnId = theIndex.column();
64 if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
65 QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( theEditor );
66 double aValue = anItem->data( Qt::UserRole ).toDouble();
68 aDblSpin->setValue( aValue );
72 QItemDelegate::setEditorData( theEditor, theIndex );
75 void CurveCreator_TableItemDelegate::setModelData( QWidget* theEditor,
76 QAbstractItemModel* theModel,
77 const QModelIndex& theIndex ) const
79 QTableWidget* aTableWidget = dynamic_cast<QTableWidget*>( parent() );
80 QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
81 ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
83 int aColumnId = theIndex.column();
84 if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
85 QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( theEditor );
87 double aValue = aDblSpin->value();
88 anItem->setData( Qt::UserRole, aValue );
92 QItemDelegate::setModelData( theEditor, theModel, theIndex );