From: mzn Date: Thu, 28 Nov 2013 14:42:13 +0000 (+0000) Subject: Final implementation of Feature #84: Profiles georeferencement (12.4). X-Git-Tag: issue_132_11_28~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=03ac40d409e4ca78dca10fd5d1fb3bf35e033a41;p=modules%2Fhydro.git Final implementation of Feature #84: Profiles georeferencement (12.4). --- diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index 1e9db073..534ba659 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx @@ -22,13 +22,82 @@ #include "HYDROGUI_GeoreferencementDlg.h" +#include + +#include +#include +#include + +#include + #include +#include #include #include #include #include #include #include +#include + +//! 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 ) { + QVariant aData = theIndex.data( Qt::DisplayRole ); + + QLineEdit* aLineEdit = new QLineEdit( theParent ); + aLineEdit->setValidator( new QDoubleValidator( aLineEdit ) ); + aLineEdit->setText( aData.toString() ); + + anEditor = aLineEdit; + } + + if ( !anEditor) { + anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex ); + } + + return anEditor; +} + +void HYDROGUI_GeoreferencementDlg::Delegate::setEditorData( + QWidget* theEditor, const QModelIndex& theIndex ) const +{ + QLineEdit* anEditor = qobject_cast( theEditor ); + if ( anEditor ) { + anEditor->setText( theIndex.data( Qt::EditRole ).toString() ); + } +} + +void HYDROGUI_GeoreferencementDlg::Delegate::setModelData( + QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const +{ + QLineEdit* anEditor = qobject_cast( theEditor ); + if ( anEditor ) { + theModel->setData( theIndex, anEditor->text() ); + } +} HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) @@ -51,6 +120,7 @@ HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* the // Table myTable = new QTableWidget( mainFrame() ); + myTable->setItemDelegate( new Delegate( this ) ); myTable->verticalHeader()->setVisible( false ); myTable->setSelectionBehavior( QAbstractItemView::SelectItems ); myTable->setSelectionMode( QAbstractItemView::SingleSelection ); @@ -86,11 +156,6 @@ void HYDROGUI_GeoreferencementDlg::reset() myTable->setRowCount( 0 ); } -void HYDROGUI_GeoreferencementDlg::onProfilesSelectionChanged() -{ - // MZN TODO -} - void HYDROGUI_GeoreferencementDlg::setMode( const int theMode ) { bool isBlocked = myModeButtons->blockSignals( true ); @@ -117,10 +182,10 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) ProfileGeoData aGeoData = theMap.value( aProfileName ); QString aXg, anYg, aXd, anYd; if ( aGeoData.isValid ) { - aXg = QString::number( aGeoData.Xg ); - anYg = QString::number( aGeoData.Yg ); - aXd = QString::number( aGeoData.Xd ); - anYd = QString::number( aGeoData.Yd ); + aXg = getString( aGeoData.Xg ); + anYg = getString( aGeoData.Yg ); + aXd = getString( aGeoData.Xd ); + anYd = getString( aGeoData.Yd ); } // Insert row with the data @@ -130,28 +195,25 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) // "Profile" column QTableWidgetItem* aNameItem = new QTableWidgetItem( aProfileName ); aNameItem->setFlags( Qt::ItemIsEnabled ); + QFont aFont = aNameItem->font(); + aFont.setBold( true ); + aNameItem->setFont( aFont ); myTable->setItem( aRow, 0, aNameItem ); // "Xg" column - QLineEdit* aXgEdit = new QLineEdit( aXg ); - aXgEdit->setValidator( new QDoubleValidator( aXgEdit ) ); - myTable->setCellWidget( aRow, 1, aXgEdit ); + myTable->setItem( aRow, 1, new QTableWidgetItem( aXg ) ); // "Yg" column - QLineEdit* anYgEdit = new QLineEdit( anYg ); - anYgEdit->setValidator( new QDoubleValidator( anYgEdit ) ); - myTable->setCellWidget( aRow, 2, anYgEdit ); + myTable->setItem( aRow, 2, new QTableWidgetItem( anYg ) ); // "Xd" column - QLineEdit* aXdEdit = new QLineEdit( aXd ); - aXdEdit->setValidator( new QDoubleValidator( aXdEdit ) ); - myTable->setCellWidget( aRow, 3, aXdEdit ); + myTable->setItem( aRow, 3, new QTableWidgetItem( aXd ) ); // "Yd" column - QLineEdit* anYdEdit = new QLineEdit( anYd ); - anYdEdit->setValidator( new QDoubleValidator( anYdEdit ) ); - myTable->setCellWidget( aRow, 4, anYdEdit ); + myTable->setItem( aRow, 4, new QTableWidgetItem( anYd ) ); } + + myTable->resizeColumnToContents( 0 ); } void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap ) @@ -167,27 +229,54 @@ void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap ) theMap.insert( aProfileName, ProfileGeoData() ); double aXg, anYg, aXd, anYd; - - QLineEdit* aLineEdit = qobject_cast( myTable->cellWidget( aRow, 1 ) ); - QString aCellText = aLineEdit ? aLineEdit->text() : ""; - aXg = aCellText.toDouble( &isOk ); + + aXg = myTable->item( aRow, 1 )->text().toDouble( &isOk ); if ( !isOk ) continue; - aLineEdit = qobject_cast( myTable->cellWidget( aRow, 2 ) ); - aCellText = aLineEdit ? aLineEdit->text() : ""; - anYg = aCellText.toDouble( &isOk ); + anYg = myTable->item( aRow, 2 )->text().toDouble( &isOk ); if ( !isOk ) continue; - aLineEdit = qobject_cast( myTable->cellWidget( aRow, 3 ) ); - aCellText = aLineEdit ? aLineEdit->text() : ""; - aXd = aCellText.toDouble( &isOk ); + aXd = myTable->item( aRow, 3 )->text().toDouble( &isOk ); if ( !isOk ) continue; - aLineEdit = qobject_cast( myTable->cellWidget( aRow, 4 ) ); - aCellText = aLineEdit ? aLineEdit->text() : ""; - anYd = aCellText.toDouble( &isOk ); + anYd = myTable->item( aRow, 4 )->text().toDouble( &isOk ); if ( !isOk ) continue; theMap[aProfileName] = ProfileGeoData( aXg, anYg, aXd, anYd ); } } + +void HYDROGUI_GeoreferencementDlg::onMousePress( + SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent ) +{ + // Check the parameters + OCCViewer_ViewWindow* anOCCViewWindow = + dynamic_cast(theViewWindow); + if ( !anOCCViewWindow || (theEvent->button() != Qt::LeftButton) ) { + return; + } + + // Check for current cell + int aRow = myTable->currentRow(); + int aColumn = myTable->currentColumn(); + if ( aRow < 0 || aColumn <= 0 ) { + return; + } + + // Get the selected point coordinates + OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort(); + gp_Pnt aPnt = GEOMUtils::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; + + 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 ); +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h index a2a1c0bd..25e2130e 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h @@ -25,6 +25,8 @@ #include "HYDROGUI_InputPanel.h" +class SUIT_ViewWindow; + class QGroupBox; class QButtonGroup; class QTableWidget; @@ -33,6 +35,8 @@ class HYDROGUI_GeoreferencementDlg : public HYDROGUI_InputPanel { Q_OBJECT + class Delegate; + public: enum ProfilesMode { AllProfiles, SelectedProfiles }; @@ -64,13 +68,18 @@ public: void setData( const ProfilesGeoDataMap& theMap ); void getData( ProfilesGeoDataMap& theMap ); +public slots: + void onMousePress( SUIT_ViewWindow*, QMouseEvent* ); + protected slots: void onModeActivated( int ); - void onProfilesSelectionChanged(); signals: void modeActivated( int ); +private: + QString getString( const double theNumber ) const; + private: QButtonGroup* myModeButtons; QTableWidget* myTable; diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx index 58e29d0e..e1dfd89d 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx @@ -35,6 +35,11 @@ #include #include +#include +#include + +#include + #include HYDROGUI_GeoreferencementOp::HYDROGUI_GeoreferencementOp( HYDROGUI_Module* theModule, const int theInitialMode ) @@ -69,6 +74,17 @@ void HYDROGUI_GeoreferencementOp::startOperation() aPanel->setMode( aSelectionMode ); onModeActivated( aSelectionMode ); } + + LightApp_Application* anApp = module()->getApp(); + OCCViewer_ViewManager* aViewManager = + dynamic_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), false ) ); + if ( aViewManager ) { + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + aPanel, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } + + connect( anApp->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); } void HYDROGUI_GeoreferencementOp::abortOperation() @@ -102,6 +118,10 @@ bool HYDROGUI_GeoreferencementOp::processApply( int& theUpdateFlags, HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aGeoDataMap; aPanel->getData( aGeoDataMap ); + if ( aGeoDataMap.empty() ) { + return false; + } + // Set the data foreach ( const QString& aProfileName, aGeoDataMap.keys() ) { Handle(HYDROData_Profile) aProfile = @@ -167,5 +187,22 @@ void HYDROGUI_GeoreferencementOp::onModeActivated( const int theActualMode ) aPanel->setData( aDataMap ); } +void HYDROGUI_GeoreferencementOp::onWindowActivated( SUIT_ViewWindow* theViewWindow ) +{ + if ( !theViewWindow ) { + return; + } + + OCCViewer_ViewManager* aViewManager = + dynamic_cast( theViewWindow->getViewManager() ); + if ( aViewManager ) { + HYDROGUI_GeoreferencementDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) { + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + aPanel, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } + } +} diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h index 41484355..e8c362b4 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h @@ -25,6 +25,7 @@ #include "HYDROGUI_Operation.h" +class SUIT_ViewWindow; class HYDROGUI_GeoreferencementOp : public HYDROGUI_Operation { @@ -48,6 +49,7 @@ protected: protected slots: void onModeActivated( const int theActualMode ); + void onWindowActivated( SUIT_ViewWindow* theViewWindow ); private: int myInitialMode;