use strings for shapeType for JS Entity properties

This commit is contained in:
Andrew Meadows 2015-02-20 16:54:58 -08:00
parent 5d6d9bb1d4
commit 27e6f99deb
4 changed files with 47 additions and 17 deletions

View file

@ -406,7 +406,7 @@
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings'));
elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
elModelShapeType.addEventListener('change', createEmitNumberPropertyUpdateFunction('shapeType'));
elModelShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType'));
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
@ -671,9 +671,9 @@
<div class="label">Shape Type</div>
<div class="value">
<select name="SelectShapeType" id="property-model-shape" name="SelectShapeType">
<option value=0>None</option>
<option value=1>Box</option>
<option value=2>Sphere</option>
<option value='none'>none</option>
<option value='box'>box</option>
<option value='sphere'>sphere</option>
</select>
</div>
</div>

View file

@ -10,6 +10,7 @@
//
#include <QDebug>
#include <QHash>
#include <QObject>
#include <QtCore/QJsonDocument>
@ -170,6 +171,35 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) {
_lastEdited = usecTime > _created ? usecTime : _created;
}
const char* shapeTypeNames[] = {"none", "box", "sphere"};
QString EntityItemProperties::getShapeTypeString() const {
return QString(shapeTypeNames[_shapeType]);
}
QHash<QString, ShapeType> stringToShapeTypeLookup;
void buildStringToShapeTypeLookup() {
stringToShapeTypeLookup["none"] = SHAPE_TYPE_NONE;
stringToShapeTypeLookup["box"] = SHAPE_TYPE_BOX;
stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE;
}
void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) {
if (stringToShapeTypeLookup.empty()) {
buildStringToShapeTypeLookup();
}
auto shapeTypeItr = stringToShapeTypeLookup.find(shapeName.toLower());
ShapeType newShapeType = SHAPE_TYPE_NONE;
if (shapeTypeItr != stringToShapeTypeLookup.end()) {
newShapeType = shapeTypeItr.value();
}
if (newShapeType != _shapeType) {
_shapeType = newShapeType;
_shapeTypeChanged = true;
}
}
EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
EntityPropertyFlags changedProperties;
@ -270,7 +300,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
COPY_PROPERTY_TO_QSCRIPTVALUE(lineHeight);
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(textColor, getTextColor());
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(backgroundColor, getBackgroundColor());
COPY_PROPERTY_TO_QSCRIPTVALUE(shapeType);
properties.setProperty("shapeType", getShapeTypeString());
// Sitting properties support
QScriptValue sittingPoints = engine->newObject();
@ -303,8 +333,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
}
void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
QScriptValue typeScriptValue = object.property("type");
if (typeScriptValue.isValid()) {
setType(typeScriptValue.toVariant().toString());
@ -350,7 +378,15 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(lineHeight, setLineHeight);
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(textColor, setTextColor);
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(backgroundColor, setBackgroundColor);
COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(shapeType, setShapeType, ShapeType);
QScriptValue shapeType = object.property("shapeType");
if (shapeType.isValid()) {
QString newValue = shapeType.toVariant().toString();
if (_defaultSettings || newValue != getShapeTypeString()) {
setShapeTypeFromString(newValue);
}
}
_lastEdited = usecTimestampNow();
}

View file

@ -183,6 +183,9 @@ public:
DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor);
DEFINE_PROPERTY_REF(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
QString getShapeTypeString() const;
void setShapeTypeFromString(const QString& shapeName);
public:
float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); }

View file

@ -180,15 +180,6 @@
#define COPY_PROPERTY_TO_QSCRIPTVALUE(P) \
properties.setProperty(#P, _##P);
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(P, S, E) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \
E newValue = (E)(P.toVariant().toInt()); \
if (_defaultSettings || newValue != _##P) { \
S(newValue); \
} \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(P, S) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \