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()
11 mySelectors.setAutoDelete( true );
14 void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel )
16 if ( sel && !mySelectors.contains( sel ) )
17 mySelectors.append( sel );
20 void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel )
22 mySelectors.remove( sel );
25 void SUIT_SelectionMgr::selectors( QPtrList<SUIT_Selector>& lst ) const
28 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
29 lst.append( it.current() );
32 void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList<SUIT_Selector>& lst ) const
35 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
37 if ( it.current()->type() == typ )
38 lst.append( it.current() );
42 void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ )
44 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
46 if ( typ.isEmpty() || it.current()->type() == typ )
47 it.current()->setEnabled( on );
51 void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& type ) const
55 QMap<const SUIT_DataOwner*, int> map;
56 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
58 if ( !type.isEmpty() && it.current()->type() != type )
60 SUIT_DataOwnerPtrList curList;
61 it.current()->selected( curList );
62 for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr )
64 const SUIT_DataOwnerPtr& ptr = *itr;
65 if ( !map.contains( ptr.operator->() ) )
67 map.insert( ptr.operator->(), 0 );
72 void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const bool append )
74 SUIT_DataOwnerPtrList owners;
75 filterOwners( lst, owners );
77 for ( SelectorListIterator it( mySelectors ); it.current(); ++it )
81 SUIT_DataOwnerPtrList current;
82 it.current()->selected( current );
83 for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it )
86 it.current()->setSelected( owners );
90 void SUIT_SelectionMgr::clearSelected()
92 setSelected( SUIT_DataOwnerPtrList() );
95 void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel )
97 if ( !sel || !myIsSelChangeEnabled || !sel->isEnabled() )
100 SUIT_DataOwnerPtrList owners;
102 myIsSelChangeEnabled = false;
103 sel->selected( owners );
105 SUIT_DataOwnerPtrList newOwners;
106 filterOwners( owners, newOwners );
108 for ( int i = 0; i < myIterations; i++ )
110 for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() )
112 // Temporary action(to avoid selection of the objects which don't pass the filters):
114 aSel->setSelected( newOwners );
117 myIsSelChangeEnabled = true;
119 emit selectionChanged();
122 bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const
124 return mySelModes.contains( mode );
127 void SUIT_SelectionMgr::selectionModes( QValueList<int>& vals ) const
132 void SUIT_SelectionMgr::setSelectionModes( const int mode )
136 setSelectionModes( lst );
139 void SUIT_SelectionMgr::setSelectionModes( const QValueList<int>& lst )
144 void SUIT_SelectionMgr::appendSelectionModes( const int mode )
148 appendSelectionModes( lst );
151 void SUIT_SelectionMgr::appendSelectionModes( const QValueList<int>& lst )
154 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
155 map.insert( *it, 0 );
157 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
159 if ( !map.contains( *itr ) )
160 mySelModes.append( *itr );
164 void SUIT_SelectionMgr::removeSelectionModes( const int mode )
168 removeSelectionModes( lst );
171 void SUIT_SelectionMgr::removeSelectionModes( const QValueList<int>& lst )
174 for ( QValueList<int>::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it )
175 map.insert( *it, 0 );
177 for ( QValueList<int>::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
181 for ( QMap<int, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
182 mySelModes.append( iter.key() );
185 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const
191 for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it )
192 ok = it.current()->isOk( owner );
197 bool SUIT_SelectionMgr::isOk( const SUIT_DataOwnerPtr& ptr ) const
202 return isOk( ptr.operator->() );
205 bool SUIT_SelectionMgr::hasFilter( SUIT_SelectionFilter* f ) const
207 return myFilters.contains( f );
210 void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updateSelection )
212 if ( !hasFilter( f ) )
214 SUIT_DataOwnerPtrList selOwners;
215 if( updateSelection )
216 selected( selOwners );
218 myFilters.append( f );
220 if( updateSelection )
221 setSelected( selOwners );
225 void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f )
227 myFilters.remove( f );
230 void SUIT_SelectionMgr::clearFilters()
235 bool SUIT_SelectionMgr::autoDeleteFilter() const
237 return myFilters.autoDelete();
240 void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on )
242 myFilters.setAutoDelete( on );
245 void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_DataOwnerPtrList& out ) const
248 for ( SUIT_DataOwnerPtrList::const_iterator it = in.begin(); it != in.end(); ++it )