property_tree_widget.h
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 #ifndef PROPERTY_TREE_WIDGET_H
30 #define PROPERTY_TREE_WIDGET_H
31 
32 #include <QTreeView>
33 
34 #include "rviz/config.h"
36 
37 namespace rviz
38 {
39 
40 class Property;
41 class SplitterHandle;
42 
43 class PropertyTreeWidget: public QTreeView
44 {
45 Q_OBJECT
46 public:
47  PropertyTreeWidget( QWidget* parent = 0 );
48 
50  void setModel( PropertyTreeModel* model );
51  PropertyTreeModel* getModel() const { return model_; }
52 
54  template<class Type>
55  QList<Type*> getSelectedObjects()
56  {
57  QModelIndexList indexes = selectedIndexes();
58  int num_selected = indexes.size();
59 
60  QList<Type*> objects_out;
61 
62  for( int i = 0; i < num_selected; i++ )
63  {
64  if( indexes[ i ].column() == 0 )
65  {
66  Property* prop = model_->getProp( indexes[ i ] );
67  if( prop != model_->getRoot() )
68  {
69  Type* obj = qobject_cast<Type*>( prop );
70  if( obj )
71  {
72  objects_out.push_back( obj );
73  }
74  }
75  }
76  }
77  return objects_out;
78  }
79 
81  void save( Config config ) const;
82 
84  void load( const Config& config );
85 
86 protected:
89  virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous );
90 
93  virtual void selectionChanged( const QItemSelection& selected, const QItemSelection& deselected );
94 
95 protected Q_SLOTS:
96  virtual void propertyHiddenChanged( const Property* property );
97 
98 Q_SIGNALS:
99  void currentPropertyChanged( const Property* new_current_property );
100  void selectionHasChanged();
101 
102 private:
104  void saveExpandedEntries( Config config, const QModelIndex& parent_index, const QString& prefix ) const;
105 
107  void expandEntries( const QSet<QString>& expanded_full_names,
108  const QModelIndex& parent_index,
109  const QString& prefix );
110 
113 };
114 
115 } // end namespace rviz
116 
117 #endif // PROPERTY_TREE_WIDGET_H
void setModel(PropertyTreeModel *model)
Set the data model this widget should view.
QList< Type * > getSelectedObjects()
Return the list of objects of a given type which are currently selected.
PropertyTreeModel * getModel() const
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
config
A tall skinny invisible widget providing left-right sliding column separator adjustment for a two-col...
Configuration data storage class.
Definition: config.h:125
void load(const Config &config)
Read state from the given Config.
void currentPropertyChanged(const Property *new_current_property)
virtual void propertyHiddenChanged(const Property *property)
void save(Config config) const
Write state to the given Config.
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Called whenever selection changes. Calls QTreeView implementation then emits selectionHasChanged().
void expandEntries(const QSet< QString > &expanded_full_names, const QModelIndex &parent_index, const QString &prefix)
Recursively expand entries whose full names appear in expanded_full_names.
PropertyTreeWidget(QWidget *parent=0)
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
Property * getRoot() const
void saveExpandedEntries(Config config, const QModelIndex &parent_index, const QString &prefix) const
Recursively write full names of properties which are expanded in this view to the given Config...
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Called whenever current item changes. Calls QTreeView implementation then emits currentPropertyChange...


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42