Salome HOME
7b23bb9f9c66b47b78beaaddb14f30ddefc47c62
[modules/gui.git] / src / SUIT / SUIT_Selector.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "SUIT_Selector.h"
20
21 #include "SUIT_SelectionMgr.h"
22
23 /*!\class SUIT_Selector
24  * Class provide selector for data owners.
25  */
26
27 /*!
28   Constructor.
29 */
30 SUIT_Selector::SUIT_Selector( SUIT_SelectionMgr* selMgr, QObject* parent ) :
31 QObject( parent ), 
32 mySelMgr( selMgr ),
33 myBlock( false ),
34 myEnabled( true ),
35 myAutoBlock( true )
36 {
37   if ( selMgr )
38     selMgr->installSelector( this );
39 }
40
41 /*!
42   Destructor.
43 */
44 SUIT_Selector::~SUIT_Selector()
45 {
46   if ( selectionMgr() )
47     selectionMgr()->removeSelector( this );
48 }
49
50 /*!
51   Gets selection manager.
52 */
53 SUIT_SelectionMgr* SUIT_Selector::selectionMgr() const
54 {
55   return mySelMgr;
56 }
57
58 /*!
59   Checks: Is selctor enabled?
60 */
61 bool SUIT_Selector::isEnabled() const
62 {
63   return myEnabled;
64 }
65
66 /*!
67   Sets selctor anbled to \a on.
68 */
69 void SUIT_Selector::setEnabled( const bool on )
70 {
71   myEnabled = on;
72 }
73
74 /*!
75   Checks: Is selector auto block?
76 */
77 bool SUIT_Selector::autoBlock() const
78 {
79   return myAutoBlock;
80 }
81
82 /*!
83   Sets selctor autoblock to \a on.
84 */
85 void SUIT_Selector::setAutoBlock( const bool on )
86 {
87   myAutoBlock = on;
88 }
89
90 /*!
91   Puts to \a lst selection list of data owners.
92 */
93 void SUIT_Selector::selected( SUIT_DataOwnerPtrList& lst ) const
94 {
95   lst.clear();
96   getSelection( lst );
97 }
98
99 /*!
100   Puts to selection list of data owners \a lst..
101 */
102 void SUIT_Selector::setSelected( const SUIT_DataOwnerPtrList& lst )
103 {
104   if ( !isEnabled() )
105     return;
106
107   bool block = myBlock;
108   myBlock = true;
109
110   setSelection( lst );
111
112   myBlock = block;
113 }
114
115 /*!
116   On selection changed.
117 */
118 void SUIT_Selector::selectionChanged()
119 {
120   if ( selectionMgr() && isEnabled() && ( !autoBlock() || !myBlock ) )
121     selectionMgr()->selectionChanged( this );
122 }
123
124 /*!
125   Checks: Is selection manager has selection mode \a mode?
126 */
127 bool SUIT_Selector::hasSelectionMode( const int mode ) const
128 {
129   if ( !selectionMgr() )
130     return false;
131
132   return selectionMgr()->hasSelectionMode( mode );
133 }
134
135 /*!
136   Puts to list \a lst selection modes from selection manager.
137 */
138 void SUIT_Selector::selectionModes( QValueList<int>& lst ) const
139 {
140   if ( selectionMgr() )
141     selectionMgr()->selectionModes( lst );
142 }