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 #include "rviz/rviz_export.h"
40 
41 class QModelIndex;
42 class QPainter;
43 class QStyleOptionViewItem;
44 
45 namespace rviz
46 {
47 class PropertyTreeModel;
48 
100 class RVIZ_EXPORT Property : public QObject
101 {
102  Q_OBJECT
103 public:
132  Property(const QString& name = QString(),
133  const QVariant default_value = QVariant(),
134  const QString& description = QString(),
135  Property* parent = nullptr,
136  const char* changed_slot = nullptr,
137  QObject* receiver = nullptr);
138 
142  ~Property() override;
143 
151  virtual void removeChildren(int start_index = 0, int count = -1);
152 
164  virtual bool setValue(const QVariant& new_value);
165 
168  virtual QVariant getValue() const;
169 
174  virtual void setName(const QString& name);
175 
177  virtual QString getName() const;
178 
180  std::string getNameStd() const
181  {
182  return getName().toStdString();
183  }
184 
187  virtual void setDescription(const QString& description);
188 
190  virtual QString getDescription() const;
191 
193  virtual void setIcon(const QIcon& icon)
194  {
195  icon_ = icon;
196  }
197 
198  virtual QIcon getIcon() const
199  {
200  return icon_;
201  }
202 
221  virtual Property* subProp(const QString& sub_name);
222 
227  virtual int numChildren() const
228  {
229  return children_.size();
230  }
231 
239  Property* childAt(int index) const;
240 
246  virtual Property* childAtUnchecked(int index) const;
247 
249  bool contains(Property* possible_child) const;
250 
252  Property* getParent() const;
253 
260  void setParent(Property* new_parent);
261 
274  virtual QVariant getViewData(int column, int role) const;
275 
281  virtual Qt::ItemFlags getViewFlags(int column) const;
282 
294  virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option) const
295  {
296  (void)painter;
297  (void)option;
298  return false;
299  }
300 
301 
319  virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option);
320 
324  bool isAncestorOf(Property* possible_child) const;
325 
334  Property* takeChild(Property* child);
335 
340  virtual Property* takeChildAt(int index);
341 
347  virtual void addChild(Property* child, int index = -1);
348 
350  void setModel(PropertyTreeModel* model);
351 
354  {
355  return model_;
356  }
357 
364  int rowNumberInParent() const;
365 
367  virtual void moveChild(int from_index, int to_index);
368 
371  virtual void load(const Config& config);
372 
375  virtual void save(Config config) const;
376 
378  bool shouldBeSaved() const
379  {
380  return !is_read_only_ && save_;
381  }
382 
385  void setShouldBeSaved(bool save)
386  {
387  save_ = save;
388  }
389 
392  virtual bool getDisableChildren();
393 
398  void hide()
399  {
400  setHidden(true);
401  }
402 
407  void show()
408  {
409  setHidden(false);
410  }
411 
417  virtual void setHidden(bool hidden);
418 
421  virtual bool getHidden() const
422  {
423  return hidden_;
424  }
425 
433  virtual void setReadOnly(bool read_only)
434  {
435  is_read_only_ = read_only;
436  }
437 
440  virtual bool getReadOnly()
441  {
442  return is_read_only_;
443  }
444 
449  virtual void collapse();
450 
460  virtual void expand();
461 
462 Q_SIGNALS:
464  void aboutToChange();
466  void changed();
467 
469  void childListChanged(Property* this_property);
470 
471 protected:
476  void loadValue(const Config& config);
477 
482  QVariant value_;
483 
497 
504 
505  QIcon icon_;
506 
507 private:
510  void reindexChildren();
511 
513  QList<Property*> children_;
514  QString description_;
515  bool hidden_;
516 
520 
523  bool save_;
524 };
525 
526 } // end namespace rviz
527 
528 #endif // PROPERTY_H
QList< Property * > children_
Definition: property.h:513
virtual QIcon getIcon() const
Definition: property.h:198
QString description_
Definition: property.h:514
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:496
bool child_indexes_valid_
True if row_number_within_parent_ of all children is valid, false if not.
Definition: property.h:503
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
config
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
PropertyTreeModel * getModel() const
Return the model managing this Property and its childrent.
Definition: property.h:353
def default_value(type_)
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:482
int row_number_within_parent_
Definition: property.h:521
Configuration data storage class.
Definition: config.h:124
virtual void setIcon(const QIcon &icon)
Set the icon to be displayed next to the property.
Definition: property.h:193
description
static Property * failprop_
The property returned by subProp() when the requested name is not found.
Definition: property.h:519
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:407
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:294
Property * parent_
Definition: property.h:512
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
Definition: property.h:378
void setShouldBeSaved(bool save)
If save is true and getReadOnly() is false, shouldBeSaved will return true; otherwise false...
Definition: property.h:385
std::string getNameStd() const
Return the name of this Property as a std::string.
Definition: property.h:180
bool is_read_only_
Definition: property.h:522
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
Definition: property.h:227
virtual bool getHidden() const
Return the hidden/shown state. True means hidden, false means visible.
Definition: property.h:421
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:398
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:433
virtual bool getReadOnly()
Return the read-only-ness of this property.
Definition: property.h:440


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Nov 6 2021 02:06:35