Salome HOME
merge master 2015/06/04
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.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_StreamDlg.h"
20
21 #include "HYDROGUI_Tool.h"
22
23 #include <QComboBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QLineEdit>
28 #include <QListWidget>
29 #include <QPushButton>
30
31 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
32 : HYDROGUI_InputPanel( theModule, theTitle )
33 {
34   // Stream name
35   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
36
37   myObjectName = new QLineEdit( myObjectNameGroup );
38
39   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
40   aNameLayout->setMargin( 5 );
41   aNameLayout->setSpacing( 5 );
42   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
43   aNameLayout->addWidget( myObjectName );
44
45   // Stream parameters
46   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
47
48   myAxes = new QComboBox( aParamGroup );
49   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
50   QBoxLayout* anAxisLayout = new QHBoxLayout();
51   anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
52   anAxisLayout->addWidget( myAxes );
53
54   myProfiles = new QListWidget( aParamGroup );
55   myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
56   myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
57   myProfiles->setViewMode( QListWidget::ListMode );
58   myProfiles->setSortingEnabled( false );
59
60   myAddButton = new QPushButton( aParamGroup );
61   myAddButton->setText( tr("ADD") );
62   myRemoveButton = new QPushButton( aParamGroup );
63   myRemoveButton->setText( tr("REMOVE") );
64   QBoxLayout* aButtonsLayout = new QHBoxLayout();
65   aButtonsLayout->addWidget( myAddButton );
66   aButtonsLayout->addWidget( myRemoveButton );
67   aButtonsLayout->addStretch();
68  
69   QBoxLayout* aParamLayout = new QVBoxLayout();
70   aParamLayout->setMargin( 5 );
71   aParamLayout->setSpacing( 5 );
72   aParamLayout->addLayout( anAxisLayout );
73   aParamLayout->addWidget( myProfiles );
74   aParamLayout->addLayout( aButtonsLayout );
75
76   aParamGroup->setLayout( aParamLayout );
77
78   // Common
79   addWidget( myObjectNameGroup );
80   addWidget( aParamGroup );
81   addStretch();
82
83   // Connect signals and slots
84   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
85            this, SIGNAL( AxisChanged( const QString& ) ) );
86   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
87   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
88 }
89
90 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
91 {
92 }
93
94 void HYDROGUI_StreamDlg::reset()
95 {
96   bool isBlocked = blockSignals( true );
97
98   myObjectName->clear();
99
100   myAxes->clear();
101   myProfiles->clear();
102   myAddButton->setEnabled( false );
103   myRemoveButton->setEnabled( false );
104
105   blockSignals( isBlocked );
106 }
107
108 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
109 {
110   myObjectName->setText( theName );
111 }
112
113 QString HYDROGUI_StreamDlg::getObjectName() const
114 {
115   return myObjectName->text();
116 }
117
118 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
119 {
120   bool isBlocked = blockSignals( true );
121
122   myAxes->clear();
123   myAxes->addItems( theAxises );
124
125   blockSignals( isBlocked );
126 }
127
128 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
129 {
130   bool isBlocked = blockSignals( true );
131
132   int aNewId = myAxes->findText( theName );
133   if ( aNewId != myAxes->currentIndex() ) {
134     myAxes->setCurrentIndex( aNewId );
135   }
136   myAddButton->setEnabled( myAxes->currentIndex() > -1 );
137
138   blockSignals( isBlocked );
139 }
140
141 QString HYDROGUI_StreamDlg::getAxisName() const
142 {
143   return myAxes->currentText();
144 }
145
146 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
147 {
148   bool isBlocked = blockSignals( true );
149
150   myProfiles->setUpdatesEnabled( false );
151   
152   myProfiles->clear();
153   foreach ( const QString& aProfileName, theProfiles ) {
154     QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
155     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
156   }
157
158   myRemoveButton->setEnabled( myProfiles->count() > 0 );
159
160   myProfiles->setUpdatesEnabled( true );
161
162   blockSignals( isBlocked );
163 }
164
165 void HYDROGUI_StreamDlg::onRemoveProfiles()
166 {
167   QStringList aSelectedProfiles;
168
169   QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
170   foreach( const QListWidgetItem* anItem, aSelectedItems ) {
171     QString aProfileName = anItem->text();
172     if ( !aProfileName.isEmpty() ) {
173       aSelectedProfiles << aProfileName;
174     }
175   }
176
177   emit RemoveProfiles( aSelectedProfiles );
178 }