Salome HOME
linear stream interpolator : insertPoints() : deny to add more points than needed
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_GeoreferencementDlg.cxx
index aa73cd03a19a37f64f9c28b0562e04e14539611f..8c31879e395bac82e8ab9b183d5ee86365150462 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,8 +19,9 @@
 #include "HYDROGUI_GeoreferencementDlg.h"
 
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_LineEditDoubleValidator.h"
 
-#include <GEOMUtils.hxx>
+#include <CurveCreator_Utils.hxx>
 
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewManager.h>
@@ -33,7 +30,6 @@
 #include <AIS_InteractiveContext.hxx>
 
 #include <QTableWidget>
-#include <QItemDelegate>
 #include <QHeaderView>
 #include <QRadioButton>
 #include <QPushButton>
@@ -71,64 +67,6 @@ HYDROGUI_GeoreferencementDlg::ProfileGeoData::ProfileGeoData(
   }
 }
 
-//! Custom item delegate (line edit with double validator)
-class HYDROGUI_GeoreferencementDlg::Delegate : public QItemDelegate
-{
-public:
-  Delegate( QObject* = 0 );
-  
-  QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
-                         const QModelIndex& ) const;
-  
-  void setEditorData( QWidget*, const QModelIndex& ) const;
-  void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
-};
-
-HYDROGUI_GeoreferencementDlg::Delegate::Delegate( QObject* theParent )
- : QItemDelegate( theParent )
-{
-}
-
-QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor( 
-  QWidget* theParent, const QStyleOptionViewItem& theOption,
-  const QModelIndex& theIndex ) const
-{
-  QWidget* anEditor = 0;
-
-  if ( theIndex.column() > 0 ) {
-    QLineEdit* aLineEdit = new QLineEdit( theParent );
-    QDoubleValidator* aDoubleValidator = new QDoubleValidator();
-    aDoubleValidator->setNotation( QDoubleValidator::StandardNotation );
-    aDoubleValidator->setDecimals( 2 );
-    aLineEdit->setValidator( aDoubleValidator );
-    anEditor = aLineEdit;
-  } else {
-    anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex );
-  }
-
-  return anEditor;
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setEditorData( 
-  QWidget* theEditor, const QModelIndex& theIndex ) const
-{
-  if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
-    aLineEdit->setText( theIndex.data( Qt::EditRole ).toString() );
-  } else {
-    QItemDelegate::setEditorData( theEditor, theIndex );
-  }
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setModelData( 
-  QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const
-{
-  if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
-    theModel->setData( theIndex, aLineEdit->text() );
-  } else {
-    QItemDelegate::setModelData( theEditor, theModel, theIndex );
-  }
-}
-
 HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle ), myIsModified( false )
 {
@@ -157,7 +95,7 @@ HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* the
 
   // Table
   myTable = new QTableWidget( mainFrame() );
-  myTable->setItemDelegate( new Delegate( this ) );
+  myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
   myTable->verticalHeader()->setVisible( false );
   myTable->setSelectionBehavior( QAbstractItemView::SelectItems );
   myTable->setSelectionMode( QAbstractItemView::SingleSelection );
@@ -228,10 +166,10 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataList& theData )
     // Get georeferencement data for the current profile
     QString aXg, anYg, aXd, anYd;
     if ( !aGeoData.isEmpty ) {
-      aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg );
-      anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg );
-      aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd );
-      anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd );
+      aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg, false );
+      anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg, false );
+      aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd, false );
+      anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd, false );
     }
     
     // Insert row with the data
@@ -240,10 +178,12 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataList& theData )
 
     // "Profile" column
     QTableWidgetItem* aNameItem = new QTableWidgetItem( aGeoData.Name );
-    aNameItem->setFlags( Qt::ItemIsEnabled );
+    aNameItem->setFlags( aNameItem->flags() & ~Qt::ItemIsEnabled );
+    /* Bold font is not used in other tables. Keep the common style.
     QFont aFont = aNameItem->font();
     aFont.setBold( true );
-    aNameItem->setFont( aFont ); 
+    aNameItem->setFont( aFont );
+    */ 
     myTable->setItem( aRow, 0, aNameItem );
 
     // "Xg" column
@@ -307,15 +247,15 @@ void HYDROGUI_GeoreferencementDlg::onMousePress(
 
   // Get the selected point coordinates
   OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
-  gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(), 
-                                                aViewPort->getView() );
+  gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), 
+                                                         aViewPort->getView() );
 
   // Set the coordinates to the corresponding cells of the table
   int aColumnX = aColumn < 3 ? 1 : 3;
   int aColumnY = aColumnX + 1;
   
-  QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
-  QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
+  QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), false );
+  QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), false );
   myTable->item( aRow, aColumnX )->setText( aXStr );
   myTable->item( aRow, aColumnY )->setText( anYStr );
 }