Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an "upgrade" that resets the analysis to defaults #5693

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Desktop/analysis/analyses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Analysis* Analyses::createFromJaspFileEntry(Json::Value analysisData, RibbonMode

analysisEntry = Modules::DynamicModules::dynMods()->retrieveCorrespondingAnalysisEntry(analysisData["dynamicModule"]);
analysis = create(analysisData, analysisEntry, id, status, false, title, analysisData["dynamicModule"]["moduleVersion"].asString(), &optionsJson);

if(msgs.count(Modules::analysisLog))
{
QStringList msgAna = tq(msgs[Modules::analysisLog]);
analysis->setErrorInResults(fq(msgAna.join("\n")));
}
}

if(wasUpgraded)
Expand Down
9 changes: 2 additions & 7 deletions Desktop/analysis/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@

#include <boost/uuid/uuid.hpp>

#include "common.h"
#include "version.h"

#include "enginedefinitions.h"
#include "controls/jaspcontrol.h"

#include <set>
#include "analysisbase.h"
#include "modules/dynamicmodules.h"
#include "data/datasetpackage.h"
#include "utilities/qutils.h"
#include "modules/upgrader/upgradechange.h"
#include "modules/dynamicmodules.h"
#include <QFileSystemWatcher>
#include <QQuickItem>

class Column;
class AnalysisForm;


///
/// A single instantiated analysis, aka it was clicked by the user and now has a qml-form loaded and some (rudimentary) output in the results or is on its way there.
/// This has its counterpart in AnysisForm which is the backend of the qml `Form {}` element.
Expand Down
18 changes: 9 additions & 9 deletions Desktop/modules/dynamicmodules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@



#include "log.h"
#include "dynamicmodules.h"
#include "utilities/extractarchive.h"
#include "utilities/qutils.h"
#include <QRegularExpression>
#include "utilities/appdirs.h"
#include "utilities/settings.h"
#include "utilities/extractarchive.h"
#include "utilities/messageforwarder.h"
#include "utilities/appdirs.h"
#include "utilities/qutils.h"
#include "log.h"
#include "modules/description/description.h"
#include "modules/description/entrybase.h"
#include "modules/upgrader/upgrades.h"
#include "modules/upgrader/upgrade.h"
#include "modules/upgrader/changejs.h"
#include "modules/upgrader/changecopy.h"
#include "modules/upgrader/changeremove.h"
#include "modules/upgrader/changerename.h"
#include "modules/upgrader/changesetvalue.h"
#include "gui/preferencesmodel.h"
#include "dirs.h"
#include <QRegularExpression>
#include "modules/upgrader/changeincompatible.h"
#include "modules/description/description.h"
#include "modules/description/entrybase.h"

namespace Modules
{
Expand Down Expand Up @@ -883,6 +882,7 @@ void DynamicModules::registerQMLTypes()
qmlRegisterType<Modules::ChangeCopy> ("JASP.Module", 1, 0, "ChangeCopy" );
qmlRegisterType<Modules::ChangeRename> ("JASP.Module", 1, 0, "ChangeRename" );
qmlRegisterType<Modules::ChangeRemove> ("JASP.Module", 1, 0, "ChangeRemove" );
qmlRegisterType<Modules::ChangeIncompatible> ("JASP.Module", 1, 0, "ChangeIncompatible" );
qmlRegisterType<Modules::ChangeSetValue> ("JASP.Module", 1, 0, "ChangeSetValue" );
qmlRegisterUncreatableType<Modules::EntryBase> ("JASP.Module", 1, 0, "EntryBase", "Superclass for menu entries, shouldn't be instantiated manually");
qmlRegisterUncreatableType<Modules::DynamicModule> ("JASP.Module", 1, 0, "DynamicModule", "Can only be instantiated by JASP");
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChangeBase : public QQuickItem
~ChangeBase();

virtual QString toString() const = 0;
virtual void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const = 0;
virtual void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const = 0;
bool conditionSatisfied(const Json::Value & options) const;

QJSValue condition() const { return _condition; }
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ChangeCopy::ChangeCopy()

}

