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() )
111 // Temporary action(to avoid selection of the objects which don't pass the filters):
113 aSel->setSelected( newOwners );
116 myIsSelChangeEnabled = true;
118 emit selectionChanged();
121 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
123 return mySelModes.contains( mode );
126 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
131 void SUIT_SelectionMgr::setSelectionModes( const int mode )
135 setSelectionModes( lst );
138 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
143 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
147 appendSelectionModes( lst );
150 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
153 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
154 map.insert( *it, 0 );
156 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
158 if ( !map.contains( *itr ) )
159 mySelModes.append( *itr );
163 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
167 removeSelectionModes( lst );
170 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
173 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
174 map.insert( *it, 0 );
176 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
180 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
181 mySelModes.append( iter.key() );
184 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
190 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
191 ok = it.current()->isOk( owner );
196 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
201 return isOk( ptr.operator->() );
204 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
206 return myFilters.contains( f );
209 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
211 if ( !hasFilter( f ) )
213 SUIT_DataOwnerPtrList selOwners;
214 if( updateSelection )
215 selected( selOwners );
217 myFilters.append( f );
219 if( updateSelection )
220 setSelected( selOwners );
224 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
226 myFilters.remove( f );
229 void SUIT_SelectionMgr::clearFilters()
234 bool SUIT_SelectionMgr::autoDeleteFilter() const
236 return myFilters.autoDelete();
239 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
241 myFilters.setAutoDelete( on );
244 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
247 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )