Developer Documentation

QtWidgetObject.cc
1
2 /*===========================================================================*\
3 * *
4 * OpenFlipper *
5 * Copyright (c) 2001-2015, RWTH-Aachen University *
6 * Department of Computer Graphics and Multimedia *
7 * All rights reserved. *
8 * www.openflipper.org *
9 * *
10 *---------------------------------------------------------------------------*
11 * This file is part of OpenFlipper. *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41 \*===========================================================================*/
42
43
44
45 //=============================================================================
46 //
47 // QtWidget Object
48 //
49 //=============================================================================
50
51 //== INCLUDES =================================================================
52 #include "QtWidgetObject.hh"
53 #include "QtWidget.hh"
54
55 //== DEFINES ==================================================================
56
57 //== TYPEDEFS =================================================================
58 QtWidgetObject::QtWidgetObject( ) :
59 BaseObjectData(),
60 widgetNode_(NULL)
61 {
62 setDataType(DATA_QT_WIDGET);
63 setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
64 init(NULL);
65 }
66
70 QtWidgetObject::QtWidgetObject(const QtWidgetObject & _object) :
71 BaseObjectData(_object),
72 widgetNode_(NULL)
73 {
74 init(_object.widget());
75 setName( name() );
76 }
77
81 QtWidgetObject::~QtWidgetObject()
82 {
83 // Delete the data attached to this object ( this will remove all perObject data)
84 // Not the best way to do it but it will work.
85 // This is only necessary if people use references to the light below and
86 // they do something with the light in the destructor of their
87 // perObjectData.
88 deleteData();
89
90 // Move children to parent
91 BaseNode* parent = static_cast<BaseNode*>(widgetNode_)->parent();
92
93 // First, collect all children as the iterator will get invalid if we delete while iterating!
94 std::vector< BaseNode*> children;
95 for (BaseNode::ChildIter cIt=widgetNode_->childrenBegin(); cIt!=widgetNode_->childrenEnd(); ++cIt)
96 children.push_back( (*cIt) );
97
98 // Move the children
99 for (unsigned int i = 0 ; i < children.size(); ++i )
100 children[i]->set_parent(parent);
101
102 // Delete the scenegraph node
103 delete widgetNode_;
104 }
105
109 void QtWidgetObject::cleanup() {
110
111 BaseObjectData::cleanup();
112
113 widgetNode_ = NULL;
114
115 setDataType(DATA_QT_WIDGET);
116 setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
117
118 }
119
123 BaseObject* QtWidgetObject::copy() {
124 QtWidgetObject* object = new QtWidgetObject(*this);
125 return dynamic_cast< BaseObject* >(object);
126 }
127
130 void QtWidgetObject::init(QWidget* _widget) {
131
132 widgetNode_ = new QtWidgetNode( _widget ,materialNode() , "QtWidgetNode");
133 }
134
135 // ===============================================================================
136 // Name/Path Handling
137 // ===============================================================================
138
142 void QtWidgetObject::setName( QString _name ) {
143 BaseObjectData::setName(_name);
144
145 std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
146 widgetNode_->name( nodename );
147 }
148
149 // ===============================================================================
150 // Visualization
151 // ===============================================================================
152
153 QtWidgetNode* QtWidgetObject::qtWidgetNode() {
154 return widgetNode_;
155 }
156
157
158 bool QtWidgetObject::hasNode(BaseNode* _node) {
159 if ( BaseObjectData::hasNode(_node) )
160 return true;
161
162 if ( _node == widgetNode_ )
163 return true;
164
165 return false;
166 }
167
168 // ===============================================================================
169 // Object information
170 // ===============================================================================
171
177 QString QtWidgetObject::getObjectinfo() {
178 QString output;
179
180 output += "========================================================================\n";
181 output += BaseObjectData::getObjectinfo();
182
183 if ( dataType( DATA_QT_WIDGET ) ) {
184 output += "Qt Accessible Name: ";
185 output += widgetNode_->widget()->accessibleName();
186 output += "\n";
187 } else {
188 output += "!!Unable to access data type DATA_QT_WIDGET ";
189 }
190 output += "========================================================================\n";
191 return output;
192 }
193
194 // ===============================================================================
195 // Picking
196 // ===============================================================================
197
204 bool QtWidgetObject::picked( uint _node_idx ) {
205 return ( _node_idx == widgetNode_->id() );
206 }
207
208 void QtWidgetObject::enablePicking( bool _enable ) {
209 widgetNode_->enablePicking( _enable );
210 }
211
212 bool QtWidgetObject::pickingEnabled() {
213 return widgetNode_->pickingEnabled();
214 }
215
216 void QtWidgetObject::show() {
217 if ( !visible_ ) {
218 BaseObjectData::show();
219 visible_ = true;
220
221 static_cast<BaseNode*>(widgetNode_)->show();
222
223 emit visibilityChanged( id() );
224 }
225 }
226
227 void QtWidgetObject::hide() {
228 if ( visible_ ) {
229 BaseObjectData::hide();
230 visible_ = false;
231 static_cast<BaseNode*>(widgetNode_)->hide();
232
233 emit visibilityChanged( id() );
234 }
235 }
236
237 void QtWidgetObject::visible(bool _visible) {
238 if ( _visible )
239 show();
240 else
241 hide();
242 }
243
244 bool QtWidgetObject::visible() {
245 return visible_;
246 }
247
248
249 // ===============================================================================
250 // Update
251 // ===============================================================================
252
253 void QtWidgetObject::update(UpdateType _type) {
254 BaseObject::update(_type);
255 }
256
257
258 //=============================================================================
259
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
QtWidgetObject::show
virtual void show()
Show Node.
Definition: QtWidgetObject.cc:216
QtWidgetObject::QtWidgetObject
QtWidgetObject()
constructor
Definition: QtWidgetObject.cc:58
QtWidgetObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: QtWidgetObject.cc:204
BaseObject::visibilityChanged
void visibilityChanged(int _objectId)
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
BaseObjectData::show
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
Definition: BaseObjectData.cc:188
QtWidgetObject::hide
virtual void hide()
Hide Node.
Definition: QtWidgetObject.cc:227
BaseObjectData::setName
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
ACG::SceneGraph::QtWidgetNode
Definition: QtWidgetNode.hh:80
QtWidgetObject::copy
BaseObject * copy()
Definition: QtWidgetObject.cc:123
BaseObject
Definition: BaseObject.hh:82
BaseObjectData::hasNode
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
Definition: BaseObjectData.cc:229
QtWidgetObject::qtWidgetNode
ACG::SceneGraph::QtWidgetNode * qtWidgetNode()
Get the scenegraph Node.
Definition: QtWidgetObject.cc:153
QtWidgetObject
Definition: QtWidgetObject.hh:74
QtWidgetObject.hh
QtWidgetObject::visible
virtual bool visible()
Show Node.
Definition: QtWidgetObject.cc:244
QtWidgetObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: QtWidgetObject.cc:212
QtWidget.hh
QtWidgetObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: QtWidgetObject.cc:208
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: MeshNode2T_impl.hh:423
QtWidgetObject::~QtWidgetObject
virtual ~QtWidgetObject()
destructor
Definition: QtWidgetObject.cc:81
QtWidgetNode
ACG::SceneGraph::QtWidgetNode QtWidgetNode
Simple Name for QtWidgetNode.
Definition: QtWidgetTypes.hh:67
BaseObject::visible_
bool visible_
Definition: BaseObject.hh:274
QtWidgetObject::init
virtual void init(QWidget *_widget)
Initialize current object, including all related nodes.
Definition: QtWidgetObject.cc:130
BaseObjectData::cleanup
virtual void cleanup() override
Definition: BaseObjectData.cc:102
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T_impl.hh:294
BaseObject::parent
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:466
setTypeIcon
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
BaseObjectData::hide
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
Definition: BaseObjectData.cc:197
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
BaseObjectData
Definition: BaseObjectData.hh:102
UpdateType
Update type class.
Definition: UpdateType.hh:60
DATA_QT_WIDGET
#define DATA_QT_WIDGET
Definition: QtWidget.hh:59
ACG::SceneGraph::BaseNode::ChildIter
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:286
QtWidgetObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: QtWidgetObject.cc:109
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
QtWidgetObject::update
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: QtWidgetObject.cc:253
QtWidgetObject::widgetNode_
QtWidgetNode * widgetNode_
Get the scenegraph Node.
Definition: QtWidgetObject.hh:139
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T_impl.hh:265
QtWidgetObject::hasNode
virtual bool hasNode(BaseNode *_node)
Get the scenegraph Node.
Definition: QtWidgetObject.cc:158
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T_impl.hh:415
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
QtWidgetObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: QtWidgetObject.cc:177
BaseObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
QtWidgetObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: QtWidgetObject.cc:142
ACG::SceneGraph::ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: MeshNode2T_impl.hh:269
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenEnd
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T_impl.hh:298