From a41f10b3b56849bee984267acecb5c3ffd12cc98 Mon Sep 17 00:00:00 2001 From: boutinb Date: Tue, 26 Nov 2024 17:31:55 +0100 Subject: [PATCH 1/3] Prevent setting an empty column name Fixes https://github.com/jasp-stats/jasp-test-release/issues/2808 --- CommonData/column.cpp | 8 +++++--- CommonData/column.h | 2 +- Desktop/data/datasetpackage.cpp | 17 +++++++++-------- Desktop/data/datasetpackage.h | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CommonData/column.cpp b/CommonData/column.cpp index 3395c7b7e9..2161284d5a 100644 --- a/CommonData/column.cpp +++ b/CommonData/column.cpp @@ -116,12 +116,12 @@ void Column::invalidateDependents() col->invalidate(); } -void Column::setName(const std::string &name) +bool Column::setName(const std::string &name) { JASPTIMER_SCOPE(Column::setName); - if(_name == name) - return; + if(_name == name || name.empty()) + return false; std::string orgName = _name; _name = getUniqueName(name); @@ -131,6 +131,8 @@ void Column::setName(const std::string &name) db().columnSetName(_id, _name); incRevision(); + + return true; } void Column::setTitle(const std::string &title) diff --git a/CommonData/column.h b/CommonData/column.h index 8ff95507ce..3b4edba025 100644 --- a/CommonData/column.h +++ b/CommonData/column.h @@ -57,7 +57,7 @@ class Column : public DataSetBaseNode void dbDelete(bool cleanUpRest = true); - void setName( const std::string & name ); + bool setName( const std::string & name ); void setTitle( const std::string & title ); bool setRCode( const std::string & rCode ); bool setError( const std::string & error ); diff --git a/Desktop/data/datasetpackage.cpp b/Desktop/data/datasetpackage.cpp index dba40e101d..2b4373193e 100644 --- a/Desktop/data/datasetpackage.cpp +++ b/Desktop/data/datasetpackage.cpp @@ -1623,7 +1623,7 @@ stringvec DataSetPackage::getColumnDataStrs(size_t columnIndex) return out; } -void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newName, bool resetModel) +void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newName) { if(!_dataSet) return; @@ -1634,16 +1634,17 @@ void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newNa std::string oldName = getColumnName(columnIndex); - if(resetModel) - beginResetModel(); + beginResetModel(); - column->setName(newName); + bool change = column->setName(newName); - if(resetModel) - endResetModel(); + endResetModel(); - setManualEdits(true); - emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); + if (change) + { + setManualEdits(true); + emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); + } } void DataSetPackage::setColumnTitle(size_t columnIndex, const std::string & newTitle) diff --git a/Desktop/data/datasetpackage.h b/Desktop/data/datasetpackage.h index 29c996dd89..4286219c3a 100644 --- a/Desktop/data/datasetpackage.h +++ b/Desktop/data/datasetpackage.h @@ -231,7 +231,7 @@ class DataSetPackage : public QAbstractItemModel //Not QAbstractTableModel becau enum columnType getColumnType( const QString & name) const; std::string getColumnName( size_t columnIndex) const; stringvec getColumnDataStrs( size_t columnIndex); - void setColumnName( size_t columnIndex, const std::string & newName, bool resetModel = true); + void setColumnName( size_t columnIndex, const std::string & newName); void setColumnTitle( size_t columnIndex, const std::string & newTitle); void setColumnDescription( size_t columnIndex, const std::string & newDescription); void setColumnComputedType( size_t columnIndex, computedColumnType type); From 268b031fc30ed9257c1b764096a50a2b6483d2fd Mon Sep 17 00:00:00 2001 From: Joris Goosen Date: Wed, 27 Nov 2024 15:49:36 +0100 Subject: [PATCH 2/3] no change variable --- Desktop/data/datasetpackage.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Desktop/data/datasetpackage.cpp b/Desktop/data/datasetpackage.cpp index 2b4373193e..f8a47b7e79 100644 --- a/Desktop/data/datasetpackage.cpp +++ b/Desktop/data/datasetpackage.cpp @@ -1634,17 +1634,13 @@ void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newNa std::string oldName = getColumnName(columnIndex); - beginResetModel(); - - bool change = column->setName(newName); - - endResetModel(); - - if (change) - { - setManualEdits(true); - emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); - } + if(!column->setName(newName)) + return; + + + setManualEdits(true); + emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); + refresh(); } void DataSetPackage::setColumnTitle(size_t columnIndex, const std::string & newTitle) From 4c7faf73a288b41c1dea028fb3b3250698d91049 Mon Sep 17 00:00:00 2001 From: Joris Goosen Date: Wed, 27 Nov 2024 16:23:12 +0100 Subject: [PATCH 3/3] ok so the refresh serves a purpose --- Desktop/data/datasetpackage.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Desktop/data/datasetpackage.cpp b/Desktop/data/datasetpackage.cpp index f8a47b7e79..d8103f39cd 100644 --- a/Desktop/data/datasetpackage.cpp +++ b/Desktop/data/datasetpackage.cpp @@ -1634,13 +1634,12 @@ void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newNa std::string oldName = getColumnName(columnIndex); - if(!column->setName(newName)) - return; - - - setManualEdits(true); - emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); - refresh(); + if(column->setName(newName)) + { + setManualEdits(true); + emit datasetChanged({}, {}, QMap({{tq(oldName), tq(newName)}}), false, false); + } + refresh(); //We do refresh in any case because then the emptied name of the column in variableswindow will get filled again } void DataSetPackage::setColumnTitle(size_t columnIndex, const std::string & newTitle)