Skip to content

Commit 39dca09

Browse files
authored
add store state etc option, default off (#5969)
* add store state etc option, default off implements jasp-stats/INTERNAL-jasp#2915 Saving example file BFI Network goes from 2.3mb to 617kb * add extra property to analysis that stroes whether it was loaded with state and give the user a nice oui/non box on trying to resize or save plots
1 parent 2918e2f commit 39dca09

File tree

13 files changed

+74
-17
lines changed

13 files changed

+74
-17
lines changed

Common/tempfiles.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ void TempFiles::createSpecific(const string &name, int id, string &root, string
247247
relativePath += "/" + name;
248248
}
249249

250+
bool TempFiles::stateFileExists(int id)
251+
{
252+
std::filesystem::path stateFilePath = Utils::osPath(_sessionDirName + "/resources" + (id >= 0 ? "/" + std::to_string(id) : "") + "/state");
253+
254+
std::error_code error;
255+
return std::filesystem::exists(stateFilePath, error) && !error;
256+
}
257+
250258
void TempFiles::create(const string &extension, int id, string &root, string &relativePath)
251259
{
252260
std::error_code error;

Common/tempfiles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TempFiles
5555

5656
static std::string sessionDirName() { return _sessionDirName; }
5757
static stringvec retrieveList(int id = -1);
58+
static bool stateFileExists(int id);
5859

5960
static void deleteList(const stringvec &files);
6061
static void deleteAll(int id = -1);

Desktop/analysis/analyses.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
//
1818

1919
#include "analyses.h"
20+
#include "tempfiles.h"
2021
#include "utilities/settings.h"
22+
#include "gui/jaspConfiguration/jaspconfiguration.h"
2123
#include "modules/ribbonmodel.h"
2224
#include "analysisform.h"
2325
#include "knownissues.h"
2426
#include "timers.h"
2527
#include <QTimer>
2628
#include <QFile>
2729
#include "log.h"
28-
#include "gui/jaspConfiguration/jaspconfiguration.h"
2930

3031
using namespace std;
3132
using Modules::Upgrader;
@@ -110,6 +111,9 @@ Analysis* Analyses::createFromJaspFileEntry(Json::Value analysisData, RibbonMode
110111

111112
if(wasUpgraded)
112113
analysis->setUpgradeMsgs(msgs);
114+
115+
if(!TempFiles::stateFileExists(id))
116+
analysis->_storedWithoutState = true; //This will trigger the "you need a refresh" on resize
113117

114118
return analysis;
115119
}

Desktop/analysis/analysis.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ void Analysis::setResults(const Json::Value & results, Status status, const Json
223223
if(_status == Analysis::Complete)
224224
checkForRSources();
225225

226-
_wasUpgraded = false;
226+
_wasUpgraded = false;
227+
_storedWithoutState = false;
227228
}
228229

229230
void Analysis::exportResults()
@@ -473,9 +474,10 @@ void Analysis::setStatus(Analysis::Status status)
473474
bool neededRefresh = needsRefresh();
474475

475476
TempFiles::deleteList(TempFiles::retrieveList(_id));
476-
_wasUpgraded = false;
477-
478-
_moduleVersion = _dynamicModule ? _dynamicModule->version() : AppInfo::version;
477+
478+
_wasUpgraded = false;
479+
_storedWithoutState = false;
480+
_moduleVersion = _dynamicModule ? _dynamicModule->version() : AppInfo::version;
479481

480482
if(neededRefresh != needsRefresh())
481483
emit needsRefreshChanged();
@@ -987,7 +989,7 @@ void Analysis::setUpgradeMsgs(const Modules::UpgradeMsgs &msgs)
987989
bool Analysis::needsRefresh() const
988990
{
989991
bool differentVersion = _moduleVersion != (_dynamicModule ? _dynamicModule->version() : AppInfo::version);
990-
return _wasUpgraded || differentVersion;
992+
return _wasUpgraded || _storedWithoutState || differentVersion;
991993
}
992994

993995
bool Analysis::isWaitingForModule()

Desktop/analysis/analysis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Analysis : public AnalysisBase
6868

6969
bool needsRefresh() const override;
7070
bool wasUpgraded() const override { return _wasUpgraded; }
71+
bool storedWithoutState() const { return _storedWithoutState; }
7172
bool isWaitingForModule();
7273
void setResults( const Json::Value & results, analysisResultStatus status, const Json::Value & progress = Json::nullValue) { setResults(results, analysisResultsStatusToAnalysisStatus(status), progress); }
7374
void setResults( const Json::Value & results, Status status, const Json::Value & progress = Json::nullValue);
@@ -245,6 +246,7 @@ public slots:
245246
_lastQmlFormPath = "";
246247
bool _isDuplicate = false,
247248
_wasUpgraded = false,
249+
_storedWithoutState = false,
248250
_tryToFixNotes = false,
249251
_hasReport = false,
250252
_beingTranslated = false;

Desktop/components/JASP/Widgets/FileMenu/PrefsResults.qml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ PrefsScrollView
9393
onCheckedChanged: preferencesModel.useDefaultPPI = checked
9494
height: implicitHeight * preferencesModel.uiScale
9595
toolTip: qsTr("Use the Pixels Per Inch of your screen to render your plots.")
96-
focus: true
96+
9797

9898
KeyNavigation.tab: customPPISpinBox
9999
}
@@ -198,7 +198,20 @@ PrefsScrollView
198198
onCheckedChanged: preferencesModel.showRSyntaxInResults = checked
199199
height: implicitHeight * preferencesModel.uiScale
200200
toolTip: qsTr("Add R syntax for each analysis")
201-
focus: true
201+
202+
203+
KeyNavigation.tab: displayExactPVals
204+
}
205+
206+
CheckBox
207+
{
208+
id: storeStateEtc
209+
label: qsTr("Store analysis state and plot in jasp-files")
210+
checked: preferencesModel.storeStateEtc
211+
onCheckedChanged: preferencesModel.storeStateEtc = checked
212+
height: implicitHeight * preferencesModel.uiScale
213+
toolTip: qsTr("Enabling this can cause filesize of jaspfiles to increase, sometimes by a lot.")
214+
202215

203216
KeyNavigation.tab: displayExactPVals
204217
}

