]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_Selector.cxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / SUIT / SUIT_Selector.cxx
1 // Copyright (C) 2007-2012  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 "SUIT_Selector.h"
24
25 #include "SUIT_SelectionMgr.h"
26
27 #include <QObject>
28
29 /*!\class SUIT_Selector::Destroyer
30   Class provide the watching for qobject parent class of the selector.
31 */
32
33 class SUIT_Selector::Destroyer : public QObject
34 {
35 public:
36   Destroyer( SUIT_Selector*, QObject* = 0 );
37   virtual ~Destroyer();
38
39   SUIT_Selector* selector() const;
40   void           setSelector( SUIT_Selector* );
41
42 private:
43   SUIT_Selector* mySelector;
44 };
45
46 SUIT_Selector::Destroyer::Destroyer( SUIT_Selector* s, QObject* p )
47 : QObject( p ),
48   mySelector( s )
49 {
50 }
51
52 SUIT_Selector::Destroyer::~Destroyer()
53 {
54   SUIT_Selector* s = mySelector;
55   mySelector = 0;
56   if ( s )
57     delete s;
58 }
59
60 SUIT_Selector* SUIT_Selector::Destroyer::selector() const
61 {
62   return mySelector;
63 }
64
65 void SUIT_Selector::Destroyer::setSelector( SUIT_Selector* s )
66 {
67   mySelector = s;
68 }
69
70 /*!\class SUIT_Selector
71  * Class provide selector for data owners.
72  */
73
74 /*!
75   Constructor.
76 */
77 SUIT_Selector::SUIT_Selector( SUIT_SelectionMgr* selMgr, QObject* parent )
78 : mySelMgr( selMgr ),
79 myBlock( false ),
80 myEnabled( true ),
81 myAutoBlock( true ),
82 myDestroyer( 0 )
83 {
84   if ( selMgr )
85     selMgr->installSelector( this );
86
87   if ( parent )
88     myDestroyer = new Destroyer( this, parent );
89 }
90
91 /*!
92   Destructor.
93 */
94 SUIT_Selector::~SUIT_Selector()
95 {
96   if ( selectionMgr() )
97     selectionMgr()->removeSelector( this );
98
99   if ( myDestroyer && myDestroyer->selector() == this )
100   {
101     myDestroyer->setSelector( 0 );
102     delete myDestroyer;
103   }
104 }
105
106 /*!
107   Gets selection manager.
108 */
109 SUIT_SelectionMgr* SUIT_Selector::selectionMgr() const
110 {
111   return mySelMgr;
112 }
113
114 /*!
115   Checks: Is selctor enabled?
116 */
117 bool SUIT_Selector::isEnabled() const
118 {
119   return myEnabled;
120 }
121
122 /*!
123   Sets selctor anbled to \a on.
124 */
125 void SUIT_Selector::setEnabled( const bool on )
126 {
127   myEnabled = on;
128 }
129
130 /*!
131   Checks: Is selector auto block?
132 */
133 bool SUIT_Selector::autoBlock() const
134 {
135   return myAutoBlock;
136 }
137
138 /*!
139   Sets selctor autoblock to \a on.
140 */
141 void SUIT_Selector::setAutoBlock( const bool on )
142 {
143   myAutoBlock = on;
144 }
145
146 /*!
147   Puts to \a lst selection list of data owners.
148 */
149 void SUIT_Selector::selected( SUIT_DataOwnerPtrList& lst ) const
150 {
151   lst.clear();
152   getSelection( lst );
153 }
154
155 /*!
156   Puts to selection list of data owners \a lst..
157 */
158 void SUIT_Selector::setSelected( const SUIT_DataOwnerPtrList& lst )
159 {
160   if ( !isEnabled() )
161     return;
162
163   bool block = myBlock;
164   myBlock = true;
165
166   setSelection( lst );
167
168   myBlock = block;
169 }
170
171 /*!
172   On selection changed.
173 */
174 void SUIT_Selector::selectionChanged()
175 {
176   if ( selectionMgr() && isEnabled() && ( !autoBlock() || !myBlock ) )
177     selectionMgr()->selectionChanged( this );
178 }
179
180 /*!
181   Checks: Is selection manager has selection mode \a mode?
182 */
183 bool SUIT_Selector::hasSelectionMode( const int mode ) const
184 {
185   if ( !selectionMgr() )
186     return false;
187
188   return selectionMgr()->hasSelectionMode( mode );
189 }
190
191 /*!
192   Puts to list \a lst selection modes from selection manager.
193 */
194 void SUIT_Selector::selectionModes( QList<int>& lst ) const
195 {
196   if ( selectionMgr() )
197     selectionMgr()->selectionModes( lst );
198 }