From 79fe68319c4411e6901693e54a5606ba24b7b240 Mon Sep 17 00:00:00 2001 From: Joris Goosen Date: Thu, 10 Oct 2024 18:11:21 +0200 Subject: [PATCH] add an "upgrade" that resets the analysis to defaults (#5693) * upgrade seems ok, now just show the msg somewhere the user can see it add an "upgrade" that resets the analysis to defaults Implements https://github.com/jasp-stats/INTERNAL-jasp/issues/2660 Show an error in Analysis after loading * translatable please --- Desktop/analysis/analyses.cpp | 6 +++++ Desktop/analysis/analysis.h | 9 ++----- Desktop/modules/dynamicmodules.cpp | 18 ++++++------- Desktop/modules/upgrader/changebase.h | 2 +- Desktop/modules/upgrader/changecopy.cpp | 2 +- Desktop/modules/upgrader/changecopy.h | 2 +- .../modules/upgrader/changeincompatible.cpp | 19 ++++++++++++++ Desktop/modules/upgrader/changeincompatible.h | 25 +++++++++++++++++++ Desktop/modules/upgrader/changejs.cpp | 2 +- Desktop/modules/upgrader/changejs.h | 2 +- Desktop/modules/upgrader/changeremove.cpp | 2 +- Desktop/modules/upgrader/changeremove.h | 2 +- Desktop/modules/upgrader/changerename.cpp | 2 +- Desktop/modules/upgrader/changerename.h | 2 +- Desktop/modules/upgrader/changesetvalue.cpp | 2 +- Desktop/modules/upgrader/changesetvalue.h | 2 +- Desktop/modules/upgrader/upgrade.cpp | 4 +-- .../modules/upgrader/upgradeDefinitions.cpp | 1 + Desktop/modules/upgrader/upgradeDefinitions.h | 2 ++ Desktop/modules/upgrader/upgrader.cpp | 2 ++ Desktop/results/resultsjsinterface.cpp | 3 +-- Modules/jaspTestModule | 2 +- 22 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 Desktop/modules/upgrader/changeincompatible.cpp create mode 100644 Desktop/modules/upgrader/changeincompatible.h diff --git a/Desktop/analysis/analyses.cpp b/Desktop/analysis/analyses.cpp index 3eb7249309..d03f29690e 100644 --- a/Desktop/analysis/analyses.cpp +++ b/Desktop/analysis/analyses.cpp @@ -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) diff --git a/Desktop/analysis/analysis.h b/Desktop/analysis/analysis.h index 98aebd7921..e37ce4eb9e 100644 --- a/Desktop/analysis/analysis.h +++ b/Desktop/analysis/analysis.h @@ -20,24 +20,19 @@ #include -#include "common.h" -#include "version.h" - #include "enginedefinitions.h" -#include "controls/jaspcontrol.h" #include #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 #include 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. diff --git a/Desktop/modules/dynamicmodules.cpp b/Desktop/modules/dynamicmodules.cpp index df83ceb54e..c4e23fe140 100644 --- a/Desktop/modules/dynamicmodules.cpp +++ b/Desktop/modules/dynamicmodules.cpp @@ -18,15 +18,14 @@ +#include "log.h" #include "dynamicmodules.h" -#include "utilities/extractarchive.h" +#include "utilities/qutils.h" +#include +#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" @@ -34,9 +33,9 @@ #include "modules/upgrader/changeremove.h" #include "modules/upgrader/changerename.h" #include "modules/upgrader/changesetvalue.h" -#include "gui/preferencesmodel.h" -#include "dirs.h" -#include +#include "modules/upgrader/changeincompatible.h" +#include "modules/description/description.h" +#include "modules/description/entrybase.h" namespace Modules { @@ -883,6 +882,7 @@ void DynamicModules::registerQMLTypes() qmlRegisterType ("JASP.Module", 1, 0, "ChangeCopy" ); qmlRegisterType ("JASP.Module", 1, 0, "ChangeRename" ); qmlRegisterType ("JASP.Module", 1, 0, "ChangeRemove" ); + qmlRegisterType ("JASP.Module", 1, 0, "ChangeIncompatible" ); qmlRegisterType ("JASP.Module", 1, 0, "ChangeSetValue" ); qmlRegisterUncreatableType ("JASP.Module", 1, 0, "EntryBase", "Superclass for menu entries, shouldn't be instantiated manually"); qmlRegisterUncreatableType ("JASP.Module", 1, 0, "DynamicModule", "Can only be instantiated by JASP"); diff --git a/Desktop/modules/upgrader/changebase.h b/Desktop/modules/upgrader/changebase.h index dd6e3db30c..36b530e1e0 100644 --- a/Desktop/modules/upgrader/changebase.h +++ b/Desktop/modules/upgrader/changebase.h @@ -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; } diff --git a/Desktop/modules/upgrader/changecopy.cpp b/Desktop/modules/upgrader/changecopy.cpp index f16cb02587..9129c0a51c 100644 --- a/Desktop/modules/upgrader/changecopy.cpp +++ b/Desktop/modules/upgrader/changecopy.cpp @@ -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" diff --git a/Desktop/modules/upgrader/changecopy.h b/Desktop/modules/upgrader/changecopy.h index 45c4abe192..eca51c9de6 100644 --- a/Desktop/modules/upgrader/changecopy.h +++ b/Desktop/modules/upgrader/changecopy.h @@ -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; } diff --git a/Desktop/modules/upgrader/changeincompatible.cpp b/Desktop/modules/upgrader/changeincompatible.cpp new file mode 100644 index 0000000000..f876d250f6 --- /dev/null +++ b/Desktop/modules/upgrader/changeincompatible.cpp @@ -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()); +} + +} diff --git a/Desktop/modules/upgrader/changeincompatible.h b/Desktop/modules/upgrader/changeincompatible.h new file mode 100644 index 0000000000..eea4ca5739 --- /dev/null +++ b/Desktop/modules/upgrader/changeincompatible.h @@ -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 diff --git a/Desktop/modules/upgrader/changejs.cpp b/Desktop/modules/upgrader/changejs.cpp index 15106ed52b..02aa9c5759 100644 --- a/Desktop/modules/upgrader/changejs.cpp +++ b/Desktop/modules/upgrader/changejs.cpp @@ -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); diff --git a/Desktop/modules/upgrader/changejs.h b/Desktop/modules/upgrader/changejs.h index 0b1e528e4a..6d95a6529e 100644 --- a/Desktop/modules/upgrader/changejs.h +++ b/Desktop/modules/upgrader/changejs.h @@ -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; } diff --git a/Desktop/modules/upgrader/changeremove.cpp b/Desktop/modules/upgrader/changeremove.cpp index ffc9d649c2..dceaa1b108 100644 --- a/Desktop/modules/upgrader/changeremove.cpp +++ b/Desktop/modules/upgrader/changeremove.cpp @@ -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); diff --git a/Desktop/modules/upgrader/changeremove.h b/Desktop/modules/upgrader/changeremove.h index 07131b196e..6e74328bdf 100644 --- a/Desktop/modules/upgrader/changeremove.h +++ b/Desktop/modules/upgrader/changeremove.h @@ -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() + "'"; }; diff --git a/Desktop/modules/upgrader/changerename.cpp b/Desktop/modules/upgrader/changerename.cpp index dcb6ff29ba..b878ec0849 100644 --- a/Desktop/modules/upgrader/changerename.cpp +++ b/Desktop/modules/upgrader/changerename.cpp @@ -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); diff --git a/Desktop/modules/upgrader/changerename.h b/Desktop/modules/upgrader/changerename.h index c71969d75a..4fd109f98a 100644 --- a/Desktop/modules/upgrader/changerename.h +++ b/Desktop/modules/upgrader/changerename.h @@ -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; } diff --git a/Desktop/modules/upgrader/changesetvalue.cpp b/Desktop/modules/upgrader/changesetvalue.cpp index 0a259b408f..f7d3cd546b 100644 --- a/Desktop/modules/upgrader/changesetvalue.cpp +++ b/Desktop/modules/upgrader/changesetvalue.cpp @@ -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); diff --git a/Desktop/modules/upgrader/changesetvalue.h b/Desktop/modules/upgrader/changesetvalue.h index 94b0eb4393..ec4fda77ce 100644 --- a/Desktop/modules/upgrader/changesetvalue.h +++ b/Desktop/modules/upgrader/changesetvalue.h @@ -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; } diff --git a/Desktop/modules/upgrader/upgrade.cpp b/Desktop/modules/upgrader/upgrade.cpp index ecab166a28..35a890a0a1 100644 --- a/Desktop/modules/upgrader/upgrade.cpp +++ b/Desktop/modules/upgrader/upgrade.cpp @@ -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) { diff --git a/Desktop/modules/upgrader/upgradeDefinitions.cpp b/Desktop/modules/upgrader/upgradeDefinitions.cpp index 2805b96f38..6f02816bb1 100644 --- a/Desktop/modules/upgrader/upgradeDefinitions.cpp +++ b/Desktop/modules/upgrader/upgradeDefinitions.cpp @@ -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 { diff --git a/Desktop/modules/upgrader/upgradeDefinitions.h b/Desktop/modules/upgrader/upgradeDefinitions.h index b175134d92..043888ac50 100644 --- a/Desktop/modules/upgrader/upgradeDefinitions.h +++ b/Desktop/modules/upgrader/upgradeDefinitions.h @@ -15,6 +15,8 @@ typedef std::map> UpgradeMsgs; //option na extern const std::string prefixLog; extern const char * logId; +extern const char * analysisLog; + struct upgradeError : public std::runtime_error { diff --git a/Desktop/modules/upgrader/upgrader.cpp b/Desktop/modules/upgrader/upgrader.cpp index 47a0e0c2b3..757f879c02 100644 --- a/Desktop/modules/upgrader/upgrader.cpp +++ b/Desktop/modules/upgrader/upgrader.cpp @@ -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; diff --git a/Desktop/results/resultsjsinterface.cpp b/Desktop/results/resultsjsinterface.cpp index 338b543b21..66392b8768 100644 --- a/Desktop/results/resultsjsinterface.cpp +++ b/Desktop/results/resultsjsinterface.cpp @@ -26,10 +26,9 @@ #include "utilities/qutils.h" #include "gui/aboutmodel.h" -#include "appinfo.h" #include "tempfiles.h" +#include "data/datasetpackage.h" #include -#include "timers.h" #include "utilities/settings.h" #include #include diff --git a/Modules/jaspTestModule b/Modules/jaspTestModule index 66e57bc793..78b83698f4 160000 --- a/Modules/jaspTestModule +++ b/Modules/jaspTestModule @@ -1 +1 @@ -Subproject commit 66e57bc7939a28e6f4547cf087122c86db6cda1f +Subproject commit 78b83698f490c6ec79149ac9c7fcdf58271b79de