Skip to content

Commit b39f6dd

Browse files
committed
R Syntax: split analysis and analysisForm
For the R Script project, we need to split the analysis and analysisForm objects. For this the AnalysisFormBase is added (AnalysisBase existed already), the Base objects contain all calls from Analysis to AnalysisForm and vice-versa. Also the initColumnWithString is function is moved to the DataSet object so that the RDataFrame importer can use it.
1 parent 1f51343 commit b39f6dd

File tree

12 files changed

+299
-194
lines changed

12 files changed

+299
-194
lines changed

CommonData/dataset.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,24 @@ stringset DataSet::findUsedColumnNames(std::string searchThis)
598598

599599
return columnsFound;
600600
}
601+
602+
bool DataSet::initColumnWithStrings(int colIndex, const std::string & newName, const stringvec &values, const stringvec & labels, const std::string & title, columnType desiredType, const stringset & emptyValues, int threshold, bool orderLabelsByValue)
603+
{
604+
Column * column = columns()[colIndex];
605+
column -> setHasCustomEmptyValues(emptyValues.size());
606+
column -> setCustomEmptyValues(emptyValues);
607+
column -> setName(newName);
608+
column -> setTitle(title);
609+
column -> beginBatchedLabelsDB();
610+
bool anyChanges = title != column->title() || newName != column->name();
611+
columnType prevType = column->type(),
612+
suggestedType = column->setValues(values, labels, threshold, &anyChanges); //If less unique integers than the thresholdScale then we think it must be ordinal: https://github.com/jasp-stats/INTERNAL-jasp/issues/270
613+
column -> setType(column->type() != columnType::unknown ? column->type() : desiredType == columnType::unknown ? suggestedType : desiredType);
614+
column -> endBatchedLabelsDB();
615+
616+
if(orderLabelsByValue)
617+
column->labelsOrderByValue();
618+
619+
return anyChanges || column->type() != prevType;
620+
}
621+

CommonData/dataset.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class DataSet : public DataSetBaseNode
6969

7070
void loadOldComputedColumnsJson(const Json::Value & json); ///< Should act the same as the old ComputedColumns::fromJson() to allow loading "older jaspfiles"
7171
stringset findUsedColumnNames(std::string searchThis);
72+
bool initColumnWithStrings(int colIndex, const std::string & newName, const stringvec &values, const stringvec & labels, const std::string & title, columnType desiredType, const stringset & emptyValues, int threshold, bool orderLabelsByValue);
7273

7374
DatabaseInterface & db();
7475
const DatabaseInterface & db() const;

Desktop/analysis/analysis.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,27 @@ Analysis::Status Analysis::parseStatus(std::string name)
330330
else return Analysis::FatalError;
331331
}
332332

333+
AnalysisForm * Analysis::form() const
334+
{
335+
return qobject_cast<AnalysisForm*>(_analysisForm);
336+
}
337+
333338
void Analysis::createForm(QQuickItem* parentItem)
334339
{
335340
AnalysisBase::createForm(parentItem);
336341

337-
if (_analysisForm)
342+
if (hasForm())
338343
{
339-
connect(this, &Analysis::rSourceChanged, _analysisForm, &AnalysisForm::rSourceChanged );
340-
connect(this, &Analysis::refreshTableViewModels, _analysisForm, &AnalysisForm::refreshTableViewModels );
341-
connect(this, &Analysis::titleChanged, _analysisForm, &AnalysisForm::titleChanged );
342-
connect(this, &Analysis::needsRefreshChanged, _analysisForm, &AnalysisForm::needsRefreshChanged );
344+
AnalysisForm* analysisForm = form();
345+
connect(this, &Analysis::rSourceChanged, analysisForm, &AnalysisForm::rSourceChanged );
346+
connect(this, &Analysis::refreshTableViewModels, analysisForm, &AnalysisForm::refreshTableViewModels );
347+
connect(this, &Analysis::titleChanged, analysisForm, &AnalysisForm::titleChanged );
348+
connect(this, &Analysis::needsRefreshChanged, analysisForm, &AnalysisForm::needsRefreshChanged );
343349
connect(this, &Analysis::boundValuesChanged, this, &Analysis::setRSyntaxTextInResult, Qt::QueuedConnection );
344350

345351
setRSyntaxTextInResult();
346-
_analysisForm->setShowRButton(_moduleData->hasWrapper());
347-
_analysisForm->setDeveloperMode(_dynamicModule->isDevMod());
352+
analysisForm->setShowRButton(_moduleData->hasWrapper());
353+
analysisForm->setDeveloperMode(_dynamicModule->isDevMod());
348354

349355
emit analysisInitialized();
350356
}
@@ -536,14 +542,14 @@ stringset Analysis::createdVariables()
536542

537543
void Analysis::runScriptRequestDone(const QString& result, const QString& controlName, bool hasError)
538544
{
539-
if (_analysisForm)
540-
_analysisForm->runScriptRequestDone(result, controlName, hasError);
545+
if (hasForm())
546+
form()->runScriptRequestDone(result, controlName, hasError);
541547
}
542548

543549
void Analysis::filterByNameDone(const QString &name, const QString &error)
544550
{
545-
if (_analysisForm)
546-
_analysisForm->filterByNameDone(name, error);
551+
if (hasForm())
552+
form()->filterByNameDone(name, error);
547553
}
548554

549555
Json::Value Analysis::createAnalysisRequestJson()

Desktop/analysis/analysis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Analysis : public AnalysisBase
106106
const Json::Value & imgOptions() const { return _imgOptions; }
107107
const Json::Value & imgResults() const { return _imgResults; }
108108
Modules::DynamicModule * dynamicModule() const { return _dynamicModule; }
109-
AnalysisForm * form() const { return _analysisForm; }
109+
AnalysisForm * form() const;
110110
bool hasForm() const { return _analysisForm; }
111111
bool isDuplicate() const override { return _isDuplicate; }
112112
bool shouldRun() { return !isWaitingForModule() && ( isSaveImg() || isEditImg() || isRewriteImgs() || isEmpty() ) && form(); }

Engine/engine.h

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "enginebase.h"
2222
#include "enginedefinitions.h"
23-
#include "dataset.h"
2423
#include "ipcchannel.h"
2524
#include <json/json.h>
2625
#include "columnencoder.h"

QMLComponents/analysisbase.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include "analysisbase.h"
2-
#include "analysisform.h"
2+
#include "analysisformbase.h"
33
#include "log.h"
44
#include "utilities/qmlutils.h"
55

66
const std::string AnalysisBase::emptyString;
77
const stringvec AnalysisBase::emptyStringVec;
88

9-
AnalysisBase::AnalysisBase(QObject* parent, Version moduleVersion)
9+
AnalysisBase::AnalysisBase(QObject* parent, Version moduleVersion, const QString& moduleName, const QString& analysisName, const QString& qmlFileName)
1010
: QObject(parent)
1111
, _moduleVersion(moduleVersion)
12+
, _moduleName(fq(moduleName))
13+
, _analysisName(fq(analysisName))
14+
, _qmlFileName(fq(qmlFileName))
1215
{
1316
}
1417

@@ -49,17 +52,17 @@ void AnalysisBase::createForm(QQuickItem* parentItem)
4952
Log::log() << "Analysis(" << this << ")::createForm() called with parentItem " << parentItem << std::endl;
5053

5154
setQmlError("");
52-
55+
5356
if(parentItem)
5457
_parentItem = parentItem;
5558

5659
if(_analysisForm)
5760
{
5861
Log::log() << "It already has a form, so we destroy it." << std::endl;
59-
60-
if (!parentItem)
62+
63+
if (!parentItem)
6164
parentItem = _analysisForm->parentItem();
62-
65+
6366
destroyForm();
6467
}
6568
else if(!parentItem)
@@ -73,7 +76,7 @@ void AnalysisBase::createForm(QQuickItem* parentItem)
7376

7477
Log::log() << "Created a form, got pointer " << newForm << std::endl;
7578

76-
_analysisForm = qobject_cast<AnalysisForm *>(newForm);
79+
_analysisForm = qobject_cast<AnalysisFormBase *>(newForm);
7780

7881
if(!_analysisForm)
7982
throw std::logic_error("QML file '" + qmlFormPath(false, false) + "' didn't spawn into AnalysisForm, but into: " + (newForm ? fq(newForm->objectName()) : "null"));
@@ -116,7 +119,7 @@ void AnalysisBase::setQmlError(const QString &newQmlError)
116119

117120
// This method tries to find the parent keys in _boundValues Json object
118121
// If found, it sets the path to this reference to parentNames and returns a reference of the sub Json object
119-
Json::Value& AnalysisBase::_getParentBoundValue(const QVector<JASPControl::ParentKey>& parentKeys, QVector<std::string>& parentNames, bool& found, bool createAnyway)
122+
Json::Value& AnalysisBase::_getParentBoundValue(const QVector<AnalysisBase::ParentKey>& parentKeys, QVector<std::string>& parentNames, bool& found, bool createAnyway)
120123
{
121124
found = (parentKeys.size() == 0);
122125
Json::Value* parentBoundValue = &_boundValues;
@@ -208,7 +211,7 @@ Json::Value& AnalysisBase::_getParentBoundValue(const QVector<JASPControl::Paren
208211
return *parentBoundValue;
209212
}
210213

211-
std::string AnalysisBase::_displayParentKeys(const QVector<JASPControl::ParentKey> & parentKeys) const
214+
std::string AnalysisBase::_displayParentKeys(const QVector<AnalysisBase::ParentKey> & parentKeys) const
212215
{
213216
std::string keys;
214217
bool firstKey = true;
@@ -231,7 +234,7 @@ std::string AnalysisBase::_displayParentKeys(const QVector<JASPControl::ParentKe
231234
return keys;
232235
}
233236

234-
void AnalysisBase::setBoundValue(const std::string &name, const Json::Value &value, const Json::Value &meta, const QVector<JASPControl::ParentKey>& parentKeys)
237+
void AnalysisBase::setBoundValue(const std::string &name, const Json::Value &value, const Json::Value &meta, const QVector<AnalysisBase::ParentKey>& parentKeys)
235238
{
236239
bool found = false;
237240
QVector<std::string> parents;
@@ -261,7 +264,7 @@ void AnalysisBase::setBoundValues(const Json::Value &boundValues)
261264
_boundValues = boundValues;
262265
}
263266

264-
const Json::Value &AnalysisBase::boundValue(const std::string &name, const QVector<JASPControl::ParentKey> &parentKeys)
267+
const Json::Value &AnalysisBase::boundValue(const std::string &name, const QVector<AnalysisBase::ParentKey> &parentKeys)
265268
{
266269
bool found = false;
267270
QVector<std::string> parentNames;

QMLComponents/analysisbase.h

+73-60
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#include <QObject>
55
#include <json/json.h>
6-
#include "controls/jaspcontrol.h"
76
#include "appinfo.h"
7+
#include "utilities/qutils.h"
8+
#include "columntype.h"
89

9-
class AnalysisForm;
10+
class AnalysisFormBase;
1011

1112
class AnalysisBase : public QObject
1213
{
@@ -15,62 +16,72 @@ class AnalysisBase : public QObject
1516
Q_PROPERTY(QString qmlError READ qmlError WRITE setQmlError NOTIFY qmlErrorChanged )
1617

1718
public:
18-
explicit AnalysisBase(QObject *parent = nullptr, Version moduleVersion = AppInfo::version);
19+
struct ParentKey
20+
{
21+
std::string name, key;
22+
stringvec value;
23+
ParentKey(const std::string & _name, const std::string & _key, const stringvec & _value)
24+
: name(_name), key(_key), value(_value) {}
25+
};
26+
27+
explicit AnalysisBase(QObject *parent = nullptr, Version moduleVersion = AppInfo::version, const QString& moduleName = "", const QString& analysisName = "", const QString& qmlFileName = "");
1928
AnalysisBase(QObject *parent, AnalysisBase* duplicateMe);
2029

21-
virtual bool isOwnComputedColumn(const std::string &col) const { return false; }
22-
virtual void refresh() {}
23-
virtual void run() {}
24-
virtual void reloadForm() {}
25-
virtual void exportResults() {}
26-
virtual bool isDuplicate() const { return false; }
27-
virtual bool wasUpgraded() const { return false; }
28-
virtual bool needsRefresh() const { return false; }
29-
virtual const std::string & module() const { return emptyString; }
30-
virtual const std::string & name() const { return emptyString; }
31-
virtual const std::string & title() const { return emptyString; }
32-
virtual void setTitle(const std::string& titel) {}
33-
virtual void preprocessMarkdownHelp(const QString& md) const {}
34-
virtual QString helpFile() { return ""; }
35-
virtual const stringvec & upgradeMsgsForOption(const std::string& name) const { return emptyStringVec; }
36-
virtual const Json::Value & resultsMeta() const { return Json::Value::null; }
37-
virtual const Json::Value & getRSource(const std::string& name) const { return Json::Value::null; }
38-
virtual void initialized(AnalysisForm* form, bool isNewAnalysis) {}
39-
virtual std::string qmlFormPath(bool addFileProtocol = true,
40-
bool ignoreReadyForUse = false) const;
41-
virtual Q_INVOKABLE QString helpFile() const { return ""; }
42-
virtual Q_INVOKABLE void createForm(QQuickItem* parentItem=nullptr);
43-
virtual void destroyForm();
44-
virtual bool isColumnFreeOrMine(const QString & columnName) const { return false; }
45-
46-
const Json::Value & boundValues() const { return _boundValues; }
47-
const Json::Value & orgBoundValues() const { return _orgBoundValues; }
48-
const Json::Value & boundValue(const std::string& name,
49-
const QVector<JASPControl::ParentKey>& parentKeys = {});
50-
51-
void setBoundValue(const std::string& name, const Json::Value& value, const Json::Value& meta, const QVector<JASPControl::ParentKey>& parentKeys = {});
52-
void setBoundValues(const Json::Value& boundValues);
53-
void setOrgBoundValues(const Json::Value& orgBoundValues) { _orgBoundValues = orgBoundValues; }
54-
const Json::Value optionsMeta() const { return _boundValues.get(".meta", Json::nullValue); }
55-
void clearOptions() { _boundValues.clear(); }
56-
57-
const Version & moduleVersion() const { return _moduleVersion; }
58-
59-
QQuickItem * formItem() const;
60-
61-
const QString & qmlError() const;
62-
void setQmlError(const QString &newQmlError);
63-
void sendRScript(const QString & script, const QString & controlName, bool whiteListedVersion) { emit sendRScriptSignal(script, controlName, whiteListedVersion, tq(module())); }
64-
void sendFilter( const QString & name) { emit sendFilterSignal(name, tq(module())); }
65-
30+
virtual bool isOwnComputedColumn(const std::string &col) const { return false; }
31+
virtual void refresh() {}
32+
virtual void run() {}
33+
virtual void reloadForm() {}
34+
virtual void exportResults() {}
35+
virtual bool isDuplicate() const { return false; }
36+
virtual bool wasUpgraded() const { return false; }
37+
virtual bool needsRefresh() const { return false; }
38+
virtual const std::string & module() const { return _moduleName; }
39+
virtual const std::string & name() const { return _analysisName; }
40+
virtual const std::string & qmlFileName() const { return _qmlFileName; }
41+
virtual const std::string & title() const { return emptyString; }
42+
virtual void setTitle(const std::string& titel) {}
43+
virtual void preprocessMarkdownHelp(const QString& md) const {}
44+
virtual QString helpFile() { return ""; }
45+
virtual const stringvec & upgradeMsgsForOption(const std::string& name) const { return emptyStringVec; }
46+
virtual const Json::Value & resultsMeta() const { return Json::Value::null; }
47+
virtual const Json::Value & getRSource(const std::string& name) const { return Json::Value::null; }
48+
virtual void initialized(AnalysisFormBase* form, bool isNewAnalysis) {}
49+
virtual std::string qmlFormPath(bool addFileProtocol = true,
50+
bool ignoreReadyForUse = false) const;
51+
52+
virtual Q_INVOKABLE QString helpFile() const { return ""; }
53+
virtual Q_INVOKABLE void createForm(QQuickItem* parentItem=nullptr);
54+
virtual void destroyForm();
55+
virtual bool isColumnFreeOrMine(const QString & columnName) const { return false; }
56+
57+
const Json::Value& boundValues() const { return _boundValues; }
58+
const Json::Value& orgBoundValues() const { return _orgBoundValues; }
59+
const Json::Value& boundValue(const std::string& name,
60+
const QVector<AnalysisBase::ParentKey>& parentKeys = {});
61+
62+
void setBoundValue(const std::string& name, const Json::Value& value, const Json::Value& meta, const QVector<AnalysisBase::ParentKey>& parentKeys = {});
63+
void setBoundValues(const Json::Value& boundValues);
64+
void setOrgBoundValues(const Json::Value& orgBoundValues) { _orgBoundValues = orgBoundValues; }
65+
const Json::Value optionsMeta() const { return _boundValues.get(".meta", Json::nullValue); }
66+
void clearOptions() { _boundValues.clear(); }
67+
68+
const Version & moduleVersion() const { return _moduleVersion; }
69+
70+
QQuickItem * formItem() const;
71+
72+
const QString & qmlError() const;
73+
void setQmlError(const QString &newQmlError);
74+
75+
void sendRScript(const QString & script, const QString & controlName, bool whiteListedVersion) { emit sendRScriptSignal(script, controlName, whiteListedVersion, tq(module())); }
76+
void sendFilter( const QString & name) { emit sendFilterSignal(name, tq(module())); }
6677

6778
public slots:
6879
virtual void boundValueChangedHandler() {}
6980
virtual void requestColumnCreationHandler( const std::string & columnName, columnType colType) {}
7081
virtual void requestComputedColumnCreationHandler( const std::string & columnName) {}
7182
virtual void requestComputedColumnDestructionHandler(const std::string & columnName) {}
7283
virtual void onUsedVariablesChanged() {}
73-
84+
7485

7586
signals:
7687
void sendRScriptSignal(QString script, QString controlName, bool whiteListedVersion, QString module);
@@ -81,24 +92,26 @@ public slots:
8192

8293

8394
protected:
84-
Json::Value& _getParentBoundValue(const QVector<JASPControl::ParentKey> & parentKeys, QVector<std::string>& parentNames, bool & found, bool createAnyway = false);
85-
std::string _displayParentKeys(const QVector<JASPControl::ParentKey> & parentKeys) const;
86-
95+
Json::Value& _getParentBoundValue(const QVector<AnalysisBase::ParentKey> & parentKeys, QVector<std::string>& parentNames, bool & found, bool createAnyway = false);
96+
std::string _displayParentKeys(const QVector<AnalysisBase::ParentKey> & parentKeys) const;
8797

88-
AnalysisForm* _analysisForm = nullptr;
89-
QQuickItem * _parentItem = nullptr;
90-
QString _qmlError;
91-
Version _moduleVersion;
98+
AnalysisFormBase* _analysisForm = nullptr;
99+
QQuickItem * _parentItem = nullptr;
100+
QString _qmlError;
101+
Version _moduleVersion;
102+
std::string _qmlFileName,
103+
_analysisName,
104+
_moduleName;
92105

93106
private:
94-
Json::Value _boundValues = Json::objectValue,
95-
_orgBoundValues = Json::objectValue;
107+
Json::Value _boundValues = Json::objectValue,
108+
_orgBoundValues = Json::objectValue;
96109

97110

98111

99112
protected:
100-
static const std::string emptyString; ///< Otherwise we return references to a temporary object (std::string(""))
101-
static const stringvec emptyStringVec;
113+
static const std::string emptyString; ///< Otherwise we return references to a temporary object (std::string(""))
114+
static const stringvec emptyStringVec;
102115
};
103116

104117
#endif // ANALYSISBASE_H

0 commit comments

Comments
 (0)