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_ImportLandCoverDlg.h"
24 #include <QListWidget>
25 #include <QVBoxLayout>
26 #include <QToolButton>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_FileDlg.h>
32 HYDROGUI_ImportLandCoverDlg::HYDROGUI_ImportLandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
33 : HYDROGUI_InputPanel( theModule, theTitle )
35 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
37 myFileNameGroup = new QGroupBox( tr( "IMPORT_LANDCOVER_FROM_FILE" ) );
39 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
41 myFileName = new QLineEdit( myFileNameGroup );
42 myFileName->setReadOnly( true );
44 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
45 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
47 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
48 aFileNameLayout->setMargin( 5 );
49 aFileNameLayout->setSpacing( 5 );
50 aFileNameLayout->addWidget( aFileNameLabel );
51 aFileNameLayout->addWidget( myFileName );
52 aFileNameLayout->addWidget( aBrowseBtn );
54 myObjectNameGroup = new QGroupBox( tr( "LANDCOVER_NAME" ) );
56 QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
57 myObjectName = new QLineEdit( myObjectNameGroup );
59 QBoxLayout* aLandcoverNameLayout = new QHBoxLayout( myObjectNameGroup );
60 aLandcoverNameLayout->setMargin( 5 );
61 aLandcoverNameLayout->setSpacing( 5 );
62 aLandcoverNameLayout->addWidget( aLandcoverNameLabel );
63 aLandcoverNameLayout->addWidget( myObjectName );
65 QGroupBox* aPolygonsGroup = new QGroupBox( tr( "FOUNDED_POLYGONS" ), mainFrame() );
66 myPolygons = new QListWidget( aPolygonsGroup );
67 myPolygons->setSelectionMode( QListWidget::ExtendedSelection );
68 myPolygons->setEditTriggers( QListWidget::NoEditTriggers );
69 myPolygons->setViewMode( QListWidget::ListMode );
70 myPolygons->setSortingEnabled( false );
72 QBoxLayout* aPolygonsLayout = new QVBoxLayout;
73 aPolygonsLayout->addWidget( myPolygons );
74 aPolygonsGroup->setLayout( aPolygonsLayout );
77 addWidget( myFileNameGroup );
78 addWidget( myObjectNameGroup );
79 addWidget( aPolygonsGroup );
82 connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
83 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
86 HYDROGUI_ImportLandCoverDlg::~HYDROGUI_ImportLandCoverDlg()
90 void HYDROGUI_ImportLandCoverDlg::reset()
95 void HYDROGUI_ImportLandCoverDlg::setPolygonNames( const QStringList& theNames )
98 myPolygons->addItems( theNames );
101 void HYDROGUI_ImportLandCoverDlg::removePolygonNames( const QStringList& theNames )
103 QList<QListWidgetItem*> aFoundItems;
105 foreach ( const QString& aName, theNames ) {
106 aFoundItems = myPolygons->findItems( aName, Qt::MatchExactly );
107 foreach ( QListWidgetItem* anItem, aFoundItems ) {
108 anItem = myPolygons->takeItem( myPolygons->row( anItem ) );
114 void HYDROGUI_ImportLandCoverDlg::setSelectedPolygonNames( const QStringList& theNames )
116 myPolygons->clearSelection();
118 foreach( const QString aName, theNames ) {
119 QList<QListWidgetItem*> anItems = myPolygons->findItems( aName, Qt::MatchExactly );
120 if ( anItems.count() == 1 ) {
121 anItems.first()->setSelected( true );
126 void HYDROGUI_ImportLandCoverDlg::onItemSelectionChanged()
128 emit selectionChanged( getSelectedPolygonNames() );
131 QStringList HYDROGUI_ImportLandCoverDlg::getSelectedPolygonNames() const
133 QStringList aSelectedNames;
135 QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
136 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
137 aSelectedNames << anItem->text();
140 return aSelectedNames;
144 void HYDROGUI_ImportLandCoverDlg::onBrowse()
146 QString aFilter( tr( "LANDCOVER_FILTER" ) );
147 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVER_FROM_FILE" ), true );
149 if( !aFileName.isEmpty() )
151 setFileName( aFileName );
152 emit FileSelected( aFileName );
156 void HYDROGUI_ImportLandCoverDlg::setObjectName( const QString& theName )
158 myObjectName->setText( theName );
159 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
162 QString HYDROGUI_ImportLandCoverDlg::getObjectName() const
164 return myObjectName->text();
167 void HYDROGUI_ImportLandCoverDlg::setFileName( const QString& theFileName )
169 myFileName->setText( theFileName );
171 if ( !myObjectNameGroup->isEnabled() )
172 myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
175 QString HYDROGUI_ImportLandCoverDlg::getFileName() const
177 return myFileName->text();