void ChangeCopy::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
void ChangeCopy::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const
{
//It is ok to overwrite whatever is in newName? Because it is a sort of "set value"

Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changecopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChangeCopy : public ChangeBase
public:
ChangeCopy();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const override;
void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString toString() const override { return _toString() + " copying option from '" + from() + "' to '" + to() + "'"; };
QString from() const { return _from; }
Expand Down
19 changes: 19 additions & 0 deletions Desktop/modules/upgrader/changeincompatible.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "changeincompatible.h"

namespace Modules
{

ChangeIncompatible::ChangeIncompatible()
{

}

void ChangeIncompatible::applyUpgrade(Json::Value &options, UpgradeMsgs &msgs, bool inMeta) const
{
options = Json::objectValue;

if(!inMeta)
msgs[analysisLog].push_back(prefixLog + tr("Reset analysis because of '%1'").arg(msg().isEmpty() ? "???" : msg()).toStdString());
}

}
25 changes: 25 additions & 0 deletions Desktop/modules/upgrader/changeincompatible.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CHANGEINCOMPATIBLE_H
#define CHANGEINCOMPATIBLE_H

#include "changebase.h"


namespace Modules
{

/// Removes all options and adds a message that from version * onwards it was reset.
class ChangeIncompatible : public ChangeBase
{
Q_OBJECT
public:
ChangeIncompatible();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString toString() const override { return _toString() + " removing all options, because '" + msg() + "'"; };
};


}

#endif // CHANGEINCOMPATIBLE_H
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changejs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ChangeJS::ChangeJS()

}

void ChangeJS::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
void ChangeJS::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const
{
const std::string name = fq(_name);

Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changejs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChangeJS : public ChangeBase
public:
ChangeJS();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const override;
void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString toString() const override { return _toString() + " running javascript function for option '" + name() + "', function: '" + jsFunction().toString() + "'"; };
QString name() const { return _name; }
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changeremove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ChangeRemove::ChangeRemove()

}

void ChangeRemove::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
void ChangeRemove::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const
{
const std::string name = fq(_name);

Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changeremove.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChangeRemove : public ChangeBase
public:
ChangeRemove();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const override;
void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString name() const { return _name; }
QString toString() const override { return _toString() + " removing option '" + name() + "'"; };
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changerename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ChangeRename::ChangeRename()

}

void ChangeRename::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
void ChangeRename::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const
{
const std::string oldName = fq(_from),
newName = fq(_to);
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changerename.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChangeRename : public ChangeBase
public:
ChangeRename();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const override;
void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString from() const { return _from; }
QString to() const { return _to; }
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changesetvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ChangeSetValue::ChangeSetValue()

}

void ChangeSetValue::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const
void ChangeSetValue::applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const
{
const std::string name = fq(_name);

Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/upgrader/changesetvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChangeSetValue : public ChangeBase
public:
ChangeSetValue();

void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs) const override;
void applyUpgrade(Json::Value & options, UpgradeMsgs & msgs, bool inMeta) const override;

QString toString() const override;
QString name() const { return _name; }
Expand Down
4 changes: 2 additions & 2 deletions Desktop/modules/upgrader/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void Upgrade::applyUpgrade(const std::string & function, const Version & version
if(change->conditionSatisfied(analysesJson["options"]))
{
Log::log(false) << "it is and applying the change!" << std::endl;
change->applyUpgrade(analysesJson["options"], msgs);
change->applyUpgrade(analysesJson["options"], msgs, false);

try //Also try it on .meta
{
change->applyUpgrade(analysesJson["options"][".meta"], msgs);
change->applyUpgrade(analysesJson["options"][".meta"], msgs, true);
}
catch(upgradeError & e)
{
Expand Down
1 change: 1 addition & 0 deletions Desktop/modules/upgrader/upgradeDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Modules

const std::string prefixLog = "\t\t";
const char * logId = "!log!"; //To add general logging to UpgradeMsgs as opposed to for a specific option
const char * analysisLog = "!analysis!"; //On the level of an analysis

const char * upgradeError::what() const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions Desktop/modules/upgrader/upgradeDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef std::map<std::string, std::vector<std::string>> UpgradeMsgs; //option na

extern const std::string prefixLog;
extern const char * logId;
extern const char * analysisLog;


struct upgradeError : public std::runtime_error
{
Expand Down
2 changes: 2 additions & 0 deletions Desktop/modules/upgrader/upgrader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ bool Upgrader::upgradeAnalysisData(Json::Value & analysis, UpgradeMsgs & msgs) c
try
{
_upgradeOptionsFromJaspFile(analysis, msgs, stepsTaken);



#ifdef JASP_DEBUG
Log::log() << "Options are now: " << analysis["options"].toStyledString() << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions Desktop/results/resultsjsinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

#include "utilities/qutils.h"
#include "gui/aboutmodel.h"
#include "appinfo.h"
#include "tempfiles.h"
#include "data/datasetpackage.h"
#include <functional>
#include "timers.h"
#include "utilities/settings.h"
#include <QMimeData>
#include <QAction>
Expand Down
2 changes: 1 addition & 1 deletion Modules/jaspTestModule
Loading