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 // Import bathymetry from file
38 myFileNameGroup = new QGroupBox( tr( "IMPORT_POLYGON_FROM_FILE" ) );
40 QLabel* aFileNameLabel = new QLabel( tr( "LANCOVER_NAME" ), myFileNameGroup );
42 myFileName = new QLineEdit( myFileNameGroup );
43 myFileName->setReadOnly( true );
45 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
46 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
48 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
49 aFileNameLayout->setMargin( 5 );
50 aFileNameLayout->setSpacing( 5 );
51 aFileNameLayout->addWidget( aFileNameLabel );
52 aFileNameLayout->addWidget( myFileName );
53 aFileNameLayout->addWidget( aBrowseBtn );
56 myObjectNameGroup = new QGroupBox( tr( "FILE_NAME" ) );
58 QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
59 myObjectName = new QLineEdit( myObjectNameGroup );
61 QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
62 aBathymetryNameLayout->setMargin( 5 );
63 aBathymetryNameLayout->setSpacing( 5 );
64 aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
65 aBathymetryNameLayout->addWidget( myObjectName );
67 // List of recognized polylines
68 QGroupBox* aPolylinesGroup = new QGroupBox( tr( "FOUND_POLYGONS_OF_SHP_FILE" ), mainFrame() );
69 myPolylines = new QListWidget( aPolylinesGroup );
70 myPolylines->setSelectionMode( QListWidget::ExtendedSelection );
71 myPolylines->setEditTriggers( QListWidget::NoEditTriggers );
72 myPolylines->setViewMode( QListWidget::ListMode );
73 myPolylines->setSortingEnabled( false );
75 QBoxLayout* aPolylinesLayout = new QVBoxLayout;
76 aPolylinesLayout->addWidget( myPolylines );
77 aPolylinesGroup->setLayout( aPolylinesLayout );
80 addWidget( myFileNameGroup );
81 addWidget( myObjectNameGroup );
82 addWidget( aPolylinesGroup );
85 connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
86 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
89 HYDROGUI_ImportLandCoverDlg::~HYDROGUI_ImportLandCoverDlg()
93 void HYDROGUI_ImportLandCoverDlg::setImageName( const QString& theName )
95 myImageName->setText( theName );
98 void HYDROGUI_ImportLandCoverDlg::reset()
100 myImageName->clear();
101 myPolylines->clear();
104 void HYDROGUI_ImportLandCoverDlg::setPolylineNames( const QStringList& theNames )
106 myPolylines->clear();
107 myPolylines->addItems( theNames );
110 void HYDROGUI_ImportLandCoverDlg::removePolylineNames( const QStringList& theNames )
112 QList<QListWidgetItem*> aFoundItems;
114 foreach ( const QString& aName, theNames ) {
115 aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly );
116 foreach ( QListWidgetItem* anItem, aFoundItems ) {
117 anItem = myPolylines->takeItem( myPolylines->row( anItem ) );
123 void HYDROGUI_ImportLandCoverDlg::setSelectedPolylineNames( const QStringList& theNames )
125 myPolylines->clearSelection();
127 foreach( const QString aName, theNames ) {
128 QList<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
129 if ( anItems.count() == 1 ) {
130 anItems.first()->setSelected( true );
135 void HYDROGUI_ImportLandCoverDlg::onItemSelectionChanged()
137 emit selectionChanged( getSelectedtPolylineNames() );
140 QStringList HYDROGUI_ImportLandCoverDlg::getSelectedtPolylineNames() const
142 QStringList aSelectedNames;
144 QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
145 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
146 aSelectedNames << anItem->text();
149 return aSelectedNames;
153 void HYDROGUI_ImportLandCoverDlg::onBrowse()
155 QString aFilter( tr( "LANDCOVER_FILTER" ) );
156 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_LANDCOVER_FROM_FILE" ), true );
158 if( !aFileName.isEmpty() )
160 setFileName( aFileName );
161 emit FileSelected( aFileName );
165 void HYDROGUI_ImportLandCoverDlg::setObjectName( const QString& theName )
167 myObjectName->setText( theName );
168 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
171 QString HYDROGUI_ImportLandCoverDlg::getObjectName() const
173 return myObjectName->text();
176 void HYDROGUI_ImportLandCoverDlg::setFileName( const QString& theFileName )
178 myFileName->setText( theFileName );
180 if ( !myObjectNameGroup->isEnabled() )
181 myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
184 QString HYDROGUI_ImportLandCoverDlg::getFileName() const
186 return myFileName->text();