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