QWidget* DynamicObjectItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { if (index.column() == 1) { auto node = (DynamicObjectModel::Node*)index.internalPointer(); if (!node) { return QStyledItemDelegate::createEditor(parent, option, index); } if (node->onCreateEditor) { return node->onCreateEditor(parent, option); } else if (node->m_getter().type() == QMetaType::Bool) { return nullptr; } else if (node->m_getter().type() == QMetaType::Float) { QDoubleSpinBox* input = new QDoubleSpinBox(parent); input->setMaximum(FLT_MAX); input->setMinimum(-FLT_MAX); connect(input, (void (QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged, [node](double value){ node->m_setter(value); }); input->setSingleStep(0.1); return input; } } return QStyledItemDelegate::createEditor(parent, option, index); }
bool Global::SetValue(const Argument &value) const { // read only? if (m_setter != nullptr) { m_setter( value ); return true; } return false; }
void IndexMapper::Set(unsigned int i, UInt32 value) { #if NAZARA_UTILITY_SAFE if (i >= m_indexCount) { NazaraError("Index out of range (" + String::Number(i) + " >= " + String::Number(m_indexCount) + ')'); return; } #endif m_setter(m_mapper.GetPointer(), i, value); }
void ResourceModel::fillMaterialInfo(Lumix::Material* material, Node& node) { auto object = Object<Lumix::Material>(material, &node); node.m_getter = [material]() -> QVariant { return material->getPath().c_str(); }; node.m_name = "Material"; object.getNode().onCreateEditor = [this, material]( QWidget* parent, const QStyleOptionViewItem&) -> QWidget* { auto* widget = new QWidget(parent); auto* layout = new QHBoxLayout(widget); layout->setContentsMargins(0, 0, 0, 0); auto* label = new QLabel(material->getPath().c_str(), widget); layout->addWidget(label); layout->addStretch(); QPushButton* button = new QPushButton("Save", widget); connect(button, &QPushButton::clicked, [this, material]() { saveMaterial(material); }); layout->addWidget(button); return widget; }; object.getNode().enablePeristentEditor(); object.property("Alpha cutout", &Lumix::Material::isAlphaCutout, &Lumix::Material::enableAlphaCutout) .property("Backface culling", &Lumix::Material::isBackfaceCulling, &Lumix::Material::enableBackfaceCulling) .property("Shadow receiver", &Lumix::Material::isShadowReceiver, &Lumix::Material::enableShadowReceiving) .property("Shininess", &Lumix::Material::getShininess, &Lumix::Material::setShininess) .propertyColor("Specular", &Lumix::Material::getSpecular, &Lumix::Material::setSpecular) .property( "Z test", &Lumix::Material::isZTest, &Lumix::Material::enableZTest) .property("Shader", [](Lumix::Material* material) -> QVariant { return material->getShader() ? material->getShader()->getPath().c_str() : ""; }, [this](Lumix::Material* material, QVariant value) { setMaterialShader(material, value.toString()); }); auto shader_node = object.getNode().m_children.back(); shader_node->enablePeristentEditor(); shader_node->onCreateEditor = [shader_node](QWidget* parent, const QStyleOptionViewItem&) { auto input = new FileInput(parent); input->setValue(shader_node->m_getter().toString()); input->connect(input, &FileInput::valueChanged, [shader_node, input]() { shader_node->m_setter(input->value()); }); return input; }; for (int i = 0; i < material->getUniformCount(); ++i) { auto& uniform = material->getUniform(i); QString name = uniform.m_name; object.property(uniform.m_name, [name](Lumix::Material* material) -> QVariant { Lumix::Material::Uniform* uniform = getMaterialUniform(material, name); if (uniform) { switch (uniform->m_type) { case Lumix::Material::Uniform::FLOAT: return uniform->m_float; } } return QVariant(); }, [name](Lumix::Material* material, const QVariant& value) { Lumix::Material::Uniform* uniform = getMaterialUniform(material, name); if (uniform) { switch (uniform->m_type) { case Lumix::Material::Uniform::FLOAT: uniform->m_float = value.toFloat(); break; } } }); } for (int i = 0; material->getShader() && i < material->getShader()->getTextureSlotCount(); ++i) { const auto& slot = material->getShader()->getTextureSlot(i); Object<const Lumix::Shader::TextureSlot> slot_object( &slot, &object.getNode().addChild(slot.m_name)); auto& node = slot_object.getNode(); auto texture = material->getTexture(i); if (texture) { fillTextureInfo(texture, node); } node.m_name = slot.m_name; node.m_getter = [texture]() -> QVariant { return texture ? texture->getPath().c_str() : ""; }; node.onCreateEditor = [&node, i, texture, material]( QWidget* parent, const QStyleOptionViewItem&) -> QWidget* { auto input = new FileInput(parent); input->setValue(texture ? texture->getPath().c_str() : ""); input->connect(input, &FileInput::valueChanged, [&node, input]() { node.m_setter(input->value()); }); return input; }; node.m_setter = [material, i](const QVariant& value) { if (value.isValid()) { material->setTexturePath( i, Lumix::Path(value.toString().toLatin1().data())); } }; node.enablePeristentEditor(); } }
void AccessorArrayValue<Type, Size>::set(size_t i, const Type & value) { m_setter(i, value); }
void AccessorArrayValue<Type, Size>::set(const std::array<Type, Size> & array) { for (size_t i = 0; i < Size; ++i) m_setter(i, array[i]); }