1 #include "SUIT_SelectionMgr.h"
3 SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback )
4 : myIterations( Feedback ? 1 : 0 ),
5 myIsSelChangeEnabled( true )
9 SUIT_SelectionMgr::~SUIT_SelectionMgr()
13 void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
15 if ( sel && !mySelectors.contains( sel ) )
16 mySelectors.append( sel );
19 void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
21 mySelectors.remove( sel );
24 void SUIT_SelectionMgr::selectors( QPtrList<SUIT_Selector>& lst ) const
27 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
28 lst.append( it.current() );
31 void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList<SUIT_Selector>& lst ) const
34 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
36 if ( it.current()->type() == typ )
37 lst.append( it.current() );
41 void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
43 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
45 if ( typ.isEmpty() || it.current()->type() == typ )
46 it.current()->setEnabled( on );
50 void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
54 QMap<const SUIT_DataOwner*, int> map;
55 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
57 if ( !type.isEmpty() && it.current()->type() != type )
59 SUIT_DataOwnerPtrList curList;
60 it.current()->selected( curList );
61 for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
63 const SUIT_DataOwnerPtr& ptr = *itr;
64 if ( !map.contains( ptr.operator->() ) )
66 map.insert( ptr.operator->(), 0 );
71 void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
73 SUIT_DataOwnerPtrList owners;
74 filterOwners( lst, owners );
76 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
80 SUIT_DataOwnerPtrList current;
81 it.current()->selected( current );
82 for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
85 it.current()->setSelected( owners );
89 void SUIT_SelectionMgr::clearSelected()
91 setSelected( SUIT_DataOwnerPtrList() );
94 void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
96 if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
99 SUIT_DataOwnerPtrList owners;
101 myIsSelChangeEnabled = false;
102 sel->selected( owners );
104 SUIT_DataOwnerPtrList newOwners;
105 filterOwners( owners, newOwners );
107 for ( int i = 0; i < myIterations; i++ )
109 for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() )
112 aSel->setSelected( newOwners );
115 myIsSelChangeEnabled = true;
117 emit selectionChanged();
120 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
122 return mySelModes.contains( mode );
125 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
130 void SUIT_SelectionMgr::setSelectionModes( const int mode )
134 setSelectionModes( lst );
137 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
142 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
146 appendSelectionModes( lst );
149 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
152 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
153 map.insert( *it, 0 );
155 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
157 if ( !map.contains( *itr ) )
158 mySelModes.append( *itr );
162 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
166 removeSelectionModes( lst );
169 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
172 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
173 map.insert( *it, 0 );
175 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
179 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
180 mySelModes.append( iter.key() );
183 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
189 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
190 ok = it.current()->isOk( owner );
195 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
200 return isOk( ptr.operator->() );
203 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
205 return myFilters.contains( f );
208 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
210 if ( !hasFilter( f ) )
212 SUIT_DataOwnerPtrList selOwners;
213 if( updateSelection )
214 selected( selOwners );
216 myFilters.append( f );
218 if( updateSelection )
219 setSelected( selOwners );
223 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
225 myFilters.remove( f );
228 void SUIT_SelectionMgr::clearFilters()
233 bool SUIT_SelectionMgr::autoDeleteFilter() const
235 return myFilters.autoDelete();
238 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
240 myFilters.setAutoDelete( on );
243 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
246 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )