1 #include "SUIT_SelectionMgr.h"
3 /*!\class SUIT_SelectionMgr
4 * Provide selection manager. Manipulate by selection filters, modes, data owners.
7 /*!constructor. initialize myIterations and myIsSelChangeEnabled.*/
8 SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback )
9 : myIterations( Feedback ? 1 : 0 ),
10 myIsSelChangeEnabled( true )
14 /*!destructor. mySelectors auto delete.*/
15 SUIT_SelectionMgr::~SUIT_SelectionMgr()
17 mySelectors.setAutoDelete( true );
20 /*!Add selector \a sel to selectors list,if it's not exists in list.*/
21 void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
23 if ( sel && !mySelectors.contains( sel ) )
24 mySelectors.append( sel );
27 /*!Remove selector \a sel from list.*/
28 void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
30 mySelectors.remove( sel );
33 /*!Gets selectors list to \a lst.*/
34 void SUIT_SelectionMgr::selectors( QPtrList<SUIT_Selector>& lst ) const
37 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
38 lst.append( it.current() );
41 /*!Gets selectors list to \a lst with type \a typ.*/
42 void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList<SUIT_Selector>& lst ) const
45 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
47 if ( it.current()->type() == typ )
48 lst.append( it.current() );
52 /*! Sets ebabled to \a on for all data owners with type \a typ.
54 void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
56 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
58 if ( typ.isEmpty() || it.current()->type() == typ )
59 it.current()->setEnabled( on );
63 /*! Gets selected data owners from list with type \a type to list \a lst.
65 void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
69 QMap<const SUIT_DataOwner*, int> map;
70 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
72 if ( !type.isEmpty() && it.current()->type() != type )
74 SUIT_DataOwnerPtrList curList;
75 it.current()->selected( curList );
76 for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
78 const SUIT_DataOwnerPtr& ptr = *itr;
79 if ( !map.contains( ptr.operator->() ) )
81 map.insert( ptr.operator->(), 0 );
86 /*! Sets selected data owners from \a lst and append to list, if \a append - true.
88 void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
90 SUIT_DataOwnerPtrList owners;
91 filterOwners( lst, owners );
93 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
97 SUIT_DataOwnerPtrList current;
98 it.current()->selected( current );
99 for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
100 owners.append( *it );
102 it.current()->setSelected( owners );
106 /*! Clear selected data owners.
108 void SUIT_SelectionMgr::clearSelected()
110 setSelected( SUIT_DataOwnerPtrList() );
113 /*! On selection \a sel changed.
115 void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
117 if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
120 SUIT_DataOwnerPtrList owners;
122 myIsSelChangeEnabled = false;
123 sel->selected( owners );
125 SUIT_DataOwnerPtrList newOwners;
126 filterOwners( owners, newOwners );
128 for ( int i = 0; i < myIterations; i++ )
130 for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() )
132 // Temporary action(to avoid selection of the objects which don't pass the filters):
134 aSel->setSelected( newOwners );
137 myIsSelChangeEnabled = true;
139 emit selectionChanged();
142 /*! Checks: Is selection manager has selection mode \a mode?
144 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
146 return mySelModes.contains( mode );
149 /*! Gets selection modes to list \a vals.
151 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
156 /*! Set selection mode \a mode to list of selection modes.
158 void SUIT_SelectionMgr::setSelectionModes( const int mode )
162 setSelectionModes( lst );
165 /*! Sets selection modes list from \a lst.
167 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
172 /*! Append selection mode \a mode to list of selection modes.
174 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
178 appendSelectionModes( lst );
181 /*! Append selection modes \a lst list.
183 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
186 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
187 map.insert( *it, 0 );
189 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
191 if ( !map.contains( *itr ) )
192 mySelModes.append( *itr );
196 /*! Remove selection mode \a mode from list.
198 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
202 removeSelectionModes( lst );
205 /*! Remove selection modea \a lst from list.
207 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
210 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
211 map.insert( *it, 0 );
213 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
217 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
218 mySelModes.append( iter.key() );
221 /*! Checks data owner is ok?
223 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
229 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
230 ok = it.current()->isOk( owner );
235 /*! Checks data owner pointer is ok?
237 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
242 return isOk( ptr.operator->() );
245 /*! Checks selection manager has filter \a f?
247 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
249 return myFilters.contains( f );
252 /*! Install filter \a f and set selected, if \a update = true.
254 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
256 if ( !hasFilter( f ) )
258 SUIT_DataOwnerPtrList selOwners;
259 if( updateSelection )
260 selected( selOwners );
262 myFilters.append( f );
264 if( updateSelection )
265 setSelected( selOwners );
269 /*! Remove filter \a f from filters list.
271 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
273 myFilters.remove( f );
276 /*! Clear filters list.
278 void SUIT_SelectionMgr::clearFilters()
283 /*! Sets auto delete filter.
285 bool SUIT_SelectionMgr::autoDeleteFilter() const
287 return myFilters.autoDelete();
290 /*! Sets auto delete filter to \a on.
292 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
294 myFilters.setAutoDelete( on );
297 /*! Gets good data owners list to \a out from \a in.
299 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
302 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )