Salome HOME
Renaming, add selector for selection synchronization.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ZLevelsDlg.h"
24
25 #include "HYDROGUI_OrderedListWidget.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_ListSelector.h"
28
29 #include "LightApp_Application.h"
30 #include "LightApp_SelectionMgr.h"
31
32 #include <QCheckBox>
33 #include <QLayout>
34 #include <QPushButton>
35
36
37 /**
38   Constructor.
39   @param theParent the parent widget
40 */
41 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
42 : QDialog( theParent )
43 {
44   // Dialog title
45   setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
46
47   // Main layout
48   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
49   aMainLayout->setMargin( 5 );
50   aMainLayout->setSpacing( 5 );
51
52   // Ordered list widget
53   myListWidget = new HYDROGUI_OrderedListWidget( this );
54
55   // "All objects" check box
56   myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
57
58   // Apply and close buttons
59   myApply = new QPushButton( tr("APPLY") );
60   myClose = new QPushButton( tr("CLOSE") );
61   
62   // Layout
63   // apply and close buttons
64   QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); 
65   aDlgButtonsLayout->addWidget( myApply );
66   aDlgButtonsLayout->addWidget( myClose );
67   aDlgButtonsLayout->addStretch();
68   // main
69   aMainLayout->addWidget( myListWidget );
70   aMainLayout->addWidget( myAllObjects );
71   aMainLayout->addLayout( aDlgButtonsLayout );
72
73   // Connections
74   connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
75
76   connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
77   connect( myClose, SIGNAL( clicked() ), this, SLOT( close() ) );
78
79   // Initialize
80   onStateChanged();
81
82   // Create selector
83   if ( theModule ) {
84     new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
85   }
86 }
87
88 /**
89   Destructor.
90 */
91 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
92 {
93 }
94
95 /**
96   Set the list of objects (which supposed to be ordered by the dialog).
97   @param theObjects the list of objects
98 */
99 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
100 {
101   myListWidget->setObjects( theObjects );
102 }
103
104 /**
105   Returns the ordered list of objects.
106   @return the list of objects
107 */
108 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
109 {
110   return myListWidget->getObjects();
111 }
112
113 /**
114   Slot called on "All objects" check box state change.
115 */
116 void HYDROGUI_ZLevelsDlg::onStateChanged()
117 {
118   bool isAll = myAllObjects->isChecked();
119   myListWidget->setHiddenObjectsShown( isAll );
120 }