Salome HOME
Minor changes.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.cxx
index b2aa1e1a0a01681726e39594f03e85df268099d1..91373c422fc3965608e5cef0e725e4ccfcbf62c0 100644 (file)
@@ -30,6 +30,7 @@
 #include <QLayout>
 #include <QLineEdit>
 #include <QListWidget>
+#include <QPushButton>
 
 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle )
@@ -48,30 +49,46 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   // Stream parameters
   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
 
-  myAxises = new QComboBox( aParamGroup );
-  myAxises->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myAxes = new QComboBox( aParamGroup );
+  myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  QBoxLayout* anAxisLayout = new QHBoxLayout();
+  anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
+  anAxisLayout->addWidget( myAxes );
 
   myProfiles = new QListWidget( aParamGroup );
-  myProfiles->setSelectionMode( QListWidget::SingleSelection );
+  myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
   myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
   myProfiles->setViewMode( QListWidget::ListMode );
   myProfiles->setSortingEnabled( false );
+
+  myAddButton = new QPushButton( aParamGroup );
+  myAddButton->setText( tr("ADD") );
+  myRemoveButton = new QPushButton( aParamGroup );
+  myRemoveButton->setText( tr("REMOVE") );
+  QBoxLayout* aButtonsLayout = new QHBoxLayout();
+  aButtonsLayout->addWidget( myAddButton );
+  aButtonsLayout->addWidget( myRemoveButton );
+  aButtonsLayout->addStretch();
  
-  QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
+  QBoxLayout* aParamLayout = new QVBoxLayout();
   aParamLayout->setMargin( 5 );
   aParamLayout->setSpacing( 5 );
-  aParamLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ), aParamGroup ), 0, 0 );
-  aParamLayout->addWidget( myAxises, 0, 1 );
-  aParamLayout->addWidget( myProfiles, 1, 0, 1, 2 );
+  aParamLayout->addLayout( anAxisLayout );
+  aParamLayout->addWidget( myProfiles );
+  aParamLayout->addLayout( aButtonsLayout );
+
+  aParamGroup->setLayout( aParamLayout );
 
   // Common
   addWidget( myObjectNameGroup );
   addWidget( aParamGroup );
-
   addStretch();
 
   // Connect signals and slots
-  connect( myAxises, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onStreamDefChanged() ) );
+  connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
+           this, SIGNAL( AxisChanged( const QString& ) ) );
+  connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
+  connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
 }
 
 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
@@ -84,12 +101,12 @@ void HYDROGUI_StreamDlg::reset()
 
   myObjectName->clear();
 
-  myAxises->clear();
+  myAxes->clear();
   myProfiles->clear();
+  myAddButton->setEnabled( false );
+  myRemoveButton->setEnabled( false );
 
   blockSignals( isBlocked );
-
-  onStreamDefChanged();
 }
 
 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
@@ -106,72 +123,60 @@ void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
 {
   bool isBlocked = blockSignals( true );
 
-  myAxises->clear();
-  myAxises->addItems( theAxises );
+  myAxes->clear();
+  myAxes->addItems( theAxises );
 
   blockSignals( isBlocked );
 }
 
 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
 {
-  int aNewIdx = myAxises->findText( theName );
-  if ( aNewIdx != myAxises->currentIndex() )
-  {
-    myAxises->setCurrentIndex( aNewIdx );
-  }
-  else
-  {
-    onStreamDefChanged();
+  bool isBlocked = blockSignals( true );
+
+  int aNewId = myAxes->findText( theName );
+  if ( aNewId != myAxes->currentIndex() ) {
+    myAxes->setCurrentIndex( aNewId );
   }
+  myAddButton->setEnabled( myAxes->currentIndex() > -1 );
+
+  blockSignals( isBlocked );
 }
 
 QString HYDROGUI_StreamDlg::getAxisName() const
 {
-  return myAxises->currentText();
+  return myAxes->currentText();
 }
 
-void HYDROGUI_StreamDlg::setSelectedProfiles( const QStringList& theProfiles )
+void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 {
   bool isBlocked = blockSignals( true );
 
   myProfiles->setUpdatesEnabled( false );
   
   myProfiles->clear();
-  for ( int i = 0, n = theProfiles.length(); i < n; ++i )
-  {
-    const QString& aProfileName = theProfiles.at( i );
+  foreach ( const QString& aProfileName, theProfiles ) {
     QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
   }
 
+  myRemoveButton->setEnabled( myProfiles->count() > 0 );
+
   myProfiles->setUpdatesEnabled( true );
 
   blockSignals( isBlocked );
-
-  onStreamDefChanged();
 }
 
-QStringList HYDROGUI_StreamDlg::getSelectedProfiles() const
+void HYDROGUI_StreamDlg::onRemoveProfiles()
 {
-  QStringList aProfiles;
-
-  for ( int i = 0, n = myProfiles->count(); i < n; ++i )
-  {
-    QListWidgetItem* aListItem = myProfiles->item( i );
-    if ( !aListItem )
-      continue;
-
-    QString aProfileName = aListItem->text();
-    aProfiles << aProfileName;
+  QStringList aSelectedProfiles;
+
+  QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
+  foreach( const QListWidgetItem* anItem, aSelectedItems ) {
+    QString aProfileName = anItem->text();
+    if ( !aProfileName.isEmpty() ) {
+      aSelectedProfiles << aProfileName;
+    }
   }
 
-  return aProfiles;
-}
-
-void HYDROGUI_StreamDlg::onStreamDefChanged()
-{
-  if ( signalsBlocked() )
-    return;
-
-  emit CreatePreview();
+  emit RemoveProfiles( aSelectedProfiles );
 }