]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Double editor in table
authornds <nds@opencascade.com>
Fri, 22 Nov 2013 08:43:58 +0000 (08:43 +0000)
committernds <nds@opencascade.com>
Fri, 22 Nov 2013 08:43:58 +0000 (08:43 +0000)
src/HYDROCurveCreator/CMakeLists.txt
src/HYDROCurveCreator/CurveCreator_TableView.cxx [new file with mode: 0644]
src/HYDROCurveCreator/CurveCreator_TableView.h [new file with mode: 0644]
src/HYDROCurveCreator/CurveCreator_Widget.cxx

index b2aaec5b5acdf4cb468d6d3243966fc6e69f3d39..24bf5f5601680debfa6c933a343b6e89d729aaf1 100644 (file)
@@ -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 (file)
index 0000000..9949922
--- /dev/null
@@ -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 <QTableWidget>
+#include <QTableWidgetItem>
+//#include <QDoubleSpinBox>
+#include <QtxDoubleSpinBox.h>
+
+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<QTableWidget*>( parent() );
+  QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
+                                  ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
+  int aColumnId = theIndex.column();
+  if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
+    QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( 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<QTableWidget*>( parent() );
+  QTableWidgetItem* anItem = aTableWidget ? dynamic_cast<QTableWidgetItem*>
+                      ( aTableWidget->item( theIndex.row(), theIndex.column() ) ) : 0;
+
+  int aColumnId = theIndex.column();
+  if ( anItem && ( aColumnId == 2 || aColumnId == 3 ) ) {
+    QDoubleSpinBox* aDblSpin = dynamic_cast<QDoubleSpinBox*>( 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 (file)
index 0000000..a1e185a
--- /dev/null
@@ -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 <QItemDelegate>
+
+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
index 511810438fad8014df53312582e487d0e477eda9..56ae6c123358bb31b87f131dac788d00fccb8e93 100644 (file)
@@ -25,6 +25,7 @@
 //#include "CurveCreator_NewPointDlg.h"
 #include "CurveCreator_NewSectionDlg.h"
 #include "CurveCreator_Utils.h"
+#include "CurveCreator_TableView.h"
 
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
@@ -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<float> aChangedPos;
   aChangedPos.push_back( aX );
   aChangedPos.push_back( anY );