33 #include <QApplication> 59 const QVariant default_value,
60 const QString& description,
62 const char* changed_slot,
78 if (receiver ==
nullptr)
82 if (receiver && changed_slot)
84 connect(
this, SIGNAL(
changed()), receiver, changed_slot);
96 for (
int i =
children_.size() - 1; i >= 0; i--)
119 for (
int i = start_index; i < start_index + count; i++)
182 for (
int i = 0; i < size; i++)
185 if (prop->
getName() == sub_name)
193 QString ancestry =
"";
196 ancestry =
"\"" + prop->
getName() +
"\"->" + ancestry;
198 printf(
"ERROR: Undefined property %s \"%s\" accessed.\n", qPrintable(ancestry), qPrintable(sub_name));
221 for (
int i = 0; i < num_children; i++)
244 return QApplication::palette().brush(QPalette::Disabled, QPalette::Text);
251 case Qt::DisplayRole:
253 case Qt::DecorationRole:
262 case Qt::DisplayRole:
264 return (
value_.type() == QVariant::Bool ? QVariant() :
getValue());
265 case Qt::CheckStateRole:
266 if (
value_.type() == QVariant::Bool)
267 return (
value_.toBool() ? Qt::Checked : Qt::Unchecked);
293 Qt::ItemFlags enabled_flag =
298 return enabled_flag | Qt::ItemIsSelectable;
302 if (
value_.type() == QVariant::Bool)
304 return Qt::ItemIsUserCheckable | enabled_flag | Qt::ItemIsSelectable;
306 return Qt::ItemIsEditable | enabled_flag | Qt::ItemIsSelectable;
308 return enabled_flag | Qt::ItemIsSelectable;
314 while (prop !=
nullptr && prop !=
this)
335 if (index < 0 || index >=
children_.size())
362 if (index < 0 || index > num_children)
364 index = num_children;
401 for (
int i = 0; i < num_children; i++)
411 for (
int i = 0; i < num_children; i++)
453 int num_property_children =
children_.size();
454 for (
int i = 0; i < num_property_children; i++)
467 switch (
int(
value_.type()))
472 case QMetaType::Float:
473 case QVariant::Double:
476 case QVariant::String:
483 printf(
"Property::loadValue() TODO: error handling - unexpected QVariant type %d.\n",
502 for (
int i = 0; i < num_properties; i++)
527 switch (
int(
value_.type()))
531 QSpinBox* editor =
new QSpinBox(parent);
532 editor->setFrame(
false);
533 editor->setRange(INT_MIN, INT_MAX);
536 case QMetaType::Float:
537 case QVariant::Double:
542 case QVariant::String:
545 QLineEdit* editor =
new QLineEdit(parent);
546 editor->setFrame(
false);
QList< Property * > children_
void setValue(const QVariant &value)
Ensures this is a valid Config object, sets the type to Value then sets the value.
virtual void save(Config config) const
Write the value of this property and/or its children into the given Config reference.
virtual void expand()
Expand (show the children of) this Property.
Property * subProp(const QString &) override
Return the first child Property with the given name, or the FailureProperty if no child has the name...
QVariant getValue() const
If this config object is valid and is a Value type, this returns its value. Otherwise it returns an i...
void changed()
Emitted by setValue() just after the value has changed.
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Property * getParent() const
Return the parent Property.
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...
virtual void load(const Config &config)
Load the value of this property and/or its children from the given Config reference.
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...
bool child_indexes_valid_
True if row_number_within_parent_ of all children is valid, false if not.
A single element of a property tree, with a name, value, description, and possibly children...
void childListChanged(Property *this_property)
Emitted after insertions and deletions of child Properties.
virtual void setName(const QString &name)
Set the name.
virtual bool getDisableChildren()
If true, the children of this property should set their ItemIsEnabled flag to false.
Config mapGetChild(const QString &key) const
If the referenced Node is a Map and it has a child with the given key, return a reference to the chil...
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
virtual void setDescription(const QString &description)
Set the description.
QVariant value_
This is the central property value. If you set it directly in a subclass, do so with care because man...
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
virtual QString getDescription() const
Return the description.
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Property * takeChild(Property *child)
Remove a given child object and return a pointer to it.
int row_number_within_parent_
Configuration data storage class.
virtual void collapse()
Collapse (hide the children of) this Property.
void loadValue(const Config &config)
Load the value of this property specifically, not including children.
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...
void reindexChildren()
Set row_number_within_parent_ correctly for every child. Sets child_indexes_valid_ to true when done...
void expandProperty(Property *property)
Expand (show the children of) the given Property.
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...
static Property * failprop_
The property returned by subProp() when the requested name is not found.
void setParent(Property *new_parent)
Set parent property, without telling the parent.
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property. ...
void setModel(PropertyTreeModel *model)
Set the model managing this Property and all its child properties, recursively.
virtual void moveChild(int from_index, int to_index)
Move the child at from_index to to_index.
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
virtual QString getName() const
Return the name of this Property as a QString.
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
Property(const QString &name=QString(), const QVariant default_value=QVariant(), const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
Constructor.
Type getType() const
Return the Type of the referenced Node, or Invalid if this Config does not refer to a Node at all...
void insertChildSorted(Property *child)
Insert a child property, sorted by name.
virtual Property * takeChildAt(int index)
Take a child out of the child list, but don't destroy it.
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
~Property() override
Destructor. Removes this property from its parent's list of children.
virtual Property * childAtUnchecked(int index) const
Return the child Property with the given index, without checking whether the index is within bounds...
void aboutToChange()
Emitted by setValue() just before the value has changed.
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...
virtual void addChild(Property *child, int index=-1)
Add a child property.
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
void emitDataChanged(Property *property)
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option)
Create an editor widget to edit the value of this property.
bool contains(Property *possible_child) const
Return true if the list of children includes possible_child, false if not.
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
void emitPropertyHiddenChanged(const Property *property)
Emit the propertyHiddenChanged() signal for the given Property.
void setType(Type new_type)
Set the type of this Config Node.