1 // Copyright (C) 2005-2021 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : LIGHTGUI_DataObject.cxx
20 // Author : Julia DOROVSKIKH
22 #include "LIGHTGUI_DataObject.h"
23 #include "LIGHTGUI_DataModel.h"
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_Session.h>
29 \class LIGHTGUI_DataObject
30 \brief LIGHT module data object.
32 This class presents an elementary unit of the data model.
33 It includes presentation methods like: name(), icon(), toolTip(), etc.
38 \param id line identifier
39 \param txt text line corresponding to the data object
40 \param parent parent data object
42 \note Due to virtual inheritance, the constructor explicitly
43 invokes constructor of all base classes
45 LIGHTGUI_DataObject::LIGHTGUI_DataObject( const int id,
47 SUIT_DataObject* parent )
48 : CAM_DataObject( parent ),
49 LightApp_DataObject( parent ),
58 LIGHTGUI_DataObject::~LIGHTGUI_DataObject()
63 \brief Get data object name.
64 \return data object name
66 QString LIGHTGUI_DataObject::name() const
68 return myLineTxt.trimmed().isEmpty() ? QObject::tr( "LIGHT_PARAGRAPH" ) : myLineTxt;
72 \brief Get data object entry.
73 \return data object entry
75 QString LIGHTGUI_DataObject::entry() const
77 return LIGHTGUI_DataModel::entry( id() );
81 \brief Get data object icon.
82 \param index data column index
83 \return data object icon for the specified column
85 QPixmap LIGHTGUI_DataObject::icon( const int index ) const
87 if ( index == NameId ) {
88 // show icon only for the "Name" column
89 static QPixmap pxp = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_PARAGRAPH" ), false );
90 static QPixmap pxl = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LINE" ), false );
91 return myLineTxt.trimmed().isEmpty() ? pxp : pxl;
93 return LightApp_DataObject::icon( index );
97 \brief Get data object tooltip.
98 \param index data column index
99 \return data object tooltip for the specified column
101 QString LIGHTGUI_DataObject::toolTip( const int /*index*/ ) const
103 // show the same tooltip for all columns
104 return lineText().trimmed().isEmpty() ?
105 QString( QObject::tr( "LIGHT_PARAGRAPH") + " %1" ).arg( parent()->childPos( this ) + 1 ) :
106 QString( QObject::tr( "LIGHT_LINE" ) + " %1: %2" ).arg( lineNb() ).arg( lineText() );
110 \brief Get text line corresponding to the data object.
111 \return text line (empty lines means paragraph)
114 QString LIGHTGUI_DataObject::lineText() const
120 \brief Set text line corresponding to the data object.
121 \param txt text line (empty lines means paragraph)
124 void LIGHTGUI_DataObject::setLineText( const QString& txt )
130 \brief Get line number.
133 int LIGHTGUI_DataObject::lineNb() const
135 if ( level() == 1 ) // root object
139 SUIT_DataObject* o = (SUIT_DataObject*)this;
140 if ( level() == 3 ) {
141 pos += parent()->childPos( this ) + 1;
144 o = o->prevBrother();
146 pos += o->childCount() + 1;
147 o = o->prevBrother();
154 \brief Get line identifier.
155 \return line identifier
157 int LIGHTGUI_DataObject::id() const