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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ImportLandCoverMapDlg.h"
24 #include <QListWidget>
25 #include <QVBoxLayout>
26 #include <QToolButton>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_FileDlg.h>
31 #include <HYDROGUI_Module.h>
32 #include <SUIT_MessageBox.h>
33 #include <LightApp_Application.h>
34 #include <QTableWidget>
35 #include <QHeaderView>
37 #include <QStackedWidget>
39 HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
40 : HYDROGUI_Wizard( theModule, theTitle )
42 addPage( createPage1() );
43 addPage( createPage2() );
44 addPage( createPage3() );
45 myFirstPageState = false;
48 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
49 QWizardPage* aPage = new QWizardPage( mainFrame() );
50 QFrame* aFrame = new QFrame( aPage );
52 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
54 myFileNameGroup = new QGroupBox( tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ) );
56 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
58 myFileName = new QLineEdit( myFileNameGroup );
59 myFileName->setReadOnly( true );
61 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
62 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
64 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
65 aFileNameLayout->setMargin( 5 );
66 aFileNameLayout->setSpacing( 5 );
67 aFileNameLayout->addWidget( aFileNameLabel );
68 aFileNameLayout->addWidget( myFileName );
69 aFileNameLayout->addWidget( aBrowseBtn );
71 myObjectNameGroup = new QGroupBox( tr( "LANDCOVERMAP_NAME" ) );
73 QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
74 myObjectName = new QLineEdit( myObjectNameGroup );
76 QBoxLayout* aLandcoverNameLayout = new QHBoxLayout( myObjectNameGroup );
77 aLandcoverNameLayout->setMargin( 5 );
78 aLandcoverNameLayout->setSpacing( 5 );
79 aLandcoverNameLayout->addWidget( aLandcoverNameLabel );
80 aLandcoverNameLayout->addWidget( myObjectName );
82 QGroupBox* aPolygonsGroup = new QGroupBox( tr( "FOUNDED_POLYGONS" ) );
83 myPolygons = new QListWidget( aPolygonsGroup );
84 myPolygons->setSelectionMode( QListWidget::ExtendedSelection );
85 myPolygons->setEditTriggers( QListWidget::NoEditTriggers );
86 myPolygons->setViewMode( QListWidget::ListMode );
87 myPolygons->setSortingEnabled( false );
89 QBoxLayout* aPolygonsLayout = new QVBoxLayout;
90 aPolygonsLayout->addWidget( myPolygons );
91 aPolygonsGroup->setLayout( aPolygonsLayout );
94 QVBoxLayout* aPageLayout = new QVBoxLayout;
95 aPageLayout->setMargin( 5 );
96 aPageLayout->setSpacing( 5 );
97 aPageLayout->addWidget( myFileNameGroup );
98 aPageLayout->addWidget( myObjectNameGroup );
99 aPageLayout->addWidget( aPolygonsGroup );
100 aPage->setLayout( aPageLayout );
103 connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
104 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
109 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() {
110 QWizardPage* aPage = new QWizardPage( mainFrame() );
111 QFrame* aFrame = new QFrame( aPage );
113 myAttrNameGroup = new QGroupBox( "Available attributes" );
115 QCheckBox* anAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types", myAttrNameGroup );
117 QBoxLayout* aFileNameLayout = new QHBoxLayout( myAttrNameGroup );
118 aFileNameLayout->setMargin( 5 );
119 aFileNameLayout->setSpacing( 5 );
120 aFileNameLayout->addWidget( anAttrCheckBox );
123 myDBFAttr = new QListWidget( aPage );
124 myDBFAttr->setSelectionMode( QListWidget::SingleSelection );
125 myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers );
126 myDBFAttr->setViewMode( QListWidget::ListMode );
127 myDBFAttr->setSortingEnabled( false );
130 QVBoxLayout* aPageLayout = new QVBoxLayout;
131 aPageLayout->setMargin( 5 );
132 aPageLayout->setSpacing( 5 );
133 aPageLayout->addWidget( myAttrNameGroup );
134 aPageLayout->addWidget( myDBFAttr );
135 aPage->setLayout( aPageLayout );
139 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() {
141 QWizardPage* aPage = new QWizardPage( mainFrame() );
142 QFrame* aFrame = new QFrame( aPage );
143 myCLabel = new QLabel();
144 myCLabel->setText("Correspondence");
146 myTableW = new QTableWidget();
149 QVBoxLayout* aPageLayout = new QVBoxLayout;
150 aPageLayout->setMargin( 5 );
151 aPageLayout->setSpacing( 5 );
152 aPageLayout->addWidget( myCLabel );
153 aPageLayout->addWidget( myTableW );
154 aPage->setLayout( aPageLayout );
159 HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg()
163 void HYDROGUI_ImportLandCoverMapDlg::reset()
169 void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames )
172 myPolygons->addItems( theNames );
175 void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAttrNames )
178 myDBFAttr->addItems( theAttrNames );
181 /*void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
183 QList<QListWidgetItem*> aFoundItems;
185 foreach ( const QString& aName, theNames ) {
186 aFoundItems = myPolygons->findItems( aName, Qt::MatchExactly );
187 foreach ( QListWidgetItem* anItem, aFoundItems ) {
188 anItem = myPolygons->takeItem( myPolygons->row( anItem ) );
194 void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
196 myPolygons->clearSelection();
198 foreach( const QString aName, theNames ) {
199 QList<QListWidgetItem*> anItems = myPolygons->findItems( aName, Qt::MatchExactly );
200 if ( anItems.count() == 1 ) {
201 anItems.first()->setSelected( true );
206 void HYDROGUI_ImportLandCoverMapDlg::onItemSelectionChanged()
208 emit selectionChanged( getSelectedPolygonNames() );
211 QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const
213 QStringList aSelectedNames;
215 QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
216 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
217 aSelectedNames << anItem->text();
220 return aSelectedNames;
225 void HYDROGUI_ImportLandCoverMapDlg::onBrowse()
227 QString aFilter( tr( "LANDCOVERMAP_FILTER" ) );
228 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ), true );
230 if( !aFileName.isEmpty() )
232 setFileName( aFileName );
233 emit FileSelected( aFileName );
237 void HYDROGUI_ImportLandCoverMapDlg::setObjectName( const QString& theName )
239 myObjectName->setText( theName );
240 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
243 QString HYDROGUI_ImportLandCoverMapDlg::getObjectName() const
245 return myObjectName->text();
248 void HYDROGUI_ImportLandCoverMapDlg::setFileName( const QString& theFileName )
250 myFileName->setText( theFileName );
252 if ( !myObjectNameGroup->isEnabled() )
253 myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
256 QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const
258 return myFileName->text();
262 void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn)
264 int FCSize = theFirstColumn.size();
265 int SCSize = theSecondColumn.size();
267 myTableW->setRowCount(FCSize);
268 myTableW->setColumnCount(2);
270 for (int i = 0; i < FCSize; i++)
272 QTableWidgetItem* aTWI = new QTableWidgetItem();
273 aTWI->setText(theFirstColumn.at(i));
274 aTWI->setFlags(Qt::ItemIsUserCheckable);
275 myTableW->setItem(i, 0, aTWI);
278 for (int i = 0; i < FCSize; i++)
280 QComboBox* aCB = new QComboBox();
281 aCB->addItems(theSecondColumn);
282 myTableW->setCellWidget(i, 1, aCB);
286 QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const
288 return myDBFAttr->selectedItems().first()->text();
291 void HYDROGUI_ImportLandCoverMapDlg::setFirstPageState(bool bState)
293 myFirstPageState = bState;
296 bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const
298 //Check the state of curent page
299 int CurrPage = wizard()->currentIndex();
304 if (!myFirstPageState)
310 if (this->myDBFAttr->selectedItems().empty())
321 void HYDROGUI_ImportLandCoverMapDlg::GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST)
323 int aRowCount = myTableW->rowCount();
324 for (int i = 0; i < aRowCount; i++)
326 QTableWidgetItem* aTWI = myTableW->item(i, 0);
327 AttrValues.push_back(aTWI->text());
330 for (int i = 0; i < aRowCount; i++)
332 QWidget* aW = myTableW->cellWidget(i, 1);
333 QComboBox* aCB = dynamic_cast<QComboBox*> (aW);
334 ST.push_back(aCB->currentText());
339 QVector<int> HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const
341 QVector<int> aSelectedIndices;
343 QModelIndexList aSelectedItems = myPolygons->selectionModel()->selectedIndexes();
344 foreach( QModelIndex index, aSelectedItems ) {
345 aSelectedIndices << index.row();
348 return aSelectedIndices;