Desktop/data/exporters/jaspexporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "utilities/qutils.h"
3232
#include <fstream>
3333
#include "appinfo.h"
34+
#include "gui/preferencesmodel.h"
3435

3536

3637
const Version JASPExporter::jaspArchiveVersion = Version("5.0.0");
@@ -164,7 +165,8 @@ void JASPExporter::saveAnalyses(archive *a)
164165

165166
for (const Json::Value & analysisJson : analysesDataList)
166167
for (const std::string & path : TempFiles::retrieveList(analysisJson["id"].asInt()))
167-
saveTempFile(a, path);
168+
if(PreferencesModel::prefs()->storeStateEtc() || !stringUtils::endsWith(path, "/state"))
169+
saveTempFile(a, path);
168170
}
169171

170172
void JASPExporter::saveDatabase(archive * a)

Desktop/gui/preferencesmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ GET_PREF_FUNC_BOOL( remoteConfiguration, Settings::REMOTE_CONFIGURATION
191191
GET_PREF_FUNC_STR( remoteConfigurationURL, Settings::REMOTE_CONFIGURATION_URL )
192192
GET_PREF_FUNC_BOOL( useConfigurationFile, Settings::USE_CONFIGURATION_FILE )
193193
GET_PREF_FUNC_BOOL( startMaximized, Settings::START_MAXIMIZED )
194+
GET_PREF_FUNC_BOOL( storeStateEtc, Settings::STORE_STATE_ETC )
194195

195196
bool PreferencesModel::engineSandbox() const
196197
{
@@ -397,7 +398,7 @@ SET_PREF_FUNCTION( bool, setRemoteConfiguration, remoteConfiguration, re
397398
SET_PREF_FUNCTION( QString, setRemoteConfigurationURL, remoteConfigurationURL, remoteConfigurationURLChanged, Settings::REMOTE_CONFIGURATION_URL )
398399
SET_PREF_FUNCTION( bool, setUseConfigurationFile, useConfigurationFile, useConfigurationFileChanged, Settings::USE_CONFIGURATION_FILE )
399400
SET_PREF_FUNCTION( bool, setStartMaximized, startMaximized, startMaximizedChanged, Settings::START_MAXIMIZED )
400-
401+
SET_PREF_FUNCTION( bool, setStoreStateEtc, storeStateEtc, storeStateEtcChanged, Settings::STORE_STATE_ETC )
401402

402403
void PreferencesModel::setGithubPatCustom(QString newPat)
403404
{

Desktop/gui/preferencesmodel.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ class PreferencesModel : public PreferencesModelBase
8282
Q_PROPERTY(QString remoteConfigurationURL READ remoteConfigurationURL WRITE setRemoteConfigurationURL NOTIFY remoteConfigurationURLChanged )
8383
Q_PROPERTY(bool useConfigurationFile READ useConfigurationFile WRITE setUseConfigurationFile NOTIFY useConfigurationFileChanged )
8484
Q_PROPERTY(bool startMaximized READ startMaximized WRITE setStartMaximized NOTIFY startMaximizedChanged )
85-
85+
Q_PROPERTY(bool storeStateEtc READ storeStateEtc WRITE setStoreStateEtc NOTIFY storeStateEtcChanged )
86+
8687

8788
public:
88-
89-
9089
explicit PreferencesModel(QObject *parent = 0);
9190

9291
static PreferencesModel * prefs() { return qobject_cast<PreferencesModel*>(_singleton); }
@@ -175,6 +174,9 @@ class PreferencesModel : public PreferencesModelBase
175174
bool startMaximized() const;
176175
void setStartMaximized(bool newStartMaximized);
177176

177+
bool storeStateEtc() const;
178+
void setStoreStateEtc(bool newStoreStateEtc);
179+
178180
public slots:
179181
bool engineSandbox() const;
180182
bool useNativeFileDialog() const;
@@ -309,6 +311,7 @@ public slots:
309311
void remoteConfigurationURLChanged( QString remoteConfigurationURL);
310312
void useConfigurationFileChanged( bool enabled);
311313
void startMaximizedChanged( bool startMaximized);
314+
void storeStateEtcChanged( bool state);
312315

313316
private slots:
314317
void dataLabelNAChangedSlot(QString label);

Desktop/mainwindow.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,11 @@ void MainWindow::analysisSaveImageHandler(int id, QString options)
10811081

10821082
if (analysis->needsRefresh())
10831083
{
1084-
if(MessageForwarder::showYesNo(tr("Version incompatibility"), tr("This analysis was created in an older version of JASP, to save the image it must be refreshed first.\n\nRefresh the analysis?")))
1084+
if( analysis->storedWithoutState()
1085+
? MessageForwarder::showYesNo(tr("Stored without state"), tr("This analysis was saved without state, to save the image it must be refreshed first.\n\nRefresh the analysis?"))
1086+
: MessageForwarder::showYesNo(tr("Version incompatibility"), tr("This analysis was created in an older version of JASP, to save the image it must be refreshed first.\n\nRefresh the analysis?"))
1087+
1088+
)
10851089
analysis->refresh();
10861090
}
10871091
else
@@ -1147,7 +1151,10 @@ void MainWindow::analysisEditImageHandler(int id, QString options)
11471151

11481152
if (analysis->needsRefresh())
11491153
{
1150-
if (MessageForwarder::showYesNo(tr("Version incompatibility"), tr("This analysis was created in an older version of JASP, to resize the image it must be refreshed first.\n\nRefresh the analysis?")))
1154+
if ( analysis->storedWithoutState()
1155+
? MessageForwarder::showYesNo(tr("Stored without state"), tr("This analysis was stored without state, to resize the image it must be refreshed first.\n\nRefresh the analysis?"))
1156+
: MessageForwarder::showYesNo(tr("Version incompatibility"), tr("This analysis was created in an older version of JASP, to resize the image it must be refreshed first.\n\nRefresh the analysis?"))
1157+
)
11511158
analysis->refresh();
11521159
else
11531160
emit editImageCancelled(id);

0 commit comments

Comments
 (0)