Salome HOME
Merge remote-tracking branch 'origin/BR_SHP_FORMAT2' into BR_LAND_COVER_MAP
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.cxx
index 8b4f7050fada1831bd6eaeec0962f11f574f2cbc..95f0750bda8f08194e944d5882ba655a72347a68 100644 (file)
 
 #include "HYDROGUI_StreamDlg.h"
 
+#include "HYDROGUI_ListSelector.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_OrderedListWidget.h"
 #include "HYDROGUI_Tool.h"
 
+#include <HYDROData_Profile.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
 #include <QComboBox>
 #include <QGroupBox>
 #include <QLabel>
@@ -51,12 +59,12 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
   anAxisLayout->addWidget( myAxes );
 
-  myProfiles = new QListWidget( aParamGroup );
-  myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
-  myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
-  myProfiles->setViewMode( QListWidget::ListMode );
-  myProfiles->setSortingEnabled( false );
-
+  myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
+  myProfiles->setHiddenObjectsShown(true);
+  myProfiles->setVisibilityIconShown(false);
+  myProfiles->setContentsMargins(QMargins());
+  myProfiles->setOrderingEnabled( false );
   myAddButton = new QPushButton( aParamGroup );
   myAddButton->setText( tr("ADD") );
   myRemoveButton = new QPushButton( aParamGroup );
@@ -80,6 +88,13 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   addWidget( aParamGroup );
   addStretch();
 
+  // Create selector
+  if ( module() ) {
+    HYDROGUI_ListSelector* aListSelector = 
+      new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
+    aListSelector->setAutoBlock( true );
+  }
+
   // Connect signals and slots
   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
            this, SIGNAL( AxisChanged( const QString& ) ) );
@@ -98,7 +113,7 @@ void HYDROGUI_StreamDlg::reset()
   myObjectName->clear();
 
   myAxes->clear();
-  myProfiles->clear();
+  myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
   myAddButton->setEnabled( false );
   myRemoveButton->setEnabled( false );
 
@@ -149,13 +164,18 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 
   myProfiles->setUpdatesEnabled( false );
   
-  myProfiles->clear();
+  HYDROGUI_ListModel::Object2VisibleList aProfiles;
   foreach ( const QString& aProfileName, theProfiles ) {
-    QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
-    aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+    Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
+    if ( !anObject.IsNull() ) {
+      aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
+    }
   }
 
-  myRemoveButton->setEnabled( myProfiles->count() > 0 );
+  myProfiles->setObjects( aProfiles );
+
+  myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
 
   myProfiles->setUpdatesEnabled( true );
 
@@ -164,15 +184,7 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 
 void HYDROGUI_StreamDlg::onRemoveProfiles()
 {
-  QStringList aSelectedProfiles;
-
-  QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
-  foreach( const QListWidgetItem* anItem, aSelectedItems ) {
-    QString aProfileName = anItem->text();
-    if ( !aProfileName.isEmpty() ) {
-      aSelectedProfiles << aProfileName;
-    }
-  }
+  QStringList aSelectedProfiles = myProfiles->getSelectedNames();
 
   emit RemoveProfiles( aSelectedProfiles );
 }