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_ObjListBox.h>
20 #include <HYDROGUI_ObjComboBox.h>
21 #include <HYDROGUI_Tool.h>
22 #include <QGridLayout>
23 #include <QListWidget>
25 #include <QPushButton>
27 HYDROGUI_ObjListBox::HYDROGUI_ObjListBox( HYDROGUI_Module* theModule, const QString& theTitle, const ObjectKind& theType, QWidget* theParent )
28 : QWidget( theParent ),
29 myModule( theModule ),
32 myTypes.append( theType );
36 HYDROGUI_ObjListBox::HYDROGUI_ObjListBox( HYDROGUI_Module* theModule, const QString& theTitle, const QList<ObjectKind>& theTypes, QWidget* theParent )
37 : QWidget( theParent ),
39 myModule( theModule ),
45 void HYDROGUI_ObjListBox::Init(const QString& theTitle)
47 QGridLayout* aBase = new QGridLayout( this );
48 aBase->setMargin( 0 );
50 QPushButton* anInclude = new QPushButton( tr( "INCLUDE" ), this );
51 QPushButton* anExclude = new QPushButton( tr( "EXCLUDE" ), this );
53 aBase->addWidget( anInclude, 0, 0 );
54 aBase->addWidget( anExclude, 0, 1 );
55 if( !theTitle.isEmpty() )
56 aBase->addWidget( new QLabel( theTitle, this ), 1, 0 );
57 aBase->addWidget( myList = new QListWidget( this ), 1, 1, 1, 2 );
58 aBase->setColumnStretch( 0, 0 );
59 aBase->setColumnStretch( 1, 0 );
60 aBase->setColumnStretch( 2, 1 );
62 myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
63 myList->setSelectionMode( QListWidget::ExtendedSelection );
65 connect( anInclude, SIGNAL( clicked() ), this, SLOT( OnInclude() ) );
66 connect( anExclude, SIGNAL( clicked() ), this, SLOT( OnExclude() ) );
69 HYDROGUI_ObjListBox::~HYDROGUI_ObjListBox()
73 HYDROGUI_Module* HYDROGUI_ObjListBox::module() const
78 QList<ObjectKind> HYDROGUI_ObjListBox::objectTypes() const
83 HYDROGUI_ObjComboBoxFilter* HYDROGUI_ObjListBox::objectFilter() const
88 void HYDROGUI_ObjListBox::setObjectFilter( HYDROGUI_ObjComboBoxFilter* filter )
93 void HYDROGUI_ObjListBox::reset()
97 emit selectionChanged();
100 void HYDROGUI_ObjListBox::setSelectedObjects( const HYDROData_SequenceOfObjects& theObjects )
103 Append( theObjects );
106 void HYDROGUI_ObjListBox::setObjectsFromSelection()
108 setSelectedObjects( HYDROGUI_Tool::GetSelectedObjects( module() ) );
111 HYDROData_SequenceOfObjects HYDROGUI_ObjListBox::selectedObjects() const
116 void HYDROGUI_ObjListBox::OnInclude()
118 Append( HYDROGUI_Tool::GetSelectedObjects( module() ) );
119 emit selectionChanged();
122 void HYDROGUI_ObjListBox::OnExclude()
124 QList<QListWidgetItem*> aSelection = myList->selectedItems();
125 foreach( QListWidgetItem* anItem, aSelection )
127 int anIndex = myList->row( anItem );
128 myList->takeItem( anIndex );
129 mySelection.Remove( anIndex, anIndex );
131 emit selectionChanged();
134 void HYDROGUI_ObjListBox::Append( const HYDROData_SequenceOfObjects& theObjects )
136 for( int i=theObjects.Lower(), n=theObjects.Upper(); i<=n; i++ )
138 Handle( HYDROData_Entity ) anObject = theObjects.Value( i );
139 bool isOK = !anObject.IsNull() && myTypes.contains(anObject->GetKind());
140 if( myFilter && isOK )
141 isOK = myFilter->isOk( anObject );
145 QString aName = anObject->GetName();
146 myList->addItem( aName );
147 mySelection.Append( anObject );