diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 9d0b169..4fff6d5 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -786,7 +786,7 @@ void Object::load(QDataStream &stream) init(); } -bool Object::setPropertyRecursive(const QString &name, QVariant value) +bool Object::setExistingProperty(const QString &name, QVariant value) { if (this->metaObject()->indexOfProperty(qPrintable(name)) == -1) return false; @@ -795,6 +795,56 @@ bool Object::setPropertyRecursive(const QString &name, QVariant value) return true; } +QList Object::getChildren() const +{ + QList output; + for (int i=0; i < metaObject()->propertyCount(); i++) { + const char *prop_name = metaObject()->property(i).name(); + const QVariant &variant = this->property(prop_name); + + if (variant.canConvert()) { + Transform *tform = variant.value(); + if (tform) + output.append((Object* ) variant.value()); + } + else if (variant.canConvert >()) { + foreach (const Transform *tform, variant.value >()) { + if (tform) + output.append((Object *) tform); + } + } + else if (variant.canConvert()) { + Distance *dist = variant.value(); + if (dist) + output.append((Object* ) variant.value()); + } + else if (variant.canConvert >()) { + foreach (const Distance *dist, variant.value >()) { + if (dist) + output.append((Object *) dist); + } + } + } + return output; +} + +bool Object::setPropertyRecursive(const QString &name, QVariant value) +{ + // collect children + bool res = setExistingProperty(name, value); + if (res) + return true; + + QList children = getChildren(); + foreach (Object *obj, children) { + if (obj->setPropertyRecursive(name, value)) { + init(); + return true; + } + } + return false; +} + void Object::setProperty(const QString &name, QVariant value) { QString type; @@ -1408,24 +1458,9 @@ void Transform::project(const TemplateList &src, TemplateList &dst) const futures.waitForFinished(); } -QList Transform::getChildren() const -{ - QList output; - for (int i=0; i < metaObject()->propertyCount(); i++) { - const char *prop_name = metaObject()->property(i).name(); - const QVariant &variant = this->property(prop_name); - - if (variant.canConvert()) - output.append(variant.value()); - if (variant.canConvert >()) - output.append(variant.value >()); - } - return output; -} - TemplateEvent *Transform::getEvent(const QString &name) { - foreach (Transform *child, getChildren()) { + foreach (Transform *child, getChildren()) { TemplateEvent *probe = child->getEvent(name); if (probe) return probe; diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 437542d..8788824 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -603,6 +603,22 @@ public: void setProperty(const QString &name, QVariant value); /*!< \brief Overload of QObject::setProperty to handle OpenBR data types. */ virtual bool setPropertyRecursive(const QString &name, QVariant value); /*!< \brief Recursive version of setProperty, try to set the property on this object, or its children, returns true if successful. */ + bool setExistingProperty(const QString &name, QVariant value); /*! <\brief attempt to set property 'name' on this object. If name is not a pre-declared property, return false */ + + virtual QList getChildren() const; /*!< \brief retrieve children of this object, default version scans properties, subclasses which do not sotre their children as properties must overload. */ + + template + QList getChildren() const + { + QList children = getChildren(); + QList output; + foreach(Object *obj, children) { + T *temp = dynamic_cast(obj); + if (temp != NULL) + output.append(temp); + } + return output; + } static QStringList parse(const QString &string, char split = ','); /*!< \brief Splits the string while respecting lexical scoping of (), [], \<\>, and {}. */ @@ -1276,12 +1292,6 @@ public: */ virtual TemplateEvent *getEvent(const QString &name); - /*! - * \brief Get a list of child transforms of this transform, child transforms are considered to be - * any transforms stored as properties of this transform. - */ - QList getChildren() const; - static Transform *deserialize(QDataStream &stream) { QString desc; diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index bc8e05d..7ac93ce 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -138,9 +138,10 @@ class IndependentTransform : public MetaTransform return transform->description(expanded); } + // can't use general setPropertyRecursive because of transforms oddness bool setPropertyRecursive(const QString &name, QVariant value) { - if (br::Object::setPropertyRecursive(name, value)) + if (br::Object::setExistingProperty(name, value)) return true; if (!transform->setPropertyRecursive(name, value)) diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index d831882..aaa0e22 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -529,11 +529,11 @@ public: return res; } - bool setPropertyRecursive(const QString &name, QVariant value) + QList getChildren() const { - if (br::Object::setPropertyRecursive(name, value)) - return true; - return transform->setPropertyRecursive(name, value); + QList rval; + rval.append(transform); + return rval; } private: diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index d9a5e45..fa9e3c6 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -227,19 +227,6 @@ public: return output; } - - bool setPropertyRecursive(const QString &name, QVariant value) - { - if (br::Object::setPropertyRecursive(name, value)) - return true; - - if (transform->setPropertyRecursive(name, value)) { - init(); - return true; - } - return false; - } - Transform *smartCopy(bool &newTransform) { if (!timeVarying()) { @@ -392,21 +379,6 @@ public: return output; } - bool setPropertyRecursive(const QString &name, QVariant value) - { - if (br::Object::setPropertyRecursive(name, value)) - return true; - - for (int i=0; i < this->transforms.size();i++) { - if (transforms[i]->setPropertyRecursive(name, value)) { - init(); - return true; - } - } - return false; - } - - protected: bool isTimeVarying; diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index 223ce78..c2e5019 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -1325,9 +1325,10 @@ public: return res; } + // can't use general setPropertyRecursive due to special handling of basis bool setPropertyRecursive(const QString &name, QVariant value) { - if (br::Object::setPropertyRecursive(name, value)) + if (br::Object::setExistingProperty(name, value)) return true; for (int i=0; i < basis->transforms.size();i++) { @@ -1336,6 +1337,12 @@ public: return true; } } + + if (basis->endPoint->setPropertyRecursive(name, value)) { + basis->endPoint->init(); + return true; + } + return false; }