Skip to content

Commit

Permalink
Add isNewOption is ChangeJS upgrader
Browse files Browse the repository at this point in the history
A ChangeJS may add a new option
  • Loading branch information
boutinb committed Jul 10, 2024
1 parent 6514689 commit 22d1052
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Desktop/modules/upgrader/changejs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void ChangeJS::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
if(!_jsFunction.isCallable())
throw upgradeError("Could not apply ChangeJS to option '" + name + "' because the function cannot be called...");

if(!options.isMember(name))
if(!_isNewOption && !options.isMember(name))
throw upgradeError("Could not apply ChangeJS for option '" + name + "' because options does not contain '" + name + "'", true);

QJSValue copyFunc = _jsFunction, //To avoid const clashing with javascript "flexibility"
Expand Down Expand Up @@ -49,4 +49,9 @@ void ChangeJS::setJsFunction(QJSValue jsFunction)
emit jsFunctionChanged();
}

void ChangeJS::setIsNewOption(bool isNewOption)
{
_isNewOption = isNewOption;
emit isNewOptionChanged();
}
}
11 changes: 8 additions & 3 deletions Desktop/modules/upgrader/changejs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace Modules
class ChangeJS : public ChangeBase
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QJSValue jsFunction READ jsFunction WRITE setJsFunction NOTIFY jsFunctionChanged)
Q_PROPERTY(QJSValue jsonFunction READ jsFunction WRITE setJsFunction NOTIFY jsFunctionChanged) //lets make things robust
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QJSValue jsFunction READ jsFunction WRITE setJsFunction NOTIFY jsFunctionChanged)
Q_PROPERTY(QJSValue jsonFunction READ jsFunction WRITE setJsFunction NOTIFY jsFunctionChanged) //lets make things robust
Q_PROPERTY(bool isNewOption READ isNewOption WRITE setIsNewOption NOTIFY isNewOptionChanged)

public:
ChangeJS();
Expand All @@ -24,18 +25,22 @@ class ChangeJS : public ChangeBase
QString toString() const override { return _toString() + " running javascript function for option '" + name() + "', function: '" + jsFunction().toString() + "'"; };
QString name() const { return _name; }
QJSValue jsFunction() const { return _jsFunction; }
bool isNewOption() const { return _isNewOption; }

public slots:
void setName( QString name );
void setJsFunction( QJSValue jsFunction );
void setIsNewOption( bool isNewOption );

signals:
void nameChanged( QString name);
void jsFunctionChanged();
void isNewOptionChanged();

private:
QString _name;
QJSValue _jsFunction;
bool _isNewOption = false;
};

}
Expand Down

0 comments on commit 22d1052

Please sign in to comment.