1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_StreamDlg.h"
25 #include "HYDROGUI_Tool.h"
32 #include <QListWidget>
33 #include <QPushButton>
35 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle )
39 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
41 myObjectName = new QLineEdit( myObjectNameGroup );
43 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
44 aNameLayout->setMargin( 5 );
45 aNameLayout->setSpacing( 5 );
46 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
47 aNameLayout->addWidget( myObjectName );
50 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
52 myAxes = new QComboBox( aParamGroup );
53 myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
54 QBoxLayout* anAxisLayout = new QHBoxLayout();
55 anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
56 anAxisLayout->addWidget( myAxes );
58 myProfiles = new QListWidget( aParamGroup );
59 myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
60 myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
61 myProfiles->setViewMode( QListWidget::ListMode );
62 myProfiles->setSortingEnabled( false );
64 myAddButton = new QPushButton( aParamGroup );
65 myAddButton->setText( tr("ADD") );
66 myRemoveButton = new QPushButton( aParamGroup );
67 myRemoveButton->setText( tr("REMOVE") );
68 QBoxLayout* aButtonsLayout = new QHBoxLayout();
69 aButtonsLayout->addWidget( myAddButton );
70 aButtonsLayout->addWidget( myRemoveButton );
71 aButtonsLayout->addStretch();
73 QBoxLayout* aParamLayout = new QVBoxLayout();
74 aParamLayout->setMargin( 5 );
75 aParamLayout->setSpacing( 5 );
76 aParamLayout->addLayout( anAxisLayout );
77 aParamLayout->addWidget( myProfiles );
78 aParamLayout->addLayout( aButtonsLayout );
80 aParamGroup->setLayout( aParamLayout );
83 addWidget( myObjectNameGroup );
84 addWidget( aParamGroup );
87 // Connect signals and slots
88 connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ),
89 this, SIGNAL( AxisChanged( const QString& ) ) );
90 connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
91 connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
94 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
98 void HYDROGUI_StreamDlg::reset()
100 bool isBlocked = blockSignals( true );
102 myObjectName->clear();
106 myAddButton->setEnabled( false );
107 myRemoveButton->setEnabled( false );
109 blockSignals( isBlocked );
112 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
114 myObjectName->setText( theName );
117 QString HYDROGUI_StreamDlg::getObjectName() const
119 return myObjectName->text();
122 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
124 bool isBlocked = blockSignals( true );
127 myAxes->addItems( theAxises );
129 blockSignals( isBlocked );
132 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
134 bool isBlocked = blockSignals( true );
136 int aNewId = myAxes->findText( theName );
137 if ( aNewId != myAxes->currentIndex() ) {
138 myAxes->setCurrentIndex( aNewId );
140 myAddButton->setEnabled( myAxes->currentIndex() > -1 );
142 blockSignals( isBlocked );
145 QString HYDROGUI_StreamDlg::getAxisName() const
147 return myAxes->currentText();
150 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
152 bool isBlocked = blockSignals( true );
154 myProfiles->setUpdatesEnabled( false );
157 foreach ( const QString& aProfileName, theProfiles ) {
158 QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
159 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
162 myRemoveButton->setEnabled( myProfiles->count() > 0 );
164 myProfiles->setUpdatesEnabled( true );
166 blockSignals( isBlocked );
169 void HYDROGUI_StreamDlg::onRemoveProfiles()
171 QStringList aSelectedProfiles;
173 QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
174 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
175 QString aProfileName = anItem->text();
176 if ( !aProfileName.isEmpty() ) {
177 aSelectedProfiles << aProfileName;
181 emit RemoveProfiles( aSelectedProfiles );