]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx
Salome HOME
refs #568: Land Cover: a draft of data model and implementation of dialog box and...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_LandCoverDlg.h"
20
21 #include <QGroupBox>
22 #include <QLabel>
23 #include <QLayout>
24 #include <QListWidget>
25
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" ) )
30 {
31   myPolylines = new QListWidget( myPolylineFrame );
32   myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
33   myPolylines->setSelectionMode( QAbstractItemView::ExtendedSelection );
34
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 );
40   
41   QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
42   aParamLayout->setMargin( 5 );
43   aParamLayout->setSpacing( 5 );
44   aParamLayout->addWidget( myPolylineFrame );
45
46   // Connect signals and slots
47   connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
48 }
49
50 HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
51 {
52 }
53
54 void HYDROGUI_LandCoverDlg::reset()
55 {
56   bool isBlocked = blockSignals( true );
57
58   HYDROGUI_BasicZoneDlg::reset();
59
60   myPolylines->clear();
61   
62   blockSignals( isBlocked );
63
64   onZoneDefChanged();
65 }
66
67 void HYDROGUI_LandCoverDlg::setPolylineNames( const QStringList& thePolylines )
68 {
69   bool isBlocked = blockSignals( true );
70
71   myPolylines->clear();
72   myPolylines->addItems( thePolylines );
73
74   blockSignals( isBlocked );
75 }
76
77 void HYDROGUI_LandCoverDlg::setSelectedPolylineNames( const QStringList& theSelectedPolylines )
78 {
79   bool anUpdateNeeded = false;
80   for (int i =0; i< myPolylines->count(); i++)
81   {
82     QListWidgetItem* anItem = myPolylines->item( i );
83     if ( anItem )
84     {
85       bool aIsSelected = anItem->isSelected();
86       if ( theSelectedPolylines.contains( anItem->text() ) )
87       {
88         if ( !aIsSelected )
89         {
90           anUpdateNeeded = true;
91           anItem->setSelected( true );
92         }
93       }
94       else if ( aIsSelected )
95       {
96         anUpdateNeeded = true;
97         anItem->setSelected( false );
98       }
99     }
100   }
101
102   if ( anUpdateNeeded )
103     onZoneDefChanged();
104 }
105
106 QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
107 {
108   QStringList aSelectedPolylines;
109
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() );
114
115   return aSelectedPolylines;
116 }
117
118 void HYDROGUI_LandCoverDlg::onZoneDefChanged()
119 {
120   if ( signalsBlocked() )
121     return;
122
123   QStringList aPolylineNames = getSelectedPolylineNames();
124   emit CreatePreview( aPolylineNames );
125 }