]> SALOME platform Git repositories - samples/light.git/blob - src/LIGHTGUI/LIGHTGUI_DataObject.cxx
Salome HOME
Using LightApp library
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_DataObject.cxx
1 //  LIGHT : sample (no-corba-engine) SALOME module
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //  Author : Julia DOROVSKIKH
23 //  Date   : 01/01/2005
24 //  $Header$
25
26 #include "LIGHTGUI_DataObject.h"
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29
30 /*!
31  *  Class:       LIGHTGUI_DataObject
32  *  Description: LIGHT module's data object
33  */
34
35 //=================================================================================
36 // function : LIGHTGUI_DataObject()
37 // purpose  : default constructor
38 //=================================================================================
39 LIGHTGUI_DataObject::LIGHTGUI_DataObject ( SUIT_DataObject* parent )
40 : LightApp_DataObject( parent ),
41   CAM_DataObject( parent )    
42 {
43 }
44
45 //=================================================================================
46 // function : LIGHTGUI_DataObject()
47 // purpose  : constructor
48 //=================================================================================
49 LIGHTGUI_DataObject::LIGHTGUI_DataObject ( const QString& line_text, SUIT_DataObject* parent )
50 : LightApp_DataObject( parent ),
51   myLineTxt( line_text ),
52   CAM_DataObject( parent)
53 {
54 }
55
56 //=================================================================================
57 // function : ~LIGHTGUI_DataObject()
58 // purpose  : destructor
59 //=================================================================================
60 LIGHTGUI_DataObject::~LIGHTGUI_DataObject()
61 {
62 }
63
64 /*!Gets object ID.
65  *\retval QString
66  */
67 QString LIGHTGUI_DataObject::entry() const
68 {
69   QString aStr = QString("LIGHTGUI_%1").arg(lineNb());
70   return aStr;
71 }
72
73 //=================================================================================
74 // function : name()
75 // purpose  : gets an name of the object
76 //=================================================================================
77 QString LIGHTGUI_DataObject::name() const
78 {
79   return myLineTxt.stripWhiteSpace().isEmpty() ? QObject::tr( "LIGHT_PARAGRAPH" ) : myLineTxt ;
80 }
81
82 //=================================================================================
83 // function : icon()
84 // purpose  : gets an icon for the data object
85 //=================================================================================
86 QPixmap LIGHTGUI_DataObject::icon() const
87 {
88   static QPixmap pxp = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_PARAGRAPH" ), false );
89   static QPixmap pxl = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LINE" ), false );
90   return myLineTxt.stripWhiteSpace().isEmpty() ? pxp : pxl;
91 }
92
93 //=================================================================================
94 // function : toolTip()
95 // purpose  : gets a tooltip for the object (to be displayed in the Object Browser)
96 //=================================================================================
97 QString LIGHTGUI_DataObject::toolTip() const
98 {
99   return lineText().stripWhiteSpace().isEmpty() ?
100     QString( QObject::tr( "LIGHT_PARAGRAPH") + " %1" ).arg( parent()->childPos( this ) + 1 ) :
101     QString( QObject::tr( "LIGHT_LINE" ) + " %1: %2" ).arg( lineNb() ).arg( lineText() );
102 }
103
104 //=================================================================================
105 // function : lineText()
106 // purpose  : gets line text
107 //=================================================================================
108 QString LIGHTGUI_DataObject::lineText() const
109 {
110   return myLineTxt;
111 }
112
113 //=================================================================================
114 // function : setLineText()
115 // purpose  : sets line text
116 //=================================================================================
117 void LIGHTGUI_DataObject::setLineText( const QString& text )
118 {
119   myLineTxt = text;
120 }
121
122 //=================================================================================
123 // function : lineNb()
124 // purpose  : gets the line number
125 //=================================================================================
126 int LIGHTGUI_DataObject::lineNb() const
127 {
128   if ( level() == 1 ) // root object
129     return -1;
130   int pos = 0;
131   if ( parent() ) {
132     SUIT_DataObject* o = (SUIT_DataObject*)this;
133     if ( level() == 3 ) {
134       pos += parent()->childPos( this ) + 1;
135       o = parent();
136     }
137     o = o->prevBrother();
138     while ( o ) {
139       pos += o->childCount() + 1;
140       o = o->prevBrother();
141     }
142   }
143   return pos;
144 }
145
146 /*!
147  *  Class:       LIGHTGUI_ModuleObject
148  *  Description: LIGHT module's root data object
149  */
150
151 //=================================================================================
152 // function : LIGHTGUI_ModuleObject()
153 // purpose  : one more constructor
154 //=================================================================================
155 LIGHTGUI_ModuleObject::LIGHTGUI_ModuleObject ( CAM_DataModel* dm, SUIT_DataObject* parent )
156 : LIGHTGUI_DataObject( parent ),
157   CAM_RootObject( dm, parent ),
158   CAM_DataObject( parent )
159 {
160 }
161
162 //=================================================================================
163 // function : name()
164 // purpose  : gets an name of the root object
165 //=================================================================================
166 QString LIGHTGUI_ModuleObject::name() const
167 {
168   return QObject::tr( "LIGHT_LIGHT" );
169 }
170
171 //=================================================================================
172 // function : icon()
173 // purpose  : gets an icon for the root object
174 //=================================================================================
175 QPixmap LIGHTGUI_ModuleObject::icon() const
176 {
177   static QPixmap px = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LIGHT" ), false );
178   return px;
179 }
180
181 //=================================================================================
182 // function : toolTip()
183 // purpose  : gets a tootip for the root object
184 //=================================================================================
185 QString LIGHTGUI_ModuleObject::toolTip() const
186 {
187   return QObject::tr( "LIGHT_ROOT_TOOLTIP" );
188 }