Add skipThoseWithBadParents functionality to octree visitor; reviewer suggestions

This commit is contained in:
Simon Walton 2018-11-08 18:20:20 -08:00
parent 6f6c92e647
commit d183968175
7 changed files with 18 additions and 42 deletions

View file

@ -13,10 +13,11 @@
#include "EntityItemProperties.h"
RecurseOctreeToJSONOperator::RecurseOctreeToJSONOperator(const OctreeElementPointer&, QScriptEngine* engine,
QString jsonPrefix /* = QString() */, bool skipDefaults /* = true */)
: _engine(engine)
, _json(jsonPrefix)
, _skipDefaults(skipDefaults)
QString jsonPrefix, bool skipDefaults, bool skipThoseWithBadParents):
_engine(engine),
_json(jsonPrefix),
_skipDefaults(skipDefaults),
_skipThoseWithBadParents(skipThoseWithBadParents)
{
_toStringMethod = _engine->evaluate("(function() { return JSON.stringify(this, null, ' ') })");
}
@ -29,18 +30,21 @@ bool RecurseOctreeToJSONOperator::postRecursion(const OctreeElementPointer& elem
}
void RecurseOctreeToJSONOperator::processEntity(const EntityItemPointer& entity) {
if (_skipThoseWithBadParents && !entity->isParentIDValid()) {
return; // we weren't able to resolve a parent from _parentID, so don't save this entity.
}
QScriptValue qScriptValues = _skipDefaults
? EntityItemNonDefaultPropertiesToScriptValue(_engine, entity->getProperties())
: EntityItemPropertiesToScriptValue(_engine, entity->getProperties());
if (comma) {
if (_comma) {
_json += ',';
};
comma = true;
_comma = true;
_json += "\n ";
// Override default toString():
qScriptValues.setProperty("toString", _toStringMethod);
_json += qScriptValues.toString();
//auto exceptionString2 = _engine->uncaughtException().toString();
}

View file

@ -13,7 +13,8 @@
class RecurseOctreeToJSONOperator : public RecurseOctreeOperator {
public:
RecurseOctreeToJSONOperator(const OctreeElementPointer&, QScriptEngine* engine, QString jsonPrefix = QString(), bool skipDefaults = true);
RecurseOctreeToJSONOperator(const OctreeElementPointer&, QScriptEngine* engine, QString jsonPrefix = QString(), bool skipDefaults = true,
bool skipThoseWithBadParents = false);
virtual bool preRecursion(const OctreeElementPointer& element) override { return true; };
virtual bool postRecursion(const OctreeElementPointer& element) override;
@ -27,5 +28,6 @@ private:
QString _json;
const bool _skipDefaults;
bool comma { false };
bool _skipThoseWithBadParents;
bool _comma { false };
};

View file

@ -925,9 +925,6 @@ bool Octree::toJSONString(QString& jsonString, const OctreeElementPointer& eleme
}
bool Octree::toJSON(QByteArray* data, const OctreeElementPointer& element, bool doGzip) {
#define HIFI_USE_DIRECT_TO_JSON
#ifdef HIFI_USE_DIRECT_TO_JSON
QString jsonString;
toJSONString(jsonString);
@ -940,29 +937,6 @@ bool Octree::toJSON(QByteArray* data, const OctreeElementPointer& element, bool
*data = jsonString.toUtf8();
}
#else
QJsonDocument doc;
if (!toJSONDocument(&doc, element)) {
qCritical("Failed to convert Entities to JSON document.");
return false;
}
QString jsonString;
toJSONString(jsonString);
if (doGzip) {
QByteArray jsonData = doc.toJson();
if (!gzip(jsonData, *data, -1)) {
qCritical("Unable to gzip data while saving to json.");
return false;
}
} else {
*data = doc.toJson();
}
#endif // HIFI_USE_DIRECT_TO_JSON
return true;
}

View file

@ -56,7 +56,7 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
return true;
}
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromMap(QVariantMap map) {
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromMap(const QVariantMap& map) {
if (map.contains("Id") && map.contains("DataVersion") && map.contains("Version")) {
id = map["Id"].toUuid();
dataVersion = map["DataVersion"].toInt();

View file

@ -43,7 +43,7 @@ public:
bool readOctreeDataInfoFromData(QByteArray data);
bool readOctreeDataInfoFromFile(QString path);
bool readOctreeDataInfoFromJSON(QJsonObject root);
bool readOctreeDataInfoFromMap(QVariantMap map);
bool readOctreeDataInfoFromMap(const QVariantMap& map);
};
class RawEntityData : public RawOctreeData {

View file

@ -19,9 +19,6 @@
using std::string;
OctreeEntitiesFileParser::OctreeEntitiesFileParser() {
}
std::string OctreeEntitiesFileParser::getErrorString() const {
std::ostringstream err;
if (_errorString.size() != 0) {
@ -86,7 +83,7 @@ bool OctreeEntitiesFileParser::parseEntities(QVariantMap& parsedEntities) {
return false;
}
parsedEntities["Entities"] = entitiesValue;
parsedEntities["Entities"] = std::move(entitiesValue);
gotEntities = true;
} else if (key == "Id") {
if (gotId) {

View file

@ -19,7 +19,6 @@
class OctreeEntitiesFileParser {
public:
OctreeEntitiesFileParser();
void setEntitiesString(const QByteArray& entitiesContents);
bool parseEntities(QVariantMap& parsedEntities);
std::string getErrorString() const;