From 86fb88cdeed6e33582266bca151a968322fa7233 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Thu, 28 Jun 2018 04:46:38 -0400 Subject: [PATCH] [Companion][AutoComboBox] Add updateValue() function in line with other Auto* widgets; Add currentDataChanged() signal. --- companion/src/shared/autocombobox.h | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/companion/src/shared/autocombobox.h b/companion/src/shared/autocombobox.h index 9851e8df6..edb1de514 100644 --- a/companion/src/shared/autocombobox.h +++ b/companion/src/shared/autocombobox.h @@ -63,50 +63,53 @@ class AutoComboBox: public QComboBox { lock = true; QComboBox::addItem(item, value); - if (field && *field==value) { - setCurrentIndex(count()-1); - } lock = false; + updateValue(); } void setField(unsigned int & field, GenericPanel * panel=NULL) { this->field = (int *)&field; this->panel = panel; - for (int i=0; ifield = &field; this->panel = panel; - for (int i=0; ifield && *this->field == i) - setCurrentIndex(i); - } + updateValue(); } + void updateValue() + { + if (!field) + return; + lock = true; + setCurrentIndex(findData(*field)); + lock = false; + } + + signals: + void currentDataChanged(int value); + protected slots: void onCurrentIndexChanged(int index) { + const int val = itemData(index).toInt(); if (field && !lock) { - *field = itemData(index).toInt(); - if (panel) { + *field = val; + if (panel) emit panel->modified(); - } } + emit currentDataChanged(val); } protected: