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::ExtendedSelection );
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();
144 myTableW->setRowCount(5);
145 myTableW->setColumnCount(2);
148 list << "1" << "2" << "3";
150 for (int i = 0; i < 5; i++)
151 for (int j = 0; j < 2; j++)
153 QComboBox* CB = new QComboBox();
155 myTableW->setCellWidget(i,j,CB);
159 QVBoxLayout* aPageLayout = new QVBoxLayout;
160 aPageLayout->setMargin( 5 );
161 aPageLayout->setSpacing( 5 );
162 aPageLayout->addWidget( myCLabel );
163 aPageLayout->addWidget( myTableW );
164 aPage->setLayout( aPageLayout );
169 HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg()
173 void HYDROGUI_ImportLandCoverMapDlg::reset()
178 void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames )
181 myPolygons->addItems( theNames );
184 void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
186 QList<QListWidgetItem*> aFoundItems;
188 foreach ( const QString& aName, theNames ) {
189 aFoundItems = myPolygons->findItems( aName, Qt::MatchExactly );
190 foreach ( QListWidgetItem* anItem, aFoundItems ) {
191 anItem = myPolygons->takeItem( myPolygons->row( anItem ) );
197 void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
199 myPolygons->clearSelection();
201 foreach( const QString aName, theNames ) {
202 QList<QListWidgetItem*> anItems = myPolygons->findItems( aName, Qt::MatchExactly );
203 if ( anItems.count() == 1 ) {
204 anItems.first()->setSelected( true );
209 void HYDROGUI_ImportLandCoverMapDlg::onItemSelectionChanged()
211 emit selectionChanged( getSelectedPolygonNames() );
214 QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const
216 QStringList aSelectedNames;
218 QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
219 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
220 aSelectedNames << anItem->text();
223 return aSelectedNames;
227 void HYDROGUI_ImportLandCoverMapDlg::onBrowse()
229 QString aFilter( tr( "LANDCOVERMAP_FILTER" ) );
230 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVERMAP_FROM_FILE" ), true );
232 if( !aFileName.isEmpty() )
234 setFileName( aFileName );
235 emit FileSelected( aFileName );
239 void HYDROGUI_ImportLandCoverMapDlg::setObjectName( const QString& theName )
241 myObjectName->setText( theName );
242 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
245 QString HYDROGUI_ImportLandCoverMapDlg::getObjectName() const
247 return myObjectName->text();
250 void HYDROGUI_ImportLandCoverMapDlg::setFileName( const QString& theFileName )
252 myFileName->setText( theFileName );
254 if ( !myObjectNameGroup->isEnabled() )
255 myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
258 QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const
260 return myFileName->text();