Salome HOME
lot 12 GUI p.1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StricklerTypeComboBox.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_StricklerTypeComboBox.h"
20
21 #include "HYDROGUI_Module.h"
22
23 #include <QLayout>
24 #include <QLabel>
25 #include <QComboBox>
26
27 #include <HYDROData_Iterator.h>
28 #include <HYDROData_Document.h>
29 #include <HYDROData_StricklerTable.h>
30
31 HYDROGUI_StricklerTypeComboBox::HYDROGUI_StricklerTypeComboBox( HYDROGUI_Module* theModule,
32                                                                 const QString& theTitle,
33                                                                 QWidget* theParent )
34 : QWidget( theParent ),
35   myModule( theModule )
36 {
37   QBoxLayout* base = new QHBoxLayout( this );
38   base->setMargin( 0 );
39
40   if ( !theTitle.isEmpty() )
41     base->addWidget( new QLabel( theTitle, this ) );    
42   myStricklerTypes = new QComboBox( this );  
43   myStricklerTypes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
44   base->addWidget( myStricklerTypes );
45
46   if ( myModule )
47   {
48     // Construct a list of unique names of all Strickler types defined within the data model
49     Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myModule->getStudyId() );
50     if ( aDoc )
51     {
52       QStringList aStricklerTypes;
53       HYDROData_Iterator anIterator( aDoc, KIND_STRICKLER_TABLE );
54       for( ; anIterator.More(); anIterator.Next() )
55       {
56         Handle(HYDROData_StricklerTable) aStricklerTableObj =
57           Handle(HYDROData_StricklerTable)::DownCast( anIterator.Current() );   
58         if ( !aStricklerTableObj.IsNull() )
59         {
60           // Get Strickler table data from the data model
61           QStringList aTypes = aStricklerTableObj->GetTypes();
62           for ( QStringList::iterator it = aTypes.begin(); it != aTypes.end(); ++it )
63           {
64             QString aType = *it;
65             if ( !aType.isEmpty() && !aStricklerTypes.contains( aType ) )
66               aStricklerTypes.append( aType );
67           }
68         }
69       }
70
71       aStricklerTypes.sort();
72       setStricklerTypes( aStricklerTypes );
73     }
74   }
75 }
76
77 HYDROGUI_StricklerTypeComboBox::~HYDROGUI_StricklerTypeComboBox()
78 {
79 }
80
81 HYDROGUI_Module* HYDROGUI_StricklerTypeComboBox::module() const
82 {
83   return myModule;
84 }
85
86 void HYDROGUI_StricklerTypeComboBox::setStricklerTypes( const QStringList& theTypes )
87 {
88   bool isBlocked = blockSignals( true );
89
90   myStricklerTypes->clear();
91   myStricklerTypes->addItems( theTypes );
92
93   blockSignals( isBlocked );
94 }
95
96 void HYDROGUI_StricklerTypeComboBox::setSelectedStricklerTypeName( const QString& theName )
97 {
98   myStricklerTypes->setCurrentIndex( myStricklerTypes->findText( theName ) );
99 }
100
101 QString HYDROGUI_StricklerTypeComboBox::getSelectedStricklerTypeName() const
102 {
103   return myStricklerTypes->currentText();
104 }