From 9488952cdf264de49e24970f8aae488ca06bbe9e Mon Sep 17 00:00:00 2001 From: mzn Date: Wed, 4 Dec 2013 08:06:57 +0000 Subject: [PATCH] Feature #102: Display of Lambert coordinates. --- .../CurveCreator_TableView.cxx | 25 +++++++----------- src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx | 26 ++++++++++--------- src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h | 3 --- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.cxx b/src/HYDROCurveCreator/CurveCreator_TableView.cxx index 52a8f492..4d5bd272 100644 --- a/src/HYDROCurveCreator/CurveCreator_TableView.cxx +++ b/src/HYDROCurveCreator/CurveCreator_TableView.cxx @@ -22,7 +22,7 @@ #include #include -//#include + #include const double DBL_MINIMUM = -10000000.; @@ -50,7 +50,7 @@ QWidget* CurveCreator_TableItemDelegate::createEditor( QWidget* theParent, int aColumnId = theIndex.column(); if ( aColumnId == 2 || aColumnId == 3 ) { QDoubleSpinBox* aSpin = new QtxDoubleSpinBox( theParent ); - aSpin->setDecimals( 6 ); + aSpin->setDecimals( 2 ); aSpin->setRange( DBL_MINIMUM, DBL_MAXIMUM ); anEditor = aSpin; } @@ -63,14 +63,11 @@ QWidget* CurveCreator_TableItemDelegate::createEditor( QWidget* theParent, 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 ) ) { + if ( aColumnId == 2 || aColumnId == 3 ) { QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); - double aValue = anItem->data( Qt::UserRole ).toDouble(); if ( aDblSpin ) { + double aValue = theIndex.model()->data( theIndex, Qt::EditRole ).toDouble(); aDblSpin->setValue( aValue ); } } @@ -82,16 +79,12 @@ 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 ) ) { + if ( aColumnId == 2 || aColumnId == 3 ) { QDoubleSpinBox* aDblSpin = dynamic_cast( theEditor ); if ( aDblSpin ) { double aValue = aDblSpin->value(); - anItem->setData( Qt::UserRole, aValue ); + theModel->setData( theIndex, aValue, Qt::UserRole); } } else @@ -162,12 +155,12 @@ void CurveCreator_TableView::addLocalPointToTable( const double theX, const doub anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); anItem->setData( Qt::UserRole, aPointId ); setItem( aRowId, 1, anItem ); - - anItem = new QTableWidgetItem( QString::number( theX ) ); + + anItem = new QTableWidgetItem( QString::number( theX, 'f', 2 ) ); anItem->setData( Qt::UserRole, theX ); setItem( aRowId, 2, anItem ); - anItem = new QTableWidgetItem( QString::number( theY ) ); + anItem = new QTableWidgetItem( QString::number( theY, 'f', 2 ) ); anItem->setData( Qt::UserRole, theY ); setItem( aRowId, 3, anItem ); } diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index 57bfafb6..7ef449c4 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx @@ -22,6 +22,8 @@ #include "HYDROGUI_GeoreferencementDlg.h" +#include "HYDROGUI_Tool.h" + #include #include @@ -93,7 +95,10 @@ QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor( if ( theIndex.column() > 0 ) { QLineEdit* aLineEdit = new QLineEdit( theParent ); - aLineEdit->setValidator( new QDoubleValidator( aLineEdit ) ); + QDoubleValidator* aDoubleValidator = new QDoubleValidator(); + aDoubleValidator->setNotation( QDoubleValidator::StandardNotation ); + aDoubleValidator->setDecimals( 2 ); + aLineEdit->setValidator( aDoubleValidator ); anEditor = aLineEdit; } else { anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex ); @@ -222,10 +227,10 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) ProfileGeoData aGeoData = theMap.value( aProfileName ); QString aXg, anYg, aXd, anYd; if ( !aGeoData.isEmpty ) { - aXg = getString( aGeoData.Xg ); - anYg = getString( aGeoData.Yg ); - aXd = getString( aGeoData.Xd ); - anYd = getString( aGeoData.Yd ); + aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg ); + anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg ); + aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd ); + anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd ); } // Insert row with the data @@ -308,13 +313,10 @@ void HYDROGUI_GeoreferencementDlg::onMousePress( int aColumnX = aColumn < 3 ? 1 : 3; int aColumnY = aColumnX + 1; - myTable->item( aRow, aColumnX )->setText( getString( aPnt.X() ) ); - myTable->item( aRow, aColumnY )->setText( getString( aPnt.Y() ) ); -} - -QString HYDROGUI_GeoreferencementDlg::getString( const double theNumber ) const -{ - return QString::number( theNumber, 'g', 12 ); + QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X() ); + QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() ); + myTable->item( aRow, aColumnX )->setText( aXStr ); + myTable->item( aRow, aColumnY )->setText( anYStr ); } void HYDROGUI_GeoreferencementDlg::onDataChanged() diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h index 8ac5f6d9..1d2a72a0 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h @@ -87,9 +87,6 @@ signals: void modeActivated( int ); void updateSelection(); -private: - QString getString( const double theNumber ) const; - private: QButtonGroup* myModeButtons; QPushButton* myUpdateSelBtn; -- 2.39.2