Commit 6dea1280056b8e1b9aa917dbb0563aa9dfe7a979
Merge pull request #141 from biometrics/composite_propcopy
Improvements to CompositeTransform::smartCopy
Showing
3 changed files
with
26 additions
and
10 deletions
openbr/core/core.cpp
| ... | ... | @@ -45,7 +45,8 @@ struct AlgorithmCore |
| 45 | 45 | qDebug("Training on %s%s", qPrintable(input.flat()), |
| 46 | 46 | model.isEmpty() ? "" : qPrintable(" to " + model)); |
| 47 | 47 | |
| 48 | - QScopedPointer<Transform> trainingWrapper(Transform::make("DirectStream([Identity],readMode=DistributeFrames)", NULL)); | |
| 48 | + QScopedPointer<Transform> trainingWrapper(Transform::make("DirectStream([Identity], readMode=DistributeFrames)", NULL)); | |
| 49 | + | |
| 49 | 50 | CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(trainingWrapper.data()); |
| 50 | 51 | if (downcast == NULL) |
| 51 | 52 | qFatal("downcast failed?"); | ... | ... |
openbr/openbr_plugin.cpp
| ... | ... | @@ -550,20 +550,18 @@ QStringList Object::parameters() const |
| 550 | 550 | |
| 551 | 551 | for (int i = firstAvailablePropertyIdx; i < metaObject()->propertyCount();i++) { |
| 552 | 552 | QMetaProperty property = metaObject()->property(i); |
| 553 | - if (property.isStored(this)) continue; | |
| 554 | 553 | parameters.append(QString("%1 %2 = %3").arg(property.typeName(), property.name(), property.read(this).toString())); |
| 555 | 554 | } |
| 555 | + | |
| 556 | 556 | return parameters; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | QStringList Object::arguments() const |
| 560 | 560 | { |
| 561 | 561 | QStringList arguments; |
| 562 | - for (int i=metaObject()->propertyOffset(); i<metaObject()->propertyCount(); i++) { | |
| 563 | - QMetaProperty property = metaObject()->property(i); | |
| 564 | - if (property.isStored(this)) continue; | |
| 562 | + for (int i=metaObject()->propertyOffset(); i<metaObject()->propertyCount(); i++) | |
| 565 | 563 | arguments.append(argument(i)); |
| 566 | - } | |
| 564 | + | |
| 567 | 565 | return arguments; |
| 568 | 566 | } |
| 569 | 567 | |
| ... | ... | @@ -705,7 +703,14 @@ void Object::setProperty(const QString &name, QVariant value) |
| 705 | 703 | int index = metaObject()->indexOfProperty(qPrintable(name)); |
| 706 | 704 | if (index != -1) type = metaObject()->property(index).typeName(); |
| 707 | 705 | |
| 708 | - if ((type.startsWith("QList<") && type.endsWith(">")) || (type == "QStringList")) { | |
| 706 | + if (metaObject()->property(index).isEnumType()) { | |
| 707 | + // This is necessary because setProperty can only set enums | |
| 708 | + // using their integer value if the QVariant is of type int (or uint) | |
| 709 | + bool ok; | |
| 710 | + int v = value.toInt(&ok); | |
| 711 | + if (ok) | |
| 712 | + value = v; | |
| 713 | + } else if ((type.startsWith("QList<") && type.endsWith(">")) || (type == "QStringList")) { | |
| 709 | 714 | QVariantList elements; |
| 710 | 715 | if (value.canConvert<QVariantList>()) { |
| 711 | 716 | elements = value.value<QVariantList>(); |
| ... | ... | @@ -766,8 +771,8 @@ void Object::setProperty(const QString &name, QVariant value) |
| 766 | 771 | } |
| 767 | 772 | |
| 768 | 773 | if (!QObject::setProperty(qPrintable(name), value) && !type.isEmpty()) |
| 769 | - qFatal("Failed to set %s::%s to: %s", | |
| 770 | - metaObject()->className(), qPrintable(name), qPrintable(value.toString())); | |
| 774 | + qFatal("Failed to set %s %s::%s to: %s", | |
| 775 | + qPrintable(type), metaObject()->className(), qPrintable(name), qPrintable(value.toString())); | |
| 771 | 776 | } |
| 772 | 777 | |
| 773 | 778 | QStringList Object::parse(const QString &string, char split) | ... | ... |
openbr/plugins/openbr_internal.h
| ... | ... | @@ -260,9 +260,19 @@ public: |
| 260 | 260 | newTransform = true; |
| 261 | 261 | |
| 262 | 262 | QString name = metaObject()->className(); |
| 263 | + | |
| 263 | 264 | name.replace("Transform",""); |
| 264 | - name += "([])"; | |
| 265 | + name += "([]"; | |
| 266 | + | |
| 267 | + QStringList arguments = this->arguments(); | |
| 268 | + if (!arguments.isEmpty()) { | |
| 269 | + name += ","; | |
| 270 | + name += this->arguments().join(","); | |
| 271 | + } | |
| 272 | + | |
| 273 | + name += ")"; | |
| 265 | 274 | name.replace("br::",""); |
| 275 | + | |
| 266 | 276 | CompositeTransform * output = dynamic_cast<CompositeTransform *>(Transform::make(name, NULL)); |
| 267 | 277 | |
| 268 | 278 | if (output == NULL) | ... | ... |