property.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_H
30 #define PROPERTY_H
31 
32 #include <string>
33 
34 #include <QObject>
35 #include <QIcon>
36 #include <QVariant>
37 
38 #include "rviz/config.h"
39 
40 class QModelIndex;
41 class QPainter;
42 class QStyleOptionViewItem;
43 
44 namespace rviz
45 {
46 
47 class PropertyTreeModel;
48 
100 class Property: public QObject
101 {
102 Q_OBJECT
103 public:
130  Property( const QString& name = QString(),
131  const QVariant default_value = QVariant(),
132  const QString& description = QString(),
133  Property* parent = 0,
134  const char *changed_slot = 0,
135  QObject* receiver = 0 );
136 
140  virtual ~Property();
141 
148  virtual void removeChildren( int start_index = 0, int count = -1 );
149 
161  virtual bool setValue( const QVariant& new_value );
162 
165  virtual QVariant getValue() const;
166 
171  virtual void setName( const QString& name );
172 
174  virtual QString getName() const;
175 
177  std::string getNameStd() const { return getName().toStdString(); }
178 
181  virtual void setDescription( const QString& description );
182 
184  virtual QString getDescription() const;
185 
187  virtual void setIcon( const QIcon& icon ) { icon_=icon; }
188 
189  virtual QIcon getIcon() const { return icon_; }
190 
209  virtual Property* subProp( const QString& sub_name );
210 
215  virtual int numChildren() const { return children_.size(); }
216 
224  Property* childAt( int index ) const;
225 
231  virtual Property* childAtUnchecked( int index ) const;
232 
234  bool contains( Property* possible_child ) const;
235 
237  Property* getParent() const;
238 
245  void setParent( Property* new_parent );
246 
259  virtual QVariant getViewData( int column, int role ) const;
260 
265  virtual Qt::ItemFlags getViewFlags( int column ) const;
266 
276  virtual bool paint( QPainter* painter, const QStyleOptionViewItem& option ) const
277  {
278  (void) painter;
279  (void) option;
280  return false;
281  }
282 
283 
300  virtual QWidget* createEditor( QWidget* parent,
301  const QStyleOptionViewItem& option );
302 
306  bool isAncestorOf( Property* possible_child ) const;
307 
316  Property* takeChild( Property* child );
317 
322  virtual Property* takeChildAt( int index );
323 
329  virtual void addChild( Property* child, int index = -1 );
330 
332  void setModel( PropertyTreeModel* model );
333 
335  PropertyTreeModel* getModel() const { return model_; }
336 
343  int rowNumberInParent() const;
344 
346  virtual void moveChild( int from_index, int to_index );
347 
350  virtual void load( const Config& config );
351 
354  virtual void save( Config config ) const;
355 
357  bool shouldBeSaved() const { return !is_read_only_ && save_; }
358 
361  void setShouldBeSaved( bool save ) { save_ = save; }
362 
365  virtual bool getDisableChildren();
366 
371  void hide() { setHidden( true ); }
372 
377  void show() { setHidden( false ); }
378 
384  virtual void setHidden( bool hidden );
385 
388  virtual bool getHidden() const { return hidden_; }
389 
397  virtual void setReadOnly( bool read_only ) { is_read_only_ = read_only; }
398 
401  virtual bool getReadOnly() { return is_read_only_; }
402 
407  virtual void collapse();
408 
418  virtual void expand();
419 
420 Q_SIGNALS:
422  void aboutToChange();
424  void changed();
425 
427  void childListChanged( Property* this_property );
428 
429 protected:
434  void loadValue( const Config& config );
435 
440  QVariant value_;
441 
455 
462 
463  QIcon icon_;
464 
465 private:
468  void reindexChildren();
469 
471  QList<Property*> children_;
472  QString description_;
473  bool hidden_;
474 
478 
481  bool save_;
482 };
483 
484 } // end namespace rviz
485 
486 #endif // PROPERTY_H
QList< Property * > children_
Definition: property.h:471
std::string getNameStd() const
Return the name of this Property as a std::string.
Definition: property.h:177
Property * getParent() const
Return the parent Property.
Definition: property.cpp:226
QString description_
Definition: property.h:472
virtual void expand()
Expand (show the children of) this Property.
Definition: property.cpp:542
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
Definition: property.cpp:405
virtual ~Property()
Destructor. Removes this property from its parent&#39;s list of children.
Definition: property.cpp:84
void changed()
Emitted by setValue() just after the value has changed.
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:454
virtual void load(const Config &config)
Load the value of this property and/or its children from the given Config reference.
Definition: property.cpp:426
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value...
Definition: property.cpp:130
bool child_indexes_valid_
True if row_number_within_parent_ of all children is valid, false if not.
Definition: property.h:461
virtual QIcon getIcon() const
Definition: property.h:189
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
config
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
Definition: property.h:357
void childListChanged(Property *this_property)
Emitted after insertions and deletions of child Properties.
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property. ...
Definition: property.cpp:236
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:150
virtual bool getDisableChildren()
If true, the children of this property should set their ItemIsEnabled flag to false.
Definition: property.cpp:275
virtual void setDescription(const QString &description)
Set the description.
Definition: property.cpp:164
QVariant value_
This is the central property value. If you set it directly in a subclass, do so with care because man...
Definition: property.h:440
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
Definition: property.h:215
Property * takeChild(Property *child)
Remove a given child object and return a pointer to it.
Definition: property.cpp:316
int row_number_within_parent_
Definition: property.h:479
Configuration data storage class.
Definition: config.h:125
virtual void collapse()
Collapse (hide the children of) this Property.
Definition: property.cpp:550
bool isAncestorOf(Property *possible_child) const
Returns true if this is an ancestor of possible_child, meaning is the parent or parent of parent etc...
Definition: property.cpp:306
void loadValue(const Config &config)
Load the value of this property specifically, not including children.
Definition: property.cpp:449
virtual void setIcon(const QIcon &icon)
Set the icon to be displayed next to the property.
Definition: property.h:187
virtual Property * subProp(const QString &sub_name)
Return the first child Property with the given name, or the FailureProperty if no child has the name...
Definition: property.cpp:174
void reindexChildren()
Set row_number_within_parent_ correctly for every child. Sets child_indexes_valid_ to true when done...
Definition: property.cpp:394
virtual void removeChildren(int start_index=0, int count=-1)
Remove and delete some or all child Properties. Does not change the value of this Property...
Definition: property.cpp:100
description
static Property * failprop_
The property returned by subProp() when the requested name is not found.
Definition: property.h:477
virtual void save(Config config) const
Write the value of this property and/or its children into the given Config reference.
Definition: property.cpp:467
Property * childAt(int index) const
Return the child Property with the given index, or NULL if the index is out of bounds or if the child...
Definition: property.cpp:197
void setParent(Property *new_parent)
Set parent property, without telling the parent.
Definition: property.cpp:231
void setModel(PropertyTreeModel *model)
Set the model managing this Property and all its child properties, recursively.
Definition: property.cpp:379
virtual void moveChild(int from_index, int to_index)
Move the child at from_index to to_index.
Definition: property.cpp:419
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:377
def default_value(type)
virtual bool getHidden() const
Return the hidden/shown state. True means hidden, false means visible.
Definition: property.h:388
Property * parent_
Definition: property.h:470
PropertyTreeModel * getModel() const
Return the model managing this Property and its childrent.
Definition: property.h:335
bool contains(Property *possible_child) const
Return true if the list of children includes possible_child, false if not.
Definition: property.cpp:213
void setShouldBeSaved(bool save)
If save is true and getReadOnly() is false, shouldBeSaved will return true; otherwise false...
Definition: property.h:361
virtual Property * takeChildAt(int index)
Take a child out of the child list, but don&#39;t destroy it.
Definition: property.cpp:328
bool is_read_only_
Definition: property.h:480
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
Definition: property.cpp:530
virtual bool paint(QPainter *painter, const QStyleOptionViewItem &option) const
Hook to provide custom painting of the value data (right-hand column) in a subclass.
Definition: property.h:276
Property(const QString &name=QString(), const QVariant default_value=QVariant(), const QString &description=QString(), Property *parent=0, const char *changed_slot=0, QObject *receiver=0)
Constructor.
Definition: property.cpp:54
void aboutToChange()
Emitted by setValue() just before the value has changed.
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:350
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
Definition: property.cpp:145
virtual QString getDescription() const
Return the description.
Definition: property.cpp:169
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option)
Create an editor widget to edit the value of this property.
Definition: property.cpp:502
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:371
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:397
virtual Property * childAtUnchecked(int index) const
Return the child Property with the given index, without checking whether the index is within bounds...
Definition: property.cpp:208
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:159
virtual bool getReadOnly()
Return the read-only-ness of this property.
Definition: property.h:401
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Definition: property.cpp:285


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51