Back to index

salome-gui  6.5.0
SUIT_Selector.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SUIT_Selector.h"
00024 
00025 #include "SUIT_SelectionMgr.h"
00026 
00027 #include <QObject>
00028 
00033 class SUIT_Selector::Destroyer : public QObject
00034 {
00035 public:
00036   Destroyer( SUIT_Selector*, QObject* = 0 );
00037   virtual ~Destroyer();
00038 
00039   SUIT_Selector* selector() const;
00040   void           setSelector( SUIT_Selector* );
00041 
00042 private:
00043   SUIT_Selector* mySelector;
00044 };
00045 
00046 SUIT_Selector::Destroyer::Destroyer( SUIT_Selector* s, QObject* p )
00047 : QObject( p ),
00048   mySelector( s )
00049 {
00050 }
00051 
00052 SUIT_Selector::Destroyer::~Destroyer()
00053 {
00054   SUIT_Selector* s = mySelector;
00055   mySelector = 0;
00056   if ( s )
00057     delete s;
00058 }
00059 
00060 SUIT_Selector* SUIT_Selector::Destroyer::selector() const
00061 {
00062   return mySelector;
00063 }
00064 
00065 void SUIT_Selector::Destroyer::setSelector( SUIT_Selector* s )
00066 {
00067   mySelector = s;
00068 }
00069 
00077 SUIT_Selector::SUIT_Selector( SUIT_SelectionMgr* selMgr, QObject* parent )
00078 : mySelMgr( selMgr ),
00079 myBlock( false ),
00080 myEnabled( true ),
00081 myAutoBlock( true ),
00082 myDestroyer( 0 )
00083 {
00084   if ( selMgr )
00085     selMgr->installSelector( this );
00086 
00087   if ( parent )
00088     myDestroyer = new Destroyer( this, parent );
00089 }
00090 
00094 SUIT_Selector::~SUIT_Selector()
00095 {
00096   if ( selectionMgr() )
00097     selectionMgr()->removeSelector( this );
00098 
00099   if ( myDestroyer && myDestroyer->selector() == this )
00100   {
00101     myDestroyer->setSelector( 0 );
00102     delete myDestroyer;
00103   }
00104 }
00105 
00109 SUIT_SelectionMgr* SUIT_Selector::selectionMgr() const
00110 {
00111   return mySelMgr;
00112 }
00113 
00117 bool SUIT_Selector::isEnabled() const
00118 {
00119   return myEnabled;
00120 }
00121 
00125 void SUIT_Selector::setEnabled( const bool on )
00126 {
00127   myEnabled = on;
00128 }
00129 
00133 bool SUIT_Selector::autoBlock() const
00134 {
00135   return myAutoBlock;
00136 }
00137 
00141 void SUIT_Selector::setAutoBlock( const bool on )
00142 {
00143   myAutoBlock = on;
00144 }
00145 
00149 void SUIT_Selector::selected( SUIT_DataOwnerPtrList& lst ) const
00150 {
00151   lst.clear();
00152   getSelection( lst );
00153 }
00154 
00158 void SUIT_Selector::setSelected( const SUIT_DataOwnerPtrList& lst )
00159 {
00160   if ( !isEnabled() )
00161     return;
00162 
00163   bool block = myBlock;
00164   myBlock = true;
00165 
00166   setSelection( lst );
00167 
00168   myBlock = block;
00169 }
00170 
00174 void SUIT_Selector::selectionChanged()
00175 {
00176   if ( selectionMgr() && isEnabled() && ( !autoBlock() || !myBlock ) )
00177     selectionMgr()->selectionChanged( this );
00178 }
00179 
00183 bool SUIT_Selector::hasSelectionMode( const int mode ) const
00184 {
00185   if ( !selectionMgr() )
00186     return false;
00187 
00188   return selectionMgr()->hasSelectionMode( mode );
00189 }
00190 
00194 void SUIT_Selector::selectionModes( QList<int>& lst ) const
00195 {
00196   if ( selectionMgr() )
00197     selectionMgr()->selectionModes( lst );
00198 }