diff --git a/src/controllers/scripting/controllerscriptenginebase.cpp b/src/controllers/scripting/controllerscriptenginebase.cpp index 74c4eaa4041..14c6fde111b 100644 --- a/src/controllers/scripting/controllerscriptenginebase.cpp +++ b/src/controllers/scripting/controllerscriptenginebase.cpp @@ -74,7 +74,7 @@ void ControllerScriptEngineBase::reload() { } bool ControllerScriptEngineBase::executeFunction( - QJSValue functionObject, QJSValueList args) { + QJSValue functionObject, const QJSValueList& args) { // This function is called from outside the controller engine, so we can't // use VERIFY_OR_DEBUG_ASSERT here if (!m_pJSEngine) { @@ -104,7 +104,7 @@ bool ControllerScriptEngineBase::executeFunction( } void ControllerScriptEngineBase::showScriptExceptionDialog( - QJSValue evaluationResult, bool bFatalError) { + const QJSValue& evaluationResult, bool bFatalError) { VERIFY_OR_DEBUG_ASSERT(evaluationResult.isError()) { return; } diff --git a/src/controllers/scripting/controllerscriptenginebase.h b/src/controllers/scripting/controllerscriptenginebase.h index 87ae4fa4019..49295dbe76b 100644 --- a/src/controllers/scripting/controllerscriptenginebase.h +++ b/src/controllers/scripting/controllerscriptenginebase.h @@ -23,11 +23,11 @@ class ControllerScriptEngineBase : public QObject { virtual bool initialize(); - bool executeFunction(QJSValue functionObject, QJSValueList arguments); + bool executeFunction(QJSValue functionObject, const QJSValueList& arguments); /// Shows a UI dialog notifying of a script evaluation error. /// Precondition: QJSValue.isError() == true - void showScriptExceptionDialog(QJSValue evaluationResult, bool bFatal = false); + void showScriptExceptionDialog(const QJSValue& evaluationResult, bool bFatal = false); void throwJSError(const QString& message); inline void setTesting(bool testing) { diff --git a/src/controllers/scripting/controllerscriptmoduleengine.h b/src/controllers/scripting/controllerscriptmoduleengine.h index 3b6c7009810..76b14ee774c 100644 --- a/src/controllers/scripting/controllerscriptmoduleengine.h +++ b/src/controllers/scripting/controllerscriptmoduleengine.h @@ -11,7 +11,7 @@ class ControllerScriptModuleEngine : public ControllerScriptEngineBase { bool initialize() override; - void setModuleFileInfo(QFileInfo moduleFileInfo) { + void setModuleFileInfo(const QFileInfo& moduleFileInfo) { m_moduleFileInfo = moduleFileInfo; } diff --git a/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp b/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp index f0789145823..32d818c9277 100644 --- a/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp +++ b/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp @@ -20,9 +20,10 @@ ControllerScriptEngineLegacy::~ControllerScriptEngineLegacy() { shutdown(); } -bool ControllerScriptEngineLegacy::callFunctionOnObjects(QList scriptFunctionPrefixes, +bool ControllerScriptEngineLegacy::callFunctionOnObjects( + const QList& scriptFunctionPrefixes, const QString& function, - QJSValueList args, + const QJSValueList& args, bool bFatalError) { VERIFY_OR_DEBUG_ASSERT(m_pJSEngine) { return false; @@ -98,7 +99,7 @@ bool ControllerScriptEngineLegacy::initialize() { engineGlobalObject.setProperty( "engine", m_pJSEngine->newQObject(legacyScriptInterface)); - for (const ControllerPreset::ScriptFileInfo& script : m_scriptFiles) { + for (const ControllerPreset::ScriptFileInfo& script : std::as_const(m_scriptFiles)) { if (!evaluateScriptFile(script.file)) { shutdown(); return false; @@ -158,7 +159,7 @@ bool ControllerScriptEngineLegacy::handleIncomingData(const QByteArray& data) { args << m_pJSEngine->toScriptValue(data); args << QJSValue(data.size()); - for (const QJSValue& function : m_incomingDataFunctions) { + for (const QJSValue& function : std::as_const(m_incomingDataFunctions)) { ControllerScriptEngineBase::executeFunction(function, args); } diff --git a/src/controllers/scripting/legacy/controllerscriptenginelegacy.h b/src/controllers/scripting/legacy/controllerscriptenginelegacy.h index 98075376e42..d8b83bb2cda 100644 --- a/src/controllers/scripting/legacy/controllerscriptenginelegacy.h +++ b/src/controllers/scripting/legacy/controllerscriptenginelegacy.h @@ -35,9 +35,9 @@ class ControllerScriptEngineLegacy : public ControllerScriptEngineBase { bool evaluateScriptFile(const QFileInfo& scriptFile); void shutdown() override; - bool callFunctionOnObjects(QList, + bool callFunctionOnObjects(const QList& scriptFunctionPrefixes, const QString&, - QJSValueList args = QJSValueList(), + const QJSValueList& args = QJSValueList(), bool bFatalError = false); QList m_scriptFunctionPrefixes; diff --git a/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp b/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp index c45231f3d45..11718bf0801 100644 --- a/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp +++ b/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp @@ -99,7 +99,7 @@ ControlObjectScript* ControllerScriptInterfaceLegacy::getControlObjectScript( return coScript; } -double ControllerScriptInterfaceLegacy::getValue(QString group, QString name) { +double ControllerScriptInterfaceLegacy::getValue(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { qWarning() << "Unknown control" << group << name @@ -110,7 +110,7 @@ double ControllerScriptInterfaceLegacy::getValue(QString group, QString name) { } void ControllerScriptInterfaceLegacy::setValue( - QString group, QString name, double newValue) { + const QString& group, const QString& name, double newValue) { if (isnan(newValue)) { qWarning() << "script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -130,7 +130,7 @@ void ControllerScriptInterfaceLegacy::setValue( } } -double ControllerScriptInterfaceLegacy::getParameter(QString group, QString name) { +double ControllerScriptInterfaceLegacy::getParameter(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { qWarning() << "Unknown control" << group << name @@ -141,7 +141,7 @@ double ControllerScriptInterfaceLegacy::getParameter(QString group, QString name } void ControllerScriptInterfaceLegacy::setParameter( - QString group, QString name, double newParameter) { + const QString& group, const QString& name, double newParameter) { if (isnan(newParameter)) { qWarning() << "script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -160,7 +160,7 @@ void ControllerScriptInterfaceLegacy::setParameter( } double ControllerScriptInterfaceLegacy::getParameterForValue( - QString group, QString name, double value) { + const QString& group, const QString& name, double value) { if (isnan(value)) { qWarning() << "script setting [" << group << "," << name << "] to NotANumber, ignoring."; @@ -178,14 +178,14 @@ double ControllerScriptInterfaceLegacy::getParameterForValue( return coScript->getParameterForValue(value); } -void ControllerScriptInterfaceLegacy::reset(QString group, QString name) { +void ControllerScriptInterfaceLegacy::reset(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript != nullptr) { coScript->reset(); } } -double ControllerScriptInterfaceLegacy::getDefaultValue(QString group, QString name) { +double ControllerScriptInterfaceLegacy::getDefaultValue(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { @@ -198,7 +198,7 @@ double ControllerScriptInterfaceLegacy::getDefaultValue(QString group, QString n } double ControllerScriptInterfaceLegacy::getDefaultParameter( - QString group, QString name) { + const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { @@ -211,7 +211,7 @@ double ControllerScriptInterfaceLegacy::getDefaultParameter( } QJSValue ControllerScriptInterfaceLegacy::makeConnection( - QString group, QString name, const QJSValue callback) { + const QString& group, const QString& name, const QJSValue& callback) { auto pJsEngine = m_pScriptEngineLegacy->jsEngine(); VERIFY_OR_DEBUG_ASSERT(pJsEngine) { return QJSValue(); @@ -254,7 +254,7 @@ QJSValue ControllerScriptInterfaceLegacy::makeConnection( } bool ControllerScriptInterfaceLegacy::removeScriptConnection( - const ScriptConnection connection) { + const ScriptConnection& connection) { ControlObjectScript* coScript = getControlObjectScript(connection.key.group, connection.key.item); @@ -266,7 +266,7 @@ bool ControllerScriptInterfaceLegacy::removeScriptConnection( } void ControllerScriptInterfaceLegacy::triggerScriptConnection( - const ScriptConnection connection) { + const ScriptConnection& connection) { VERIFY_OR_DEBUG_ASSERT(m_pScriptEngineLegacy->jsEngine()) { return; } @@ -288,8 +288,10 @@ void ControllerScriptInterfaceLegacy::triggerScriptConnection( // it is disconnected. // WARNING: These behaviors are quirky and confusing, so if you change this function, // be sure to run the ControllerScriptInterfaceTest suite to make sure you do not break old scripts. -QJSValue ControllerScriptInterfaceLegacy::connectControl( - QString group, QString name, QJSValue passedCallback, bool disconnect) { +QJSValue ControllerScriptInterfaceLegacy::connectControl(const QString& group, + const QString& name, + const QJSValue& passedCallback, + bool disconnect) { // The passedCallback may or may not actually be a function, so when // the actual callback function is found, store it in this variable. QJSValue actualCallbackFunction; @@ -404,14 +406,14 @@ QJSValue ControllerScriptInterfaceLegacy::connectControl( return makeConnection(group, name, actualCallbackFunction); } -void ControllerScriptInterfaceLegacy::trigger(QString group, QString name) { +void ControllerScriptInterfaceLegacy::trigger(const QString& group, const QString& name) { ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript != nullptr) { coScript->emitValueChanged(); } } -void ControllerScriptInterfaceLegacy::log(QString message) { +void ControllerScriptInterfaceLegacy::log(const QString& message) { controllerDebug(message); } int ControllerScriptInterfaceLegacy::beginTimer( @@ -494,7 +496,7 @@ void ControllerScriptInterfaceLegacy::timerEvent(QTimerEvent* event) { } void ControllerScriptInterfaceLegacy::softTakeover( - QString group, QString name, bool set) { + const QString& group, const QString& name, bool set) { ControlObject* pControl = ControlObject::getControl( ConfigKey(group, name), ControllerDebug::shouldAssertForInvalidControlObjects()); if (!pControl) { @@ -508,7 +510,7 @@ void ControllerScriptInterfaceLegacy::softTakeover( } void ControllerScriptInterfaceLegacy::softTakeoverIgnoreNextValue( - QString group, const QString name) { + const QString& group, const QString& name) { ControlObject* pControl = ControlObject::getControl( ConfigKey(group, name), ControllerDebug::shouldAssertForInvalidControlObjects()); if (!pControl) { @@ -553,7 +555,7 @@ void ControllerScriptInterfaceLegacy::scratchEnable(int deck, double beta, bool ramp) { // If we're already scratching this deck, override that with this request - if (m_dx[deck]) { + if (static_cast(m_dx[deck])) { //qDebug() << "Already scratching deck" << deck << ". Overriding."; int timerId = m_scratchTimers.key(deck); killTimer(timerId); @@ -603,7 +605,7 @@ void ControllerScriptInterfaceLegacy::scratchEnable(int deck, } // Initialize scratch filter - if (alpha && beta) { + if (static_cast(alpha) && static_cast(beta)) { m_scratchFilters[deck]->init(kAlphaBetaDt, initVelocity, alpha, beta); } else { // Use filter's defaults if not specified diff --git a/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.h b/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.h index 2043b6beadc..11087394eb5 100644 --- a/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.h +++ b/src/controllers/scripting/legacy/controllerscriptinterfacelegacy.h @@ -20,23 +20,25 @@ class ControllerScriptInterfaceLegacy : public QObject { virtual ~ControllerScriptInterfaceLegacy(); - Q_INVOKABLE double getValue(QString group, QString name); - Q_INVOKABLE void setValue(QString group, QString name, double newValue); - Q_INVOKABLE double getParameter(QString group, QString name); - Q_INVOKABLE void setParameter(QString group, QString name, double newValue); - Q_INVOKABLE double getParameterForValue(QString group, QString name, double value); - Q_INVOKABLE void reset(QString group, QString name); - Q_INVOKABLE double getDefaultValue(QString group, QString name); - Q_INVOKABLE double getDefaultParameter(QString group, QString name); - Q_INVOKABLE QJSValue makeConnection(QString group, QString name, const QJSValue callback); + Q_INVOKABLE double getValue(const QString& group, const QString& name); + Q_INVOKABLE void setValue(const QString& group, const QString& name, double newValue); + Q_INVOKABLE double getParameter(const QString& group, const QString& name); + Q_INVOKABLE void setParameter(const QString& group, const QString& name, double newValue); + Q_INVOKABLE double getParameterForValue( + const QString& group, const QString& name, double value); + Q_INVOKABLE void reset(const QString& group, const QString& name); + Q_INVOKABLE double getDefaultValue(const QString& group, const QString& name); + Q_INVOKABLE double getDefaultParameter(const QString& group, const QString& name); + Q_INVOKABLE QJSValue makeConnection( + const QString& group, const QString& name, const QJSValue& callback); // DEPRECATED: Use makeConnection instead. - Q_INVOKABLE QJSValue connectControl(QString group, - QString name, - const QJSValue passedCallback, + Q_INVOKABLE QJSValue connectControl(const QString& group, + const QString& name, + const QJSValue& passedCallback, bool disconnect = false); // Called indirectly by the objects returned by connectControl - Q_INVOKABLE void trigger(QString group, QString name); - Q_INVOKABLE void log(QString message); + Q_INVOKABLE void trigger(const QString& group, const QString& name); + Q_INVOKABLE void log(const QString& message); Q_INVOKABLE int beginTimer(int interval, QJSValue scriptCode, bool oneShot = false); Q_INVOKABLE void stopTimer(int timerId); Q_INVOKABLE void scratchEnable(int deck, @@ -48,15 +50,15 @@ class ControllerScriptInterfaceLegacy : public QObject { Q_INVOKABLE void scratchTick(int deck, int interval); Q_INVOKABLE void scratchDisable(int deck, bool ramp = true); Q_INVOKABLE bool isScratching(int deck); - Q_INVOKABLE void softTakeover(QString group, QString name, bool set); - Q_INVOKABLE void softTakeoverIgnoreNextValue(QString group, QString name); + Q_INVOKABLE void softTakeover(const QString& group, const QString& name, bool set); + Q_INVOKABLE void softTakeoverIgnoreNextValue(const QString& group, const QString& name); Q_INVOKABLE void brake(int deck, bool activate, double factor = 1.0, double rate = 1.0); Q_INVOKABLE void spinback(int deck, bool activate, double factor = 1.8, double rate = -10.0); Q_INVOKABLE void softStart(int deck, bool activate, double factor = 1.0); - bool removeScriptConnection(const ScriptConnection conn); + bool removeScriptConnection(const ScriptConnection& conn); /// Execute a ScriptConnection's JS callback - void triggerScriptConnection(const ScriptConnection conn); + void triggerScriptConnection(const ScriptConnection& conn); /// Handler for timers that scripts set. virtual void timerEvent(QTimerEvent* event);