Skip to content

Commit

Permalink
Fix current item on float-type combobox property
Browse files Browse the repository at this point in the history
Bring the modification in obsproject/obs-studio#6788
  • Loading branch information
norihiro committed Jul 25, 2022
1 parent b070cf9 commit 1e1b4b2
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src-obsstudio/properties-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,30 +429,30 @@ static void AddComboItem(QComboBox *combo, obs_property_t *prop,
template<long long get_int(obs_data_t *, const char *),
double get_double(obs_data_t *, const char *),
const char *get_string(obs_data_t *, const char *)>
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<long long>(get_int(data, name));
case OBS_COMBO_FORMAT_FLOAT:
return to_string(get_double(data, name));
return QVariant::fromValue<double>(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<obs_data_get_int, obs_data_get_double,
obs_data_get_string>(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_data<obs_data_get_autoselect_int,
obs_data_get_autoselect_double,
Expand All @@ -478,13 +478,13 @@ QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
combo->setMaxVisibleItems(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)
Expand All @@ -495,9 +495,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);
Expand Down

0 comments on commit 1e1b4b2

Please sign in to comment.