55 const QVariant default_value,
56 const QString& description,
58 const char *changed_slot,
78 if( receiver && changed_slot )
80 connect(
this, SIGNAL(
changed() ), receiver, changed_slot );
92 for(
int i =
children_.size() - 1; i >= 0; i-- )
115 for(
int i = start_index; i < start_index + count; i++ )
132 if( new_value !=
value_ ) {
152 setObjectName( name );
177 for(
int i = 0; i < size; i++ )
180 if( prop->
getName() == sub_name )
188 QString ancestry =
"";
189 for(
Property* prop =
this; prop !=
NULL; prop = prop->getParent() )
191 ancestry =
"\"" + prop->
getName() +
"\"->" + ancestry;
193 printf(
"ERROR: Undefined property %s \"%s\" accessed.\n", qPrintable( ancestry ), qPrintable( sub_name ));
216 for(
int i = 0; i < num_children; i++ )
238 if ( role == Qt::TextColorRole &&
241 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) 244 return QColor(Qt::gray);
253 case Qt::DisplayRole:
return getName();
254 case Qt::DecorationRole:
return icon_;
255 default:
return QVariant();
261 case Qt::DisplayRole:
262 case Qt::EditRole:
return (
value_.type() == QVariant::Bool ? QVariant() :
getValue());
263 case Qt::CheckStateRole:
264 if(
value_.type() == QVariant::Bool )
265 return (
value_.toBool() ? Qt::Checked : Qt::Unchecked);
268 default:
return QVariant();
271 default:
return QVariant();
293 return enabled_flag | Qt::ItemIsSelectable;
297 if(
value_.type() == QVariant::Bool )
299 return Qt::ItemIsUserCheckable | enabled_flag | Qt::ItemIsSelectable;
301 return Qt::ItemIsEditable | enabled_flag | Qt::ItemIsSelectable;
303 return enabled_flag | Qt::ItemIsSelectable;
309 while( prop !=
NULL && prop !=
this )
330 if( index < 0 || index >=
children_.size() )
357 if( index < 0 || index > num_children )
359 index = num_children;
387 for(
int i = 0; i < num_children; i++ )
397 for(
int i = 0; i < num_children; i++ )
439 int num_property_children =
children_.size();
440 for(
int i = 0; i < num_property_children; i++ )
453 switch(
int(
value_.type() ))
456 case QMetaType::Float:
461 printf(
"Property::loadValue() TODO: error handling - unexpected QVariant type %d.\n",
int(
value_.type() ));
479 for(
int i = 0; i < num_properties; i++ )
503 const QStyleOptionViewItem& option )
505 switch(
int(
value_.type() ))
509 QSpinBox* editor =
new QSpinBox( parent );
510 editor->setFrame(
false );
511 editor->setRange( INT_MIN, INT_MAX );
514 case QMetaType::Float:
515 case QVariant::Double:
520 case QVariant::String:
523 QLineEdit* editor =
new QLineEdit( parent );
524 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.
Property * getParent() const
Return the parent Property.
virtual void expand()
Expand (show the children of) this Property.
Type getType() const
Return the Type of the referenced Node, or Invalid if this Config does not refer to a Node at all...
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
virtual ~Property()
Destructor. Removes this property from its parent's list of children.
void changed()
Emitted by setValue() just after the value has changed.
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
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...
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
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. ...
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.
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 int numChildren() const
Return the number of child objects (Property or otherwise).
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.
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...
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.
virtual void save(Config config) const
Write the value of this property and/or its children into the given Config reference.
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...
void setParent(Property *new_parent)
Set parent property, without telling the parent.
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.
QVariant getValue() const
If this config object is valid and is a Value type, this returns its value. Otherwise it returns an i...
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
bool contains(Property *possible_child) const
Return true if the list of children includes possible_child, false if not.
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.
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.
void aboutToChange()
Emitted by setValue() just before the value has changed.
virtual void addChild(Property *child, int index=-1)
Add a child property.
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
virtual QString getDescription() const
Return the description.
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.
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...
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...
void emitPropertyHiddenChanged(const Property *property)
Emit the propertyHiddenChanged() signal for the given Property.
virtual Property * childAtUnchecked(int index) const
Return the child Property with the given index, without checking whether the index is within bounds...
virtual QString getName() const
Return the name of this Property as a QString.
void setType(Type new_type)
Set the type of this Config Node.
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.