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_StreamDlg.h"
21 #include "HYDROGUI_Tool.h"
28 #include <QListWidget>
29 #include <QPushButton>
31 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
32 : HYDROGUI_InputPanel( theModule, theTitle )
35 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
37 myObjectName = new QLineEdit( myObjectNameGroup );
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 );
46 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
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 );
54 myProfiles = new QListWidget( aParamGroup );
55 myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
56 myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
57 myProfiles->setViewMode( QListWidget::ListMode );
58 myProfiles->setSortingEnabled( false );
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();
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 );
76 aParamGroup->setLayout( aParamLayout );
79 addWidget( myObjectNameGroup );
80 addWidget( aParamGroup );
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() ) );
90 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
94 void HYDROGUI_StreamDlg::reset()
96 bool isBlocked = blockSignals( true );
98 myObjectName->clear();
102 myAddButton->setEnabled( false );
103 myRemoveButton->setEnabled( false );
105 blockSignals( isBlocked );
108 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
110 myObjectName->setText( theName );
113 QString HYDROGUI_StreamDlg::getObjectName() const
115 return myObjectName->text();
118 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
120 bool isBlocked = blockSignals( true );
123 myAxes->addItems( theAxises );
125 blockSignals( isBlocked );
128 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
130 bool isBlocked = blockSignals( true );
132 int aNewId = myAxes->findText( theName );
133 if ( aNewId != myAxes->currentIndex() ) {
134 myAxes->setCurrentIndex( aNewId );
136 myAddButton->setEnabled( myAxes->currentIndex() > -1 );
138 blockSignals( isBlocked );
141 QString HYDROGUI_StreamDlg::getAxisName() const
143 return myAxes->currentText();
146 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
148 bool isBlocked = blockSignals( true );
150 myProfiles->setUpdatesEnabled( false );
153 foreach ( const QString& aProfileName, theProfiles ) {
154 QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
155 aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
158 myRemoveButton->setEnabled( myProfiles->count() > 0 );
160 myProfiles->setUpdatesEnabled( true );
162 blockSignals( isBlocked );
165 void HYDROGUI_StreamDlg::onRemoveProfiles()
167 QStringList aSelectedProfiles;
169 QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
170 foreach( const QListWidgetItem* anItem, aSelectedItems ) {
171 QString aProfileName = anItem->text();
172 if ( !aProfileName.isEmpty() ) {
173 aSelectedProfiles << aProfileName;
177 emit RemoveProfiles( aSelectedProfiles );