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>
32 #include <QTableWidget>
33 #include <QHeaderView>
36 HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_Wizard( theModule, theTitle )
39 addPage( createPage1() );
40 addPage( createPage2() );
41 addPage( createPage3() );
44 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
45 QWizardPage* aPage = new QWizardPage( mainFrame() );
46 QFrame* aFrame = new QFrame( aPage );
48 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
50 myFileNameGroup = new QGroupBox( tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ) );
52 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
54 myFileName = new QLineEdit( myFileNameGroup );
55 myFileName->setReadOnly( true );
57 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
58 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
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 );
67 myObjectNameGroup = new QGroupBox( tr( "LANDCOVERMAP_NAME" ) );
69 QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
70 myObjectName = new QLineEdit( myObjectNameGroup );
72 QBoxLayout* aLandcoverNameLayout = new QHBoxLayout( myObjectNameGroup );
73 aLandcoverNameLayout->setMargin( 5 );
74 aLandcoverNameLayout->setSpacing( 5 );
75 aLandcoverNameLayout->addWidget( aLandcoverNameLabel );
76 aLandcoverNameLayout->addWidget( myObjectName );
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 );
85 QBoxLayout* aPolygonsLayout = new QVBoxLayout;
86 aPolygonsLayout->addWidget( myPolygons );
87 aPolygonsGroup->setLayout( aPolygonsLayout );
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 );
99 connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
100 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
105 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() {
106 QWizardPage* aPage = new QWizardPage( mainFrame() );
107 QFrame* aFrame = new QFrame( aPage );
109 myAttrNameGroup = new QGroupBox( "Available attributes" );
111 QCheckBox* anAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types", myAttrNameGroup );
113 QBoxLayout* aFileNameLayout = new QHBoxLayout( myAttrNameGroup );
114 aFileNameLayout->setMargin( 5 );
115 aFileNameLayout->setSpacing( 5 );
116 aFileNameLayout->addWidget( anAttrCheckBox );
119 myDBFAttr = new QListWidget( aPage );
120 myDBFAttr->setSelectionMode( QListWidget::SingleSelection );
121 myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers );
122 myDBFAttr->setViewMode( QListWidget::ListMode );
123 myDBFAttr->setSortingEnabled( false );
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 );
135 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() {
137 QWizardPage* aPage = new QWizardPage( mainFrame() );
138 QFrame* aFrame = new QFrame( aPage );
139 myCLabel = new QLabel();
140 myCLabel->setText("Correspondence");
142 myTableW = new QTableWidget();
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 );
155 HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg()
159 void HYDROGUI_ImportLandCoverMapDlg::reset()
165 void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames )
168 myPolygons->addItems( theNames );
171 void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAttrNames )
174 myDBFAttr->addItems( theAttrNames );
177 void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
179 QList<QListWidgetItem*> aFoundItems;
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 ) );
190 void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
192 myPolygons->clearSelection();
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 );
202 void HYDROGUI_ImportLandCoverMapDlg::onItemSelectionChanged()
204 emit selectionChanged( getSelectedPolygonNames() );
207 QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const
209 QStringList aSelectedNames;
211 QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
212 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
213 aSelectedNames << anItem->text();
216 return aSelectedNames;
221 void HYDROGUI_ImportLandCoverMapDlg::onBrowse()
223 QString aFilter( tr( "LANDCOVERMAP_FILTER" ) );
224 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ), true );
226 if( !aFileName.isEmpty() )
228 setFileName( aFileName );
229 emit FileSelected( aFileName );
233 void HYDROGUI_ImportLandCoverMapDlg::setObjectName( const QString& theName )
235 myObjectName->setText( theName );
236 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
239 QString HYDROGUI_ImportLandCoverMapDlg::getObjectName() const
241 return myObjectName->text();
244 void HYDROGUI_ImportLandCoverMapDlg::setFileName( const QString& theFileName )
246 myFileName->setText( theFileName );
248 if ( !myObjectNameGroup->isEnabled() )
249 myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
252 QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const
254 return myFileName->text();
258 void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn)
260 int FCSize = theFirstColumn.size();
261 int SCSize = theSecondColumn.size();
263 myTableW->setRowCount(FCSize);
264 myTableW->setColumnCount(2);
266 for (int i = 0; i < FCSize; i++)
268 QTableWidgetItem* aTWI = new QTableWidgetItem();
269 aTWI->setText(theFirstColumn.at(i));
270 aTWI->setFlags(Qt::ItemIsUserCheckable);
271 myTableW->setItem(i, 0, aTWI);
274 for (int i = 0; i < FCSize; i++)
276 QComboBox* aCB = new QComboBox();
277 aCB->addItems(theSecondColumn);
278 myTableW->setCellWidget(i, 1, aCB);
282 QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const
284 return myDBFAttr->selectedItems().first()->text();