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>
36 #include <HYDROData_Iterator.h>
37 #include <HYDROData_Document.h>
39 HYDROGUI_ObjComboBox::HYDROGUI_ObjComboBox( HYDROGUI_Module* theModule, const QString& theTitle, const ObjectKind& theType, QWidget* theParent )
40 : QWidget( theParent ),
42 myModule( theModule ),
45 QBoxLayout* base = new QHBoxLayout( this );
48 if ( !theTitle.isEmpty() )
49 base->addWidget( new QLabel( theTitle, this ) );
50 base->addWidget( myObject = new QComboBox( this ) );
52 myObject->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
54 // Connect signals and slots
55 connect( myObject, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onIndexChanged( int ) ) );
56 connect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
59 HYDROGUI_ObjComboBox::~HYDROGUI_ObjComboBox()
63 HYDROGUI_Module* HYDROGUI_ObjComboBox::module() const
68 ObjectKind HYDROGUI_ObjComboBox::objectType() const
73 HYDROGUI_ObjComboBoxFilter* HYDROGUI_ObjComboBox::objectFilter() const
78 void HYDROGUI_ObjComboBox::setObjectFilter( HYDROGUI_ObjComboBoxFilter* filter )
83 void HYDROGUI_ObjComboBox::reset()
85 bool block = myObject->signalsBlocked();
86 myObject->blockSignals( true );
89 myObject->addItems( objectNames() );
90 myObject->setCurrentIndex( -1 );
92 myObject->blockSignals( block );
94 onIndexChanged( myObject->currentIndex() );
98 void HYDROGUI_ObjComboBox::setSectedObject( const QString& theName )
100 int aNewIdx = myObject->findText( theName );
101 if ( aNewIdx != myObject->currentIndex() )
102 myObject->setCurrentIndex( aNewIdx );
105 QString HYDROGUI_ObjComboBox::selectedObject() const
107 return myObject->currentText();
110 SUIT_SelectionMgr* HYDROGUI_ObjComboBox::selectionMgr() const
112 SUIT_SelectionMgr* aSelMgr = 0;
115 LightApp_Application* app = module()->getApp();
117 aSelMgr = app->selectionMgr();
122 QStringList HYDROGUI_ObjComboBox::objectNames() const
125 for ( HYDROData_Iterator it( HYDROData_Document::Document( module()->getStudyId() ), objectType() ); it.More(); it.Next() )
127 if ( !objectFilter() || objectFilter()->isOk( it.Current() ) )
128 aNames.append( it.Current()->GetName() );
133 void HYDROGUI_ObjComboBox::onIndexChanged( int idx )
138 emit objectSelected( myObject->itemText( idx ) );
141 void HYDROGUI_ObjComboBox::onSelectionChanged()
143 if ( !objectFilter() || objectFilter()->isActive( this ) )
144 QTimer::singleShot( 0, this, SLOT( updateSelection() ) );
147 void HYDROGUI_ObjComboBox::updateSelection()
150 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
151 if ( !anObject.IsNull() )
152 idx = myObject->findText( anObject->GetName() );
154 if ( idx >= 0 && myObject->currentIndex() != idx )
156 myObject->setCurrentIndex( idx );
157 emit objectSelected( myObject->itemText( idx ) );