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

Adding levels #5789

Open
wants to merge 22 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e9cb4dd
Adding levels
JorisGoosen Jan 23, 2025
a6aaeec
support either dropping levels or not, also based on if anything is f…
JorisGoosen Feb 11, 2025
dd5b76a
added a button for turning drop levels on and off
JorisGoosen Feb 11, 2025
d67a2f1
interaction with computed columns seems ok now
JorisGoosen Feb 11, 2025
40184e3
finishing touches
JorisGoosen Feb 11, 2025
b7ee6e2
little bit prettier
JorisGoosen Feb 11, 2025
86a23d9
use dropLevels in checking levels
JorisGoosen Feb 13, 2025
143a44d
Add keep/drop levels to filterconstructor and add something in the help
JorisGoosen Feb 13, 2025
24d1565
comment dataChanged call away cause it crashes my debug on windows an…
JorisGoosen Feb 13, 2025
dbb70eb
droplevels now does always drop levels
JorisGoosen Feb 17, 2025
6d0d02f
use ⌫ as icon and rename the "erase" col to "remove"
JorisGoosen Feb 17, 2025
b3f9158
remove unused stuff from sql and code
JorisGoosen Feb 17, 2025
28f6d06
add computeFilter to Columns db table
JorisGoosen Feb 17, 2025
8a3efb6
add computeFilter meat and make new level entry a bit tighter
JorisGoosen Feb 17, 2025
05a5901
allow for dropdown of filters in a column to work
JorisGoosen Feb 18, 2025
e419761
make sure the computed columns now use tthe filter if its enabled
JorisGoosen Feb 18, 2025
c1ccbd4
move dropLevels to Column from Filter
JorisGoosen Feb 25, 2025
4aa5512
button added and works, reused the eye icon
JorisGoosen Feb 25, 2025
2e0dadf
add level on enter and try to fix the weird issue with the filterallo…
JorisGoosen Feb 25, 2025
686439e
make all filterallows work and tweak sizing of filterwindow and varsw…
JorisGoosen Feb 26, 2025
1e4a8eb
add noChoice -> drop/keep behaviour
JorisGoosen Feb 26, 2025
3d3556d
Fix https://github.com/jasp-stats/INTERNAL-jasp/issues/2700 because i…
JorisGoosen Feb 26, 2025
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
Next Next commit
Adding levels
entry boxes for level addition

adding and removing labels now works
  • Loading branch information
JorisGoosen committed Feb 26, 2025
commit e9cb4ddea9de1f6d106972316ba7e95035416f07
56 changes: 53 additions & 3 deletions CommonData/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,11 @@ int Column::labelsAdd(int display)
}

int Column::labelsAdd(const std::string &display)
{
return labelsAdd(display, display);
}

int Column::labelsAdd(const std::string &display, const std::string &value)
{

JASPTIMER_SCOPE(Column::labelsAdd displaystring);
Expand All @@ -737,10 +742,10 @@ int Column::labelsAdd(const std::string &display)
int anInt;
double aDouble;

Json::Value original = display;
Json::Value original = value;

if (ColumnUtils::getIntValue( display, anInt)) original = anInt;
else if (ColumnUtils::getDoubleValue( display, aDouble)) original = aDouble;
if (ColumnUtils::getIntValue( value, anInt)) original = anInt;
else if (ColumnUtils::getDoubleValue( value, aDouble)) original = aDouble;

return labelsAdd(display, "", original);
}
Expand Down Expand Up @@ -775,9 +780,54 @@ int Column::labelsAdd(int value, const std::string & display, bool filterAllows,
Label * label = new Label(this, display, value, filterAllows, description, originalValue, order, id);
_labels.push_back(label);

labelsTempReset();

return _labelMapIt(label);
}

void Column::labelsRemove(int labelIndex)
{
if(_labels.size() <= labelIndex)
{
//So it might be a temp label?
if(labelsTempCount() <= labelIndex)
return;

//So we can assume that label == value and it is a double
double val = labelsTempValueDouble(labelIndex);

for(size_t i=0; i<_ints.size(); i++)
if(_dbls[i] == val && _ints[i] == Label::DOUBLE_LABEL_VALUE)
{
_ints[i] = EmptyValues::missingValueInteger;
_dbls[i] = EmptyValues::missingValueDouble;
}

}
else
{

Label * label = _labels[labelIndex];

int intsId = label->intsId();

labelsRemoveByIntsId({intsId}, false);

for(size_t i=0; i<_ints.size(); i++)
if(_ints[i] == intsId)
{
_ints[i] = EmptyValues::missingValueInteger;
_dbls[i] = EmptyValues::missingValueDouble;
}
}

db().columnSetValues(_id, _ints, _dbls);
labelsTempReset();
_dbUpdateLabelOrder();

incRevision();
}

