Skip to content

Commit b04d52b

Browse files
committed
EditTableDialog: Don't allow two columns with the same name
Don't allow the user to type in a field name that is already used in the edited table. Show a warning and reset the name if he tries do so anyway. Also fix the warning for the foreign key check. Here a warning was shown and the renaming cancelled but the field name wasn't reset to the old value.
1 parent 5af384f commit b04d52b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/EditTableDialog.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
216216
switch(column)
217217
{
218218
case kName:
219+
// When a field of that name already exists, show a warning to the user and don't apply the new name
220+
if(fieldNameExists(item->text(column)))
221+
{
222+
QMessageBox::warning(this, qApp->applicationName(), tr("There already is a field with that name. Please rename it first or choose a different "
223+
"name for this field."));
224+
// Reset the name to the old value but avoid calling this method again for that automatic change
225+
ui->treeWidget->blockSignals(true);
226+
item->setText(column, oldFieldName);
227+
ui->treeWidget->blockSignals(false);
228+
return;
229+
}
230+
219231
// When editing an exiting table, check if any foreign keys would cause trouble in case this name is edited
220232
if(!m_bNewTable)
221233
{
@@ -229,6 +241,10 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
229241
{
230242
QMessageBox::warning(this, qApp->applicationName(), tr("This column is referenced in a foreign key in table %1, column %2 and thus "
231243
"its name cannot be changed.").arg(fkobj.getname()).arg(fkfield->name()));
244+
// Reset the name to the old value but avoid calling this method again for that automatic change
245+
ui->treeWidget->blockSignals(true);
246+
item->setText(column, oldFieldName);
247+
ui->treeWidget->blockSignals(false);
232248
return;
233249
}
234250
}

0 commit comments

Comments
 (0)