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 
48 ViewsPanel::ViewsPanel( QWidget* parent )
49  : Panel( parent )
50  , view_man_( NULL )
51 {
52  camera_type_selector_ = new QComboBox;
54 
55  save_button_ = new QPushButton( "Save" );
56  QPushButton* remove_button = new QPushButton( "Remove" );
57  QPushButton* rename_button = new QPushButton( "Rename" );
58  QPushButton* zero_button = new QPushButton( "Zero" );
59  zero_button->setToolTip( "Jump to 0,0,0 with the current view controller. Shortcut: Z" );
60 
61  QHBoxLayout* top_layout = new QHBoxLayout;
62  top_layout->addWidget( new QLabel( "Type:" ));
63  top_layout->addWidget( camera_type_selector_ );
64  top_layout->addStretch();
65  top_layout->addWidget( zero_button );
66  top_layout->setContentsMargins( 2, 6, 2, 2 );
67 
68  QHBoxLayout* button_layout = new QHBoxLayout;
69  button_layout->addWidget( save_button_ );
70  button_layout->addWidget( remove_button );
71  button_layout->addWidget( rename_button );
72  button_layout->setContentsMargins( 2, 0, 2, 2 );
73 
74  QVBoxLayout* main_layout = new QVBoxLayout;
75  main_layout->setContentsMargins( 0,0,0,0 );
76  main_layout->addLayout( top_layout );
77  main_layout->addWidget( properties_view_ );
78  main_layout->addLayout( button_layout );
79  setLayout( main_layout );
80 
81  connect( remove_button, SIGNAL( clicked() ), this, SLOT( onDeleteClicked() ));
82  connect( rename_button, SIGNAL( clicked() ), this, SLOT( renameSelected() ));
83  connect( zero_button, SIGNAL( clicked() ), this, SLOT( onZeroClicked() ));
84  connect( properties_view_, SIGNAL( clicked( const QModelIndex& )), this, SLOT( setCurrentViewFromIndex( const QModelIndex& )));
85  connect( properties_view_, SIGNAL( activated( const QModelIndex& )), this, SLOT( setCurrentViewFromIndex( const QModelIndex& )));
86 }
87 
89 {
91 }
92 
94 {
95  if( view_man_ )
96  {
97  disconnect( save_button_, SIGNAL( clicked() ), view_man_, SLOT( copyCurrentToList() ));
98  disconnect( camera_type_selector_, SIGNAL( activated( int )), this, SLOT( onTypeSelectorChanged( int )));
99  disconnect( view_man_, SIGNAL( currentChanged() ), this, SLOT( onCurrentChanged() ));
100  }
101  view_man_ = view_man;
102  camera_type_selector_->clear();
103  if( view_man_ )
104  {
106 
107  QStringList ids = view_man_->getFactory()->getDeclaredClassIds();
108  for( int i = 0; i < ids.size(); i++ )
109  {
110  const QString& id = ids[ i ];
111  camera_type_selector_->addItem( ViewController::formatClassId( id ), 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  {
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 = QInputDialog::getText( this, "Rename View", "New Name?", QLineEdit::Normal, old_name );
181 
182  if( new_name.isEmpty() || new_name == old_name )
183  {
184  return;
185  }
186 
187  view->setName( new_name );
188  }
189 }
190 
192 {
193  QString formatted_class_id = ViewController::formatClassId( view_man_->getCurrent()->getClassId() );
194 
195  // Make sure the type selector shows the type of the current view.
196  // This is only here in case the type is changed programmatically,
197  // instead of via the camera_type_selector_ being used.
198  camera_type_selector_->setCurrentIndex( camera_type_selector_->findText( formatted_class_id ));
199 
200  properties_view_->setAnimated( false );
202  properties_view_->setAnimated( true );
203 }
204 
205 void ViewsPanel::save( Config config ) const
206 {
207  Panel::save( config );
208  properties_view_->save( config );
209 }
210 
211 void ViewsPanel::load( const Config& config )
212 {
213  Panel::load( config );
214  properties_view_->load( config );
215 }
216 
217 } // namespace rviz
218 
#define NULL
Definition: global.h:37
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:93
virtual void save(Config config) const
Save configuration data, specifically the PropertyTreeWidget view settings.
virtual void expand()
Expand (show the children of) this Property.
Definition: property.cpp:542
ViewController * getCurrent() const
Return the current ViewController in use for the main RenderWindow.
VisualizationManager * vis_manager_
Definition: panel.h:92
virtual ViewManager * getViewManager() const
Return a pointer to the ViewManager.
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.
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:150
static QString formatClassId(const QString &class_id)
PropertyTreeWidget * properties_view_
Definition: views_panel.h:88
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
Configuration data storage class.
Definition: config.h:125
QPushButton * save_button_
Definition: views_panel.h:89
void load(const Config &config)
Read state from the given Config.
PropertyTreeModel * getPropertyModel()
Definition: view_manager.h:85
void save(Config config) const
Write state to the given Config.
PluginlibFactory< ViewController > * getFactory() const
Definition: view_manager.h:97
QComboBox * camera_type_selector_
Definition: views_panel.h:90
ViewsPanel(QWidget *parent=0)
Definition: views_panel.cpp:48
void setCurrentViewFromIndex(const QModelIndex &index)
virtual void reset()=0
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:52
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
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:58
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 * view_man_
Definition: views_panel.h:87
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:159
virtual void load(const Config &config)
Load configuration data, specifically the PropertyTreeWidget view settings.
virtual void onInitialize()
Overridden from Panel. Just calls setViewManager() with vis_manager_->getViewManager().
Definition: views_panel.cpp:88


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51