Salome HOME
refs #430: incorrect coordinates in dump polyline
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsDlg.cxx
index 7055cd082f588afc506015a31ba3c6af71db0ac0..5511c6695edf50e91b0faf8a5ce38ab15a8410c5 100644 (file)
 //
 
 #include "HYDROGUI_ZLevelsDlg.h"
-#include "HYDROGUI_ZLevelsModel.h"
+
+#include "HYDROGUI_OrderedListWidget.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_ListSelector.h"
+
+#include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
 
 #include <QCheckBox>
 #include <QLayout>
-#include <QListView>
 #include <QPushButton>
-#include <QSignalMapper>
-#include <QSortFilterProxyModel>
 
 
-HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent )
+/**
+  Constructor.
+  @param theParent the parent widget
+*/
+HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
 : QDialog( theParent )
 {
+  // Change windows flags to remove minimize button
+  Qt::WindowFlags aFlags = windowFlags();
+  aFlags |= Qt::CustomizeWindowHint;
+  aFlags &= ~Qt::WindowMinimizeButtonHint;
+  aFlags &= ~Qt::WindowMaximizeButtonHint;
+  setWindowFlags( aFlags );
+
+  // Dialog title
+  setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
+
+  // Main layout
   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
   aMainLayout->setMargin( 5 );
+  aMainLayout->setSpacing( 5 );
 
-  QHBoxLayout* aListLayout = new QHBoxLayout();
-
-  myList = new QListView( this );
-  myList->setSelectionMode( QAbstractItemView::ExtendedSelection );
-  myList->setDragEnabled( true );
-  myList->setAcceptDrops( true );
-  myList->viewport()->setAcceptDrops( true );
-  myList->setDropIndicatorShown( true );
-  myList->setDragDropMode( QAbstractItemView::InternalMove );
-
-  HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
-  QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel();
-  aFilteredModel->setSourceModel( aModel );
-  aFilteredModel->setFilterKeyColumn( 0 );
-  aFilteredModel->setFilterRole( HYDROGUI_VisibleRole );
-
-  myList->setModel( aFilteredModel );
-
-  myTop = new QPushButton( tr("TOP") );
-  myUp = new QPushButton( tr("UP") );
-  myDown = new QPushButton( tr("DOWN") );
-  myBottom = new QPushButton( tr("BOTTOM") );
-  QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
-  aListButtonsLayout->addWidget( myTop );
-  aListButtonsLayout->addWidget( myUp );
-  aListButtonsLayout->addWidget( myDown );
-  aListButtonsLayout->addWidget( myBottom );
-  aListButtonsLayout->addStretch();
-  aListLayout->addWidget( myList );
-  aListLayout->addLayout( aListButtonsLayout );
-  aMainLayout->addLayout( aListLayout );
+  // Ordered list widget
+  myListWidget = new HYDROGUI_OrderedListWidget( this );
 
+  // "All objects" check box
   myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
-  aMainLayout->addWidget( myAllObjects );
 
-  QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout();
+  // Apply and close buttons
   myApply = new QPushButton( tr("APPLY") );
+  myApply->setDefault( true );
   myClose = new QPushButton( tr("CLOSE") );
+  
+  // Layout
+  // apply and close buttons
+  QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); 
   aDlgButtonsLayout->addWidget( myApply );
   aDlgButtonsLayout->addWidget( myClose );
   aDlgButtonsLayout->addStretch();
+  // main
+  aMainLayout->addWidget( myListWidget );
+  aMainLayout->addWidget( myAllObjects );
   aMainLayout->addLayout( aDlgButtonsLayout );
 
-  QSignalMapper* aSignalMapper = new QSignalMapper( this );
-  aSignalMapper->setMapping( myTop, HYDROGUI_ZLevelsModel::Top );
-  aSignalMapper->setMapping( myUp, HYDROGUI_ZLevelsModel::Up );
-  aSignalMapper->setMapping( myDown, HYDROGUI_ZLevelsModel::Down );
-  aSignalMapper->setMapping( myBottom, HYDROGUI_ZLevelsModel::Bottom );
-  connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
+  // Connections
+  connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
 
-  connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) );
+  connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
+  connect( myClose, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
-  connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
+  // Initialize
+  onStateChanged();
 
-  OnStateChanged();
+  // Create selector
+  if ( theModule ) {
+    HYDROGUI_ListSelector* aListSelector = 
+      new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
+    aListSelector->setAutoBlock( true );
+  }
 }
 
+/**
+  Destructor.
+*/
 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
 {
 }
 
-void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects )
+/**
+  Set the list of objects (which supposed to be ordered by the dialog).
+  @param theObjects the list of objects
+*/
+void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
 {
-  HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
-  if( aModel ) {
-    aModel->setObjects( theObjects );
-  }
+  myListWidget->setObjects( theObjects );
 }
 
+/**
+  Returns the ordered list of objects.
+  @return the list of objects
+*/
 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
 {
-  QList<Handle(HYDROData_Entity)> anObjects;
-
-  HYDROGUI_ZLevelsModel* aModel = getListSourceModel();
-  if( aModel ) {
-    anObjects = aModel->getObjects();
-  }
-
-  return anObjects;
-}
-
-void HYDROGUI_ZLevelsDlg::onMove( int theType )
-{
-  QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
-  if( aFilterModel ) {
-    HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
-    if( aModel ) {
-      QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
-      QModelIndexList aSelectedSourceIndexes;
-      foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
-        aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
-      }
-      QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
-      aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType, 
-                    !myAllObjects->isChecked() );      
-    }
-  }
+  return myListWidget->getObjects();
 }
 
-void HYDROGUI_ZLevelsDlg::OnStateChanged()
+/**
+  Slot called on "All objects" check box state change.
+*/
+void HYDROGUI_ZLevelsDlg::onStateChanged()
 {
-  QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
   bool isAll = myAllObjects->isChecked();
-  QString anExpr = isAll ? "true|false" : "true";
-  aFilterModel->setFilterRegExp( anExpr );
-}
 
-HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const
-{
-  HYDROGUI_ZLevelsModel* aSourceModel = 0;
+  QString aToolTip = isAll ? tr( "ALL_OBJECTS_CHECKED_TLT" ) :
+                             tr( "ALL_OBJECTS_UNCHECKED_TLT" );
+  myAllObjects->setToolTip( aToolTip );
 
-  QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
-  if( aFilterModel ) {
-    aSourceModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
-  }
-
-  return aSourceModel;
-}
\ No newline at end of file
+  myListWidget->setHiddenObjectsShown( isAll );
+}