From 9db175350be8223f947a2c0436f59586a86e921b Mon Sep 17 00:00:00 2001 From: Janne Kangas Date: Fri, 21 Feb 2020 13:52:58 +0200 Subject: Remove evaluator type datainput dead code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-id: QT3DS-3912 Change-Id: I76415b68bbe145bcc308263228358f69cac89c3c Reviewed-by: Antti Määttä Reviewed-by: Tomi Korpipää --- src/runtime/Qt3DSApplication.cpp | 14 ---- src/runtime/Qt3DSApplication.h | 6 -- src/runtime/Qt3DSQmlEngine.cpp | 161 --------------------------------------- 3 files changed, 181 deletions(-) diff --git a/src/runtime/Qt3DSApplication.cpp b/src/runtime/Qt3DSApplication.cpp index b8d3d31..c597802 100644 --- a/src/runtime/Qt3DSApplication.cpp +++ b/src/runtime/Qt3DSApplication.cpp @@ -1429,14 +1429,12 @@ struct SApp : public IApplication DataInputDef diDef; const char8_t *name = ""; const char8_t *type = ""; - const char8_t *evaluator = ""; const char8_t *metadataStr = ""; diDef.value = QVariant::Invalid; inReader.UnregisteredAtt("name", name); inReader.UnregisteredAtt("type", type); inReader.Att("min", diDef.min); inReader.Att("max", diDef.max); - inReader.UnregisteredAtt("evaluator", evaluator); if (AreEqual(type, "Ranged Number")) diDef.type = DataInOutTypeRangedNumber; else if (AreEqual(type, "String")) @@ -1454,11 +1452,6 @@ struct SApp : public IApplication else if (AreEqual(type, "Variant")) diDef.type = DataInOutTypeVariant; - if (AreEqual(type, "Evaluator")) { - diDef.type = DataInOutTypeEvaluator; - diDef.evaluator = QString::fromUtf8(evaluator); - } - inReader.UnregisteredAtt("metadata", metadataStr); QString metaData = QString(metadataStr); if (!metaData.isEmpty()) { @@ -2319,9 +2312,6 @@ QDebug operator<<(QDebug debug, const DataInOutType &value) case DataInOutType::DataInOutTypeFloat: debug.nospace() << "DataInOutTypeFloat"; break; - case DataInOutType::DataInOutTypeEvaluator: - debug.nospace() << "DataInOutTypeEvaluator"; - break; case DataInOutType::DataInOutTypeBoolean: debug.nospace() << "DataInOutTypeBoolean"; break; @@ -2377,11 +2367,7 @@ QDebug operator<<(QDebug debug, const DataInputDef &value) debug.nospace() << "}, min:" << value.min; debug.nospace() << ", min:" << value.min << ", max:" << value.max; - debug.nospace() << ", evaluator:" << value.evaluator; debug.nospace() << ", value:" << value.value; - debug.nospace() << ", dependents:{"; - for (auto dep : value.dependents) - debug << dep; debug.nospace() << "})"; return debug; diff --git a/src/runtime/Qt3DSApplication.h b/src/runtime/Qt3DSApplication.h index ce1b366..fd9c871 100644 --- a/src/runtime/Qt3DSApplication.h +++ b/src/runtime/Qt3DSApplication.h @@ -101,7 +101,6 @@ enum DataInOutType { DataInOutTypeRangedNumber, DataInOutTypeString, DataInOutTypeFloat, - DataInOutTypeEvaluator, DataInOutTypeBoolean, DataInOutTypeVector4, DataInOutTypeVector3, @@ -122,12 +121,7 @@ struct DataInputDef DataInOutType type = DataInOutTypeInvalid; float min = 0.0f; float max = 0.0f; - QString evaluator; - QJSValue evalFunc; // keep both evaluator string and JS function - // to avoid having to evaluate string several times QVariant value; // most recently set value - // evaluator datainputs that need to re-evaluate when this datainput changes value - QVector dependents; QHash metadata; }; diff --git a/src/runtime/Qt3DSQmlEngine.cpp b/src/runtime/Qt3DSQmlEngine.cpp index 6730e6e..5507655 100644 --- a/src/runtime/Qt3DSQmlEngine.cpp +++ b/src/runtime/Qt3DSQmlEngine.cpp @@ -497,18 +497,6 @@ private: TElement *elem); bool getAttributeVector2(QVector &outAttVec, const QByteArray &attName, TElement *elem); - // build and evaluate Evaluator datainput type expression - QJSValue buildJSFunc(const QString &userFunc); - // pass controller name for error reporting purposes - QVariant callJSFunc(const QString &controllerName, qt3ds::runtime::DataInputDef &diDef, - const QVariant::Type type); - // matches all numeric datatypes so we do not get datatype mismatch when JS - // decides to change result datatype (f.ex from double to int when result - // fractional part for specific input values happens to be exactly zero) - bool isMatchingDatatype(QVariant::Type resultType, QVariant::Type propertyType); - // find out which datainputs are used in the expression - QVector resolveDependentDatainputs(const QString &expression, - const QString &controllerName); // Methods to add element attributes to list for element creation void addStringAttribute(qt3ds::foundation::IStringTable &strTable, @@ -820,9 +808,6 @@ void CQmlEngineImpl::SetDataInputValue( // the incoming value is cast to target property type without checking. // Caveat emptor. - // For Evaluator, typecheck the JS evaluation result to see if it - // matches with the target property. - // Handle ranged number similarly to generic float // if it is bound to properties other // than timeline animation i.e. disregard range min and max @@ -832,8 +817,6 @@ void CQmlEngineImpl::SetDataInputValue( || diDef.type == qt3ds::runtime::DataInOutTypeRangedNumber || diDef.type == qt3ds::runtime::DataInOutTypeVariant) { valueFloat = value.toFloat(); - } else if (diDef.type == qt3ds::runtime::DataInOutTypeEvaluator) { - valueFloat = callJSFunc(name, diDef, QVariant::Type::Double).toFloat(); } else { qWarning() << __FUNCTION__ << "Property type " << ctrlElem.propertyType @@ -874,9 +857,6 @@ void CQmlEngineImpl::SetDataInputValue( if (diDef.type == qt3ds::runtime::DataInOutTypeVector3 || diDef.type == qt3ds::runtime::DataInOutTypeVariant) { valueVec = value.value(); - } else if (diDef.type == qt3ds::runtime::DataInOutTypeEvaluator) { - const QVariant res = callJSFunc(name, diDef, QVariant::Type::Vector3D); - valueVec = res.value(); } else { qWarning() << __FUNCTION__ << "Property type " << ctrlElem.propertyType @@ -900,9 +880,6 @@ void CQmlEngineImpl::SetDataInputValue( if (diDef.type == qt3ds::runtime::DataInOutTypeVector2 || diDef.type == qt3ds::runtime::DataInOutTypeVariant) { valueVec = value.value(); - } else if (diDef.type == qt3ds::runtime::DataInOutTypeEvaluator) { - const QVariant res = callJSFunc(name, diDef, QVariant::Type::Vector2D); - valueVec = res.value(); } else { qWarning() << __FUNCTION__ << "Property type " << ctrlElem.propertyType @@ -925,8 +902,6 @@ void CQmlEngineImpl::SetDataInputValue( if (diDef.type == qt3ds::runtime::DataInOutTypeBoolean || diDef.type == qt3ds::runtime::DataInOutTypeVariant) { valueBool = value.toBool(); - } else if (diDef.type == qt3ds::runtime::DataInOutTypeEvaluator) { - valueBool = callJSFunc(name, diDef, QVariant::Type::Bool).toBool(); } else { qWarning() << __FUNCTION__ << "Property type " << ctrlElem.propertyType @@ -960,9 +935,6 @@ void CQmlEngineImpl::SetDataInputValue( || diDef.type == qt3ds::runtime::DataInOutTypeFloat || diDef.type == qt3ds::runtime::DataInOutTypeVariant) { valueStr = value.toString().toUtf8(); - } else if (diDef.type == qt3ds::runtime::DataInOutTypeEvaluator) { - valueStr = callJSFunc(name, diDef, QVariant::Type::String) - .toString().toUtf8(); } else { qWarning() << __FUNCTION__ << "Property type " << ctrlElem.propertyType @@ -982,17 +954,6 @@ void CQmlEngineImpl::SetDataInputValue( break; } } - - // Trigger re-evaluation of Evaluator datainputs that use this datainput - // as source data. Do this by calling setDataInputValue for evaluator - // with the current set value of the Evaluator (_not_ the evaluator result) - for (auto dependent : diDef.dependents) { - // Dependent list also contains the name of this datainput if - // the value of this datainput is used as source data. In this case - // obviously do not cause infinite recursion. - if (dependent != name) - SetDataInputValue(dependent, diMap[dependent].value); - } break; } case qt3ds::runtime::DataInputValueRole::Max: { // switch (valueRole) @@ -2271,25 +2232,6 @@ void CQmlEngineImpl::initializeDataInputsInPresentation(CPresentation &presentat << " was not expanded to vector"; ctrlElem.propertyType = ATTRIBUTETYPE_NONE; } - } else if (diMap[controllerName].type - == qt3ds::runtime::DataInOutTypeEvaluator) { - diMap[controllerName].evalFunc - = buildJSFunc(diMap[controllerName].evaluator); - auto referencedDIs = resolveDependentDatainputs( - diMap[controllerName].evaluator, controllerName); - // add this evaluator datainput to the dependent list - // for those datainputs that are used in the expression - // for this evaluator - for (auto ref : referencedDIs) - diMap[ref].dependents.append(controllerName); - - ctrlElem.elementPath.append(element->path()); - TStringHash attHash = CHash::HashAttribute( - QString(ctrlElem.attributeName.first())); - Option attInfo - = element->FindProperty(attHash); - if (attInfo.hasValue()) - ctrlElem.propertyType = attInfo->first.type(); } else { // all other scalar datatypes ctrlElem.elementPath.append(element->path()); @@ -2553,109 +2495,6 @@ bool CQmlEngineImpl::getAttributeVector2(QVector &outAttVec, return false; } -QJSValue CQmlEngineImpl::buildJSFunc(const QString &userFunc) -{ - auto res = this->m_engine->evaluate(userFunc); - if (res.isError()) { - qWarning() << __FUNCTION__ - << "Uncaught exception during datainput evaluation. Evaluator function" << userFunc; - } - return res; -} - -QVariant CQmlEngineImpl::callJSFunc(const QString &controllerName, - qt3ds::runtime::DataInputDef &diDef, - const QVariant::Type type) -{ - qt3ds::runtime::DataInputMap &diMap = m_Application->dataInputMap(); - QJSValueList args; - QVector sourceDIs = resolveDependentDatainputs(diDef.evaluator, controllerName); - - // get the most recent set values for datainput sources (arguments) in the expression - for (auto diVal : sourceDIs) - args << this->m_engine->toScriptValue(diMap[diVal].value); - - if (diDef.evalFunc.isCallable()) { - QJSValue res = diDef.evalFunc.call(args); - if (res.isError()) { - qWarning() << __FUNCTION__ << "Error during datainput" << controllerName - << "evaluator call:" << res.toString() << "\nEvaluator function" - << diDef.evaluator; - return QVariant::Invalid; - } - - QVariant ret = res.toVariant(); - if (ret.isValid() && isMatchingDatatype(ret.type(), type)) { - // further check if the result is valid number - if (ret.type() == QVariant::Double && qIsNaN(res.toNumber())) { - qWarning() << __FUNCTION__ << "Datainput" << controllerName << "evaluator" - << "result not a number (NaN)." - << "\nEvaluator function" << diDef.evaluator; - return QVariant::Invalid; - } else { - return ret; - } - } else { - qWarning() << __FUNCTION__ << "Datainput" << controllerName << "evaluator" - << "result not valid or matching with target attribute type. Result type" - << QVariant::typeToName(ret.type()) << " target attribute type " - << QVariant::typeToName(type) << "\nEvaluator function" << diDef.evaluator; - } - } else { - qWarning() << __FUNCTION__ << "Datainput" << controllerName << "evaluator" - << diDef.evaluator << " not valid callable"; - } - return QVariant::Invalid; -} - -bool CQmlEngineImpl::isMatchingDatatype(QVariant::Type resultType, QVariant::Type propertyType) -{ - if (resultType == propertyType) - return true; - // Allow binding from numeric datainput to string target - if ((resultType == QVariant::Double || resultType == QVariant::Int - || resultType == QVariant::LongLong) - && (propertyType == QVariant::Double || propertyType == QVariant::Int - || propertyType == QVariant::LongLong || propertyType == QVariant::String)) { - return true; - } - return false; -} - -QVector CQmlEngineImpl::resolveDependentDatainputs(const QString &expression, - const QString &controllerName) -{ - QVector ret; - qt3ds::runtime::DataInputMap &diMap = m_Application->dataInputMap(); - if (!expression.contains("function", Qt::CaseInsensitive)) { - qWarning() << __FUNCTION__ << "Function keyword not found in datainput" - << controllerName << "evaluator"; - return QVector(); - } - - int argListStart = expression.indexOf("function(") + 9; - int argListStop = expression.indexOf(')', argListStart); - QString argstr = expression.mid(argListStart , argListStop - argListStart); - QStringList args = argstr.split(','); - - for (auto di : args) { - auto diTrim = di.trimmed(); - if (diMap.contains(diTrim)) { - if (diMap[diTrim].type == qt3ds::runtime::DataInOutTypeEvaluator - && diTrim != controllerName) { - qWarning() << __FUNCTION__ << "Invalid evaluator function in" << controllerName - << ". Another evaluator is used as source data."; - } else { - ret.append(diTrim); - } - } else { - qWarning() << __FUNCTION__ << "Evaluator in" << controllerName << "evaluator" - << "is using unknown datainput" << diTrim << " as input argument name"; - } - } - return ret; -} - void CQmlEngineImpl::addStringAttribute(IStringTable &strTable, CQmlEngineImpl::TPropertyDescAndValueList &list, const QString &inAttName, const QString &inValue) -- cgit v1.2.3