int Column::labelsSet(int labelIndex, int value, const std::string &display, bool filterAllows, const std::string &description, const Json::Value &originalValue, int order, int id)
{
JASPTIMER_SCOPE(Column::labelsSet);
Expand Down
2 changes: 2 additions & 0 deletions CommonData/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ class Column : public DataSetBaseNode
void labelsClear(bool doIncRevision=true);
int labelsAdd( int display);
int labelsAdd( const std::string & display);
int labelsAdd( const std::string &display, const std::string &value);
int labelsAdd( const std::string & display, const std::string & description, const Json::Value & originalValue);
int labelsAdd( int value, const std::string & display, bool filterAllows, const std::string & description, const Json::Value & originalValue, int order=-1, int id=-1);
void labelsRemove( int labelIndex);
int labelsSet(int lbId, int value, const std::string & display, bool filterAllows, const std::string & description, const Json::Value & originalValue, int order=-1, int id=-1);
void labelsRemoveByIntsId( intset valuesToRemove, bool updateOrder = true);
strintmap labelsResetValues( int & maxValue);
Expand Down
111 changes: 109 additions & 2 deletions Desktop/components/JASP/Widgets/LabelEditorWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FocusScope
top: parent.top
left: buttonColumnFlickable.right
right: parent.right
bottom: parent.bottom
bottom: newLabelContainer.top
leftMargin: jaspTheme.generalAnchorMargin
}

Expand Down Expand Up @@ -62,7 +62,7 @@ FocusScope
}

property real filterColWidth: 60 * jaspTheme.uiScale
property real remainingWidth: width - filterColWidth
property real remainingWidth: width - (2* filterColWidth)
property real valueColWidth: Math.min(columnModel.valueMaxWidth + 10, remainingWidth * 0.5) * jaspTheme.uiScale
property real labelColWidth: Math.min(columnModel.labelMaxWidth + 10, remainingWidth * 0.5) * jaspTheme.uiScale
property int selectedRow: -1
Expand Down Expand Up @@ -123,6 +123,21 @@ FocusScope
leftPadding: 3 * jaspTheme.uiScale
anchors.verticalCenter: parent.verticalCenter
width: levelsTableView.labelColWidth;
}
Rectangle
{
width: 1
height: parent.height
color: jaspTheme.uiBorder
}
Text
{
text: qsTr("Erase")
font: jaspTheme.font
color: jaspTheme.textEnabled
leftPadding: 3 * jaspTheme.uiScale
anchors.verticalCenter: parent.verticalCenter
width: levelsTableView.filterColWidth;
}
}
}
Expand Down Expand Up @@ -410,12 +425,104 @@ FocusScope
}
}
}

MouseArea
{
id: deleteButton
width: levelsTableView.filterColWidth;
height: parent.height
z: -1
cursorShape: Qt.PointingHandCursor


onClicked:
{
columnModel.deleteLabel(rowIndex);
}

Image
{
source: jaspTheme.iconPath + ("eraser.png")
sourceSize.width: Math.max(40, width)
sourceSize.height: Math.max(40, height)
width: height
anchors
{
top: deleteButton.top
bottom: deleteButton.bottom
margins: levelsTableView.itemVerticalPadding
horizontalCenter: deleteButton.horizontalCenter
}
}
}
}
}
}
}

}

Row
{
id: newLabelContainer
anchors
{
left: parent.left
right: parent.right
bottom: parent.bottom
}


TextField
{
id: newLevelValueInput

displayValue: ""
placeholderText: qsTr("Value")
control.height: buttonColumnVariablesWindow.buttonHeight

}

TextField
{
id: newLevelLabelInput

displayValue: ""
placeholderText: qsTr("Label")
control.height: buttonColumnVariablesWindow.buttonHeight
}

RoundedButton
{
iconSource: jaspTheme.iconPath + "addition-sign-small.svg"
onClicked:
{
if(newLevelValueInput.displayValue == "" && newLevelLabelInput.displayValue == "")
{
newLevelValueInput.forceActiveFocus();
return
}

var newValue = newLevelValueInput.displayValue
var newLabel = newLevelLabelInput.displayValue

if(newLabel == "")
newLabel = newValue

forceActiveFocus();
columnModel.addLabel(newValue, newLabel);

newLevelValueInput.displayValue = ""
newLevelLabelInput.displayValue = ""
}

toolTip: qsTr("Add a level that's missing from the data")

height: implicitHeight
implicitHeight: buttonColumnVariablesWindow.buttonHeight
width: height
}
}

Flickable
{
Expand Down
33 changes: 33 additions & 0 deletions Desktop/data/columnmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,38 @@ void ColumnModel::setLabel(int rowIndex, QString label)
_editing = false;
}

