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 public:
59  PropertyTreeWidget(QWidget* parent = nullptr);
60 
62  void setModel(PropertyTreeModel* model);
64  {
65  return model_;
66  }
67 
69  template <class Type>
70  QList<Type*> getSelectedObjects()
71  {
72  QModelIndexList indexes = selectedIndexes();
73  int num_selected = indexes.size();
74 
75  QList<Type*> objects_out;
76 
77  for (int i = 0; i < num_selected; i++)
78  {
79  if (indexes[i].column() == 0)
80  {
81  Property* prop = model_->getProp(indexes[i]);
82  if (prop != model_->getRoot())
83  {
84  Type* obj = qobject_cast<Type*>(prop);
85  if (obj)
86  {
87  objects_out.push_back(obj);
88  }
89  }
90  }
91  }
92  return objects_out;
93  }
94 
96  void save(Config config) const;
97 
99  void load(const Config& config);
100 
101 protected:
104  void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
105 
108  void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;
109 
110 protected Q_SLOTS:
111  virtual void propertyHiddenChanged(const Property* property);
112 
113 Q_SIGNALS:
114  void currentPropertyChanged(const Property* new_current_property);
115  void selectionHasChanged();
116 
117 private:
120  void saveExpandedEntries(Config config, const QModelIndex& parent_index, const QString& prefix) const;
121 
123  void expandEntries(const QSet<QString>& expanded_full_names,
124  const QModelIndex& parent_index,
125  const QString& prefix);
126 
129 };
130 
131 } // end namespace rviz
132 
133 #endif // PROPERTY_TREE_WIDGET_H
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
config
A tall skinny invisible widget providing left-right sliding column separator adjustment for a two-col...
PropertyTreeModel * getModel() const
Configuration data storage class.
Definition: config.h:124
ROSLIB_DECL std::string command(const std::string &cmd)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Fri Aug 12 2022 02:06:09