X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_GeoreferencementDlg.cxx;h=8c31879e395bac82e8ab9b183d5ee86365150462;hb=dbee981213585cb317e098b0d2a288761cd3d37b;hp=bd10b2c083b98e7b594c35b1376ef2bde462d266;hpb=347f7cf014bec3113cc79c89b0d19ef5735aab10;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index bd10b2c0..8c31879e 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx @@ -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 @@ -22,7 +18,10 @@ #include "HYDROGUI_GeoreferencementDlg.h" -#include +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_LineEditDoubleValidator.h" + +#include #include #include @@ -31,9 +30,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -42,9 +41,11 @@ //! Profile data structre constructor HYDROGUI_GeoreferencementDlg::ProfileGeoData::ProfileGeoData( + const QString& theName, const QString& theXg, const QString& theYg, const QString& theXd, const QString& theYd) { + this->Name = theName; this->isEmpty = theXg.isEmpty() && theYg.isEmpty() && theXd.isEmpty() && theYd.isEmpty(); this->isIncomplete = !isEmpty; @@ -66,67 +67,8 @@ 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 ) { - 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 ) +: HYDROGUI_InputPanel( theModule, theTitle ), myIsModified( false ) { // Mode selector (all/selected) QGroupBox* aModeGroup = new QGroupBox( tr( "PROFILES" ), this ); @@ -144,9 +86,16 @@ HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* the aModeSelectorLayout->addWidget( anAllRB ); aModeSelectorLayout->addWidget( aSelectedRB ); + // Update selection button + myUpdateSelBtn = new QPushButton( mainFrame() ); + myUpdateSelBtn->setText( tr("UPDATE_SELECTION") ); + QBoxLayout* anUpdateSelLayout = new QHBoxLayout( mainFrame() ); + anUpdateSelLayout->addWidget( myUpdateSelBtn ); + anUpdateSelLayout->addStretch(); + // 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 ); @@ -158,10 +107,14 @@ HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* the // Layout addWidget( aModeGroup ); + addLayout( anUpdateSelLayout ); addWidget( myTable ); // Connect signals and slots connect( myModeButtons, SIGNAL( buttonClicked( int ) ), this, SLOT( onModeActivated( int ) ) ); + connect( myUpdateSelBtn, SIGNAL( clicked() ), this, SIGNAL( updateSelection() ) ); + connect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ), + this, SLOT( onDataChanged() ) ); } HYDROGUI_GeoreferencementDlg::~HYDROGUI_GeoreferencementDlg() @@ -170,6 +123,7 @@ HYDROGUI_GeoreferencementDlg::~HYDROGUI_GeoreferencementDlg() void HYDROGUI_GeoreferencementDlg::onModeActivated( int theMode ) { + myUpdateSelBtn->setEnabled( theMode == SelectedProfiles ); emit modeActivated( theMode ); } @@ -191,27 +145,31 @@ void HYDROGUI_GeoreferencementDlg::setMode( const int theMode ) aModeButton->setChecked( true ); } + myUpdateSelBtn->setEnabled( theMode == SelectedProfiles ); + myModeButtons->blockSignals( isBlocked ); } -void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) +void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataList& theData ) { + disconnect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ), + this, SLOT( onDataChanged() ) ); + myTable->setRowCount( 0 ); - foreach ( const QString& aProfileName, theMap.keys() ) { + foreach ( const ProfileGeoData& aGeoData, theData ) { // Check the current profile name - if ( aProfileName.isEmpty() ) { + if ( aGeoData.Name.isEmpty() ) { continue; } // Get georeferencement data for the current profile - 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, 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 @@ -219,11 +177,13 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) myTable->insertRow( aRow ); // "Profile" column - QTableWidgetItem* aNameItem = new QTableWidgetItem( aProfileName ); - aNameItem->setFlags( Qt::ItemIsEnabled ); + QTableWidgetItem* aNameItem = new QTableWidgetItem( aGeoData.Name ); + 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 @@ -240,12 +200,18 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) } myTable->resizeColumnToContents( 0 ); + myTable->resizeRowsToContents(); + + myIsModified = false; + + connect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ), + this, SLOT( onDataChanged() ) ); } -void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap ) +void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataList& theData ) const { - // Clear the map - theMap.clear(); + // Clear the list + theData.clear(); // Fill the map bool isOk = false; @@ -258,7 +224,7 @@ void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap ) aXd = myTable->item( aRow, 3 )->text(); anYd = myTable->item( aRow, 4 )->text(); - theMap.insert( aProfileName, ProfileGeoData( aXg, anYg, aXd, anYd ) ); + theData.append( ProfileGeoData( aProfileName, aXg, anYg, aXd, anYd ) ); } } @@ -281,18 +247,25 @@ 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; - myTable->item( aRow, aColumnX )->setText( getString( aPnt.X() ) ); - myTable->item( aRow, aColumnY )->setText( getString( 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 ); +} + +void HYDROGUI_GeoreferencementDlg::onDataChanged() +{ + myIsModified = true; } -QString HYDROGUI_GeoreferencementDlg::getString( const double theNumber ) const +bool HYDROGUI_GeoreferencementDlg::isModified() const { - return QString::number( theNumber, 'g', 12 ); + return myIsModified; } \ No newline at end of file