Skip to content

Commit

Permalink
fix some things in computed columns (jasp-stats#5457)
Browse files Browse the repository at this point in the history
* fix some things in computed columns

- better tooltip on "force types button"
- make sure the width of the columnnames in constructor are set correctly
- dropping a column now uses the types according to the "convert/keep types" button
- does not recheck validity afterwards though.

* columns now show the columntype they will be using.
  • Loading branch information
JorisGoosen authored Apr 2, 2024
1 parent 79ef8b5 commit 7c8f0a9
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 29 deletions.
11 changes: 10 additions & 1 deletion Desktop/components/JASP/Widgets/ComputeColumnWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ FocusScope
anchors.fill: parent
anchors.leftMargin: 1
visible: !computedColumnsInterface.computeColumnUsesRCode
forceColumnInputs: !computedColumnsInterface.computeColumnForceType
? ""
: computedColumnsInterface.columnType === columnTypeScale
? "scale"
: computedColumnsInterface.columnType === columnTypeOrdinal
? "ordinal"
: computedColumnsInterface.columnType === columnTypeNominal
? "nominal"
: "unknown"

showGeneratedRCode: false
KeyNavigation.tab: applyComputedColumnButton
Expand Down Expand Up @@ -287,7 +296,7 @@ FocusScope
{
id: forceSourceColTypeButton

toolTip: qsTr("The columns used above can be read in the type of the computed column, or as their own type.\nKeep types will import columns with the type they have, while convert will force it to the type of the computed column in question.")
toolTip: qsTr("- Keep types: use columns with their defined columntype.\n- Convert types: convert all used columns to the columntype of this computed column before use.\n\nThe button displays the *current setting*, not what will happen when you press it!")
text: !computedColumnsInterface.computeColumnForceType
? qsTr("Keep types")
: qsTr("Convert types")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import QtQuick 2.0

DragGeneric {
DragGeneric
{
property string columnName: "?"
property string columnIcon: ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ FocusScope
property alias functionModel: functieLijst.model
property string rCode: ""
property string jsonConstructed: ""
property string forceColumnInputs: ""


onSomethingChangedChanged:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Item
property bool lastCheckPassed: true
property bool showStartupMsg: true
property alias functionModel: functieLijst.model
property string forceColumnInputs: ""

signal rCodeChanged(string rScript)

Expand Down
15 changes: 7 additions & 8 deletions Desktop/components/JASP/Widgets/FilterConstructor/JASPColumn.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Item
height: filterConstructor.blockDim
implicitWidth: colIcon.width + colName.width
width: implicitWidth
property bool isNumerical: columnIcon.indexOf("scale") >= 0
property bool isOrdinal: columnIcon.indexOf("ordinal") >= 0
property bool isNumerical: (filterConstructor.forceColumnInputs !== "" && filterConstructor.forceColumnInputs === "scale") || columnIcon.indexOf("scale") >= 0
property bool isOrdinal: (filterConstructor.forceColumnInputs !== "" && filterConstructor.forceColumnInputs === "ordinal") || columnIcon.indexOf("ordinal") >= 0


property var dragKeys: isOrdinal ? ["string", "ordered"] : isNumerical ? ["number"] : ["string"]

Image
{
id: colIcon
source: columnIcon
source: filterConstructor.forceColumnInputs === "" ? columnIcon : computedColumnsInterface.computeColumnIconSource
width: height
sourceSize
{
Expand All @@ -40,7 +40,7 @@ Item
TextMetrics
{
id: columnNameMeasure
font.pixelSize: colName.font.pixelSize
font: colName.font
text: colName.text
}

Expand All @@ -49,16 +49,15 @@ Item
id: colName
anchors
{
top: parent.top
left: colIcon.right
bottom: parent.bottom
verticalCenter: parent.vertivalCenter
left: colIcon.right
}

width: Math.min(columnNameMeasure.width + 10, jaspColumnRoot.maxSize - (colIcon.width + 2*colIcon.anchors.margins))
font.pixelSize: baseFontSize * preferencesModel.uiScale
font.family: jaspTheme.font.family
color: jaspTheme.textEnabled
leftPadding: 2
leftPadding: 4 * preferencesModel.uiScale

text: columnName
elide: Text.ElideMiddle
Expand Down
2 changes: 1 addition & 1 deletion Desktop/components/JASP/Widgets/MainWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Window
}

//Utility:
readonly property Item _toolTipOverrideItem: Item
property Item _toolTipOverrideItem: Item
{
//These properties override those for ALL attached ToolTips in the application
//ToolTip.toolTip shouldn't be changed anywhere else otherwise we get hard to debug behaviour
Expand Down
20 changes: 19 additions & 1 deletion Desktop/data/computedcolumnmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "jsonutilities.h"
#include "utilities/qutils.h"
#include "columnencoder.h"
#include "analysis/analyses.h"
#include "variableinfo.h"

ComputedColumnModel * ComputedColumnModel::_singleton = nullptr;

Expand All @@ -13,11 +15,13 @@ ComputedColumnModel::ComputedColumnModel()

_undoStack = DataSetPackage::pkg()->undoStack();

connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnJsonChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnJsonChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnRCodeChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnErrorChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnUsesRCodeChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnForceTypeChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::computeColumnIconSourceChanged );
connect(this, &ComputedColumnModel::refreshProperties, this, &ComputedColumnModel::columnTypeChanged );

connect(this, &ComputedColumnModel::refreshColumn, DataSetPackage::pkg(), &DataSetPackage::refreshColumn, Qt::QueuedConnection);
connect(this, &ComputedColumnModel::refreshData, DataSetPackage::pkg(), &DataSetPackage::refresh, Qt::QueuedConnection);
Expand Down Expand Up @@ -58,6 +62,11 @@ QString ComputedColumnModel::computeColumnJson()
return json;
}

int ComputedColumnModel::computedColumnColumnType()
{
return int(!_selectedColumn ? columnType::unknown : _selectedColumn->type());
}

QString ComputedColumnModel::computeColumnError()
{
return !_selectedColumn ? "" : tq(_selectedColumn->error());
Expand Down Expand Up @@ -445,6 +454,10 @@ Column * ComputedColumnModel::createComputedColumn(const std::string & name, int
return createdColumn;
}

void ComputedColumnModel::createComputedColumn(const QString &name, int columnType, bool jsonPlease)
{
createComputedColumn(fq(name), columnType, jsonPlease ? computedColumnType::constructorCode : computedColumnType::rCode);
}

bool ComputedColumnModel::showAnalysisFormForColumn(const QString & columnName)
{
Expand Down Expand Up @@ -479,3 +492,8 @@ void ComputedColumnModel::analysisRemoved(Analysis * analysis)
for(const std::string & col : colsToRemove)
DataSetPackage::pkg()->requestComputedColumnDestruction(col);
}

QString ComputedColumnModel::computeColumnIconSource() const
{
return VariableInfo::getIconFile(!_selectedColumn ? columnType::unknown : _selectedColumn->type(), VariableInfo::DefaultIconType);
}
19 changes: 9 additions & 10 deletions Desktop/data/computedcolumnmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#define COMPUTEDCOLUMNSCODEITEM_H

#include <QQuickItem>
#include <QObject>
#include "datasetpackage.h"
#include "analysis/analyses.h"

///
/// A model for use by the computed columns editor in QML
Expand All @@ -17,7 +15,9 @@ class ComputedColumnModel : public QObject
Q_PROPERTY(bool computeColumnForceType READ computeColumnForceType WRITE setComputeColumnForceType NOTIFY computeColumnForceTypeChanged )
Q_PROPERTY(QString computeColumnJson READ computeColumnJson NOTIFY computeColumnJsonChanged )
Q_PROPERTY(QString computeColumnError READ computeColumnError NOTIFY computeColumnErrorChanged )
Q_PROPERTY(int columnType READ computedColumnColumnType NOTIFY columnTypeChanged )
Q_PROPERTY(bool datasetLoaded READ datasetLoaded NOTIFY refreshProperties )
Q_PROPERTY(QString computeColumnIconSource READ computeColumnIconSource NOTIFY computeColumnIconSourceChanged )

public:
explicit ComputedColumnModel();
Expand All @@ -29,7 +29,9 @@ class ComputedColumnModel : public QObject
QString computeColumnRCodeCommentStripped();
QString computeColumnError();
QString computeColumnJson();
int computedColumnColumnType();
bool computeColumnForceType() const;
QString computeColumnIconSource() const;
Column * column() const;
bool computeColumnUsesRCode();

Expand All @@ -45,7 +47,7 @@ class ComputedColumnModel : public QObject
Q_INVOKABLE bool isColumnNameFree(const QString & name) { return DataSetPackage::pkg()->isColumnNameFree(name.toStdString()); }

Column * createComputedColumn(const std::string & name, int columnType, computedColumnType computeType, Analysis * analysis = nullptr);
Q_INVOKABLE void createComputedColumn(const QString & name, int columnType, bool jsonPlease) { createComputedColumn(fq(name), columnType, jsonPlease ? computedColumnType::constructorCode : computedColumnType::rCode); }
Q_INVOKABLE void createComputedColumn(const QString & name, int columnType, bool jsonPlease);

bool areLoopDependenciesOk(const std::string & columnName);
bool areLoopDependenciesOk(const std::string & columnName, const std::string & code);
Expand All @@ -54,8 +56,6 @@ class ComputedColumnModel : public QObject

static ComputedColumnModel * singleton() { return _singleton; }




private:
void revertToDefaultInvalidatedColumns();
Expand All @@ -73,12 +73,15 @@ class ComputedColumnModel : public QObject
void computeColumnJsonChanged();
void refreshColumn(QString columnName);
void headerDataChanged(Qt::Orientation orientation, int first, int last);
void sendComputeCode(QString columnName, QString code, columnType columnType, bool forceType);
void sendComputeCode(QString columnName, QString code, enum columnType columnType, bool forceType);
void computeColumnUsesRCodeChanged();
void showAnalysisForm(Analysis *analysis);
void dataColumnAdded(QString columnName);
void refreshData();
void computeColumnForceTypeChanged();
void columnTypeChanged();

void computeColumnIconSourceChanged();

public slots:
void checkForDependentColumnsToBeSent(QString columnName, bool refreshMe = false);
Expand All @@ -97,11 +100,7 @@ public slots:
private:
static ComputedColumnModel * _singleton;
Column * _selectedColumn = nullptr;

UndoStack * _undoStack = nullptr;



};

#endif // COMPUTEDCOLUMNSCODEITEM_H
Expand Down
1 change: 1 addition & 0 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ void MainWindow::loadQML()
_qml->rootContext()->setContextProperty("columnTypeOrdinal", int(columnType::ordinal) );
_qml->rootContext()->setContextProperty("columnTypeNominal", int(columnType::nominal) );
_qml->rootContext()->setContextProperty("columnTypeNominalText", int(columnType::nominalText) );
_qml->rootContext()->setContextProperty("columnTypeUnknown", int(columnType::unknown) );

_qml->rootContext()->setContextProperty("computedColumnTypeRCode", int(computedColumnType::rCode) );
_qml->rootContext()->setContextProperty("computedColumnTypeAnalysis", int(computedColumnType::analysis) );
Expand Down
7 changes: 0 additions & 7 deletions QMLComponents/controls/jaspcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ JASPControl::JASPControl(QQuickItem *parent) : QQuickItem(parent)
{
setFlag(ItemIsFocusScope);
setActiveFocusOnTab(true);
/*if (JaspTheme::currentTheme()) // THis does not work...
{
// TODO: Add currentTheme changed font changed
QQmlProperty(this, "ToolTip.timeout", qmlContext(this)).write(JaspTheme::currentTheme()->toolTipTimeout());
setProperty("ToolTip.delay", JaspTheme::currentTheme()->toolTipDelay());
setProperty("ToolTip.tooltip.font", JaspTheme::currentTheme()->font());
}*/

connect(this, &JASPControl::titleChanged, this, &JASPControl::helpMDChanged);
connect(this, &JASPControl::infoChanged, this, &JASPControl::helpMDChanged);
Expand Down

0 comments on commit 7c8f0a9

Please sign in to comment.