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_ObjComboBox.h"
21 #include "HYDROGUI_Tool.h"
22 #include "HYDROGUI_Module.h"
24 #include <LightApp_Application.h>
25 #include <LightApp_SelectionMgr.h>
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_Document.h>
35 HYDROGUI_ObjComboBox::HYDROGUI_ObjComboBox( HYDROGUI_Module* theModule, const QString& theTitle, const ObjectKind& theType, QWidget* theParent )
36 : QWidget( theParent ),
38 myModule( theModule ),
41 QBoxLayout* base = new QHBoxLayout( this );
44 if ( !theTitle.isEmpty() )
45 base->addWidget( new QLabel( theTitle, this ) );
46 base->addWidget( myObject = new QComboBox( this ) );
48 myObject->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
50 // Connect signals and slots
51 connect( myObject, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onIndexChanged( int ) ) );
52 connect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
55 HYDROGUI_ObjComboBox::~HYDROGUI_ObjComboBox()
59 HYDROGUI_Module* HYDROGUI_ObjComboBox::module() const
64 ObjectKind HYDROGUI_ObjComboBox::objectType() const
69 HYDROGUI_ObjComboBoxFilter* HYDROGUI_ObjComboBox::objectFilter() const
74 void HYDROGUI_ObjComboBox::setObjectFilter( HYDROGUI_ObjComboBoxFilter* filter )
79 void HYDROGUI_ObjComboBox::reset()
81 bool block = myObject->signalsBlocked();
82 myObject->blockSignals( true );
85 myObject->addItems( objectNames() );
86 myObject->setCurrentIndex( -1 );
88 myObject->blockSignals( block );
90 onIndexChanged( myObject->currentIndex() );
94 void HYDROGUI_ObjComboBox::setSectedObject( const QString& theName )
96 int aNewIdx = myObject->findText( theName );
97 if ( aNewIdx != myObject->currentIndex() )
98 myObject->setCurrentIndex( aNewIdx );
101 QString HYDROGUI_ObjComboBox::selectedObject() const
103 return myObject->currentText();
106 SUIT_SelectionMgr* HYDROGUI_ObjComboBox::selectionMgr() const
108 SUIT_SelectionMgr* aSelMgr = 0;
111 LightApp_Application* app = module()->getApp();
113 aSelMgr = app->selectionMgr();
118 QStringList HYDROGUI_ObjComboBox::objectNames() const
121 for ( HYDROData_Iterator it( HYDROData_Document::Document( module()->getStudyId() ), objectType() ); it.More(); it.Next() )
123 if ( !objectFilter() || objectFilter()->isOk( it.Current() ) )
124 aNames.append( it.Current()->GetName() );
129 void HYDROGUI_ObjComboBox::onIndexChanged( int idx )
134 emit objectSelected( myObject->itemText( idx ) );
137 void HYDROGUI_ObjComboBox::onSelectionChanged()
139 if ( !objectFilter() || objectFilter()->isActive( this ) )
140 QTimer::singleShot( 0, this, SLOT( updateSelection() ) );
143 void HYDROGUI_ObjComboBox::updateSelection()
146 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
147 if ( !anObject.IsNull() )
148 idx = myObject->findText( anObject->GetName() );
150 if ( idx >= 0 && myObject->currentIndex() != idx )
152 myObject->setCurrentIndex( idx );
153 emit objectSelected( myObject->itemText( idx ) );