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, SIGNAL(clicked()), this, SLOT(onDeleteClicked()));
79  connect(rename_button, SIGNAL(clicked()), this, SLOT(renameSelected()));
80  connect(zero_button, SIGNAL(clicked()), this, SLOT(onZeroClicked()));
81  connect(properties_view_, SIGNAL(clicked(const QModelIndex&)), this,
82  SLOT(setCurrentViewFromIndex(const QModelIndex&)));
83  connect(properties_view_, SIGNAL(activated(const QModelIndex&)), this,
84  SLOT(setCurrentViewFromIndex(const QModelIndex&)));
85 }
86 
88 {
90 }
91 
93 {
94  if (view_man_)
95  {
96  disconnect(save_button_, SIGNAL(clicked()), view_man_, SLOT(copyCurrentToList()));
97  disconnect(camera_type_selector_, SIGNAL(activated(int)), this, SLOT(onTypeSelectorChanged(int)));
98  disconnect(view_man_, SIGNAL(currentChanged()), this, SLOT(onCurrentChanged()));
99  }
100  view_man_ = view_man;
101  camera_type_selector_->clear();
102  if (view_man_)
103  {
105 
106  QStringList ids = view_man_->getFactory()->getDeclaredClassIds();
107  for (int i = 0; i < ids.size(); i++)
108  {
109  const QString& id = ids[i];
111  id); // send the regular-formatted id as userData.
112  }
113 
114  connect(save_button_, SIGNAL(clicked()), view_man_, SLOT(copyCurrentToList()));
115  connect(camera_type_selector_, SIGNAL(activated(int)), this, SLOT(onTypeSelectorChanged(int)));
116  connect(view_man_, SIGNAL(currentChanged()), this, SLOT(onCurrentChanged()));
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 {
208  Panel::save(config);
209  properties_view_->save(config);
210 }
211 
212 void ViewsPanel::load(const Config& config)
213 {
214  Panel::load(config);
215  properties_view_->load(config);
216 }
217 
218 } // namespace rviz
void setModel(PropertyTreeModel *model)
Set the data model this widget should view.
void setViewManager(ViewManager *view_man)
Set the ViewManager which this panel should display and edit.
Definition: views_panel.cpp:92
ViewController * getCurrent() const
Return the current ViewController in use for the main RenderWindow.
virtual void expand()
Expand (show the children of) this Property.
Definition: property.cpp:564
void onInitialize() override
Overridden from Panel. Just calls setViewManager() with vis_manager_->getViewManager().
Definition: views_panel.cpp:87
VisualizationManager * vis_manager_
Definition: panel.h:113
void setCurrentFrom(ViewController *view_to_copy)
Make a copy of view_to_copy and install that as the new current ViewController.
QList< Type * > getSelectedObjects()
Return the list of objects of a given type which are currently selected.
void save(Config config) const override
Save configuration data, specifically the PropertyTreeWidget view settings.
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:155
static QString formatClassId(const QString &class_id)
PluginlibFactory< ViewController > * getFactory() const
Definition: view_manager.h:101
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
PropertyTreeWidget * properties_view_
Definition: views_panel.h:92
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
ViewsPanel(QWidget *parent=nullptr)
Definition: views_panel.cpp:47
Configuration data storage class.
Definition: config.h:124
QPushButton * save_button_
Definition: views_panel.h:93
void load(const Config &config)
Read state from the given Config.
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
PropertyTreeModel * getPropertyModel()
Definition: view_manager.h:86
QComboBox * camera_type_selector_
Definition: views_panel.h:94
void setCurrentViewFromIndex(const QModelIndex &index)
virtual void reset()=0
void onTypeSelectorChanged(int selected_index)
virtual void load(const Config &config)
Override to load configuration data. This version loads the name of the panel.
Definition: panel.cpp:56
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...
ViewManager * getViewManager() const override
Return a pointer to the ViewManager.
void save(Config config) const
Write state to the given Config.
ViewManager * view_man_
Definition: views_panel.h:91
void load(const Config &config) override
Load configuration data, specifically the PropertyTreeWidget view settings.


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25