moved ShapeType boilerplate stuff macos

This commit is contained in:
Andrew Meadows 2015-02-23 11:38:56 -08:00
parent 0fc4c732f7
commit 2e1c122915
3 changed files with 27 additions and 18 deletions

View file

@ -173,10 +173,6 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) {
const char* shapeTypeNames[] = {"none", "box", "sphere"};
QString EntityItemProperties::getShapeTypeString() const {
return QString(shapeTypeNames[_shapeType]);
}
QHash<QString, ShapeType> stringToShapeTypeLookup;
void buildStringToShapeTypeLookup() {
@ -185,6 +181,10 @@ void buildStringToShapeTypeLookup() {
stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE;
}
QString EntityItemProperties::getShapeTypeAsString() const {
return QString(shapeTypeNames[_shapeType]);
}
void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) {
if (stringToShapeTypeLookup.empty()) {
buildStringToShapeTypeLookup();
@ -300,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_GETTER(shapeType, getShapeTypeString());
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(shapeType, getShapeTypeAsString());
// Sitting properties support
QScriptValue sittingPoints = engine->newObject();
@ -378,15 +378,7 @@ 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);
QScriptValue shapeType = object.property("shapeType");
if (shapeType.isValid()) {
QString newValue = shapeType.toVariant().toString();
if (_defaultSettings || newValue != getShapeTypeString()) {
setShapeTypeFromString(newValue);
}
}
COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(shapeType, ShapeType);
_lastEdited = usecTimestampNow();
}

View file

@ -181,10 +181,7 @@ public:
DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float);
DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor);
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);
DEFINE_PROPERTY_REF_ENUM(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
public:
float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); }

View file

@ -271,6 +271,15 @@
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(P, S) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \
QString newValue = P.toVariant().toString(); \
if (_defaultSettings || newValue != get##S##AsString()) { \
set##S##FromString(newValue); \
} \
}
#define CONSTRUCT_PROPERTY(n, V) \
_##n(V), \
@ -312,6 +321,17 @@
T _##n; \
bool _##n##Changed;
#define DEFINE_PROPERTY_REF_ENUM(P, N, n, T) \
public: \
const T& get##N() const { return _##n; } \
void set##N(const T& value) { _##n = value; _##n##Changed = true; } \
bool n##Changed() const { return _##n##Changed; } \
QString get##N##AsString() const; \
void set##N##FromString(const QString& name); \
private: \
T _##n; \
bool _##n##Changed;
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
if (P.n##Changed()) { \
D << " " << #n << ":" << P.get##N() << x << "\n"; \