1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ObjComboBox.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_Module.h"
28 #include <LightApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
35 #include <HYDROData_Iterator.h>
36 #include <HYDROData_Document.h>
38 HYDROGUI_ObjComboBox::HYDROGUI_ObjComboBox( HYDROGUI_Module* theModule, const QString& theTitle, const ObjectKind& theType, QWidget* theParent )
39 : QWidget( theParent ),
41 myModule( theModule ),
44 QBoxLayout* base = new QHBoxLayout( this );
47 base->addWidget( new QLabel( theTitle, this ) );
48 base->addWidget( myObject = new QComboBox( this ) );
50 myObject->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
52 // Connect signals and slots
53 connect( myObject, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onIndexChanged( int ) ) );
54 connect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
57 HYDROGUI_ObjComboBox::~HYDROGUI_ObjComboBox()
61 HYDROGUI_Module* HYDROGUI_ObjComboBox::module() const
66 ObjectKind HYDROGUI_ObjComboBox::objectType() const
71 HYDROGUI_ObjComboBoxFilter* HYDROGUI_ObjComboBox::objectFilter() const
76 void HYDROGUI_ObjComboBox::setObjectFilter( HYDROGUI_ObjComboBoxFilter* filter )
81 void HYDROGUI_ObjComboBox::reset()
84 myObject->addItems( objectNames() );
88 void HYDROGUI_ObjComboBox::setSectedObject( const QString& theName )
90 int aNewIdx = myObject->findText( theName );
91 if ( aNewIdx != myObject->currentIndex() )
92 myObject->setCurrentIndex( aNewIdx );
95 QString HYDROGUI_ObjComboBox::selectedObject() const
97 return myObject->currentText();
100 SUIT_SelectionMgr* HYDROGUI_ObjComboBox::selectionMgr() const
102 SUIT_SelectionMgr* aSelMgr = 0;
105 LightApp_Application* app = module()->getApp();
107 aSelMgr = app->selectionMgr();
112 QStringList HYDROGUI_ObjComboBox::objectNames() const
115 for ( HYDROData_Iterator it( HYDROData_Document::Document( module()->getStudyId() ), objectType() ); it.More(); it.Next() )
117 if ( !objectFilter() || objectFilter()->isOk( it.Current() ) )
118 aNames.append( it.Current()->GetName() );
123 void HYDROGUI_ObjComboBox::onIndexChanged( int idx )
128 emit objectSelected( myObject->itemText( idx ) );
131 void HYDROGUI_ObjComboBox::onSelectionChanged()
134 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
135 if ( !anObject.IsNull() )
136 idx = myObject->findText( anObject->GetName() );
138 myObject->setCurrentIndex( idx );
140 emit objectSelected( myObject->itemText( idx ) );