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 insertChildSorted(Property* child);
351 
353  void setModel(PropertyTreeModel* model);
354 
357  {
358  return model_;
359  }
360 
367  int rowNumberInParent() const;
368 
370  virtual void moveChild(int from_index, int to_index);
371 
374  virtual void load(const Config& config);
375 
378  virtual void save(Config config) const;
379 
381  bool shouldBeSaved() const
382  {
383  return !is_read_only_ && save_;
384  }
385 
388  void setShouldBeSaved(bool save)
389  {
390  save_ = save;
391  }
392 
395  virtual bool getDisableChildren();
396 
401  void hide()
402  {
403  setHidden(true);
404  }
405 
410  void show()
411  {
412  setHidden(false);
413  }
414 
420  virtual void setHidden(bool hidden);
421 
424  virtual bool getHidden() const
425  {
426  return hidden_;
427  }
428 
436  virtual void setReadOnly(bool read_only)
437  {
438  is_read_only_ = read_only;
439  }
440 
443  virtual bool getReadOnly()
444  {
445  return is_read_only_;
446  }
447 
452  virtual void collapse();
453 
463  virtual void expand();
464 
465 Q_SIGNALS:
467  void aboutToChange();
469  void changed();
470 
472  void childListChanged(Property* this_property);
473 
474 protected:
479  void loadValue(const Config& config);
480 
485  QVariant value_;
486 
500 
507 
508  QIcon icon_;
509 
510 private:
513  void reindexChildren();
514 
516  QList<Property*> children_;
517  QString description_;
518  bool hidden_;
519 
523 
526  bool save_;
527 };
528 
529 } // end namespace rviz
530 
531 #endif // PROPERTY_H
QList< Property * > children_
Definition: property.h:516
virtual QIcon getIcon() const
Definition: property.h:198
QString description_
Definition: property.h:517
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:499
bool child_indexes_valid_
True if row_number_within_parent_ of all children is valid, false if not.
Definition: property.h:506
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:356
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:485
int row_number_within_parent_
Definition: property.h:524
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:522
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:410
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:515
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
Definition: property.h:381
void setShouldBeSaved(bool save)
If save is true and getReadOnly() is false, shouldBeSaved will return true; otherwise false...
Definition: property.h:388
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:525
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:424
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:401
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:436
virtual bool getReadOnly()
Return the read-only-ness of this property.
Definition: property.h:443


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