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

In CFA, assign the same variable to different factors #5706

Merged
merged 1 commit into from
Oct 17, 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
1 change: 1 addition & 0 deletions QMLComponents/components/JASP/Controls/FactorsForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FactorsFormBase
property int factorListHeight: (jaspTheme.defaultVariablesFormHeight - factorButtons.height) / 3 - factorsFormColumn.spacing
property int assignAvailableVariablesToList: allowInteraction ? (initNumberFactors - 1) : -1 // If interaction is used, set automatically the available variables to the last assigned variables list
property bool allowTypeChange: false
property alias keepAvailableVariables: availableVariablesList.keepVariablesWhenMoved

AvailableVariablesList
{
Expand Down
6 changes: 5 additions & 1 deletion QMLComponents/controls/variableslistbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ void VariablesListBase::_setRelations()

// When the assigned model is of type interaction or it has multiple columns, then the available model should keep its terms when they are moved to the assigned model
if (_listViewType == ListViewType::Interaction || (columns() > 1 && _listViewType != ListViewType::RepeatedMeasures))
availableModel->setKeepTerms(true);
{
VariablesListBase* listControl = qobject_cast<VariablesListBase*>(availableModel->listView());
if (listControl)
listControl->setKeepVariablesWhenMoved(true);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions QMLComponents/controls/variableslistbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class VariablesListBase : public JASPListControl, public BoundControl
Q_PROPERTY( int columns READ columns WRITE setColumns NOTIFY columnsChanged )
Q_PROPERTY( QStringList dropKeys READ dropKeys WRITE setDropKeys NOTIFY dropKeysChanged )
Q_PROPERTY( QString interactionHighOrderCheckBox READ interactionHighOrderCheckBox WRITE setInteractionHighOrderCheckBox NOTIFY interactionHighOrderCheckBoxChanged )
Q_PROPERTY( bool keepVariablesWhenMoved READ keepVariablesWhenMoved WRITE setKeepVariablesWhenMoved NOTIFY keepVariablesWhenMovedChanged )

public:
VariablesListBase(QQuickItem* parent = nullptr);
Expand All @@ -60,12 +61,14 @@ class VariablesListBase : public JASPListControl, public BoundControl
const QString & interactionHighOrderCheckBox() const { return _interactionHighOrderCheckBox; }
bool addRowControl(const QString& key, JASPControl* control) override;
void moveItems(QList<int> &indexes, ListModelDraggable* dropModel, int dropItemIndex = -1);
bool keepVariablesWhenMoved() const { return _keepVariablesWhenMoved; }

signals:
void listViewTypeChanged();
void columnsChanged();
void dropKeysChanged();
void interactionHighOrderCheckBoxChanged();
void keepVariablesWhenMovedChanged();

public slots:
void setVariableType(int index, int type);
Expand All @@ -81,6 +84,7 @@ protected slots:
GENERIC_SET_FUNCTION(ListViewType, _listViewType, listViewTypeChanged, ListViewType )
GENERIC_SET_FUNCTION(Columns, _columns, columnsChanged, int )
GENERIC_SET_FUNCTION(InteractionHighOrderCheckBox, _interactionHighOrderCheckBox, interactionHighOrderCheckBoxChanged, QString )
GENERIC_SET_FUNCTION(KeepVariablesWhenMoved, _keepVariablesWhenMoved, keepVariablesWhenMovedChanged, bool )

void _setInitialized(const Json::Value& value = Json::nullValue) override;
void setDropKeys(const QStringList& dropKeys);
Expand All @@ -93,6 +97,7 @@ protected slots:
ListModelDraggable* _draggableModel = nullptr;
ListViewType _listViewType = ListViewType::AssignedVariables;
BoundControl* _boundControl = nullptr;
bool _keepVariablesWhenMoved = false;

private:
int _columns = 1;
Expand Down
7 changes: 7 additions & 0 deletions QMLComponents/models/listmodeldraggable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "listmodeldraggable.h"
#include "analysisform.h"
#include "controls/jasplistcontrol.h"
#include "controls/variableslistbase.h"

ListModelDraggable::ListModelDraggable(JASPListControl* listView)
: ListModel(listView)
Expand All @@ -29,6 +30,12 @@ ListModelDraggable::~ListModelDraggable()
{
}

bool ListModelDraggable::keepTerms() const
{
VariablesListBase* variablesList = qobject_cast<VariablesListBase*>(listView());
return variablesList ? variablesList->keepVariablesWhenMoved() : false;
}

Terms ListModelDraggable::termsFromIndexes(const QList<int> &indexes) const
{
Terms result;
Expand Down
4 changes: 1 addition & 3 deletions QMLComponents/models/listmodeldraggable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ class ListModelDraggable : public ListModel
ListModelDraggable(JASPListControl* listView);
~ListModelDraggable();

bool keepTerms() const { return _keepTerms; }
bool keepTerms() const;
JASPControl::DropMode dropMode() const { return _dropMode; }

void setKeepTerms(bool keep) { _keepTerms = keep; }
void setDropMode(JASPControl::DropMode dropMode) { _dropMode = dropMode; }

virtual QList<int> indexesFromTerms( const Terms & terms) const;
Expand All @@ -46,7 +45,6 @@ class ListModelDraggable : public ListModel
virtual Terms termsFromIndexes( const QList<int>& indexes) const;

protected:
bool _keepTerms = false;
JASPControl::DropMode _dropMode = JASPControl::DropMode::DropNone;

bool isAllowed(const Term &term) const;
Expand Down
Loading