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_LandCoverDlg.h"
24 #include <QListWidget>
26 HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
27 : HYDROGUI_BasicZoneDlg( theModule, theTitle,
28 tr( "LAND_COVER_NAME" ), tr( "NAME" ),
29 tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) )
31 myPolylines = new QListWidget( myPolylineFrame );
32 myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
33 myPolylines->setSelectionMode( QAbstractItemView::ExtendedSelection );
35 QBoxLayout* aPolyLayout = new QVBoxLayout( myPolylineFrame );
36 aPolyLayout->setMargin( 0 );
37 aPolyLayout->setSpacing( 5 );
38 aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ) );
39 aPolyLayout->addWidget( myPolylines );
41 QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
42 aParamLayout->setMargin( 5 );
43 aParamLayout->setSpacing( 5 );
44 aParamLayout->addWidget( myPolylineFrame );
46 // Connect signals and slots
47 connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
50 HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
54 void HYDROGUI_LandCoverDlg::reset()
56 bool isBlocked = blockSignals( true );
58 HYDROGUI_BasicZoneDlg::reset();
62 blockSignals( isBlocked );
67 void HYDROGUI_LandCoverDlg::setPolylineNames( const QStringList& thePolylines )
69 bool isBlocked = blockSignals( true );
72 myPolylines->addItems( thePolylines );
74 blockSignals( isBlocked );
77 void HYDROGUI_LandCoverDlg::setSelectedPolylineNames( const QStringList& theSelectedPolylines )
79 bool anUpdateNeeded = false;
80 for (int i =0; i< myPolylines->count(); i++)
82 QListWidgetItem* anItem = myPolylines->item( i );
85 bool aIsSelected = anItem->isSelected();
86 if ( theSelectedPolylines.contains( anItem->text() ) )
90 anUpdateNeeded = true;
91 anItem->setSelected( true );
94 else if ( aIsSelected )
96 anUpdateNeeded = true;
97 anItem->setSelected( false );
102 if ( anUpdateNeeded )
106 QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
108 QStringList aSelectedPolylines;
110 QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
111 QList<QListWidgetItem*>::const_iterator anIt = aSelectedItems.begin(), aLast = aSelectedItems.end();
112 for( ; anIt!=aLast; anIt++ )
113 aSelectedPolylines.append( (*anIt)->text() );
115 return aSelectedPolylines;
118 void HYDROGUI_LandCoverDlg::onZoneDefChanged()
120 if ( signalsBlocked() )
123 QStringList aPolylineNames = getSelectedPolylineNames();
124 emit CreatePreview( aPolylineNames );