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 #include <rviz/rviz_export.h>
37 
38 namespace rviz
39 {
40 class Property;
41 class SplitterHandle;
42 
46 class RVIZ_EXPORT PropertySelectionModel : public QItemSelectionModel
47 {
48  Q_OBJECT
49 public:
50  PropertySelectionModel(QAbstractItemModel* model = nullptr);
51 
52  void setCurrentIndex(const QModelIndex& index, QItemSelectionModel::SelectionFlags command) override;
53 };
54 
55 class RVIZ_EXPORT PropertyTreeWidget : public QTreeView
56 {
57  Q_OBJECT
58 
59 public:
60  PropertyTreeWidget(QWidget* parent = nullptr);
61 
62 #ifdef __clang__
63 #pragma clang diagnostic push
64 #pragma clang diagnostic ignored "-Woverloaded-virtual"
65 #endif
66 
67  void setModel(PropertyTreeModel* model);
68 #ifdef __clang__
69 #pragma clang diagnostic pop
70 #endif
72  {
73  return model_;
74  }
75 
77  template <class Type>
78  QList<Type*> getSelectedObjects()
79  {
80  QModelIndexList indexes = selectedIndexes();
81  int num_selected = indexes.size();
82 
83  QList<Type*> objects_out;
84 
85  for (int i = 0; i < num_selected; i++)
86  {
87  if (indexes[i].column() == 0)
88  {
89  Property* prop = model_->getProp(indexes[i]);
90  if (prop != model_->getRoot())
91  {
92  Type* obj = qobject_cast<Type*>(prop);
93  if (obj)
94  {
95  objects_out.push_back(obj);
96  }
97  }
98  }
99  }
100  return objects_out;
101  }
102 
104  void save(Config config) const;
105 
107  void load(const Config& config);
108 
109 protected:
112  void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
113 
116  void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;
117 
118 protected Q_SLOTS:
119  virtual void propertyHiddenChanged(const Property* property);
120 
121 Q_SIGNALS:
122  void currentPropertyChanged(const Property* new_current_property);
123  void selectionHasChanged();
124 
125 private:
128  void saveExpandedEntries(Config config, const QModelIndex& parent_index, const QString& prefix) const;
129 
131  void expandEntries(const QSet<QString>& expanded_full_names,
132  const QModelIndex& parent_index,
133  const QString& prefix);
134 
137 };
138 
139 } // end namespace rviz
140 
141 #endif // PROPERTY_TREE_WIDGET_H
rviz::PropertyTreeModel
Definition: property_tree_model.h:38
command
ROSLIB_DECL std::string command(const std::string &cmd)
rviz::PropertyTreeWidget::model_
PropertyTreeModel * model_
Definition: property_tree_widget.h:135
rviz::PropertySelectionModel
Definition: property_tree_widget.h:46
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::PropertyTreeWidget::splitter_handle_
SplitterHandle * splitter_handle_
Definition: property_tree_widget.h:136
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz
Definition: add_display_dialog.cpp:54
rviz::SplitterHandle
A tall skinny invisible widget providing left-right sliding column separator adjustment for a two-col...
Definition: splitter_handle.h:44
property_tree_model.h
rviz::PropertyTreeWidget::getModel
PropertyTreeModel * getModel() const
Definition: property_tree_widget.h:71
config.h
rviz::PropertyTreeWidget
Definition: property_tree_widget.h:55
rviz::Config
Configuration data storage class.
Definition: config.h:124


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10