Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / LightApp / LightApp_Plot2dSelector.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "LightApp_Plot2dSelector.h"
21
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_DataObject.h"
24 #include "LightApp_Application.h"
25 #include "SUIT_SelectionMgr.h"
26
27 #ifndef DISABLE_SALOMEOBJECT
28   #include <SALOME_ListIO.hxx>
29   #ifndef DISABLE_PLOT2DVIEWER
30     #include <SPlot2d_ViewModel.h>
31   #endif
32 #endif
33
34 /*!
35   Constructor
36 */
37 LightApp_Plot2dSelector::LightApp_Plot2dSelector( Plot2d_Viewer* v, SUIT_SelectionMgr* mgr )
38   : SUIT_Selector( mgr, v ),
39     myViewer(v)
40 {
41   if ( v )
42     connect( v, SIGNAL( legendSelected( const QString& ) ), this, SLOT( onSelectionChanged( const QString& ) ) );
43     connect( v, SIGNAL( clearSelected() ), this, SLOT( onClearSelected( ) ) );
44 }
45
46 /*!
47   Destructor
48 */
49 LightApp_Plot2dSelector::~LightApp_Plot2dSelector()
50 {
51 }
52
53 /*!
54   Gets selection.
55 */
56 void LightApp_Plot2dSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
57 {
58   if( !myCurEntry.isNull() ) {
59 #ifndef DISABLE_SALOMEOBJECT
60     theList.append( new LightApp_DataOwner( new SALOME_InteractiveObject(qUtf8Printable(myCurEntry),"","") ) );
61 #else
62     theList.append( new LightApp_DataOwner( myCurEntry ) );
63 #endif
64   }
65 }
66
67 /*!Sets selection.*/
68 void LightApp_Plot2dSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
69 {
70 #ifndef DISABLE_SALOMEOBJECT
71   SALOME_ListIO anIOList;
72   for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) {
73     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
74     if ( owner  ) {
75       if( !owner->IO().IsNull() ) {
76             anIOList.Append(owner->IO());
77       }
78       else if ( !owner->entry().isEmpty() ) {
79             anIOList.Append( new SALOME_InteractiveObject(qUtf8Printable(owner->entry()),"","") );
80       }      
81     }
82   }
83   SPlot2d_Viewer* v = dynamic_cast<SPlot2d_Viewer*>(myViewer);
84
85   if(v)
86     v->setObjectsSelected(anIOList);
87 #endif
88 }
89
90 /*!On selection changed.*/
91 void LightApp_Plot2dSelector::onSelectionChanged( const QString& entry )
92 {
93   myCurEntry = entry;
94   selectionChanged();
95   myCurEntry = QString();
96 }
97
98 /*!On clear selected.*/
99 void LightApp_Plot2dSelector::onClearSelected( ) 
100 {
101         selectionMgr()->clearSelected();
102 }