static void populateRuleComponentModel(RuleComponentModel *component, QmlObject::Ptr object,
                                       const QMap<QString, QmlObject::Ptr> &mappers)
{
    if (!component) {
        return;
    }

    for (int i = 0; i < component->count(); ++i) {
        QVariant type = component->data(component->index(i), RuleComponentModel::Type);
        MetaProperty *meta = type.value<MetaProperty *>();
        if (meta) {
            QString key = meta->name();
            if (object->hasProperty(key)) {
                // TODO: migrate to MetaProperty
                QVariant value = object->property(key);
                if (value.canConvert<Reference::Ptr>()) {
                    Reference::Ptr reference = value.value<Reference::Ptr>();
                    if (mappers.contains(reference->identifier())) {
                        // Check mapper
                        QmlObject::Ptr mapper = mappers.value(reference->identifier());
                        if (mapper->type() == "TimeMapper") {
                            int hour = mapper->property("hour").toInt();
                            int minute = mapper->property("minute").toInt();
                            QTime time = QTime(hour, minute);
                            component->setValue(i, QVariant(time));
                        }
                    }
                } else {
                    component->setValue(i, value);
                }
            }
        }
    }
}
Exemple #2
0
bool MetaPropertyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
  if (index.isValid() && index.column() == 1 && m_metaObject && m_object && role == Qt::EditRole) {
    MetaProperty *property = m_metaObject->propertyAt(index.row());
    property->setValue(m_metaObject->castForPropertyAt(m_object, index.row()), value);
    return true;
  }
  return QAbstractItemModel::setData(index, value, role);
}
MetaProperty * AbstractMetaData::property(const QString &property) const
{
    Q_D(const AbstractMetaData);
    if (!d->metaProperties.contains(property)) {
        MetaProperty *meta = getProperty(property, const_cast<AbstractMetaData *>(this));
        Q_ASSERT(meta && meta->parent() == this);
        d->metaProperties.insert(property, meta);
        return meta;
    }

    return d->metaProperties[property];
}
Exemple #4
0
Qt::ItemFlags MetaPropertyModel::flags(const QModelIndex &index) const
{
  const Qt::ItemFlags f = QAbstractItemModel::flags(index);
  if (!index.isValid() || index.column() != 1 || !m_metaObject || !m_object) {
    return f;
  }

  MetaProperty *property = m_metaObject->propertyAt(index.row());
  if (property->isReadOnly()) {
    return f;
  }
  return f | Qt::ItemIsEditable;
}
Exemple #5
0
void Object::setProperty(const char *name, Variant val)
{
    int id = metaObject()->propertyId(name);

    if(id < 0) {
        LOG(Error, "Object '%s' of type '%s' does not have a property '%s'",
            this->name().data(), metaObject()->className(), name);
        return;
    }

    MetaProperty prop = metaObject()->property(id);

    if(!prop.isWritable()) {
        LOG(Error, "Property '%s' is not writable", name);
        return;
    }

    return prop.write(this, val);
}
Exemple #6
0
Variant Object::property(const char *name)
{
    int id = metaObject()->propertyId(name);

    if(id < 0) {
        LOG(Error, "Object '%s' of type '%s' does not have a property '%s'",
            this->name().data(), metaObject()->className(), name);
        return Variant();
    }

    MetaProperty prop = metaObject()->property(id);

    if(!prop.isReadable()) {
        LOG(Error, "Property '%s' is not readable", name);
        return Variant();
    }

    return prop.read(this);
}
Exemple #7
0
QVariant MetaPropertyModel::data(const QModelIndex &index, int role) const
{
  if (!m_metaObject || !index.isValid()) {
    return QVariant();
  }

  MetaProperty *property = m_metaObject->propertyAt(index.row());
  if (role == Qt::DisplayRole) {
    switch (index.column()) {
    case 0:
      return property->name();
    case 2:
      return property->typeName();
    case 3:
      return property->metaObject()->className();
    }
  }

  if (index.column() == 1) {
    if (!m_object) {
      return QVariant();
    }

    // TODO: cache this, to make this more robust against m_object becoming invalid
    const QVariant value = property->value(m_metaObject->castForPropertyAt(m_object, index.row()));
    switch (role) {
    case Qt::DisplayRole:
      return Util::variantToString(value);
    case Qt::DecorationRole:
      return Util::decorationForVariant(value);
    case Qt::EditRole:
      return value;
    }
  }
  return QVariant();
}