From 766d1bb5b15eb6fbda0c790449df53a84be0b12b Mon Sep 17 00:00:00 2001 From: Norihiro Kamae Date: Sat, 23 Jul 2022 11:08:03 +0900 Subject: [PATCH] UI: Search combo item with QVariant type A combobox with `OBS_COMBO_FORMAT_FLOAT` type couldn't be initialized to select current item from the settings data. This commit will create QVariant value with the similar code as that of adding the items and search the current item using that value. --- UI/properties-view.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/UI/properties-view.cpp b/UI/properties-view.cpp index b048d75e9..d47270c56 100644 --- a/UI/properties-view.cpp +++ b/UI/properties-view.cpp @@ -541,30 +541,30 @@ static void AddComboItem(QComboBox *combo, obs_property_t *prop, template -static string from_obs_data(obs_data_t *data, const char *name, - obs_combo_format format) +static QVariant from_obs_data(obs_data_t *data, const char *name, + obs_combo_format format) { switch (format) { case OBS_COMBO_FORMAT_INT: - return to_string(get_int(data, name)); + return QVariant::fromValue(get_int(data, name)); case OBS_COMBO_FORMAT_FLOAT: - return to_string(get_double(data, name)); + return QVariant::fromValue(get_double(data, name)); case OBS_COMBO_FORMAT_STRING: - return get_string(data, name); + return QByteArray(get_string(data, name)); default: - return ""; + return QVariant(); } } -static string from_obs_data(obs_data_t *data, const char *name, - obs_combo_format format) +static QVariant from_obs_data(obs_data_t *data, const char *name, + obs_combo_format format) { return from_obs_data(data, name, format); } -static string from_obs_data_autoselect(obs_data_t *data, const char *name, - obs_combo_format format) +static QVariant from_obs_data_autoselect(obs_data_t *data, const char *name, + obs_combo_format format) { return from_obs_datasetMaxVisibleItems(40); combo->setToolTip(QT_UTF8(obs_property_long_description(prop))); - string value = from_obs_data(settings, name, format); + QVariant value = from_obs_data(settings, name, format); if (format == OBS_COMBO_FORMAT_STRING && type == OBS_COMBO_TYPE_EDITABLE) { - combo->lineEdit()->setText(QT_UTF8(value.c_str())); + combo->lineEdit()->setText(value.toString()); } else { - idx = combo->findData(QByteArray(value.c_str())); + idx = combo->findData(value); } if (type == OBS_COMBO_TYPE_EDITABLE) @@ -607,9 +607,9 @@ QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning) combo->setCurrentIndex(idx); if (obs_data_has_autoselect_value(settings, name)) { - string autoselect = + QVariant autoselect = from_obs_data_autoselect(settings, name, format); - int id = combo->findData(QT_UTF8(autoselect.c_str())); + int id = combo->findData(autoselect); if (id != -1 && id != idx) { QString actual = combo->itemText(id);