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

Prevent setting an empty column name #5742

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
17 changes: 9 additions & 8 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,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<QString, QString>({{tq(oldName), tq(newName)}}), false, false);
if (change)
{
setManualEdits(true);
emit datasetChanged({}, {}, QMap<QString, QString>({{tq(oldName), tq(newName)}}), false, false);
JorisGoosen marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
Loading