]> SALOME platform Git repositories - samples/light.git/blob - src/LIGHTGUI/LIGHTGUI_DataObject.cxx
Salome HOME
9659f0c7dad8ebeaf7195e9a8c639f4eb84d32c1
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_DataObject.cxx
1 //  Copyright (C) 2005-2008  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.
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 // LIGHT : sample (no-corba-engine) SALOME module
20 // File   : LIGHTGUI_DataObject.cxx
21 // Author : Julia DOROVSKIKH
22 //
23 #include "LIGHTGUI_DataObject.h"
24 #include "LIGHTGUI_DataModel.h"
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <QString>
29
30 /*!
31   \class LIGHTGUI_DataObject
32   \brief LIGHT module data object.
33 */
34
35 /*!
36   \brief Constructor.
37   \param id line identifier
38   \param txt text line corresponding to the data object
39   \param parent parent data object
40 */
41 LIGHTGUI_DataObject::LIGHTGUI_DataObject( const int id, 
42                                           const QString& txt, 
43                                           SUIT_DataObject* parent )
44 : CAM_DataObject( parent ),
45   LightApp_DataObject( parent ),
46   myLineTxt( txt ),
47   myId( id )
48 {
49 }
50
51 /*!
52   \brief Destructor.
53 */
54 LIGHTGUI_DataObject::~LIGHTGUI_DataObject()
55 {
56 }
57
58 /*!
59   \brief Get data object name.
60   \return data object name
61 */
62 QString LIGHTGUI_DataObject::name() const
63 {
64   return myLineTxt.trimmed().isEmpty() ? QObject::tr( "LIGHT_PARAGRAPH" ) : myLineTxt;
65 }
66
67 /*!
68   \brief Get data object entry.
69   \return data object entry
70 */
71 QString LIGHTGUI_DataObject::entry() const
72 {
73   return LIGHTGUI_DataModel::entry( id() );
74 }
75
76 /*!
77   \brief Get data object icon.
78   \param index data column index
79   \return data object icon for the specified column
80 */
81 QPixmap LIGHTGUI_DataObject::icon( const int index ) const
82 {
83   if ( index == NameId ) {
84     // show icon only for the "Name" column
85     static QPixmap pxp = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_PARAGRAPH" ), false );
86     static QPixmap pxl = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LINE" ), false );
87     return myLineTxt.trimmed().isEmpty() ? pxp : pxl;
88   }
89   return LightApp_DataObject::icon( index );
90 }
91
92 /*!
93   \brief Get data object tooltip.
94   \param index data column index
95   \return data object tooltip for the specified column
96 */
97 QString LIGHTGUI_DataObject::toolTip( const int /*index*/ ) const
98 {
99   // show the same tooltip for all columns
100   return lineText().trimmed().isEmpty() ?
101     QString( QObject::tr( "LIGHT_PARAGRAPH") + " %1" ).arg( parent()->childPos( this ) + 1 ) :
102     QString( QObject::tr( "LIGHT_LINE" ) + " %1: %2" ).arg( lineNb() ).arg( lineText() );
103 }
104
105 /*!
106   \brief Get text line corresponding to the data object.
107   \return text line (empty lines means paragraph)
108   \sa setLineText()
109 */
110 QString LIGHTGUI_DataObject::lineText() const
111 {
112   return myLineTxt;
113 }
114
115 /*!
116   \brief Set text line corresponding to the data object.
117   \param txt text line (empty lines means paragraph)
118   \sa lineText()
119 */
120 void LIGHTGUI_DataObject::setLineText( const QString& txt )
121 {
122   myLineTxt = txt;
123 }
124
125 /*!
126   \brief Get line number.
127   \return line number
128 */
129 int LIGHTGUI_DataObject::lineNb() const
130 {
131   if ( level() == 1 ) // root object
132     return -1;
133   int pos = 0;
134   if ( parent() ) {
135     SUIT_DataObject* o = (SUIT_DataObject*)this;
136     if ( level() == 3 ) {
137       pos += parent()->childPos( this ) + 1;
138       o = parent();
139     }
140     o = o->prevBrother();
141     while ( o ) {
142       pos += o->childCount() + 1;
143       o = o->prevBrother();
144     }
145   }
146   return pos;
147 }
148
149 /*!
150   \brief Get line identifier.
151   \return line identifier
152 */
153 int LIGHTGUI_DataObject::id() const
154 {
155   return myId;
156 }