Пример #1
0
void Edge::changedHandler(capputils::ObservableClass* object, int eventId) {
  // check for the right property ID

  if ((object != this && eventId == (int)outputId) || (object == this && eventId == positionId)) {
    PropertyReference* inputRef = getInputReference().get();
    PropertyReference* outputRef = getOutputReference().get();

    if (!inputRef || !outputRef)
      return;

    capputils::reflection::IClassProperty* inProp = inputRef->getProperty();
    capputils::reflection::IClassProperty* outProp = outputRef->getProperty();

    if (inProp && outProp) {
      IMergeAttribute* merge = inProp->getAttribute<IMergeAttribute>();
      if (merge) {
        merge->setValue(*inputRef->getObject(), inProp, getInputPosition(), *outputRef->getObject(), outProp);
      } else {
        inProp->setValue(*inputRef->getObject(), *outputRef->getObject(), outProp);
      }
    }
  }
}
Пример #2
0
void updateModel(QStandardItem* parentItem, const std::string& propertyPrefix = "") {
  // Go throw keys of parentItem

  for (int iRow = 0; iRow < parentItem->rowCount(); ++iRow) {
    QStandardItem* valueItem = parentItem->child(iRow, 1);
    if (valueItem && valueItem->data(Qt::UserRole).canConvert<PropertyReference>()) {
      PropertyReference ref = valueItem->data(Qt::UserRole).value<PropertyReference>();

      IReflectableAttribute* reflectable = ref.getProperty()->getAttribute<IReflectableAttribute>();
      if (reflectable) {
        ReflectableClass* subObject = reflectable->getValuePtr(*ref.getObject(), ref.getProperty());

        // If the type of the reflectable object has changed, the subtree needs to be rebuild.
        // You need to know the previous type in order to detect a change. ScalarAttributes are
        // no longer supported in order to guarantee, that the string value is always set to the
        // previous type name.
        if (subObject) {
          std::string oldClassName(valueItem->text().toStdString());
          if (oldClassName.compare(subObject->getClassName())) {
            valueItem->setText(subObject->getClassName().c_str());
            buildModel(parentItem->child(iRow, 0), subObject, ref.getNode().get(), propertyPrefix + ref.getProperty()->getName() + ".");
          } else {
            updateModel(parentItem->child(iRow, 0), propertyPrefix + ref.getProperty()->getName() + ".");
          }
        } else {
          valueItem->setText(ref.getProperty()->getStringValue(*ref.getObject()).c_str());
        }
      } else if (ref.getProperty()->getAttribute<FlagAttribute>()) {
        ClassProperty<bool>* boolProperty = dynamic_cast<ClassProperty<bool>* >(ref.getProperty());
        // properties tagged as Flag() must be of type bool
        assert(boolProperty);
        if (boolProperty->getValue(*ref.getObject()))
          valueItem->setCheckState(Qt::Checked);
        else
          valueItem->setCheckState(Qt::Unchecked);
      } else{
        valueItem->setText(ref.getProperty()->getStringValue(*ref.getObject()).c_str());
      }
    } else {
      if (parentItem->child(iRow, 0)->hasChildren()) {
        updateModel(parentItem->child(iRow, 0), propertyPrefix);
      }
    }
  }
}