display_group_visibility_property.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 /*
30  * display_visibility_manager.cpp
31  *
32  * Created on: Aug 27, 2012
33  * Author: gossow
34  */
35 
37 
39 #include "rviz/display_context.h"
40 #include "rviz/bit_allocator.h"
41 #include "rviz/display.h"
42 #include "rviz/display_group.h"
43 
44 namespace rviz
45 {
47  DisplayGroup* display_group,
48  Display* parent_display,
49  const QString& name,
50  bool default_value,
51  const QString& description,
52  Property* parent,
53  const char* changed_slot,
54  QObject* receiver)
55  : DisplayVisibilityProperty(vis_bit,
56  display_group,
57  name,
58  default_value,
59  description,
60  parent,
61  changed_slot,
62  receiver)
63  , display_group_(display_group)
64  , parent_display_(parent_display)
65 {
66  connect(display_group, SIGNAL(displayAdded(rviz::Display*)), this,
68  connect(display_group, SIGNAL(displayRemoved(rviz::Display*)), this,
70 
71  for (int i = 0; i < display_group->numDisplays(); i++)
72  {
73  rviz::Display* display = display_group->getDisplayAt(i);
74  if (display != parent_display)
75  {
76  onDisplayAdded(display);
77  }
78  }
79 
81 }
82 
84 {
86  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.begin();
87  for (; it != disp_vis_props_.end(); it++)
88  {
89  it->second->update();
90  }
91 }
92 
94 {
95  // remove and re-add everything in our property list
96  // in the same order as it appears in the display group
97  for (int i = 0; i < display_group_->numDisplays(); i++)
98  {
100  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find(display);
101  if (it != disp_vis_props_.end())
102  {
103  takeChild(it->second);
104  addChild(it->second);
105  }
106  }
107 }
108 
110 {
111  DisplayGroup* display_group = qobject_cast<DisplayGroup*>(display);
112  DisplayVisibilityProperty* vis_prop;
113  if (display_group)
114  {
115  vis_prop =
116  new DisplayGroupVisibilityProperty(vis_bit_, display_group, parent_display_, "", true,
117  "Uncheck to hide everything in this Display Group", this);
118  }
119  else
120  {
121  vis_prop =
122  new DisplayVisibilityProperty(vis_bit_, display, "", true, "Show or hide this Display", this);
123  }
124  disp_vis_props_[display] = vis_prop;
125  sortDisplayList();
126 }
127 
129 {
130  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find(display);
131  if (it != disp_vis_props_.end())
132  {
133  Property* child = takeChild(it->second);
134  child->setParent(nullptr);
135  delete child;
136  disp_vis_props_.erase(display);
137  }
138 }
139 
140 
142 {
143 }
144 
145 } // namespace rviz
void setDisableChildrenIfFalse(bool disable)
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual int numDisplays() const
Return the number of child Displays.
DisplayGroupVisibilityProperty(uint32_t vis_bit, DisplayGroup *display_group, Display *parent_display, const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
std::map< rviz::Display *, DisplayVisibilityProperty * > disp_vis_props_
Property * takeChild(Property *child)
Remove a given child object and return a pointer to it.
Definition: property.cpp:321
DisplayVisibilityProperty(uint32_t vis_bit, Display *display, const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
void setParent(Property *new_parent)
Set parent property, without telling the parent.
Definition: property.cpp:236
A Display object which stores other Displays as children.
Definition: display_group.h:47
virtual Display * getDisplayAt(int index) const
Return the index-th Display in this group, or NULL if the index is invalid.
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:355


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:16