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 
121  void emitDataChanged(Property* property);
122 
123  void beginInsert(Property* parent_property, int row_within_parent, int count = 1);
124  void endInsert();
125 
126  void beginRemove(Property* parent_property, int row_within_parent, int count = 1);
127  void endRemove();
128 
131  Property* getProp(const QModelIndex& index) const;
132 
134  void emitPropertyHiddenChanged(const Property* property)
135  {
136  Q_EMIT propertyHiddenChanged(property);
137  }
138 
140  void expandProperty(Property* property);
141 
143  void collapseProperty(Property* property);
144 
147  void printPersistentIndices();
148 
149 Q_SIGNALS:
151  void propertyHiddenChanged(const Property* property);
152 
154  void configChanged();
155 
157  void expand(const QModelIndex& index);
158 
160  void collapse(const QModelIndex& index);
161 
162 private:
165 };
167 
168 } // end namespace rviz
169 
170 #endif // PROPERTY_MODEL_H
QStringList mimeTypes() const override
Returns a list with just "application/x-rviz-" plus drag_drop_class_.
void propertyHiddenChanged(const Property *property)
Emitted when a property within the model is hidden or shown.
PropertyTreeModel(Property *root_property, QObject *parent=nullptr)
Constructor.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex parentIndex(const Property *child) const
Same as parent() but taking a Property pointer instead of an index.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return the number of rows under the given parent index.
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
void printPersistentIndices()
For debugging only. Uses printf() to print the property names of current persistent indices...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void collapse(const QModelIndex &index)
Emitted when a Property wants to collapse (hide its children).
QModelIndex parent(const QModelIndex &index) const override
void expand(const QModelIndex &index)
Emitted when a Property wants to expand (display its children).
QMimeData * mimeData(const QModelIndexList &indexes) const override
Override from QAbstractItemModel. Returns a (non-standard) mime-encoded version of the given indexes...
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
void expandProperty(Property *property)
Expand (show the children of) the given Property.
Property * getRoot() const
~PropertyTreeModel() override
Destructor. Deletes the root property (and thus the entire property tree).
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
QVariant data(const QModelIndex &index, int role) const override
void configChanged()
Emitted when a Property which should be saved changes.
int columnCount(const QModelIndex &=QModelIndex()) const override
Return the number of columns under the given parent index, which is always 2 for this model...
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...
action
QModelIndex indexOf(Property *property) const
void setDragDropClass(const QString &drag_drop_class)
Qt::DropActions supportedDropActions() const override
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
void emitDataChanged(Property *property)
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
Qt::ItemFlags flags(const QModelIndex &index) const override
void emitPropertyHiddenChanged(const Property *property)
Emit the propertyHiddenChanged() signal for the given Property.


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25