1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ListSelector.h"
21 #include "HYDROGUI_OrderedListWidget.h"
24 #include <SUIT_DataOwner.h>
25 class TestOwner : public SUIT_DataOwner
28 TestOwner( const QString& entry ) { myEntry = entry; }
29 virtual ~TestOwner() {}
31 QString keyString() const { return myEntry; }
32 QString entry() const { return myEntry; }
37 #define OWNER_CLASS TestOwner
40 #include <LightApp_DataOwner.h>
41 #define OWNER_CLASS LightApp_DataOwner
45 HYDROGUI_ListSelector::HYDROGUI_ListSelector( HYDROGUI_OrderedListWidget* theListWidget,
46 SUIT_SelectionMgr* theSelectionMgr )
47 : SUIT_Selector( theSelectionMgr, theListWidget ),
48 myListWidget( theListWidget )
51 connect( myListWidget, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
58 HYDROGUI_ListSelector::~HYDROGUI_ListSelector()
64 @return the selector type
66 QString HYDROGUI_ListSelector::type() const
68 return "ListSelector";
73 void HYDROGUI_ListSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
75 QStringList aSelectedEntries = myListWidget->getSelectedEntries();
77 foreach ( const QString& anEntry, aSelectedEntries ) {
78 if ( !anEntry.isEmpty() ) {
79 theList.append( SUIT_DataOwnerPtr( new OWNER_CLASS( anEntry ) ) );
86 void HYDROGUI_ListSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
88 if ( !myListWidget ) {
92 QStringList aSelectedEntries;
93 SUIT_DataOwnerPtrList::const_iterator anIt = theList.begin();
94 for ( ; anIt != theList.end(); ++anIt ) {
95 const OWNER_CLASS* anOwner = dynamic_cast<const OWNER_CLASS*>( (*anIt).operator->() );
97 aSelectedEntries << anOwner->entry();
101 myListWidget->setSelectedEntries( aSelectedEntries );
105 Called when the list selection is changed.
107 void HYDROGUI_ListSelector::onSelectionChanged()