From 51c66a6767fe5b78f7ce458d2773ca9c5f264c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C3=85=C2=99=C3=83=C2=AD=20Techet?= Date: Tue, 19 Sep 2017 11:29:00 +0200 Subject: [PATCH] Fix custom type saving when only focus changes for user-entered type At the moment when user types a custom type into the type combo box and doesn't press enter, the entered type isn't used. This patch tries to fix the problem by installing an event filter for the combo box and checking when it loses focus - when it does, it performs type updates too. On the way the patch also changes the signal used inside moveCurrentField() from activated() to currentIndexChanged() to make it consistent with the rest of the file. --- src/EditTableDialog.cpp | 25 +++++++++++++++++++++---- src/EditTableDialog.h | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index bf0bffe23c..13fdbc0893 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -119,6 +119,7 @@ void EditTableDialog::populateFields() index = typeBox->count() - 1; } typeBox->setCurrentIndex(index); + typeBox->installEventFilter(this); connect(typeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypes())); ui->treeWidget->setItemWidget(tbitem, kType, typeBox); @@ -227,13 +228,13 @@ void EditTableDialog::checkInput() ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); } -void EditTableDialog::updateTypes() +void EditTableDialog::updateTypes(QObject *object) { - QComboBox* typeBox = qobject_cast(sender()); + QComboBox* typeBox = qobject_cast(object); if(typeBox) { QString type = typeBox->currentText(); - QString column = sender()->property("column").toString(); + QString column = typeBox->property("column").toString(); int index; for(index=0; index < m_table.fields().size(); ++index) @@ -249,6 +250,20 @@ void EditTableDialog::updateTypes() } } +void EditTableDialog::updateTypes() +{ + updateTypes(sender()); +} + +bool EditTableDialog::eventFilter(QObject *object, QEvent *event) +{ + if(event->type() == QEvent::FocusOut) + { + updateTypes(object); + } + return false; +} + void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column) { int index = ui->treeWidget->indexOfTopLevelItem(item); @@ -533,6 +548,7 @@ void EditTableDialog::addField() } ui->treeWidget->setItemWidget(tbitem, kType, typeBox); + typeBox->installEventFilter(this); connect(typeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypes())); tbitem->setCheckState(kNotNull, Qt::Unchecked); @@ -636,7 +652,8 @@ void EditTableDialog::moveCurrentField(bool down) QComboBox* oldCombo = qobject_cast(ui->treeWidget->itemWidget(ui->treeWidget->topLevelItem(currentRow), kType)); QComboBox* newCombo = new QComboBox(ui->treeWidget); newCombo->setProperty("column", oldCombo->property("column")); - connect(newCombo, SIGNAL(activated(int)), this, SLOT(updateTypes())); + newCombo->installEventFilter(this); + connect(newCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypes())); newCombo->setEditable(true); for(int i=0; i < oldCombo->count(); ++i) newCombo->addItem(oldCombo->itemText(i)); diff --git a/src/EditTableDialog.h b/src/EditTableDialog.h index 41d64fc2de..361e678a07 100644 --- a/src/EditTableDialog.h +++ b/src/EditTableDialog.h @@ -51,6 +51,8 @@ private slots: virtual void reject(); void checkInput(); void itemChanged(QTreeWidgetItem* item, int column); + void updateTypes(QObject *object); + bool eventFilter(QObject *object, QEvent *event); void updateTypes(); void moveUp(); void moveDown();