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 =================================================================
60  widgetNode_(NULL)
61 {
63  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
64  init(NULL);
65 }
66 
71  BaseObjectData(_object),
72  widgetNode_(NULL)
73 {
74  init(_object.widget());
75  setName( name() );
76 }
77 
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;
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 
110 
112 
113  widgetNode_ = NULL;
114 
116  setTypeIcon(DATA_QT_WIDGET,"QtWidgetType.png");
117 
118 }
119 
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 ) {
144 
145  std::string nodename = std::string("Qt WidgetNode " + _name.toUtf8() );
146  widgetNode_->name( nodename );
147 }
148 
149 // ===============================================================================
150 // Visualization
151 // ===============================================================================
152 
154  return widgetNode_;
155 }
156 
157 
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 
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 
213  return widgetNode_->pickingEnabled();
214 }
215 
217  if ( !visible_ ) {
219  visible_ = true;
220 
221  static_cast<BaseNode*>(widgetNode_)->show();
222 
223  emit visibilityChanged( id() );
224  }
225 }
226 
228  if ( visible_ ) {
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 
245  return visible_;
246 }
247 
248 
249 // ===============================================================================
250 // Update
251 // ===============================================================================
252 
254  BaseObject::update(_type);
255 }
256 
257 
258 //=============================================================================
259 
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
virtual void show()
Show Node.
QtWidgetObject()
constructor
bool picked(uint _node_idx)
detect if the node has been picked
void visibilityChanged(int _objectId)
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
virtual void hide()
Hide Node.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
BaseObject * copy()
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
ACG::SceneGraph::QtWidgetNode * qtWidgetNode()
Get the scenegraph Node.
virtual bool visible()
Show Node.
bool pickingEnabled()
Check if picking is enabled for this Object.
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
void enablePicking(bool _enable)
Enable or disable picking for this Object.
virtual ~QtWidgetObject()
destructor
ACG::SceneGraph::QtWidgetNode QtWidgetNode
Simple Name for QtWidgetNode.
bool visible_
Definition: BaseObject.hh:274
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:294
virtual void init(QWidget *_widget)
Initialize current object, including all related nodes.
virtual void cleanup() override
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:466
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
Update type class.
Definition: UpdateType.hh:59
#define DATA_QT_WIDGET
Definition: QtWidget.hh:59
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:286
virtual void cleanup()
Reset current object, including all related nodes.
MaterialNode * materialNode()
get a pointer to the materialnode
unsigned int id() const
Definition: BaseNode.hh:423
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:298
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
QtWidgetNode * widgetNode_
Get the scenegraph Node.
virtual bool hasNode(BaseNode *_node)
Get the scenegraph Node.
void setDataType(DataType _type)
Definition: BaseObject.cc:233
QString getObjectinfo()
Get all Info for the Object as a string.
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
void setName(QString _name)
Set the name of the Object.
DataType dataType() const
Definition: BaseObject.cc:229