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 
137  template <typename Func, typename R>
138  Property(const QString& name,
139  const QVariant& default_value,
140  const QString& description,
141  Property* parent,
142  Func&& changed_slot,
143  const R* receiver)
144  : Property(name, default_value, description, parent)
145  {
146  connect(receiver, std::forward<Func>(changed_slot));
147  }
148 
149  // this variant is required to allow omitting the receiver argument
150  template <typename Func, typename P>
151  Property(const QString& name,
152  const QVariant& default_value,
153  const QString& description,
154  P* parent,
155  Func&& changed_slot)
156  : Property(name, default_value, description, parent)
157  {
158  connect(parent, std::forward<Func>(changed_slot));
159  }
160 
161  using QObject::connect; // inherit QObject's connect functions
162 
164 #ifdef RVIZ_DEPRECATE_QT4_SLOTS
165  [[deprecated("Switch to modern function/functor based slot specification")]]
166 #endif
167  QMetaObject::Connection
168  connect(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::AutoConnection);
169 
171  template <typename Func, typename R>
172  inline typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction,
173  QMetaObject::Connection>::type
174  connect(const R* receiver, Func&& slot, Qt::ConnectionType type = Qt::AutoConnection)
175  {
176  static_assert(std::is_convertible<R*, typename QtPrivate::FunctionPointer<Func>::Object*>::value,
177  "receiver type doesn't match that expected by member function");
178  return QObject::connect(this, &Property::changed, receiver, std::forward<Func>(slot), type);
179  }
180 
182  template <typename Func>
183  inline typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction,
184  QMetaObject::Connection>::type
185  connect(const QObject* context, Func&& slot, Qt::ConnectionType type = Qt::AutoConnection)
186  {
187  return QObject::connect(this, &Property::changed, context, std::forward<Func>(slot), type);
188  }
189 
191  template <typename Func>
192  inline typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction,
193  QMetaObject::Connection>::type
194  connect(Func&& slot, Qt::ConnectionType type = Qt::AutoConnection)
195  {
196  return QObject::connect(this, &Property::changed, this, std::forward<Func>(slot), type);
197  }
198 
202  ~Property() override;
203 
211  virtual void removeChildren(int start_index = 0, int count = -1);
212 
224  virtual bool setValue(const QVariant& new_value);
225 
228  virtual QVariant getValue() const;
229 
234  virtual void setName(const QString& name);
235 
237  virtual QString getName() const;
238 
240  std::string getNameStd() const
241  {
242  return getName().toStdString();
243  }
244 
247  virtual void setDescription(const QString& description);
248 
250  virtual QString getDescription() const;
251 
253  virtual void setIcon(const QIcon& icon)
254  {
255  icon_ = icon;
256  }
257 
258  virtual QIcon getIcon() const
259  {
260  return icon_;
261  }
262 
281  virtual Property* subProp(const QString& sub_name);
282 
287  virtual int numChildren() const
288  {
289  return children_.size();
290  }
291 
299  Property* childAt(int index) const;
300 
306  virtual Property* childAtUnchecked(int index) const;
307 
309  bool contains(Property* possible_child) const;
310 
312  Property* getParent() const;
313 
320  void setParent(Property* new_parent);
321 
334  virtual QVariant getViewData(int column, int role) const;
335 
341  virtual Qt::ItemFlags getViewFlags(int column) const;
342 
354  virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option) const
355  {
356  (void)painter;
357  (void)option;
358  return false;
359  }
360 
361 
379  virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option);
380 
384  bool isAncestorOf(Property* possible_child) const;
385 
394  Property* takeChild(Property* child);
395 
400  virtual Property* takeChildAt(int index);
401 
407  virtual void addChild(Property* child, int index = -1);
408 
410  void insertChildSorted(Property* child);
411 
413  void setModel(PropertyTreeModel* model);
414 
417  {
418  return model_;
419  }
420 
427  int rowNumberInParent() const;
428 
430  virtual void moveChild(int from_index, int to_index);
431 
434  virtual void load(const Config& config);
435 
438  virtual void save(Config config) const;
439 
441  bool shouldBeSaved() const
442  {
443  return save_;
444  }
445 
449  void setShouldBeSaved(bool save)
450  {
451  save_ = save;
452  }
453 
456  virtual bool getDisableChildren();
457 
462  void hide()
463  {
464  setHidden(true);
465  }
466 
471  void show()
472  {
473  setHidden(false);
474  }
475 
481  virtual void setHidden(bool hidden);
482 
485  virtual bool getHidden() const
486  {
487  return hidden_;
488  }
489 
497  virtual void setReadOnly(bool read_only)
498  {
499  is_read_only_ = read_only;
500  }
501 
504  virtual bool getReadOnly() const
505  {
506  return is_read_only_;
507  }
508 
513  virtual void collapse();
514 
524  virtual void expand();
525 
526 Q_SIGNALS:
528  void aboutToChange();
530  void changed();
531 
533  void childListChanged(Property* this_property);
534 
535 protected:
540  void loadValue(const Config& config);
541 
546  QVariant value_;
547 
561 
568 
569  QIcon icon_;
570 
571 private:
574  void reindexChildren();
575 
577  QList<Property*> children_;
578  QString description_;
579  bool hidden_;
580 
584 
587  bool save_;
588 };
589 
590 } // end namespace rviz
591 
592 #endif // PROPERTY_H
rviz::Property::failprop_
static Property * failprop_
The property returned by subProp() when the requested name is not found.
Definition: property.h:583
rviz::PropertyTreeModel
Definition: property_tree_model.h:38
rviz::Property::show
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:471
getName
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
description
description
rviz::Property::getNameStd
std::string getNameStd() const
Return the name of this Property as a std::string.
Definition: property.h:240
rviz::Property::row_number_within_parent_
int row_number_within_parent_
Definition: property.h:585
rviz::Property::is_read_only_
bool is_read_only_
Definition: property.h:586
rviz::Property::shouldBeSaved
bool shouldBeSaved() const
Returns true if the property has data worth saving.
Definition: property.h:441
rviz::Property::numChildren
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
Definition: property.h:287
rviz::Property::getIcon
virtual QIcon getIcon() const
Definition: property.h:258
rviz::Property::paint
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:354
rviz::Property::description_
QString description_
Definition: property.h:578
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::Property::setShouldBeSaved
void setShouldBeSaved(bool save)
If save is false, neither the property nor its children will get saved. If true (the default),...
Definition: property.h:449
rviz::Property::hide
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:462
rviz::Property::connect
std::enable_if<!QtPrivate::FunctionPointer< Func >::IsPointerToMemberFunction, QMetaObject::Connection >::type connect(Func &&slot, Qt::ConnectionType type=Qt::AutoConnection)
Connect changed() signal to given slot functor, using this as context.
Definition: property.h:194
rviz::Property::parent_
Property * parent_
Definition: property.h:576
rviz::Property::save_
bool save_
Definition: property.h:587
rviz
Definition: add_display_dialog.cpp:54
rviz::Property::Property
Property(const QString &name, const QVariant &default_value, const QString &description, P *parent, Func &&changed_slot)
Definition: property.h:151
rviz::Property::connect
std::enable_if<!QtPrivate::FunctionPointer< Func >::IsPointerToMemberFunction, QMetaObject::Connection >::type connect(const QObject *context, Func &&slot, Qt::ConnectionType type=Qt::AutoConnection)
Connect changed() signal to given slot functor, considering context.
Definition: property.h:185
rviz::Property::hidden_
bool hidden_
Definition: property.h:579
rviz::Property::getHidden
virtual bool getHidden() const
Return the hidden/shown state. True means hidden, false means visible.
Definition: property.h:485
rviz::Property::model_
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:560
rviz::Property::child_indexes_valid_
bool child_indexes_valid_
True if row_number_within_parent_ of all children is valid, false if not.
Definition: property.h:567
rviz::Property::setReadOnly
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:497
rviz::Property::Property
Property(const QString &name, const QVariant &default_value, const QString &description, Property *parent, Func &&changed_slot, const R *receiver)
Definition: property.h:138
rviz::Property::children_
QList< Property * > children_
Definition: property.h:577
rviz::Property::connect
std::enable_if< QtPrivate::FunctionPointer< Func >::IsPointerToMemberFunction, QMetaObject::Connection >::type connect(const R *receiver, Func &&slot, Qt::ConnectionType type=Qt::AutoConnection)
Connect changed() signal to given slot member function of receiver object.
Definition: property.h:174
rviz::Property::setIcon
virtual void setIcon(const QIcon &icon)
Set the icon to be displayed next to the property.
Definition: property.h:253
default_value
def default_value(type_)
rviz::Property::changed
void changed()
Emitted by setValue() just after the value has changed.
config.h
rviz::Property::icon_
QIcon icon_
Definition: property.h:569
rviz::Property::value_
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:546
rviz::Property::getModel
PropertyTreeModel * getModel() const
Return the model managing this Property and its childrent.
Definition: property.h:416
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::Property::getReadOnly
virtual bool getReadOnly() const
Return the read-only-ness of this property.
Definition: property.h:504


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10