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 * $Revision$ *
46 * $LastChangedBy$ *
47 * $Date$ *
48 * *
49 \*===========================================================================*/
50 
51 //=============================================================================
52 //
53 // QtWidget Object
54 //
55 //=============================================================================
56 
57 //== INCLUDES =================================================================
58 #include "QtWidgetObject.hh"
59 #include "QtWidget.hh"
60 
61 //== DEFINES ==================================================================
62 
63 //== TYPEDEFS =================================================================
66  widgetNode_(NULL)
67 {
69  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
70  init(NULL);
71 }
72 
77  BaseObjectData(_object),
78  widgetNode_(NULL)
79 {
80  init(_object.widget());
81  setName( name() );
82 }
83 
88 {
89  // Delete the data attached to this object ( this will remove all perObject data)
90  // Not the best way to do it but it will work.
91  // This is only necessary if people use references to the light below and
92  // they do something with the light in the destructor of their
93  // perObjectData.
94  deleteData();
95 
96  // Move children to parent
97  BaseNode* parent = static_cast<BaseNode*>(widgetNode_)->parent();
98 
99  // First, collect all children as the iterator will get invalid if we delete while iterating!
100  std::vector< BaseNode*> children;
102  children.push_back( (*cIt) );
103 
104  // Move the children
105  for (unsigned int i = 0 ; i < children.size(); ++i )
106  children[i]->set_parent(parent);
107 
108  // Delete the scenegraph node
109  delete widgetNode_;
110 }
111 
116 
118 
119  widgetNode_ = NULL;
120 
122  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
123 
124 }
125 
130  QtWidgetObject* object = new QtWidgetObject(*this);
131  return dynamic_cast< BaseObject* >(object);
132 }
133 
136 void QtWidgetObject::init(QWidget* _widget) {
137 
138  widgetNode_ = new QtWidgetNode( _widget ,materialNode() , "QtWidgetNode");
139 }
140 
141 // ===============================================================================
142 // Name/Path Handling
143 // ===============================================================================
144 
148 void QtWidgetObject::setName( QString _name ) {
150 
151  std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
152  widgetNode_->name( nodename );
153 }
154 
155 // ===============================================================================
156 // Visualization
157 // ===============================================================================
158 
160  return widgetNode_;
161 }
162 
163 
165  if ( BaseObjectData::hasNode(_node) )
166  return true;
167 
168  if ( _node == widgetNode_ )
169  return true;
170 
171  return false;
172 }
173 
174 // ===============================================================================
175 // Object information
176 // ===============================================================================
177 
184  QString output;
185 
186  output += "========================================================================\n";
187  output += BaseObjectData::getObjectinfo();
188 
189  if ( dataType( DATA_QT_WIDGET ) ) {
190  output += "Qt Accessible Name: ";
191  output += widgetNode_->widget()->accessibleName();
192  output += "\n";
193  } else {
194  output += "!!Unable to access data type DATA_QT_WIDGET ";
195  }
196  output += "========================================================================\n";
197  return output;
198 }
199 
200 // ===============================================================================
201 // Picking
202 // ===============================================================================
203 
210 bool QtWidgetObject::picked( uint _node_idx ) {
211  return ( _node_idx == widgetNode_->id() );
212 }
213 
214 void QtWidgetObject::enablePicking( bool _enable ) {
215  widgetNode_->enablePicking( _enable );
216 }
217 
219  return widgetNode_->pickingEnabled();
220 }
221 
223  if ( !visible_ ) {
225  visible_ = true;
226 
227  static_cast<BaseNode*>(widgetNode_)->show();
228 
229  emit visibilityChanged( id() );
230  }
231 }
232 
234  if ( visible_ ) {
236  visible_ = false;
237  static_cast<BaseNode*>(widgetNode_)->hide();
238 
239  emit visibilityChanged( id() );
240  }
241 }
242 
243 void QtWidgetObject::visible(bool _visible) {
244  if ( _visible )
245  show();
246  else
247  hide();
248 }
249 
251  return visible_;
252 }
253 
254 
255 // ===============================================================================
256 // Update
257 // ===============================================================================
258 
260  BaseObject::update(_type);
261 }
262 
263 
264 //=============================================================================
265 
bool picked(uint _node_idx)
detect if the node has been picked
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:317
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
void setDataType(DataType _type)
Definition: BaseObject.cc:244
QString getObjectinfo()
Get all Info for the Object as a string.
virtual void cleanup()
void setName(QString _name)
Set the name of the Object.
BaseObject * copy()
virtual void hide()
Hide Node.
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
ACG::SceneGraph::QtWidgetNode QtWidgetNode
Simple Name for QtWidgetNode.
virtual void show()
Show Node.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:477
Update type class.
Definition: UpdateType.hh:70
QtWidgetObject()
constructor
MaterialNode * materialNode()
get a pointer to the materialnode
QtWidgetNode * widgetNode_
Get the scenegraph Node.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T.cc:329
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T.cc:325
virtual void cleanup()
Reset current object, including all related nodes.
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
void visibilityChanged(int _objectId)
ACG::SceneGraph::QtWidgetNode * qtWidgetNode()
Get the scenegraph Node.
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:446
#define DATA_QT_WIDGET
Definition: QtWidget.hh:65
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:756
virtual ~QtWidgetObject()
destructor
virtual bool visible()
Show Node.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
virtual bool hasNode(BaseNode *_node)
Get the scenegraph Node.
DataType dataType() const
Definition: BaseObject.cc:240
bool visible_
Definition: BaseObject.hh:286
virtual void init(QWidget *_widget)
Initialize current object, including all related nodes.