Salome HOME
Renaming, add selector for selection synchronization.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ListSelector.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ListSelector.h"
24
25 #include "HYDROGUI_OrderedListWidget.h"
26
27 #include <LightApp_DataOwner.h>
28
29
30 HYDROGUI_ListSelector::HYDROGUI_ListSelector( HYDROGUI_OrderedListWidget* theListWidget,
31                                               SUIT_SelectionMgr* theSelectionMgr )
32 : SUIT_Selector( theSelectionMgr, theListWidget ),
33   myListWidget( theListWidget )
34 {
35   if ( myListWidget ) {
36     connect( myListWidget, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
37   }
38 }
39
40 /**
41   Destructor.
42 */
43 HYDROGUI_ListSelector::~HYDROGUI_ListSelector()
44 {
45 }
46
47 /*!
48   Get selector type.
49   @return the selector type
50 */
51 QString HYDROGUI_ListSelector::type() const
52
53   return "ListSelector"; 
54 }
55
56 /**
57 */
58 void HYDROGUI_ListSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
59 {
60   QStringList aSelectedEntries = myListWidget->getSelectedEntries();
61
62   foreach ( const QString& anEntry, aSelectedEntries ) {
63     if ( !anEntry.isEmpty() ) {
64       theList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anEntry ) ) );
65     }
66   }
67 }
68
69 /**
70 */
71 void HYDROGUI_ListSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
72 {
73   if ( !myListWidget ) {
74     return;
75   }
76
77   QStringList aSelectedEntries;
78   SUIT_DataOwnerPtrList::const_iterator anIt = theList.begin();
79   for ( ; anIt != theList.end(); ++anIt ) {
80     const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>( (*anIt).operator->() );
81     if ( anOwner ) {
82       aSelectedEntries << anOwner->entry();
83     }
84   }
85  
86   myListWidget->setSelectedEntries( aSelectedEntries );
87 }
88
89 /**
90   Called when the list selection is changed.
91 */
92 void HYDROGUI_ListSelector::onSelectionChanged()
93 {
94   selectionChanged();
95 }