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_ListSelector.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_OrderedListWidget.h"
24 #include "HYDROGUI_Tool.h"
26 #include <HYDROData_Profile.h>
28 #include <LightApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
36 #include <QListWidget>
37 #include <QPushButton>
39 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
40 : HYDROGUI_InputPanel( theModule, theTitle )
43 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
45 myObjectName = new QLineEdit( myObjectNameGroup );
47 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
48 aNameLayout->setMargin( 5 );
49 aNameLayout->setSpacing( 5 );
50 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
51 aNameLayout->addWidget( myObjectName );
54 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
56 myAxes = new QComboBox( aParamGroup );
57 myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
58 QBoxLayout* anAxisLayout = new QHBoxLayout();
59 anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
60 anAxisLayout->addWidget( myAxes );
62 myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
63 myProfiles->setHiddenObjectsShown(true);
64 myProfiles->setVisibilityIconShown(false);
65 myProfiles->setContentsMargins(QMargins());
66 myProfiles->setOrderingEnabled( false );
68 myAddButton = new QPushButton( aParamGroup );
69 myAddButton->setText( tr("ADD") );
70 myRemoveButton = new QPushButton( aParamGroup );
71 myRemoveButton->setText( tr("REMOVE") );
72 QBoxLayout* aButtonsLayout = new QHBoxLayout();
73 aButtonsLayout->addWidget( myAddButton );
74 aButtonsLayout->addWidget( myRemoveButton );
75 aButtonsLayout->addStretch();
77 QBoxLayout* aParamLayout = new QVBoxLayout();
78 aParamLayout->setMargin( 5 );
79 aParamLayout->setSpacing( 5 );
80 aParamLayout->addLayout( anAxisLayout );
81 aParamLayout->addWidget( myProfiles );
82 aParamLayout->addLayout( aButtonsLayout );
84 aParamGroup->setLayout( aParamLayout );
87 addWidget( myObjectNameGroup );
88 addWidget( aParamGroup );
93 HYDROGUI_ListSelector* aListSelector =
94 new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
95 aListSelector->setAutoBlock( true );
98 // Connect signals and slots
99 connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ),
100 this, SIGNAL( AxisChanged( const QString& ) ) );
101 connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
102 connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
105 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
109 void HYDROGUI_StreamDlg::reset()
111 bool isBlocked = blockSignals( true );
113 myObjectName->clear();
116 myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
117 myAddButton->setEnabled( false );
118 myRemoveButton->setEnabled( false );
120 blockSignals( isBlocked );
123 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
125 myObjectName->setText( theName );
128 QString HYDROGUI_StreamDlg::getObjectName() const
130 return myObjectName->text();
133 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
135 bool isBlocked = blockSignals( true );
138 myAxes->addItems( theAxises );
140 blockSignals( isBlocked );
143 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
145 bool isBlocked = blockSignals( true );
147 int aNewId = myAxes->findText( theName );
148 if ( aNewId != myAxes->currentIndex() ) {
149 myAxes->setCurrentIndex( aNewId );
151 myAddButton->setEnabled( myAxes->currentIndex() > -1 );
153 blockSignals( isBlocked );
156 QString HYDROGUI_StreamDlg::getAxisName() const
158 return myAxes->currentText();
161 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
163 bool isBlocked = blockSignals( true );
165 myProfiles->setUpdatesEnabled( false );
167 HYDROGUI_ListModel::Object2VisibleList aProfiles;
168 foreach ( const QString& aProfileName, theProfiles ) {
169 Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast(
170 HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
171 if ( !anObject.IsNull() ) {
172 aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
176 myProfiles->setObjects( aProfiles );
178 myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
180 myProfiles->setUpdatesEnabled( true );
182 blockSignals( isBlocked );
185 void HYDROGUI_StreamDlg::onRemoveProfiles()
187 QStringList aSelectedProfiles = myProfiles->getSelectedNames();
189 emit RemoveProfiles( aSelectedProfiles );