1 #include "SUIT_SelectionMgr.h"
3 /*!constructor. initialize myIterations and myIsSelChangeEnabled.*/
4 SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback )
5 : myIterations( Feedback ? 1 : 0 ),
6 myIsSelChangeEnabled( true )
10 /*!destructor. mySelectors auto delete.*/
11 SUIT_SelectionMgr::~SUIT_SelectionMgr()
13 mySelectors.setAutoDelete( true );
16 void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
18 if ( sel && !mySelectors.contains( sel ) )
19 mySelectors.append( sel );
22 void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
24 mySelectors.remove( sel );
27 void SUIT_SelectionMgr::selectors( QPtrList<SUIT_Selector>& lst ) const
30 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
31 lst.append( it.current() );
34 void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList<SUIT_Selector>& lst ) const
37 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
39 if ( it.current()->type() == typ )
40 lst.append( it.current() );
44 void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
46 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
48 if ( typ.isEmpty() || it.current()->type() == typ )
49 it.current()->setEnabled( on );
53 void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
57 QMap<const SUIT_DataOwner*, int> map;
58 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
60 if ( !type.isEmpty() && it.current()->type() != type )
62 SUIT_DataOwnerPtrList curList;
63 it.current()->selected( curList );
64 for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
66 const SUIT_DataOwnerPtr& ptr = *itr;
67 if ( !map.contains( ptr.operator->() ) )
69 map.insert( ptr.operator->(), 0 );
74 void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
76 SUIT_DataOwnerPtrList owners;
77 filterOwners( lst, owners );
79 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
83 SUIT_DataOwnerPtrList current;
84 it.current()->selected( current );
85 for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
88 it.current()->setSelected( owners );
92 void SUIT_SelectionMgr::clearSelected()
94 setSelected( SUIT_DataOwnerPtrList() );
97 void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
99 if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
102 SUIT_DataOwnerPtrList owners;
104 myIsSelChangeEnabled = false;
105 sel->selected( owners );
107 SUIT_DataOwnerPtrList newOwners;
108 filterOwners( owners, newOwners );
110 for ( int i = 0; i < myIterations; i++ )
112 for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() )
114 // Temporary action(to avoid selection of the objects which don't pass the filters):
116 aSel->setSelected( newOwners );
119 myIsSelChangeEnabled = true;
121 emit selectionChanged();
124 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
126 return mySelModes.contains( mode );
129 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
134 void SUIT_SelectionMgr::setSelectionModes( const int mode )
138 setSelectionModes( lst );
141 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
146 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
150 appendSelectionModes( lst );
153 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
156 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
157 map.insert( *it, 0 );
159 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
161 if ( !map.contains( *itr ) )
162 mySelModes.append( *itr );
166 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
170 removeSelectionModes( lst );
173 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
176 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
177 map.insert( *it, 0 );
179 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
183 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
184 mySelModes.append( iter.key() );
187 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
193 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
194 ok = it.current()->isOk( owner );
199 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
204 return isOk( ptr.operator->() );
207 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
209 return myFilters.contains( f );
212 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
214 if ( !hasFilter( f ) )
216 SUIT_DataOwnerPtrList selOwners;
217 if( updateSelection )
218 selected( selOwners );
220 myFilters.append( f );
222 if( updateSelection )
223 setSelected( selOwners );
227 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
229 myFilters.remove( f );
232 void SUIT_SelectionMgr::clearFilters()
237 bool SUIT_SelectionMgr::autoDeleteFilter() const
239 return myFilters.autoDelete();
242 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
244 myFilters.setAutoDelete( on );
247 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
250 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )