Skip to content

Commit

Permalink
Set default minimim and maximum levels for ordinal and nominal
Browse files Browse the repository at this point in the history
If not explicitly set in the analysis:
. the minNumericLevels of a VariablesList accepting only scale variables, is set to 1.
. the maxLevels of a VariablesList accepting nominal and/or ordinal, is set to the Data/Preferences setting 'maxLevels' (default 100). Also the error message tells the user where he can change this maximum
  • Loading branch information
boutinb committed Jul 8, 2024
1 parent a086c34 commit 7243b07
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 5 deletions.
15 changes: 14 additions & 1 deletion Desktop/components/JASP/Widgets/FileMenu/PrefsData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,22 @@ QTC.ScrollView
leftMargin: jaspTheme.generalAnchorMargin
}

KeyNavigation.tab: missingValueDataLabelInput
KeyNavigation.tab: maxLevels
}
}

SpinBox
{
id: maxLevels
text: qsTr("Default maximum levels for nominal or ordinal")
value: preferencesModel.maxLevels
onValueChanged: preferencesModel.maxLevels = value

KeyNavigation.tab: missingValueDataLabelInput

toolTip: qsTr("For analysis accepting only nominal or ordinal for some variables, this setting prevents from setting a variable having too many levels.")
}

}


Expand Down
2 changes: 2 additions & 0 deletions Desktop/gui/preferencesmodel.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ GET_PREF_FUNC_BOOL( ALTNavModeActive, Settings::ALTNAVMODE_ACTIVE )
GET_PREF_FUNC_BOOL( orderByValueByDefault, Settings::ORDER_BY_VALUE_BY_DEFAULT )
GET_PREF_FUNC_BOOL( checkUpdatesAskUser, Settings::CHECK_UPDATES_ASK_USER )
GET_PREF_FUNC_BOOL( checkUpdates, Settings::CHECK_UPDATES )
GET_PREF_FUNC_INT( maxLevels, Settings::MAX_LEVELS )

int PreferencesModel::maxEngines() const
{
Expand Down Expand Up @@ -305,6 +306,7 @@ SET_PREF_FUNCTION( bool, setALTNavModeActive, ALTNavModeActive, ALTNavMod
SET_PREF_FUNCTION( bool, setOrderByValueByDefault, orderByValueByDefault, orderByValueByDefaultChanged, Settings::ORDER_BY_VALUE_BY_DEFAULT )
SET_PREF_FUNCTION( bool, setCheckUpdatesAskUser, checkUpdatesAskUser, checkUpdatesAskUserChanged, Settings::CHECK_UPDATES_ASK_USER )
SET_PREF_FUNCTION( bool, setCheckUpdates, checkUpdates, checkUpdatesChanged, Settings::CHECK_UPDATES )
SET_PREF_FUNCTION( int, setMaxLevels, maxLevels, maxLevelsChanged, Settings::MAX_LEVELS )


void PreferencesModel::setGithubPatCustom(QString newPat)
Expand Down
4 changes: 4 additions & 0 deletions Desktop/gui/preferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PreferencesModel : public PreferencesModelBase
Q_PROPERTY(bool orderByValueByDefault READ orderByValueByDefault WRITE setOrderByValueByDefault NOTIFY orderByValueByDefaultChanged )
Q_PROPERTY(bool checkUpdatesAskUser READ checkUpdatesAskUser WRITE setCheckUpdatesAskUser NOTIFY checkUpdatesAskUserChanged )
Q_PROPERTY(bool checkUpdates READ checkUpdates WRITE setCheckUpdates NOTIFY checkUpdatesChanged )
Q_PROPERTY(int maxLevels READ maxLevels WRITE setMaxLevels NOTIFY maxLevelsChanged )


public:
Expand Down Expand Up @@ -134,6 +135,7 @@ class PreferencesModel : public PreferencesModelBase
bool developerMode() const;
bool ALTNavModeActive() const;
bool orderByValueByDefault() const;
int maxLevels() const override;

bool checkUpdatesAskUser() const;
void setCheckUpdatesAskUser(bool newCheckUpdatesAskUser);
Expand Down Expand Up @@ -198,6 +200,7 @@ public slots:
void currentThemeNameHandler();
void setALTNavModeActive( bool ALTNavModeActive);
void setOrderByValueByDefault( bool orderByValueByDefault);
void setMaxLevels( int maxLevels);

signals:
void fixedDecimalsChanged( bool fixedDecimals);
Expand Down Expand Up @@ -250,6 +253,7 @@ public slots:
void orderByValueByDefaultChanged( bool orderByValueByDefault);
void checkUpdatesAskUserChanged( bool checkAsk);
void checkUpdatesChanged( bool check);
void maxLevelsChanged( int maxLevels);

private slots:
void dataLabelNAChangedSlot(QString label);
Expand Down
3 changes: 2 additions & 1 deletion Desktop/utilities/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const Settings::Setting Settings::Values[] = {
{"orderByValueByDefault", true },
{"checkUpdatesAskUser", true },
{"checkUpdates", false },
{"checkUpdatesLastTime", -1 }
{"checkUpdatesLastTime", -1 },
{"maxLevels", 100 }

};

Expand Down
3 changes: 2 additions & 1 deletion Desktop/utilities/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class Settings {
ORDER_BY_VALUE_BY_DEFAULT,
CHECK_UPDATES_ASK_USER,
CHECK_UPDATES,
LAST_CHECK
LAST_CHECK,
MAX_LEVELS
};

static QVariant value(Settings::Type key);
Expand Down
2 changes: 2 additions & 0 deletions QMLComponents/components/JASP/Controls/VariablesList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ VariablesListBase
maxRows : singleVariable ? 1 : -1
addAvailableVariablesToAssigned : listViewType === JASP.Interaction
allowAnalysisOwnComputedColumns : true
minNumericLevels : allowedColumns.length === 1 && allowedColumns[0] === 'scale' ? 1 : -1
maxLevels : allowedColumns.length > 0 && !allowedColumns.includes('scale') ? preferencesModel.maxLevels : -1

property alias label : variablesList.title
property alias itemGridView : itemGridView
Expand Down
8 changes: 6 additions & 2 deletions QMLComponents/controls/variableslistbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QQmlProperty>
#include "log.h"
#include "models/columntypesmodel.h"
#include "preferencesmodelbase.h"

VariablesListBase::VariablesListBase(QQuickItem* parent)
: JASPListControl(parent)
Expand Down Expand Up @@ -344,7 +345,10 @@ void VariablesListBase::termsChangedHandler()
}
else if (_maxLevels >= 0 && nbLevels > _maxLevels)
{
addControlErrorPermanent(tr("Maximum number of levels is %1. Variable %2 has %3 levels").arg(_maxLevels).arg(term.asQString()).arg(nbLevels));
QString msg = tr("Maximum number of levels is %1. Variable %2 has %3 levels.").arg(_maxLevels).arg(term.asQString()).arg(nbLevels);
if (_maxLevels == PreferencesModelBase::preferences()->maxLevels())
msg += "<br>" + tr("You may change this maximum in Preferences / Data menu.");
addControlErrorPermanent(msg);
hasError = true;
}
else if (_minNumericLevels >= 0 && nbNumValues < _minNumericLevels)
Expand All @@ -354,7 +358,7 @@ void VariablesListBase::termsChangedHandler()
}
else if (_maxNumericLevels >= 0 && nbNumValues > _maxNumericLevels)
{
addControlErrorPermanent(tr("Maximum number of numeric values is %1. Variable %2 has %3 different numeric values").arg(_maxNumericLevels).arg(term.asQString()).arg(nbNumValues));
addControlError(tr("Maximum number of numeric values is %1. Variable %2 has %3 different numeric values").arg(_maxNumericLevels).arg(term.asQString()).arg(nbNumValues));
hasError = true;
}

Expand Down
1 change: 1 addition & 0 deletions QMLComponents/preferencesmodelbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PreferencesModelBase : public QObject
virtual int maxFlickVelocity() const { return 808; }
virtual bool showRSyntax() const { return false; }
virtual bool showAllROptions() const { return false; }
virtual int maxLevels() const { return 100; }

static PreferencesModelBase* preferences();

Expand Down
7 changes: 7 additions & 0 deletions Resources/Help/preferences/PrefsData.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ This means that if you have fewer (or equal) than 10 different integers in the d
gets the Ordinal type (Nominal type if only 2 different integers are found) else it will get the Scale type. Be aware that this value is used when
importing the data, so data needs to be reloaded (or synchronized) to take effect.

#### Default Maximum levels for nominal or ordinal

Analyses may specify that some variables should be nominal or ordinal. But mostly, the analyses cannot accept too many levels for nominal or ordinal variables.
This setting specifies what is the default maximum number of levels that will be accepted.
An analysis may overwrite this setting: i.e. for 'Grouping Variables' in Independent Samples T-Test, the maximun (and minimum) of levels of a variables is set to 2.
But for most analyses this default setting is used: this prevent the user from using wrong variables, and make the engine running too long.

### Show missing values as

JASP shows missing values as blank in cells by default, you can also label them as others (e.g., it can even be defined as "😀" or other characters) in text field to display friendly on data pane. Note that this is different from a valid value label and means it won't appear in the results.
Expand Down

0 comments on commit 7243b07

Please sign in to comment.