]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx
Salome HOME
cf4de87aab6b083e6a3e47e30a7cc84af58b3417
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportLandCoverMapDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ImportLandCoverMapDlg.h"
20
21 #include <QGroupBox>
22 #include <QLabel>
23 #include <QLineEdit>
24 #include <QListWidget>
25 #include <QVBoxLayout>
26 #include <QToolButton>
27 #include <QCheckBox>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_FileDlg.h>
31
32 #include <QTableWidget>
33 #include <QHeaderView>
34 #include <QComboBox>
35
36 HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_Wizard( theModule, theTitle )
38 {
39   addPage( createPage1() );
40   addPage( createPage2() );
41   addPage( createPage3() );
42 }
43
44 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
45   QWizardPage* aPage = new QWizardPage( mainFrame() );
46   QFrame* aFrame = new QFrame( aPage );
47
48   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
49
50   myFileNameGroup = new QGroupBox( tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ) );
51
52   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
53
54   myFileName = new QLineEdit( myFileNameGroup );
55   myFileName->setReadOnly( true );
56
57   QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
58   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
59
60   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
61   aFileNameLayout->setMargin( 5 );
62   aFileNameLayout->setSpacing( 5 );
63   aFileNameLayout->addWidget( aFileNameLabel );
64   aFileNameLayout->addWidget( myFileName );
65   aFileNameLayout->addWidget( aBrowseBtn );
66
67   myObjectNameGroup = new QGroupBox( tr( "LANDCOVERMAP_NAME" ) );
68
69   QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
70   myObjectName = new QLineEdit( myObjectNameGroup );
71
72   QBoxLayout* aLandcoverNameLayout = new QHBoxLayout( myObjectNameGroup );
73   aLandcoverNameLayout->setMargin( 5 );
74   aLandcoverNameLayout->setSpacing( 5 );
75   aLandcoverNameLayout->addWidget( aLandcoverNameLabel );
76   aLandcoverNameLayout->addWidget( myObjectName );
77
78   QGroupBox* aPolygonsGroup = new QGroupBox( tr( "FOUNDED_POLYGONS" ) );
79   myPolygons = new QListWidget( aPolygonsGroup );
80   myPolygons->setSelectionMode( QListWidget::ExtendedSelection );
81   myPolygons->setEditTriggers( QListWidget::NoEditTriggers );
82   myPolygons->setViewMode( QListWidget::ListMode );
83   myPolygons->setSortingEnabled( false );
84
85   QBoxLayout* aPolygonsLayout = new QVBoxLayout;
86   aPolygonsLayout->addWidget( myPolygons );
87   aPolygonsGroup->setLayout( aPolygonsLayout );
88
89   // Layout
90   QVBoxLayout* aPageLayout = new QVBoxLayout;
91   aPageLayout->setMargin( 5 );
92   aPageLayout->setSpacing( 5 );
93   aPageLayout->addWidget( myFileNameGroup );
94   aPageLayout->addWidget( myObjectNameGroup );
95   aPageLayout->addWidget( aPolygonsGroup );
96   aPage->setLayout( aPageLayout );
97
98   // Conections
99   connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
100   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); 
101
102   return aPage;
103 }
104
105 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() {
106   QWizardPage* aPage = new QWizardPage( mainFrame() );
107   QFrame* aFrame = new QFrame( aPage );
108
109   myAttrNameGroup = new QGroupBox( "Available attributes" );
110  
111   QCheckBox* anAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types", myAttrNameGroup );
112
113   QBoxLayout* aFileNameLayout = new QHBoxLayout( myAttrNameGroup );
114   aFileNameLayout->setMargin( 5 );
115   aFileNameLayout->setSpacing( 5 );
116   aFileNameLayout->addWidget( anAttrCheckBox );
117
118
119   myDBFAttr = new QListWidget( aPage );
120   myDBFAttr->setSelectionMode( QListWidget::SingleSelection );
121   myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers );
122   myDBFAttr->setViewMode( QListWidget::ListMode );
123   myDBFAttr->setSortingEnabled( false );
124
125   // Layout
126   QVBoxLayout* aPageLayout = new QVBoxLayout;
127   aPageLayout->setMargin( 5 );
128   aPageLayout->setSpacing( 5 );
129   aPageLayout->addWidget( myAttrNameGroup );
130   aPageLayout->addWidget( myDBFAttr );
131   aPage->setLayout( aPageLayout );
132   return aPage;
133 }
134
135 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() {
136
137   QWizardPage* aPage = new QWizardPage( mainFrame() );
138   QFrame* aFrame = new QFrame( aPage );
139   myCLabel = new QLabel();
140   myCLabel->setText("Correspondence");
141   
142   myTableW = new QTableWidget();
143
144   // Layout
145   QVBoxLayout* aPageLayout = new QVBoxLayout;
146   aPageLayout->setMargin( 5 );
147   aPageLayout->setSpacing( 5 );
148   aPageLayout->addWidget( myCLabel );
149   aPageLayout->addWidget( myTableW );
150   aPage->setLayout( aPageLayout );
151   return aPage;
152 }
153
154
155 HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg()
156 {
157 }
158
159 void HYDROGUI_ImportLandCoverMapDlg::reset()
160 {
161   myPolygons->clear();
162   myDBFAttr->clear();
163 }
164
165 void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames )
166 {
167   myPolygons->clear();
168   myPolygons->addItems( theNames );
169 }
170
171 void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAttrNames )
172 {
173   myDBFAttr->clear();
174   myDBFAttr->addItems( theAttrNames );
175 }
176
177 void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
178 {
179   QList<QListWidgetItem*> aFoundItems;
180
181   foreach ( const QString& aName, theNames ) {
182     aFoundItems = myPolygons->findItems( aName, Qt::MatchExactly );
183     foreach ( QListWidgetItem* anItem, aFoundItems ) {
184       anItem = myPolygons->takeItem( myPolygons->row( anItem ) );
185       delete anItem;
186     }
187   }
188 }
189
190 void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
191 {
192   myPolygons->clearSelection();
193
194   foreach( const QString aName, theNames ) {
195     QList<QListWidgetItem*> anItems = myPolygons->findItems( aName, Qt::MatchExactly );
196     if ( anItems.count() == 1 ) {
197       anItems.first()->setSelected( true );
198     }
199   }
200 }
201
202 void HYDROGUI_ImportLandCoverMapDlg::onItemSelectionChanged()
203 {
204   emit selectionChanged( getSelectedPolygonNames() );
205 }
206
207 QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const
208 {
209   QStringList aSelectedNames;
210
211   QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
212   foreach( const QListWidgetItem* anItem, aSelectedItems ) {
213     aSelectedNames << anItem->text();
214   }
215
216   return aSelectedNames;
217 }
218
219
220
221 void HYDROGUI_ImportLandCoverMapDlg::onBrowse()
222 {
223   QString aFilter( tr( "LANDCOVERMAP_FILTER" ) );
224   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ), true );
225
226   if( !aFileName.isEmpty() )
227   {
228     setFileName( aFileName );
229     emit FileSelected( aFileName );
230   }
231 }
232
233 void HYDROGUI_ImportLandCoverMapDlg::setObjectName( const QString& theName )
234 {
235   myObjectName->setText( theName );
236   myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
237 }
238
239 QString HYDROGUI_ImportLandCoverMapDlg::getObjectName() const
240 {
241   return myObjectName->text();
242 }
243
244 void HYDROGUI_ImportLandCoverMapDlg::setFileName( const QString& theFileName )
245 {
246   myFileName->setText( theFileName );
247
248   if ( !myObjectNameGroup->isEnabled() )
249     myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
250 }
251
252 QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const
253 {
254   return myFileName->text();
255 }
256
257
258 void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn)
259 {
260   int FCSize = theFirstColumn.size();
261   int SCSize = theSecondColumn.size();
262  
263   myTableW->setRowCount(FCSize);
264   myTableW->setColumnCount(2);
265
266   for (int i = 0; i < FCSize; i++)
267   {
268     QTableWidgetItem* aTWI = new QTableWidgetItem();
269     aTWI->setText(theFirstColumn.at(i));
270     aTWI->setFlags(Qt::ItemIsUserCheckable);
271     myTableW->setItem(i, 0, aTWI);
272   }
273   
274   for (int i = 0; i < FCSize; i++)
275   {
276     QComboBox* aCB = new QComboBox();
277     aCB->addItems(theSecondColumn);
278     myTableW->setCellWidget(i, 1, aCB);
279   }
280 }
281
282 QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const
283 {
284   return myDBFAttr->selectedItems().first()->text();
285 }