mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-19 13:44:20 +02:00
Work on creating new attributes.
This commit is contained in:
parent
d6d95a586d
commit
5b207e4f8e
8 changed files with 103 additions and 14 deletions
|
@ -155,14 +155,13 @@ void MetavoxelEditor::selectedAttributeChanged() {
|
|||
_value->setVisible(false);
|
||||
return;
|
||||
}
|
||||
AttributePointer attribute = AttributeRegistry::getInstance()->getAttribute(selected);
|
||||
|
||||
_deleteAttribute->setEnabled(true);
|
||||
_value->setVisible(true);
|
||||
|
||||
if (_valueArea->widget()) {
|
||||
delete _valueArea->widget();
|
||||
}
|
||||
QWidget* editor = attribute->createEditor();
|
||||
QWidget* editor = AttributeRegistry::getInstance()->getAttribute(selected)->createEditor();
|
||||
if (editor) {
|
||||
_valueArea->setWidget(editor);
|
||||
}
|
||||
|
@ -181,6 +180,10 @@ void MetavoxelEditor::createNewAttribute() {
|
|||
QLineEdit name;
|
||||
form.addRow("Name:", &name);
|
||||
|
||||
SharedObjectEditor editor(&Attribute::staticMetaObject, false);
|
||||
editor.setObject(new QRgbAttribute());
|
||||
layout.addWidget(&editor);
|
||||
|
||||
QDialogButtonBox buttons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
dialog.connect(&buttons, SIGNAL(accepted()), SLOT(accept()));
|
||||
dialog.connect(&buttons, SIGNAL(rejected()), SLOT(reject()));
|
||||
|
@ -191,13 +194,17 @@ void MetavoxelEditor::createNewAttribute() {
|
|||
return;
|
||||
}
|
||||
QString nameText = name.text().trimmed();
|
||||
AttributeRegistry::getInstance()->registerAttribute(new QRgbAttribute(nameText));
|
||||
SharedObjectPointer attribute = editor.getObject();
|
||||
attribute->setObjectName(nameText);
|
||||
AttributeRegistry::getInstance()->registerAttribute(attribute.staticCast<Attribute>());
|
||||
|
||||
updateAttributes(nameText);
|
||||
}
|
||||
|
||||
void MetavoxelEditor::deleteSelectedAttribute() {
|
||||
|
||||
AttributeRegistry::getInstance()->deregisterAttribute(getSelectedAttribute());
|
||||
_attributes->selectionModel()->clear();
|
||||
updateAttributes();
|
||||
}
|
||||
|
||||
void MetavoxelEditor::centerGridPosition() {
|
||||
|
|
|
@ -53,6 +53,10 @@ AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute
|
|||
return pointer;
|
||||
}
|
||||
|
||||
void AttributeRegistry::deregisterAttribute(const QString& name) {
|
||||
_attributes.remove(name);
|
||||
}
|
||||
|
||||
QScriptValue AttributeRegistry::getAttribute(QScriptContext* context, QScriptEngine* engine) {
|
||||
return engine->newQObject(getInstance()->getAttribute(context->argument(0).toString()).data(), QScriptEngine::QtOwnership,
|
||||
QScriptEngine::PreferExistingWrapperObject);
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
/// attribute
|
||||
AttributePointer registerAttribute(AttributePointer attribute);
|
||||
|
||||
/// Deregisters an attribute.
|
||||
void deregisterAttribute(const QString& name);
|
||||
|
||||
/// Retrieves an attribute by name.
|
||||
AttributePointer getAttribute(const QString& name) const { return _attributes.value(name); }
|
||||
|
||||
|
@ -260,7 +263,8 @@ class SharedObjectAttribute : public InlineAttribute<SharedObjectPointer> {
|
|||
|
||||
public:
|
||||
|
||||
Q_INVOKABLE SharedObjectAttribute(const QString& name = QString(), const QMetaObject* metaObject = NULL,
|
||||
Q_INVOKABLE SharedObjectAttribute(const QString& name = QString(),
|
||||
const QMetaObject* metaObject = &SharedObject::staticMetaObject,
|
||||
const SharedObjectPointer& defaultValue = SharedObjectPointer());
|
||||
|
||||
virtual void read(Bitstream& in, void*& value, bool isLeaf) const;
|
||||
|
|
|
@ -68,8 +68,8 @@ IDStreamer& IDStreamer::operator>>(int& value) {
|
|||
int Bitstream::registerMetaObject(const char* className, const QMetaObject* metaObject) {
|
||||
getMetaObjects().insert(className, metaObject);
|
||||
|
||||
// register it as a subclass of all of its superclasses
|
||||
for (const QMetaObject* superClass = metaObject->superClass(); superClass != NULL; superClass = superClass->superClass()) {
|
||||
// register it as a subclass of itself and all of its superclasses
|
||||
for (const QMetaObject* superClass = metaObject; superClass != NULL; superClass = superClass->superClass()) {
|
||||
getMetaObjectSubClasses().insert(superClass, metaObject);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <QByteArray>
|
||||
#include <QColorDialog>
|
||||
#include <QComboBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
@ -104,6 +105,12 @@ static QItemEditorCreatorBase* createDoubleEditorCreator() {
|
|||
return creator;
|
||||
}
|
||||
|
||||
static QItemEditorCreatorBase* createQMetaObjectEditorCreator() {
|
||||
QItemEditorCreatorBase* creator = new LazyItemEditorCreator<QMetaObjectEditor>();
|
||||
getItemEditorFactory()->registerEditor(qMetaTypeId<const QMetaObject*>(), creator);
|
||||
return creator;
|
||||
}
|
||||
|
||||
static QItemEditorCreatorBase* createQColorEditorCreator() {
|
||||
QItemEditorCreatorBase* creator = new LazyItemEditorCreator<QColorEditor>();
|
||||
getItemEditorFactory()->registerEditor(qMetaTypeId<QColor>(), creator);
|
||||
|
@ -123,6 +130,7 @@ static QItemEditorCreatorBase* createParameterizedURLEditorCreator() {
|
|||
}
|
||||
|
||||
static QItemEditorCreatorBase* doubleEditorCreator = createDoubleEditorCreator();
|
||||
static QItemEditorCreatorBase* qMetaObjectEditorCreator = createQMetaObjectEditorCreator();
|
||||
static QItemEditorCreatorBase* qColorEditorCreator = createQColorEditorCreator();
|
||||
static QItemEditorCreatorBase* vec3EditorCreator = createVec3EditorCreator();
|
||||
static QItemEditorCreatorBase* parameterizedURLEditorCreator = createParameterizedURLEditorCreator();
|
||||
|
@ -153,6 +161,29 @@ bool Box::contains(const Box& other) const {
|
|||
other.minimum.z >= minimum.z && other.maximum.z <= maximum.z;
|
||||
}
|
||||
|
||||
QMetaObjectEditor::QMetaObjectEditor(QWidget* parent) : QWidget(parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(QMargins());
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
layout->addWidget(_box = new QComboBox());
|
||||
connect(_box, SIGNAL(currentIndexChanged(int)), SLOT(updateMetaObject()));
|
||||
|
||||
foreach (const QMetaObject* metaObject, Bitstream::getMetaObjectSubClasses(&SharedObject::staticMetaObject)) {
|
||||
_box->addItem(metaObject->className(), QVariant::fromValue(metaObject));
|
||||
}
|
||||
}
|
||||
|
||||
void QMetaObjectEditor::setMetaObject(const QMetaObject* metaObject) {
|
||||
_metaObject = metaObject;
|
||||
_box->setCurrentIndex(_metaObject ? _box->findText(_metaObject->className()) : -1);
|
||||
}
|
||||
|
||||
void QMetaObjectEditor::updateMetaObject() {
|
||||
int index = _box->currentIndex();
|
||||
emit metaObjectChanged(_metaObject = (index == -1) ? NULL : _box->itemData(index).value<const QMetaObject*>());
|
||||
}
|
||||
|
||||
QColorEditor::QColorEditor(QWidget* parent) : QWidget(parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(QMargins());
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Bitstream.h"
|
||||
|
||||
class QByteArray;
|
||||
class QComboBox;
|
||||
class QDoubleSpinBox;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
|
@ -50,6 +51,33 @@ public:
|
|||
|
||||
DECLARE_STREAMABLE_METATYPE(Box)
|
||||
|
||||
/// Editor for meta-object values.
|
||||
class QMetaObjectEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(const QMetaObject* metaObject MEMBER _metaObject WRITE setMetaObject NOTIFY metaObjectChanged USER true)
|
||||
|
||||
public:
|
||||
|
||||
QMetaObjectEditor(QWidget* parent);
|
||||
|
||||
signals:
|
||||
|
||||
void metaObjectChanged(const QMetaObject* metaObject);
|
||||
|
||||
public slots:
|
||||
|
||||
void setMetaObject(const QMetaObject* metaObject);
|
||||
|
||||
private slots:
|
||||
|
||||
void updateMetaObject();
|
||||
|
||||
private:
|
||||
|
||||
QComboBox* _box;
|
||||
const QMetaObject* _metaObject;
|
||||
};
|
||||
|
||||
/// Editor for color values.
|
||||
class QColorEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include "MetavoxelUtil.h"
|
||||
#include "SharedObject.h"
|
||||
|
||||
REGISTER_META_OBJECT(SharedObject)
|
||||
|
||||
SharedObject::SharedObject() : _referenceCount(0) {
|
||||
}
|
||||
|
||||
|
@ -72,7 +74,7 @@ bool SharedObject::equals(const SharedObject* other) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
SharedObjectEditor::SharedObjectEditor(const QMetaObject* metaObject, QWidget* parent) : QWidget(parent) {
|
||||
SharedObjectEditor::SharedObjectEditor(const QMetaObject* metaObject, bool nullable, QWidget* parent) : QWidget(parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
@ -81,9 +83,14 @@ SharedObjectEditor::SharedObjectEditor(const QMetaObject* metaObject, QWidget* p
|
|||
layout->addLayout(form);
|
||||
|
||||
form->addRow("Type:", _type = new QComboBox());
|
||||
_type->addItem("(none)");
|
||||
if (nullable) {
|
||||
_type->addItem("(none)");
|
||||
}
|
||||
foreach (const QMetaObject* metaObject, Bitstream::getMetaObjectSubClasses(metaObject)) {
|
||||
_type->addItem(metaObject->className(), QVariant::fromValue(metaObject));
|
||||
// add add constructable subclasses
|
||||
if (metaObject->constructorCount() > 0) {
|
||||
_type->addItem(metaObject->className(), QVariant::fromValue(metaObject));
|
||||
}
|
||||
}
|
||||
connect(_type, SIGNAL(currentIndexChanged(int)), SLOT(updateType()));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class SharedObject : public QObject {
|
|||
|
||||
public:
|
||||
|
||||
SharedObject();
|
||||
Q_INVOKABLE SharedObject();
|
||||
|
||||
int getReferenceCount() const { return _referenceCount; }
|
||||
void incrementReferenceCount();
|
||||
|
@ -64,6 +64,8 @@ public:
|
|||
T& operator*() const { return *_data; }
|
||||
T* operator->() const { return _data; }
|
||||
|
||||
template<class X> SharedObjectPointerTemplate<X> staticCast() const;
|
||||
|
||||
SharedObjectPointerTemplate<T>& operator=(T* data);
|
||||
SharedObjectPointerTemplate<T>& operator=(const SharedObjectPointerTemplate<T>& other);
|
||||
|
||||
|
@ -109,6 +111,10 @@ template<class T> inline void SharedObjectPointerTemplate<T>::reset() {
|
|||
_data = NULL;
|
||||
}
|
||||
|
||||
template<class T> template<class X> inline SharedObjectPointerTemplate<X> SharedObjectPointerTemplate<T>::staticCast() const {
|
||||
return SharedObjectPointerTemplate<X>(static_cast<X*>(_data));
|
||||
}
|
||||
|
||||
template<class T> inline SharedObjectPointerTemplate<T>& SharedObjectPointerTemplate<T>::operator=(T* data) {
|
||||
if (_data) {
|
||||
_data->decrementReferenceCount();
|
||||
|
@ -141,11 +147,13 @@ Q_DECLARE_METATYPE(SharedObjectPointer)
|
|||
/// Allows editing shared object instances.
|
||||
class SharedObjectEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(SharedObjectPointer object MEMBER _object WRITE setObject USER true)
|
||||
Q_PROPERTY(SharedObjectPointer object READ getObject WRITE setObject USER true)
|
||||
|
||||
public:
|
||||
|
||||
SharedObjectEditor(const QMetaObject* metaObject, QWidget* parent);
|
||||
SharedObjectEditor(const QMetaObject* metaObject, bool nullable = true, QWidget* parent = NULL);
|
||||
|
||||
const SharedObjectPointer& getObject() const { return _object; }
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
Loading…
Reference in a new issue