views_panel.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 #include <QLabel>
31 #include <QListWidget>
32 #include <QComboBox>
33 #include <QPushButton>
34 #include <QVBoxLayout>
35 #include <QHBoxLayout>
36 #include <QInputDialog>
37 
39 #include <rviz/view_controller.h>
40 #include <rviz/view_manager.h>
42 
43 #include "views_panel.h"
44 
45 namespace rviz
46 {
47 ViewsPanel::ViewsPanel(QWidget* parent) : Panel(parent), view_man_(nullptr)
48 {
49  camera_type_selector_ = new QComboBox;
51 
52  save_button_ = new QPushButton("Save");
53  QPushButton* remove_button = new QPushButton("Remove");
54  QPushButton* rename_button = new QPushButton("Rename");
55  QPushButton* zero_button = new QPushButton("Zero");
56  zero_button->setToolTip("Jump to 0,0,0 with the current view controller. Shortcut: Z");
57 
58  QHBoxLayout* top_layout = new QHBoxLayout;
59  top_layout->addWidget(new QLabel("Type:"));
60  top_layout->addWidget(camera_type_selector_);
61  top_layout->addStretch();
62  top_layout->addWidget(zero_button);
63  top_layout->setContentsMargins(2, 6, 2, 2);
64 
65  QHBoxLayout* button_layout = new QHBoxLayout;
66  button_layout->addWidget(save_button_);
67  button_layout->addWidget(remove_button);
68  button_layout->addWidget(rename_button);
69  button_layout->setContentsMargins(2, 0, 2, 2);
70 
71  QVBoxLayout* main_layout = new QVBoxLayout;
72  main_layout->setContentsMargins(0, 0, 0, 0);
73  main_layout->addLayout(top_layout);
74  main_layout->addWidget(properties_view_);
75  main_layout->addLayout(button_layout);
76  setLayout(main_layout);
77 
78  connect(remove_button, &QPushButton::clicked, this, &ViewsPanel::onDeleteClicked);
79  connect(rename_button, &QPushButton::clicked, this, &ViewsPanel::renameSelected);
80  connect(zero_button, &QPushButton::clicked, this, &ViewsPanel::onZeroClicked);
81  connect(properties_view_, &PropertyTreeWidget::clicked, this, &ViewsPanel::setCurrentViewFromIndex);
82  connect(properties_view_, &PropertyTreeWidget::activated, this, &ViewsPanel::setCurrentViewFromIndex);
83 }
84 
86 {
88 }
89 
91 {
92  if (view_man_)
93  {
94  disconnect(save_button_, &QPushButton::clicked, view_man_, &ViewManager::copyCurrentToList);
95  disconnect(camera_type_selector_, qOverload<int>(&QComboBox::activated), this,
98  }
99  view_man_ = view_man;
100  camera_type_selector_->clear();
101  if (view_man_)
102  {
104 
105  QStringList ids = view_man_->getFactory()->getDeclaredClassIds();
106  for (int i = 0; i < ids.size(); i++)
107  {
108  const QString& id = ids[i];
110  id); // send the regular-formatted id as userData.
111  }
112 
113  connect(save_button_, &QPushButton::clicked, view_man_, &ViewManager::copyCurrentToList);
114  connect(camera_type_selector_, qOverload<int>(&QComboBox::activated), this,
117  }
118  else
119  {
120  properties_view_->setModel(nullptr);
121  }
123 }
124 
125 void ViewsPanel::onTypeSelectorChanged(int selected_index)
126 {
127  QString class_id = camera_type_selector_->itemData(selected_index).toString();
129 }
130 
132 {
133  if (view_man_->getCurrent())
134  {
135  view_man_->getCurrent()->reset();
136  }
137 }
138 
139 void ViewsPanel::setCurrentViewFromIndex(const QModelIndex& index)
140 {
141  Property* prop = view_man_->getPropertyModel()->getProp(index);
142  if (ViewController* view = qobject_cast<ViewController*>(prop))
143  {
144  view_man_->setCurrentFrom(view);
145  }
146 }
147 
149 {
150  QList<ViewController*> views_to_delete = properties_view_->getSelectedObjects<ViewController>();
151 
152  for (int i = 0; i < views_to_delete.size(); i++)
153  {
154  // TODO: should eventually move to a scheme where the CURRENT view
155  // is not in the same list as the saved views, at which point this
156  // check can go away.
157  if (views_to_delete[i] != view_man_->getCurrent())
158  {
159  delete views_to_delete[i];
160  }
161  }
162 }
163 
165 {
166  QList<ViewController*> views_to_rename = properties_view_->getSelectedObjects<ViewController>();
167  if (views_to_rename.size() == 1)
168  {
169  ViewController* view = views_to_rename[0];
170 
171  // TODO: should eventually move to a scheme where the CURRENT view
172  // is not in the same list as the saved views, at which point this
173  // check can go away.
174  if (view == view_man_->getCurrent())
175  {
176  return;
177  }
178 
179  QString old_name = view->getName();
180  QString new_name =
181  QInputDialog::getText(this, "Rename View", "New Name?", QLineEdit::Normal, old_name);
182 
183  if (new_name.isEmpty() || new_name == old_name)
184  {
185  return;
186  }
187 
188  view->setName(new_name);
189  }
190 }
191 
193 {
194  QString formatted_class_id = ViewController::formatClassId(view_man_->getCurrent()->getClassId());
195 
196  // Make sure the type selector shows the type of the current view.
197  // This is only here in case the type is changed programmatically,
198  // instead of via the camera_type_selector_ being used.
199  camera_type_selector_->setCurrentIndex(camera_type_selector_->findText(formatted_class_id));
200 
201  properties_view_->setAnimated(false);
203  properties_view_->setAnimated(true);
204 }
205 
206 void ViewsPanel::save(Config config) const
207 {
210 }
211 
212 void ViewsPanel::load(const Config& config)
213 {
216 }
217 
218 } // namespace rviz
view_manager.h
rviz::Property::setName
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:155
rviz::ViewManager::getPropertyModel
PropertyTreeModel * getPropertyModel()
Definition: view_manager.h:86
rviz::Panel
Definition: panel.h:41
rviz::PropertyTreeWidget::load
void load(const Config &config)
Read state from the given Config.
Definition: property_tree_widget.cpp:172
rviz::ViewManager::copyCurrentToList
void copyCurrentToList()
Make a copy of the current ViewController and add it to the end of the list of saved views.
Definition: view_manager.cpp:157
rviz::PropertyTreeModel::getProp
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
Definition: property_tree_model.cpp:53
rviz::ViewsPanel::onCurrentChanged
void onCurrentChanged()
Definition: views_panel.cpp:192
rviz::ViewsPanel::camera_type_selector_
QComboBox * camera_type_selector_
Definition: views_panel.h:94
rviz::PropertyTreeWidget::getSelectedObjects
QList< Type * > getSelectedObjects()
Return the list of objects of a given type which are currently selected.
Definition: property_tree_widget.h:78
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::ViewManager::getFactory
PluginlibFactory< ViewController > * getFactory() const
Definition: view_manager.h:101
rviz::ViewsPanel::view_man_
ViewManager * view_man_
Definition: views_panel.h:91
rviz::VisualizationManager::getViewManager
ViewManager * getViewManager() const override
Return a pointer to the ViewManager.
Definition: visualization_manager.h:270
rviz::ViewController::reset
virtual void reset()=0
rviz::ViewsPanel::onZeroClicked
void onZeroClicked()
Definition: views_panel.cpp:131
rviz::Property::expand
virtual void expand()
Expand (show the children of) this Property.
Definition: property.cpp:578
rviz::ViewManager::currentChanged
void currentChanged()
Emitted just after the current view controller changes.
rviz
Definition: add_display_dialog.cpp:54
rviz::PropertyTreeWidget::setModel
void setModel(PropertyTreeModel *model)
Set the data model this widget should view.
Definition: property_tree_widget.cpp:95
rviz::ViewsPanel::setCurrentViewFromIndex
void setCurrentViewFromIndex(const QModelIndex &index)
Definition: views_panel.cpp:139
rviz::ViewsPanel::save_button_
QPushButton * save_button_
Definition: views_panel.h:93
rviz::ViewManager::getCurrent
ViewController * getCurrent() const
Return the current ViewController in use for the main RenderWindow.
Definition: view_manager.cpp:90
rviz::ViewsPanel::onDeleteClicked
void onDeleteClicked()
Definition: views_panel.cpp:148
property_tree_widget.h
rviz::ViewsPanel::save
void save(Config config) const override
Save configuration data, specifically the PropertyTreeWidget view settings.
Definition: views_panel.cpp:206
rviz::ViewsPanel::setViewManager
void setViewManager(ViewManager *view_man)
Set the ViewManager which this panel should display and edit.
Definition: views_panel.cpp:90
rviz::ViewManager
Definition: view_manager.h:53
rviz::PropertyTreeWidget::save
void save(Config config) const
Write state to the given Config.
Definition: property_tree_widget.cpp:135
visualization_manager.h
rviz::ViewsPanel::onTypeSelectorChanged
void onTypeSelectorChanged(int selected_index)
Definition: views_panel.cpp:125
rviz::ViewsPanel::renameSelected
void renameSelected()
Definition: views_panel.cpp:164
rviz::Property::getName
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
rviz::Panel::load
virtual void load(const Config &config)
Override to load configuration data. This version loads the name of the panel.
Definition: panel.cpp:56
rviz::ViewController
Definition: view_controller.h:55
rviz::ViewsPanel::load
void load(const Config &config) override
Load configuration data, specifically the PropertyTreeWidget view settings.
Definition: views_panel.cpp:212
rviz::Panel::save
virtual void save(Config config) const
Override to save configuration data. This version saves the name and class ID of the panel.
Definition: panel.cpp:50
rviz::ViewManager::setCurrentFrom
void setCurrentFrom(ViewController *view_to_copy)
Make a copy of view_to_copy and install that as the new current ViewController.
Definition: view_manager.cpp:95
rviz::ViewsPanel::properties_view_
PropertyTreeWidget * properties_view_
Definition: views_panel.h:92
rviz::ViewManager::setCurrentViewControllerType
void setCurrentViewControllerType(const QString &new_class_id)
Create a new view controller of the given type and set it up to mimic and replace the previous curren...
Definition: view_manager.cpp:152
rviz::ViewController::formatClassId
static QString formatClassId(const QString &class_id)
Definition: view_controller.cpp:126
view_controller.h
rviz::PropertyTreeWidget
Definition: property_tree_widget.h:55
rviz::ViewsPanel::onInitialize
void onInitialize() override
Overridden from Panel. Just calls setViewManager() with vis_manager_->getViewManager().
Definition: views_panel.cpp:85
rviz::ViewController::getClassId
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
Definition: view_controller.h:155
config
config
rviz::ViewsPanel::ViewsPanel
ViewsPanel(QWidget *parent=nullptr)
Definition: views_panel.cpp:47
rviz::Config
Configuration data storage class.
Definition: config.h:124
views_panel.h
rviz::Panel::vis_manager_
VisualizationManager * vis_manager_
Definition: panel.h:113


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53