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 
37 class Property;
38 
39 class PropertyTreeModel: public QAbstractItemModel
40 {
41 Q_OBJECT
42 public:
48  PropertyTreeModel( Property* root_property, QObject* parent = 0 );
49 
52  virtual ~PropertyTreeModel();
53 
54  void setDragDropClass( const QString& drag_drop_class ) { drag_drop_class_ = drag_drop_class; }
55 
56  // Read-only model functions:
57  virtual QVariant data( const QModelIndex &index, int role ) const;
58  virtual QVariant headerData( int section, Qt::Orientation orientation,
59  int role = Qt::DisplayRole ) const;
60 
61  virtual QModelIndex index( int row, int column,
62  const QModelIndex &parent = QModelIndex() ) const;
63  virtual QModelIndex parent( const QModelIndex &index ) const;
64 
67  QModelIndex parentIndex( const Property* child ) const;
68 
70  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
71 
74  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const { return 2; }
75 
76  // Editable model functions:
77  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
78  virtual bool setData( const QModelIndex &index, const QVariant &value,
79  int role = Qt::EditRole );
80 
81  virtual Qt::DropActions supportedDropActions() const { return Qt::MoveAction; }
82 
89  virtual QMimeData* mimeData( const QModelIndexList& indexes ) const;
90 
98  virtual bool dropMimeData( const QMimeData* data,
99  Qt::DropAction action,
100  int destination_row, int destination_column,
101  const QModelIndex& destination_parent );
102 
105  virtual QStringList mimeTypes () const;
106 
107  Property* getRoot() const { return root_property_; }
108 
109  QModelIndex indexOf( Property* property ) const;
110 
111  void emitDataChanged( Property* property );
112 
113  void beginInsert( Property* parent_property, int row_within_parent, int count = 1 );
114  void endInsert();
115 
116  void beginRemove( Property* parent_property, int row_within_parent, int count = 1 );
117  void endRemove();
118 
121  Property* getProp( const QModelIndex& index ) const;
122 
124  void emitPropertyHiddenChanged( const Property* property ) { Q_EMIT propertyHiddenChanged( property ); }
125 
127  void expandProperty( Property* property );
128 
130  void collapseProperty( Property* property );
131 
134  void printPersistentIndices();
135 
136 Q_SIGNALS:
138  void propertyHiddenChanged( const Property* property );
139 
141  void configChanged();
142 
144  void expand( const QModelIndex& index );
145 
147  void collapse( const QModelIndex& index );
148 
149 private:
152 };
153 
154 } // end namespace rviz
155 
156 #endif // PROPERTY_MODEL_H
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Return the number of columns under the given parent index, which is always 2 for this model...
void propertyHiddenChanged(const Property *property)
Emitted when a property within the model is hidden or shown.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual QModelIndex parent(const QModelIndex &index) const
PropertyTreeModel(Property *root_property, QObject *parent=0)
Constructor.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual ~PropertyTreeModel()
Destructor. Deletes the root property (and thus the entire property tree).
QString drag_drop_class_
Identifier to add to mimeTypes() entry to keep drag/drops from crossing types.
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...
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of rows under the given parent index.
void collapse(const QModelIndex &index)
Emitted when a Property wants to collapse (hide its children).
void expand(const QModelIndex &index)
Emitted when a Property wants to expand (display its children).
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
QModelIndex parentIndex(const Property *child) const
Same as parent() but taking a Property pointer instead of an index.
virtual QStringList mimeTypes() const
Returns a list with just "application/x-rviz-" plus drag_drop_class_.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Override from QAbstractItemModel. Returns a (non-standard) mime-encoded version of the given indexes...
void expandProperty(Property *property)
Expand (show the children of) the given Property.
QModelIndex indexOf(Property *property) const
virtual QVariant data(const QModelIndex &index, int role) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
void configChanged()
Emitted when a Property which should be saved changes.
action
virtual Qt::ItemFlags flags(const QModelIndex &index) const
void setDragDropClass(const QString &drag_drop_class)
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int destination_row, int destination_column, const QModelIndex &destination_parent)
Override from QAbstractItemModel. Takes a (non-standard) mime-encoded version of an index list and dr...
void emitDataChanged(Property *property)
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
void emitPropertyHiddenChanged(const Property *property)
Emit the propertyHiddenChanged() signal for the given Property.
Property * getRoot() const
virtual Qt::DropActions supportedDropActions() const


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