void ColumnModel::deleteLabel(int rowIndex)
{
_undoStack->pushCommand(new DeleteLabelCommand(this, rowIndex));
}

void ColumnModel::addLabel(QString value, QString label)
{
_undoStack->pushCommand(new AddLabelCommand(this, value, label));
}

void ColumnModel::_addLabel(QString value, QString label)
{
if(!column())
return;

column()->labelsAdd(fq(label), fq(value));
column()->incRevision();
refresh();
DataSetPackage::pkg()->emitColumnChanged(columnNameQ());
}

void ColumnModel::_deleteLabel(int labelIndex)
{
if(!column())
return;

column()->labelsRemove(labelIndex);
refresh();
DataSetPackage::pkg()->emitColumnChanged(columnNameQ());
}


bool ColumnModel::columnIsFiltered() const
{
if(column())
Expand Down Expand Up @@ -820,3 +852,4 @@ void ColumnModel::languageChangedHandler()
emit tabsChanged();
}


4 changes: 4 additions & 0 deletions Desktop/data/columnmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class ColumnModel : public DataSetTableProxy
Q_INVOKABLE bool setChecked(int rowIndex, bool checked);
Q_INVOKABLE void setValue(int rowIndex, const QString & value);
Q_INVOKABLE void setLabel(int rowIndex, QString label);
Q_INVOKABLE void deleteLabel(int rowIndex);
Q_INVOKABLE void addLabel(QString value, QString label); ///< Via UndoStack
Q_INVOKABLE void addEmptyValue( const QString & value);
Q_INVOKABLE void removeEmptyValue( const QString & value);
Q_INVOKABLE void resetEmptyValues();
Expand Down Expand Up @@ -130,6 +132,8 @@ public slots:
void checkCurrentColumn( QStringList changedColumns, QStringList missingColumns, QMap<QString, QString> changeNameColumns, bool rowCountChanged, bool hasNewColumns);
void setCompactMode(bool newCompactMode);
void languageChangedHandler();
void _addLabel(QString value, QString label); ///< Directly actually add it!
void _deleteLabel(int labelIndex);

signals:
void visibleChanged(bool visible);
Expand Down
5 changes: 5 additions & 0 deletions Desktop/data/datasetpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,11 @@ void DataSetPackage::endSynchingData( const stringvec & changedColumns,
setManualEdits(false);
}

void DataSetPackage::emitColumnChanged(const QString & colName)
{
emit datasetChanged({colName}, {}, {}, false, false);
}


void DataSetPackage::beginLoadingData(bool informEngines)
{
Expand Down
5 changes: 2 additions & 3 deletions Desktop/data/datasetpackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ class DataSetPackage : public QAbstractItemModel //Not QAbstractTableModel becau
std::string freeNewColumnName(size_t startHere);
void dbDelete();
void resetVariableTypes();



void emitColumnChanged(const QString &colName); //temporary until ColumnQ exists

signals:
void datasetChanged( QStringList changedColumns,
QStringList missingColumns,
Expand Down
35 changes: 35 additions & 0 deletions Desktop/data/undostack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,32 @@ void SetLabelOriginalValueCommand::redo()
_columnModel->setLabelMaxWidth();
}

DeleteLabelCommand::DeleteLabelCommand(QAbstractItemModel *model, int labelIndex)
: UndoModelCommandSingleColumn(model), _labelIndex(labelIndex)
{
setText(QObject::tr("Delete label %1 of column '%2'").arg(_labelIndex).arg(columnName()));
}

void DeleteLabelCommand::redo()
{
_columnModel->_deleteLabel(_labelIndex);
}


AddLabelCommand::AddLabelCommand(QAbstractItemModel *model, QString value, QString label)
: UndoModelCommandLabelChange(model), _value(value), _label(label)
{
if (_columnModel)
setText(QObject::tr("Adding value + label '%1' + '%2' to column '%3'").arg(_value).arg(_label).arg(columnName()));
}

void AddLabelCommand::redo()
{
UndoModelCommandLabelChange::redo();
if (_columnModel)
_columnModel->_addLabel(_value, _label);
}

FilterLabelCommand::FilterLabelCommand(QAbstractItemModel *model, int labelIndex, bool checked)
: UndoModelCommand(model), _labelIndex{labelIndex}, _checked{checked}

Expand Down Expand Up @@ -860,3 +884,14 @@ QString UndoModelCommand::rowName(int rowIndex) const
return result;
}



UndoModelCommandSingleColumn::UndoModelCommandSingleColumn(QAbstractItemModel *model)
: UndoModelCommandMultipleColumns(model, {qobject_cast<ColumnModel*>(model)->chosenColumn()} )
{
_columnModel = qobject_cast<ColumnModel*>(model);

if(!_columnModel)
throw std::runtime_error("UndoModelCommandSingleColumn needs to get passed a ColumnModel!");

}
Loading