property_tree_model.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_MODEL_H
30 #define PROPERTY_MODEL_H
31 
32 #include <QAbstractItemModel>
33 
34 namespace rviz
35 {
36 class Property;
37 
38 class PropertyTreeModel : public QAbstractItemModel
39 {
40  Q_OBJECT
41 public:
47  PropertyTreeModel(Property* root_property, QObject* parent = nullptr);
48 
51  ~PropertyTreeModel() override;
52 
53  void setDragDropClass(const QString& drag_drop_class)
54  {
55  drag_drop_class_ = drag_drop_class;
56  }
57 
58  // Read-only model functions:
59  QVariant data(const QModelIndex& index, int role) const override;
60  QVariant
61  headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
62 
63  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
64  QModelIndex parent(const QModelIndex& index) const override;
65 
68  QModelIndex parentIndex(const Property* child) const;
69 
71  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
72 
75  int columnCount(const QModelIndex& /*parent*/ = QModelIndex()) const override
76  {
77  return 2;
78  }
79 
80  // Editable model functions:
81  Qt::ItemFlags flags(const QModelIndex& index) const override;
82  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
83 
84  Qt::DropActions supportedDropActions() const override
85  {
86  return Qt::MoveAction;
87  }
88 
95  QMimeData* mimeData(const QModelIndexList& indexes) const override;
96 
104  bool dropMimeData(const QMimeData* data,
105  Qt::DropAction action,
106  int destination_row,
107  int destination_column,
108  const QModelIndex& destination_parent) override;
109 
112  QStringList mimeTypes() const override;
113 
114  Property* getRoot() const
115  {
116  return root_property_;
117  }
118 
119  QModelIndex indexOf(Property* property) const;
120 
122  void emitDataChanged(Property* property, bool emit_config_changed = true);
123 
124  void beginInsert(Property* parent_property, int row_within_parent, int count = 1);
125  void endInsert();
126 
127  void beginRemove(Property* parent_property, int row_within_parent, int count = 1);
128  void endRemove();
129 
132  Property* getProp(const QModelIndex& index) const;
133 
135  void emitPropertyHiddenChanged(const Property* property)
136  {
137  Q_EMIT propertyHiddenChanged(property);
138  }
139 
141  void expandProperty(Property* property);
142 
144  void collapseProperty(Property* property);
145 
148  void printPersistentIndices();
149 
150 Q_SIGNALS:
152  void propertyHiddenChanged(const Property* property);
153 
155  void configChanged();
156 
158  void expand(const QModelIndex& index);
159 
161  void collapse(const QModelIndex& index);
162 
163 private:
166 };
168 
169 } // end namespace rviz
170 
171 #endif // PROPERTY_MODEL_H
rviz::PropertyTreeModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: property_tree_model.cpp:137
rviz::PropertyTreeModel::emitPropertyHiddenChanged
void emitPropertyHiddenChanged(const Property *property)
Emit the propertyHiddenChanged() signal for the given Property.
Definition: property_tree_model.h:135
rviz::PropertyTreeModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: property_tree_model.cpp:131
rviz::PropertyTreeModel::expand
void expand(const QModelIndex &index)
Emitted when a Property wants to expand (display its children).
rviz::PropertyTreeModel::collapse
void collapse(const QModelIndex &index)
Emitted when a Property wants to collapse (hide its children).
rviz::PropertyTreeModel::expandProperty
void expandProperty(Property *property)
Expand (show the children of) the given Property.
Definition: property_tree_model.cpp:335
rviz::PropertyTreeModel
Definition: property_tree_model.h:38
rviz::PropertyTreeModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int destination_row, int destination_column, const QModelIndex &destination_parent) override
Override from QAbstractItemModel. Takes a (non-standard) mime-encoded version of an index list and dr...
Definition: property_tree_model.cpp:207
rviz::PropertyTreeModel::endInsert
void endInsert()
Definition: property_tree_model.cpp:314
rviz::PropertyTreeModel::~PropertyTreeModel
~PropertyTreeModel() override
Destructor. Deletes the root property (and thus the entire property tree).
Definition: property_tree_model.cpp:48
rviz::PropertyTreeModel::getProp
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
Definition: property_tree_model.cpp:53
rviz::PropertyTreeModel::parentIndex
QModelIndex parentIndex(const Property *child) const
Same as parent() but taking a Property pointer instead of an index.
Definition: property_tree_model.cpp:105
rviz::PropertyTreeModel::columnCount
int columnCount(const QModelIndex &=QModelIndex()) const override
Return the number of columns under the given parent index, which is always 2 for this model.
Definition: property_tree_model.h:75
rviz::PropertyTreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return the number of rows under the given parent index.
Definition: property_tree_model.cpp:115
rviz::PropertyTreeModel::propertyHiddenChanged
void propertyHiddenChanged(const Property *property)
Emitted when a property within the model is hidden or shown.
rviz::PropertyTreeModel::collapseProperty
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
Definition: property_tree_model.cpp:340
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::PropertyTreeModel::emitDataChanged
void emitDataChanged(Property *property, bool emit_config_changed=true)
Definition: property_tree_model.cpp:294
rviz
Definition: add_display_dialog.cpp:54
rviz::PropertyTreeModel::configChanged
void configChanged()
Emitted when a Property which should be saved changes.
rviz::PropertyTreeModel::endRemove
void endRemove()
Definition: property_tree_model.cpp:329
rviz::PropertyTreeModel::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: property_tree_model.cpp:95
rviz::PropertyTreeModel::indexOf
QModelIndex indexOf(Property *property) const
Definition: property_tree_model.cpp:285
rviz::PropertyTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: property_tree_model.cpp:76
rviz::PropertyTreeModel::getRoot
Property * getRoot() const
Definition: property_tree_model.h:114
rviz::PropertyTreeModel::printPersistentIndices
void printPersistentIndices()
For debugging only. Uses printf() to print the property names of current persistent indices.
Definition: property_tree_model.cpp:345
rviz::PropertyTreeModel::beginInsert
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
Definition: property_tree_model.cpp:305
rviz::PropertyTreeModel::root_property_
Property * root_property_
Definition: property_tree_model.h:164
rviz::PropertyTreeModel::beginRemove
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
Definition: property_tree_model.cpp:320
rviz::PropertyTreeModel::mimeTypes
QStringList mimeTypes() const override
Returns a list with just "application/x-rviz-" plus drag_drop_class_.
Definition: property_tree_model.cpp:278
rviz::PropertyTreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: property_tree_model.cpp:66
rviz::PropertyTreeModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
Override from QAbstractItemModel. Returns a (non-standard) mime-encoded version of the given indexes.
Definition: property_tree_model.cpp:170
rviz::PropertyTreeModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: property_tree_model.cpp:120
rviz::PropertyTreeModel::supportedDropActions
Qt::DropActions supportedDropActions() const override
Definition: property_tree_model.h:84
rviz::PropertyTreeModel::PropertyTreeModel
PropertyTreeModel(Property *root_property, QObject *parent=nullptr)
Constructor.
Definition: property_tree_model.cpp:42
rviz::PropertyTreeModel::drag_drop_class_
QString drag_drop_class_
Definition: property_tree_model.h:165
rviz::PropertyTreeModel::setDragDropClass
void setDragDropClass(const QString &drag_drop_class)
Definition: property_tree_model.h:53


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