Commit 6bb619e7476bde789d987c36da9008e26fb57f63

Authored by Josh Klontz
1 parent 23883f38

cleaned up Object::init

openbr/openbr_plugin.cpp
... ... @@ -701,42 +701,27 @@ QStringList Object::parse(const QString &string, char split)
701 701 /* Object - private methods */
702 702 void Object::init(const File &file_)
703 703 {
704   - this->file = file_;
705   -
706   - // Set name
707   - QString name = metaObject()->className();
708   - if (name.startsWith("br::")) name = name.right(name.size()-4);
709   -
710   - firstAvailablePropertyIdx = metaObject()->propertyCount();
711   -
712   - const QMetaObject * baseClass = metaObject();
713   - const QMetaObject * superClass = metaObject()->superClass();
714   -
715   - while (superClass != NULL) {
716   - const QMetaObject * nextClass = superClass->superClass();
717   -
718   - // baseClass <- something <- br::Object
719   - // baseClass is the highest class whose properties we can set via positional arguments
720   - if (nextClass && !strcmp(nextClass->className(),"br::Object")) {
  704 + file = file_;
  705 +
  706 + // Determine interfaceName and firstAvailablePropertyIdx
  707 + QString interfaceName;
  708 + const QMetaObject *baseClass = metaObject();
  709 + while (true) {
  710 + if (!strcmp(baseClass->superClass()->className(), "br::Object") /* Special case for classes that inherit directly from br::Object */ ||
  711 + !strcmp(baseClass->superClass()->superClass()->className(), "br::Object") /* General case for plugins that inherit indirectly from br::Object */) {
721 712 firstAvailablePropertyIdx = baseClass->propertyOffset();
  713 + interfaceName = QString(baseClass->superClass()->className()).remove("br::");
  714 + break;
722 715 }
723   -
724   - QString superClassName = superClass->className();
725   -
726   - // strip br:: prefix from superclass name
727   - if (superClassName.startsWith("br::"))
728   - superClassName = superClassName.right(superClassName.size()-4);
729   -
730   - // Strip superclass name from base class name (e.g. PipeTransform -> Pipe)
731   - if (name.endsWith(superClassName))
732   - name = name.left(name.size() - superClassName.size());
733   - baseClass = superClass;
734   - superClass = superClass->superClass();
735   -
  716 + baseClass = baseClass->superClass();
736 717 }
  718 +
  719 + // Strip interface name from object name (e.g. PipeTransform -> Pipe)
  720 + QString name = QString(metaObject()->className()).remove("br::");
  721 + if (name.endsWith(interfaceName)) name = name.left(name.size() - interfaceName.size());
737 722 setObjectName(name);
738 723  
739   - // Reset all properties
  724 + // Set properties to their default values
740 725 for (int i=0; i<metaObject()->propertyCount(); i++) {
741 726 QMetaProperty property = metaObject()->property(i);
742 727 if (property.isResettable())
... ...
openbr/openbr_plugin.h
... ... @@ -498,9 +498,7 @@ struct TemplateList : public QList&lt;Template&gt;
498 498 class BR_EXPORT Object : public QObject
499 499 {
500 500 Q_OBJECT
501   -
502   - // Index of the first property that can be set via command line arguments
503   - int firstAvailablePropertyIdx;
  501 + int firstAvailablePropertyIdx; /*!< \brief Index of the first property that can be set via command line arguments. */
504 502  
505 503 public:
506 504 File file; /*!< \brief The file used to construct the plugin. */
... ...