X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_GeoreferencementDlg.cxx;h=35be05cd0187f33c40e768357d133f30320d7001;hb=a1431f03eac1d1aed4203d0568d987c41ce939b3;hp=bd10b2c083b98e7b594c35b1376ef2bde462d266;hpb=347f7cf014bec3113cc79c89b0d19ef5735aab10;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index bd10b2c0..35be05cd 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 @@ -34,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -42,9 +45,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; @@ -91,16 +96,13 @@ QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor( 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() ); - + QDoubleValidator* aDoubleValidator = new QDoubleValidator(); + aDoubleValidator->setNotation( QDoubleValidator::StandardNotation ); + aDoubleValidator->setDecimals( 2 ); + aLineEdit->setValidator( aDoubleValidator ); anEditor = aLineEdit; - } - - if ( !anEditor) { + } else { anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex ); } @@ -110,23 +112,25 @@ QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor( 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() ); + if ( QLineEdit* aLineEdit = dynamic_cast( 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 { - QLineEdit* anEditor = qobject_cast( theEditor ); - if ( anEditor ) { - theModel->setData( theIndex, anEditor->text() ); + if ( QLineEdit* aLineEdit = dynamic_cast( 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 ) +: HYDROGUI_InputPanel( theModule, theTitle ), myIsModified( false ) { // Mode selector (all/selected) QGroupBox* aModeGroup = new QGroupBox( tr( "PROFILES" ), this ); @@ -144,6 +148,13 @@ 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 ) ); @@ -158,10 +169,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 +185,7 @@ HYDROGUI_GeoreferencementDlg::~HYDROGUI_GeoreferencementDlg() void HYDROGUI_GeoreferencementDlg::onModeActivated( int theMode ) { + myUpdateSelBtn->setEnabled( theMode == SelectedProfiles ); emit modeActivated( theMode ); } @@ -191,27 +207,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 ); + anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg ); + aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd ); + anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd ); } // Insert row with the data @@ -219,11 +239,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 +262,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 +286,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 ) ); } } @@ -288,11 +316,18 @@ 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 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() +{ + 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