From: nds Date: Fri, 22 Nov 2013 08:43:58 +0000 (+0000) Subject: Double editor in table X-Git-Tag: BR_hydro_v_0_3_1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a8213a40ae36460055057f09e3e0828a01e27123;p=modules%2Fhydro.git Double editor in table --- diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt index b2aaec5b..24bf5f56 100644 --- a/src/HYDROCurveCreator/CMakeLists.txt +++ b/src/HYDROCurveCreator/CMakeLists.txt @@ -58,6 +58,7 @@ IF(SALOME_BUILD_GUI) # header files / to be processed by moc SET(_moc_HEADERS CurveCreator_NewSectionDlg.h + CurveCreator_TableView.h CurveCreator_TreeView.h # CurveCreator_UndoOptsDlg.h CurveCreator_Widget.h @@ -99,6 +100,7 @@ SET(_other_SOURCES IF(SALOME_BUILD_GUI) LIST(APPEND _other_SOURCES CurveCreator_NewSectionDlg.cxx + CurveCreator_TableView.cxx CurveCreator_TreeView.cxx # CurveCreator_UndoOptsDlg.cxx CurveCreator_Widget.cxx diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.cxx b/src/HYDROCurveCreator/CurveCreator_TableView.cxx new file mode 100644 index 00000000..99499221 --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_TableView.cxx @@ -0,0 +1,94 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_TableView.h" + +#include +#include +//#include +#include + +const double DBL_MINIMUM = -10000000.; +const double DBL_MAXIMUM = 10000000.; + +CurveCreator_TableItemDelegate::CurveCreator_TableItemDelegate( QObject* theParent ) +: QItemDelegate( theParent ) +{ +} + +/** + * Creates an editor for the cell + */ +QWidget* CurveCreator_TableItemDelegate::createEditor( QWidget* theParent, + const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex ) const +{ + QWidget* anEditor = 0; + + int aColumnId = theIndex.column(); + if ( aColumnId == 2 || aColumnId == 3 ) { + QDoubleSpinBox* aSpin = new QtxDoubleSpinBox( theParent ); + aSpin->setDecimals( 6 ); + aSpin->setRange( DBL_MINIMUM, DBL_MAXIMUM ); + anEditor = aSpin; + } + else + anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex ); + + return anEditor; +} + +void CurveCreator_TableItemDelegate::setEditorData( QWidget* theEditor, + const QModelIndex& theIndex ) const +{ + QTableWidget* aTableWidget = dynamic_cast( parent() ); + QTableWidgetItem* anItem = aTableWidget ? dynamic_cast + ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0; + int aColumnId = theIndex.column(); + if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) { + QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); + double aValue = anItem->data( Qt::UserRole ).toDouble(); + if ( aDblSpin ) { + aDblSpin->setValue( aValue ); + } + } + else + QItemDelegate::setEditorData( theEditor, theIndex ); +} + +void CurveCreator_TableItemDelegate::setModelData( QWidget* theEditor, + QAbstractItemModel* theModel, + const QModelIndex& theIndex ) const +{ + QTableWidget* aTableWidget = dynamic_cast( parent() ); + QTableWidgetItem* anItem = aTableWidget ? dynamic_cast + ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0; + + int aColumnId = theIndex.column(); + if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) { + QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); + if ( aDblSpin ) { + double aValue = aDblSpin->value(); + anItem->setData( Qt::UserRole, aValue ); + } + } + else + QItemDelegate::setModelData( theEditor, theModel, theIndex ); +} + diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.h b/src/HYDROCurveCreator/CurveCreator_TableView.h new file mode 100644 index 00000000..a1e185ae --- /dev/null +++ b/src/HYDROCurveCreator/CurveCreator_TableView.h @@ -0,0 +1,39 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVECREATOR_TABLEVIEW_H +#define CURVECREATOR_TABLEVIEW_H + +#include + +class CurveCreator_TableItemDelegate : public QItemDelegate +{ +public: + CurveCreator_TableItemDelegate( QObject* theParent ); + ~CurveCreator_TableItemDelegate() {} + + virtual QWidget* createEditor( QWidget* theParent, + const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex ) const; + virtual void setEditorData( QWidget* theEditor, const QModelIndex& theIndex ) const; + virtual void setModelData( QWidget* theEditor, QAbstractItemModel* theModel, + const QModelIndex& theIndex ) const; +}; + +#endif // CURVECREATOR_TABLEVIEW_H diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 51181043..56ae6c12 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -25,6 +25,7 @@ //#include "CurveCreator_NewPointDlg.h" #include "CurveCreator_NewSectionDlg.h" #include "CurveCreator_Utils.h" +#include "CurveCreator_TableView.h" #include #include @@ -96,6 +97,7 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) ); myLocalPointView = new QTableWidget(); + myLocalPointView->setItemDelegate( new CurveCreator_TableItemDelegate( myLocalPointView ) ); myLocalPointView->setVisible( false ); myLocalPointView->setColumnCount( 4 ); myLocalPointView->setColumnWidth( 0, SECTION_NAME_COLUMN_WIDTH ); @@ -974,8 +976,8 @@ void CurveCreator_Widget::onCellChanged( int theRow, int theColumn ) SectionToPointList aSelPoints; startCurveModification( aSelPoints ); - double aX = myLocalPointView->item( theRow, 2 )->text().toDouble(); - double anY = myLocalPointView->item( theRow, 3 )->text().toDouble(); + double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble(); + double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble(); std::deque aChangedPos; aChangedPos.push_back( aX ); aChangedPos.push_back( anY );