1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_GeoreferencementDlg.h"
25 #include <QTableWidget>
26 #include <QHeaderView>
27 #include <QRadioButton>
29 #include <QButtonGroup>
33 HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* theModule, const QString& theTitle )
34 : HYDROGUI_InputPanel( theModule, theTitle )
36 // Mode selector (all/selected)
37 QGroupBox* aModeGroup = new QGroupBox( tr( "PROFILES" ), this );
39 QRadioButton* anAllRB = new QRadioButton( tr( "ALL_MODE" ), aModeGroup );
40 QRadioButton* aSelectedRB = new QRadioButton( tr( "SELECTED_MODE" ), aModeGroup );
42 myModeButtons = new QButtonGroup( aModeGroup );
43 myModeButtons->addButton( anAllRB, AllProfiles );
44 myModeButtons->addButton( aSelectedRB, SelectedProfiles );
46 QBoxLayout* aModeSelectorLayout = new QVBoxLayout( aModeGroup );
47 aModeSelectorLayout->setMargin( 5 );
48 aModeSelectorLayout->setSpacing( 5 );
49 aModeSelectorLayout->addWidget( anAllRB );
50 aModeSelectorLayout->addWidget( aSelectedRB );
53 myTable = new QTableWidget( mainFrame() );
54 myTable->verticalHeader()->setVisible( false );
55 myTable->setSelectionBehavior( QAbstractItemView::SelectItems );
56 myTable->setSelectionMode( QAbstractItemView::SingleSelection );
57 myTable->setColumnCount( 5 );
58 QStringList aColumnNames;
59 aColumnNames << tr( "PROFILE_HEADER" ) << tr( "XG_HEADER" ) << tr( "YG_HEADER" ) <<
60 tr( "XD_HEADER" ) << tr( "YD_HEADER" );
61 myTable->setHorizontalHeaderLabels( aColumnNames );
64 addWidget( aModeGroup );
67 // Connect signals and slots
68 connect( myModeButtons, SIGNAL( buttonClicked( int ) ), this, SLOT( onModeActivated( int ) ) );
71 HYDROGUI_GeoreferencementDlg::~HYDROGUI_GeoreferencementDlg()
75 void HYDROGUI_GeoreferencementDlg::onModeActivated( int theMode )
77 emit modeActivated( theMode );
80 void HYDROGUI_GeoreferencementDlg::reset()
82 // Activate the "All" mode
83 myModeButtons->button( AllProfiles )->setChecked( true );
85 // Clear the table widget
86 myTable->setRowCount( 0 );
89 void HYDROGUI_GeoreferencementDlg::onProfilesSelectionChanged()
94 void HYDROGUI_GeoreferencementDlg::setMode( const int theMode )
96 bool isBlocked = myModeButtons->blockSignals( true );
98 QAbstractButton* aModeButton = myModeButtons->button( theMode );
100 aModeButton->setChecked( true );
103 myModeButtons->blockSignals( isBlocked );
106 void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap )
108 myTable->setRowCount( 0 );
110 foreach ( const QString& aProfileName, theMap.keys() ) {
111 // Check the current profile name
112 if ( aProfileName.isEmpty() ) {
116 // Get georeferencement data for the current profile
117 ProfileGeoData aGeoData = theMap.value( aProfileName );
118 QString aXg, anYg, aXd, anYd;
119 if ( aGeoData.isValid ) {
120 aXg = QString::number( aGeoData.Xg );
121 anYg = QString::number( aGeoData.Yg );
122 aXd = QString::number( aGeoData.Xd );
123 anYd = QString::number( aGeoData.Yd );
126 // Insert row with the data
127 int aRow = myTable->rowCount();
128 myTable->insertRow( aRow );
131 QTableWidgetItem* aNameItem = new QTableWidgetItem( aProfileName );
132 aNameItem->setFlags( Qt::ItemIsEnabled );
133 myTable->setItem( aRow, 0, aNameItem );
136 QLineEdit* aXgEdit = new QLineEdit( aXg );
137 aXgEdit->setValidator( new QDoubleValidator( aXgEdit ) );
138 myTable->setCellWidget( aRow, 1, aXgEdit );
141 QLineEdit* anYgEdit = new QLineEdit( anYg );
142 anYgEdit->setValidator( new QDoubleValidator( anYgEdit ) );
143 myTable->setCellWidget( aRow, 2, anYgEdit );
146 QLineEdit* aXdEdit = new QLineEdit( aXd );
147 aXdEdit->setValidator( new QDoubleValidator( aXdEdit ) );
148 myTable->setCellWidget( aRow, 3, aXdEdit );
151 QLineEdit* anYdEdit = new QLineEdit( anYd );
152 anYdEdit->setValidator( new QDoubleValidator( anYdEdit ) );
153 myTable->setCellWidget( aRow, 4, anYdEdit );
157 void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap )
164 for ( int aRow = 0; aRow < myTable->rowCount(); aRow++ ) {
165 QString aProfileName = myTable->item( aRow, 0 )->text();
167 theMap.insert( aProfileName, ProfileGeoData() );
169 double aXg, anYg, aXd, anYd;
171 QLineEdit* aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 1 ) );
172 QString aCellText = aLineEdit ? aLineEdit->text() : "";
173 aXg = aCellText.toDouble( &isOk );
174 if ( !isOk ) continue;
176 aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 2 ) );
177 aCellText = aLineEdit ? aLineEdit->text() : "";
178 anYg = aCellText.toDouble( &isOk );
179 if ( !isOk ) continue;
181 aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 3 ) );
182 aCellText = aLineEdit ? aLineEdit->text() : "";
183 aXd = aCellText.toDouble( &isOk );
184 if ( !isOk ) continue;
186 aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 4 ) );
187 aCellText = aLineEdit ? aLineEdit->text() : "";
188 anYd = aCellText.toDouble( &isOk );
189 if ( !isOk ) continue;
191 theMap[aProfileName] = ProfileGeoData( aXg, anYg, aXd, anYd );