Skip to content

Commit

Permalink
Prevent setting an empty column name (#5742)
Browse files Browse the repository at this point in the history
* Prevent setting an empty column name

Fixes jasp-stats/jasp-test-release#2808

* no change variable

* ok so the refresh serves a purpose
  • Loading branch information
boutinb authored Nov 27, 2024
1 parent d5ab5f3 commit aae799b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
8 changes: 5 additions & 3 deletions CommonData/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CommonData/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
18 changes: 7 additions & 11 deletions Desktop/data/datasetpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1634,16 +1634,12 @@ void DataSetPackage::setColumnName(size_t columnIndex, const std::string & newNa

std::string oldName = getColumnName(columnIndex);

if(resetModel)
beginResetModel();

column->setName(newName);

if(resetModel)
endResetModel();

setManualEdits(true);
emit datasetChanged({}, {}, QMap<QString, QString>({{tq(oldName), tq(newName)}}), false, false);
if(column->setName(newName))
{
setManualEdits(true);
emit datasetChanged({}, {}, QMap<QString, QString>({{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)
Expand Down
2 changes: 1 addition & 1 deletion Desktop/data/datasetpackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aae799b

Please sign in to comment.