Salome HOME
refs #568: use ordered list view with selection synchronized with object browser...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverDlg.cxx
index fabcc56873e9972b05a5fc8cf526e8f9e330421f..39baff788ec10b4c479af0c938047929c86eb3a2 100644 (file)
 
 #include "HYDROGUI_LandCoverDlg.h"
 
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_OrderedListWidget.h"
+#include "HYDROGUI_ListSelector.h"
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
 #include <QGroupBox>
 #include <QLabel>
 #include <QLayout>
 #include <QListWidget>
+#include <QPushButton>
 
 HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_BasicZoneDlg( theModule, theTitle,
                          tr( "LAND_COVER_NAME" ), tr( "NAME" ),
                          tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) )
 {
-  myPolylines = new QListWidget( myPolylineFrame );
-  myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
-  myPolylines->setSelectionMode( QAbstractItemView::ExtendedSelection );
-
-  QBoxLayout* aPolyLayout = new QVBoxLayout( myPolylineFrame );
-  aPolyLayout->setMargin( 0 );
+  myPolylines = new HYDROGUI_OrderedListWidget( myPolylineFrame, 16 );
+  myPolylines->setHiddenObjectsShown(true);
+  myPolylines->setVisibilityIconShown(false);
+  myPolylines->setContentsMargins(QMargins());
+  myPolylines->setOrderingEnabled( true );
+
+  // Include/Exclude buttons
+  QFrame* aBtnsFrame = new QFrame( myPolylineFrame );
+  QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
+  aBtnsLayout->setMargin( 5 );
+  aBtnsLayout->setSpacing( 5 );
+  aBtnsFrame->setLayout( aBtnsLayout );
+  QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
+  QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
+
+  // Fill the butons frame with two buttons
+  aBtnsLayout->addWidget( anAddBtn );
+  aBtnsLayout->addWidget( aRemoveBtn );
+  aBtnsLayout->addStretch( 1 );
+
+  QGridLayout* aPolyLayout = new QGridLayout( myPolylineFrame );
+  aPolyLayout->setMargin( 5 );
   aPolyLayout->setSpacing( 5 );
-  aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ) );
-  aPolyLayout->addWidget( myPolylines );
+  aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ), 0, 0, 1, 2 );
+  aPolyLayout->addWidget( aBtnsFrame, 1, 0, 1, 1 );
+  aPolyLayout->addWidget( myPolylines, 1, 1, 1, 1 );
   
   QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
   aParamLayout->setMargin( 5 );
   aParamLayout->setSpacing( 5 );
   aParamLayout->addWidget( myPolylineFrame );
 
+  // Create selector
+  if ( module() ) {
+    HYDROGUI_ListSelector* aListSelector = 
+      new HYDROGUI_ListSelector( myPolylines, module()->getApp()->selectionMgr() );
+    aListSelector->setAutoBlock( true );
+  }
+
   // Connect signals and slots
   connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
+  connect( myPolylines, SIGNAL( orderPolylinesChanged() ), SLOT( onOrderPolylinesChanged() ) );
+  connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addPolylines() ) );
+  connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removePolylines() ) );
 }
 
 HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
@@ -57,62 +92,42 @@ void HYDROGUI_LandCoverDlg::reset()
 
   HYDROGUI_BasicZoneDlg::reset();
 
-  myPolylines->clear();
+  HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
+  myPolylines->setObjects(anObject2VisibleList);
+  myPolylines->setOrderingEnabled( false );
   
   blockSignals( isBlocked );
 
   onZoneDefChanged();
 }
 
-void HYDROGUI_LandCoverDlg::setPolylineNames( const QStringList& thePolylines )
+void HYDROGUI_LandCoverDlg::includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
 {
-  bool isBlocked = blockSignals( true );
-
-  myPolylines->clear();
-  myPolylines->addItems( thePolylines );
+  QStringList anIncludedPolylinesNames = myPolylines->getAllNames();
 
-  blockSignals( isBlocked );
+  foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
+  {
+    if ( !anIncludedPolylinesNames.contains( aSelectedPolyline.first->GetName() ) )
+      myPolylines->addObject( aSelectedPolyline );
+  }
+  myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
 }
 
-void HYDROGUI_LandCoverDlg::setSelectedPolylineNames( const QStringList& theSelectedPolylines )
+void HYDROGUI_LandCoverDlg::excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
 {
-  bool anUpdateNeeded = false;
-  for (int i =0; i< myPolylines->count(); i++)
-  {
-    QListWidgetItem* anItem = myPolylines->item( i );
-    if ( anItem )
-    {
-      bool aIsSelected = anItem->isSelected();
-      if ( theSelectedPolylines.contains( anItem->text() ) )
-      {
-        if ( !aIsSelected )
-        {
-          anUpdateNeeded = true;
-          anItem->setSelected( true );
-        }
-      }
-      else if ( aIsSelected )
-      {
-        anUpdateNeeded = true;
-        anItem->setSelected( false );
-      }
-    }
-  }
+  foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
+    myPolylines->removeObjectByName( aSelectedPolyline.first->GetName() );
+  myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
+}
 
-  if ( anUpdateNeeded )
-    onZoneDefChanged();
+QStringList HYDROGUI_LandCoverDlg::getPolylineNames() const
+{
+  return myPolylines->getAllNames();
 }
 
 QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
 {
-  QStringList aSelectedPolylines;
-
-  QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
-  QList<QListWidgetItem*>::const_iterator anIt = aSelectedItems.begin(), aLast = aSelectedItems.end();
-  for( ; anIt!=aLast; anIt++ )
-    aSelectedPolylines.append( (*anIt)->text() );
-
-  return aSelectedPolylines;
+  return myPolylines->getSelectedNames();
 }
 
 void HYDROGUI_LandCoverDlg::onZoneDefChanged()
@@ -120,6 +135,11 @@ void HYDROGUI_LandCoverDlg::onZoneDefChanged()
   if ( signalsBlocked() )
     return;
 
-  QStringList aPolylineNames = getSelectedPolylineNames();
+  QStringList aPolylineNames = getPolylineNames();
   emit CreatePreview( aPolylineNames );
 }
+
+void HYDROGUI_LandCoverDlg::onOrderPolylinesChanged()
+{
+  // TODO: implement this method
+}