mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 03:24:46 +02:00
Working on object attributes.
This commit is contained in:
parent
6a017e93f1
commit
64df9718f2
5 changed files with 127 additions and 13 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <QListWidget>
|
||||
#include <QMetaProperty>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <AttributeRegistry.h>
|
||||
|
@ -152,7 +153,10 @@ void MetavoxelEditor::updateValueEditor() {
|
|||
AttributePointer attribute = AttributeRegistry::getInstance()->getAttribute(selected);
|
||||
QWidget* editor = attribute->createEditor();
|
||||
if (editor) {
|
||||
_value->layout()->addWidget(editor);
|
||||
QScrollArea* area = new QScrollArea();
|
||||
area->setWidgetResizable(true);
|
||||
area->setWidget(editor);
|
||||
_value->layout()->addWidget(area);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
//
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QMetaProperty>
|
||||
#include <QPushButton>
|
||||
#include <QScriptEngine>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -22,7 +25,8 @@ AttributeRegistry* AttributeRegistry::getInstance() {
|
|||
}
|
||||
|
||||
AttributeRegistry::AttributeRegistry() :
|
||||
_guideAttribute(registerAttribute(new PolymorphicAttribute("guide", PolymorphicDataPointer(new DefaultMetavoxelGuide())))),
|
||||
_guideAttribute(registerAttribute(new SharedObjectAttribute("guide", &MetavoxelGuide::staticMetaObject,
|
||||
PolymorphicDataPointer(new DefaultMetavoxelGuide())))),
|
||||
_colorAttribute(registerAttribute(new QRgbAttribute("color"))),
|
||||
_normalAttribute(registerAttribute(new QRgbAttribute("normal", qRgb(0, 127, 0)))) {
|
||||
}
|
||||
|
@ -181,6 +185,59 @@ PolymorphicAttribute::PolymorphicAttribute(const QString& name, const Polymorphi
|
|||
InlineAttribute<PolymorphicDataPointer>(name, defaultValue) {
|
||||
}
|
||||
|
||||
void* PolymorphicAttribute::createFromVariant(const QVariant& value) const {
|
||||
return create(encodeInline(value.value<PolymorphicDataPointer>()));
|
||||
}
|
||||
|
||||
bool PolymorphicAttribute::merge(void*& parent, void* children[]) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
PolymorphicData* SharedObject::clone() const {
|
||||
// default behavior is to make a copy using the no-arg constructor and copy the stored properties
|
||||
const QMetaObject* metaObject = this->metaObject();
|
||||
QObject* newObject = metaObject->newInstance();
|
||||
for (int i = 0; i < metaObject->propertyCount(); i++) {
|
||||
QMetaProperty property = metaObject->property(i);
|
||||
if (property.isStored()) {
|
||||
property.write(newObject, property.read(this));
|
||||
}
|
||||
}
|
||||
foreach (const QByteArray& propertyName, dynamicPropertyNames()) {
|
||||
newObject->setProperty(propertyName, property(propertyName));
|
||||
}
|
||||
return static_cast<SharedObject*>(newObject);
|
||||
}
|
||||
|
||||
SharedObjectAttribute::SharedObjectAttribute(const QString& name, const QMetaObject* metaObject,
|
||||
const PolymorphicDataPointer& defaultValue) :
|
||||
PolymorphicAttribute(name, defaultValue),
|
||||
_metaObject(metaObject) {
|
||||
|
||||
}
|
||||
|
||||
QWidget* SharedObjectAttribute::createEditor(QWidget* parent) const {
|
||||
SharedObjectEditor* editor = new SharedObjectEditor(parent);
|
||||
editor->setObject(_defaultValue);
|
||||
return editor;
|
||||
}
|
||||
|
||||
SharedObjectEditor::SharedObjectEditor(QWidget* parent) : QWidget(parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
setLayout(layout);
|
||||
|
||||
QFormLayout* form = new QFormLayout();
|
||||
layout->addLayout(form);
|
||||
|
||||
form->addRow("Type:", _type = new QComboBox());
|
||||
_type->addItem("(none)");
|
||||
connect(_type, SIGNAL(currentIndexChanged(int)), SLOT(updateType()));
|
||||
}
|
||||
|
||||
void SharedObjectEditor::setObject(const PolymorphicDataPointer& object) {
|
||||
_object = object;
|
||||
}
|
||||
|
||||
void SharedObjectEditor::updateType() {
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "Bitstream.h"
|
||||
|
||||
class QComboBox;
|
||||
class QPushButton;
|
||||
class QScriptContext;
|
||||
class QScriptEngine;
|
||||
|
@ -338,13 +339,66 @@ template<> PolymorphicData* QExplicitlySharedDataPointer<PolymorphicData>::clone
|
|||
|
||||
typedef QExplicitlySharedDataPointer<PolymorphicData> PolymorphicDataPointer;
|
||||
|
||||
Q_DECLARE_METATYPE(PolymorphicDataPointer)
|
||||
|
||||
/// Provides polymorphic streaming and averaging.
|
||||
class PolymorphicAttribute : public InlineAttribute<PolymorphicDataPointer> {
|
||||
public:
|
||||
|
||||
PolymorphicAttribute(const QString& name, const PolymorphicDataPointer& defaultValue = PolymorphicDataPointer());
|
||||
|
||||
virtual void* createFromVariant(const QVariant& value) const;
|
||||
|
||||
virtual bool merge(void*& parent, void* children[]) const;
|
||||
};
|
||||
|
||||
class SharedObject : public QObject, public PolymorphicData {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/// Creates a new clone of this object.
|
||||
virtual PolymorphicData* clone() const;
|
||||
};
|
||||
|
||||
/// An attribute that takes the form of QObjects of a given meta-type (a subclass of SharedObject).
|
||||
class SharedObjectAttribute : public PolymorphicAttribute {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(const QMetaObject* metaObject MEMBER _metaObject)
|
||||
|
||||
public:
|
||||
|
||||
Q_INVOKABLE SharedObjectAttribute(const QString& name = QString(), const QMetaObject* metaObject = NULL,
|
||||
const PolymorphicDataPointer& defaultValue = PolymorphicDataPointer());
|
||||
|
||||
virtual QWidget* createEditor(QWidget* parent = NULL) const;
|
||||
|
||||
private:
|
||||
|
||||
const QMetaObject* _metaObject;
|
||||
};
|
||||
|
||||
/// Allows editing shared object instances.
|
||||
class SharedObjectEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(PolymorphicDataPointer object MEMBER _object WRITE setObject USER true)
|
||||
|
||||
public:
|
||||
|
||||
SharedObjectEditor(QWidget* parent);
|
||||
|
||||
public slots:
|
||||
|
||||
void setObject(const PolymorphicDataPointer& object);
|
||||
|
||||
private slots:
|
||||
|
||||
void updateType();
|
||||
|
||||
private:
|
||||
|
||||
QComboBox* _type;
|
||||
PolymorphicDataPointer _object;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__AttributeRegistry__) */
|
||||
|
|
|
@ -425,8 +425,7 @@ MetavoxelVisitor::MetavoxelVisitor(const QVector<AttributePointer>& inputs, cons
|
|||
MetavoxelVisitor::~MetavoxelVisitor() {
|
||||
}
|
||||
|
||||
PolymorphicData* DefaultMetavoxelGuide::clone() const {
|
||||
return new DefaultMetavoxelGuide();
|
||||
DefaultMetavoxelGuide::DefaultMetavoxelGuide() {
|
||||
}
|
||||
|
||||
void DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) {
|
||||
|
@ -592,10 +591,6 @@ ScriptedMetavoxelGuide::ScriptedMetavoxelGuide(const QScriptValue& guideFunction
|
|||
_info.setProperty(_minimumHandle, _minimum);
|
||||
}
|
||||
|
||||
PolymorphicData* ScriptedMetavoxelGuide::clone() const {
|
||||
return new ScriptedMetavoxelGuide(_guideFunction);
|
||||
}
|
||||
|
||||
void ScriptedMetavoxelGuide::guide(MetavoxelVisitation& visitation) {
|
||||
QScriptValue data = _guideFunction.engine()->newVariant(QVariant::fromValue<void*>(this));
|
||||
_getInputsFunction.setData(data);
|
||||
|
|
|
@ -150,7 +150,9 @@ protected:
|
|||
typedef QSharedPointer<MetavoxelVisitor> MetavoxelVisitorPointer;
|
||||
|
||||
/// Interface for objects that guide metavoxel visitors.
|
||||
class MetavoxelGuide : public PolymorphicData {
|
||||
class MetavoxelGuide : public SharedObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/// Guides the specified visitor to the contained voxels.
|
||||
|
@ -159,21 +161,23 @@ public:
|
|||
|
||||
/// Guides visitors through the explicit content of the system.
|
||||
class DefaultMetavoxelGuide : public MetavoxelGuide {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
virtual PolymorphicData* clone() const;
|
||||
Q_INVOKABLE DefaultMetavoxelGuide();
|
||||
|
||||
virtual void guide(MetavoxelVisitation& visitation);
|
||||
};
|
||||
|
||||
/// Represents a guide implemented in Javascript.
|
||||
class ScriptedMetavoxelGuide : public MetavoxelGuide {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ScriptedMetavoxelGuide(const QScriptValue& guideFunction);
|
||||
Q_INVOKABLE ScriptedMetavoxelGuide(const QScriptValue& guideFunction = QScriptValue());
|
||||
|
||||
virtual PolymorphicData* clone() const;
|
||||
|
||||
virtual void guide(MetavoxelVisitation& visitation);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue