Merge pull request #116 from palana/obs-data-changes
obs-data default value semantics change and autoselect value introductionmaster
commit
bd4223a20c
|
@ -66,6 +66,9 @@ Basic.Main.DefaultSceneName.Text="Scene %1"
|
|||
Basic.SourceSelect.CreateNew="Create new"
|
||||
Basic.SourceSelect.AddExisting="Add Existing"
|
||||
|
||||
# properties window
|
||||
Basic.PropertiesWindow.AutoSelectFormat="%1 (unsupported; autoselect: %2)"
|
||||
|
||||
# transform window
|
||||
Basic.TransformWindow="Scene Item Transform"
|
||||
Basic.TransformWindow.Position="Position"
|
||||
|
|
1124
libobs/obs-data.c
1124
libobs/obs-data.c
File diff suppressed because it is too large
Load Diff
|
@ -84,9 +84,6 @@ EXPORT void obs_data_setarray(obs_data_t data, const char *name,
|
|||
|
||||
/*
|
||||
* Default value functions.
|
||||
*
|
||||
* These functions check to ensure the value exists, and is of a specific type.
|
||||
* If not, it sets the default value instead.
|
||||
*/
|
||||
EXPORT void obs_data_set_default_string(obs_data_t data, const char *name,
|
||||
const char *val);
|
||||
|
@ -99,9 +96,24 @@ EXPORT void obs_data_set_default_bool(obs_data_t data, const char *name,
|
|||
EXPORT void obs_data_set_default_obj(obs_data_t data, const char *name,
|
||||
obs_data_t obj);
|
||||
|
||||
/*
|
||||
* Application overrides
|
||||
* Use these to communicate the actual values of settings in case the user
|
||||
* settings aren't appropriate
|
||||
*/
|
||||
EXPORT void obs_data_set_autoselect_string(obs_data_t data, const char *name,
|
||||
const char *val);
|
||||
EXPORT void obs_data_set_autoselect_int(obs_data_t data, const char *name,
|
||||
long long val);
|
||||
EXPORT void obs_data_set_autoselect_double(obs_data_t data, const char *name,
|
||||
double val);
|
||||
EXPORT void obs_data_set_autoselect_bool(obs_data_t data, const char *name,
|
||||
bool val);
|
||||
EXPORT void obs_data_set_autoselect_obj(obs_data_t data, const char *name,
|
||||
obs_data_t obj);
|
||||
|
||||
/*
|
||||
* Get functions
|
||||
* NOTE: use a macro if you use 'defaults' in more than one place
|
||||
*/
|
||||
EXPORT const char *obs_data_getstring(obs_data_t data, const char *name);
|
||||
EXPORT long long obs_data_getint(obs_data_t data, const char *name);
|
||||
|
@ -110,6 +122,25 @@ EXPORT bool obs_data_getbool(obs_data_t data, const char *name);
|
|||
EXPORT obs_data_t obs_data_getobj(obs_data_t data, const char *name);
|
||||
EXPORT obs_data_array_t obs_data_getarray(obs_data_t data, const char *name);
|
||||
|
||||
EXPORT const char *obs_data_get_default_string(obs_data_t data,
|
||||
const char *name);
|
||||
EXPORT long long obs_data_get_default_int(obs_data_t data, const char *name);
|
||||
EXPORT double obs_data_get_default_double(obs_data_t data, const char *name);
|
||||
EXPORT bool obs_data_get_default_bool(obs_data_t data, const char *name);
|
||||
EXPORT obs_data_t obs_data_get_default_obj(obs_data_t data, const char *name);
|
||||
EXPORT obs_data_array_t obs_data_get_default_array(obs_data_t data,
|
||||
const char *name);
|
||||
|
||||
EXPORT const char *obs_data_get_autoselect_string(obs_data_t data,
|
||||
const char *name);
|
||||
EXPORT long long obs_data_get_autoselect_int(obs_data_t data, const char *name);
|
||||
EXPORT double obs_data_get_autoselect_double(obs_data_t data, const char *name);
|
||||
EXPORT bool obs_data_get_autoselect_bool(obs_data_t data, const char *name);
|
||||
EXPORT obs_data_t obs_data_get_autoselect_obj(obs_data_t data,
|
||||
const char *name);
|
||||
EXPORT obs_data_array_t obs_data_get_autoselect_array(obs_data_t data,
|
||||
const char *name);
|
||||
|
||||
/* Array functions */
|
||||
EXPORT obs_data_array_t obs_data_array_create();
|
||||
EXPORT void obs_data_array_addref(obs_data_array_t array);
|
||||
|
@ -122,6 +153,28 @@ EXPORT void obs_data_array_insert(obs_data_array_t array, size_t idx,
|
|||
obs_data_t obj);
|
||||
EXPORT void obs_data_array_erase(obs_data_array_t array, size_t idx);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Item status inspection */
|
||||
|
||||
EXPORT bool obs_data_has_user_value(obs_data_t data, const char *name);
|
||||
EXPORT bool obs_data_has_default(obs_data_t data, const char *name);
|
||||
EXPORT bool obs_data_has_autoselect(obs_data_t data, const char *name);
|
||||
|
||||
EXPORT bool obs_data_item_has_user_value(obs_data_item_t data);
|
||||
EXPORT bool obs_data_item_has_default(obs_data_item_t data);
|
||||
EXPORT bool obs_data_item_has_autoselect(obs_data_item_t data);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Clearing data values */
|
||||
|
||||
EXPORT void obs_data_unset_user_value(obs_data_t data, const char *name);
|
||||
EXPORT void obs_data_unset_default_value(obs_data_t data, const char *name);
|
||||
EXPORT void obs_data_unset_autoselect_value(obs_data_t data, const char *name);
|
||||
|
||||
EXPORT void obs_data_item_unset_user_value(obs_data_item_t data);
|
||||
EXPORT void obs_data_item_unset_default_value(obs_data_item_t data);
|
||||
EXPORT void obs_data_item_unset_autoselect_value(obs_data_item_t data);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Item iteration */
|
||||
|
||||
|
@ -143,6 +196,28 @@ EXPORT void obs_data_item_setbool(obs_data_item_t *item, bool val);
|
|||
EXPORT void obs_data_item_setobj(obs_data_item_t *item, obs_data_t val);
|
||||
EXPORT void obs_data_item_setarray(obs_data_item_t *item, obs_data_array_t val);
|
||||
|
||||
EXPORT void obs_data_item_set_default_string(obs_data_item_t *item,
|
||||
const char *val);
|
||||
EXPORT void obs_data_item_set_default_int(obs_data_item_t *item, long long val);
|
||||
EXPORT void obs_data_item_set_default_double(obs_data_item_t *item, double val);
|
||||
EXPORT void obs_data_item_set_default_bool(obs_data_item_t *item, bool val);
|
||||
EXPORT void obs_data_item_set_default_obj(obs_data_item_t *item,
|
||||
obs_data_t val);
|
||||
EXPORT void obs_data_item_set_default_array(obs_data_item_t *item,
|
||||
obs_data_array_t val);
|
||||
|
||||
EXPORT void obs_data_item_set_autoselect_string(obs_data_item_t *item,
|
||||
const char *val);
|
||||
EXPORT void obs_data_item_set_autoselect_int(obs_data_item_t *item,
|
||||
long long val);
|
||||
EXPORT void obs_data_item_set_autoselect_double(obs_data_item_t *item,
|
||||
double val);
|
||||
EXPORT void obs_data_item_set_autoselect_bool(obs_data_item_t *item, bool val);
|
||||
EXPORT void obs_data_item_set_autoselect_obj(obs_data_item_t *item,
|
||||
obs_data_t val);
|
||||
EXPORT void obs_data_item_set_autoselect_array(obs_data_item_t *item,
|
||||
obs_data_array_t val);
|
||||
|
||||
/* Item get functions */
|
||||
EXPORT const char *obs_data_item_getstring(obs_data_item_t item);
|
||||
EXPORT long long obs_data_item_getint(obs_data_item_t item);
|
||||
|
@ -151,6 +226,21 @@ EXPORT bool obs_data_item_getbool(obs_data_item_t item);
|
|||
EXPORT obs_data_t obs_data_item_getobj(obs_data_item_t item);
|
||||
EXPORT obs_data_array_t obs_data_item_getarray(obs_data_item_t item);
|
||||
|
||||
EXPORT const char *obs_data_item_get_default_string(obs_data_item_t item);
|
||||
EXPORT long long obs_data_item_get_default_int(obs_data_item_t item);
|
||||
EXPORT double obs_data_item_get_default_double(obs_data_item_t item);
|
||||
EXPORT bool obs_data_item_get_default_bool(obs_data_item_t item);
|
||||
EXPORT obs_data_t obs_data_item_get_default_obj(obs_data_item_t item);
|
||||
EXPORT obs_data_array_t obs_data_item_get_default_array(obs_data_item_t item);
|
||||
|
||||
EXPORT const char *obs_data_item_get_autoselect_string(obs_data_item_t item);
|
||||
EXPORT long long obs_data_item_get_autoselect_int(obs_data_item_t item);
|
||||
EXPORT double obs_data_item_get_autoselect_double(obs_data_item_t item);
|
||||
EXPORT bool obs_data_item_get_autoselect_bool(obs_data_item_t item);
|
||||
EXPORT obs_data_t obs_data_item_get_autoselect_obj(obs_data_item_t item);
|
||||
EXPORT obs_data_array_t obs_data_item_get_autoselect_array(
|
||||
obs_data_item_t item);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Helper functions for certain structures */
|
||||
EXPORT void obs_data_set_vec2(obs_data_t data, const char *name,
|
||||
|
@ -171,6 +261,15 @@ EXPORT void obs_data_set_default_vec4(obs_data_t data, const char *name,
|
|||
EXPORT void obs_data_set_default_quat(obs_data_t data, const char *name,
|
||||
const struct quat *val);
|
||||
|
||||
EXPORT void obs_data_set_autoselect_vec2(obs_data_t data, const char *name,
|
||||
const struct vec2 *val);
|
||||
EXPORT void obs_data_set_autoselect_vec3(obs_data_t data, const char *name,
|
||||
const struct vec3 *val);
|
||||
EXPORT void obs_data_set_autoselect_vec4(obs_data_t data, const char *name,
|
||||
const struct vec4 *val);
|
||||
EXPORT void obs_data_set_autoselect_quat(obs_data_t data, const char *name,
|
||||
const struct quat *val);
|
||||
|
||||
EXPORT void obs_data_get_vec2(obs_data_t data, const char *name,
|
||||
struct vec2 *val);
|
||||
EXPORT void obs_data_get_vec3(obs_data_t data, const char *name,
|
||||
|
@ -180,6 +279,24 @@ EXPORT void obs_data_get_vec4(obs_data_t data, const char *name,
|
|||
EXPORT void obs_data_get_quat(obs_data_t data, const char *name,
|
||||
struct quat *val);
|
||||
|
||||
EXPORT void obs_data_get_default_vec2(obs_data_t data, const char *name,
|
||||
struct vec2 *val);
|
||||
EXPORT void obs_data_get_default_vec3(obs_data_t data, const char *name,
|
||||
struct vec3 *val);
|
||||
EXPORT void obs_data_get_default_vec4(obs_data_t data, const char *name,
|
||||
struct vec4 *val);
|
||||
EXPORT void obs_data_get_default_quat(obs_data_t data, const char *name,
|
||||
struct quat *val);
|
||||
|
||||
EXPORT void obs_data_get_autoselect_vec2(obs_data_t data, const char *name,
|
||||
struct vec2 *val);
|
||||
EXPORT void obs_data_get_autoselect_vec3(obs_data_t data, const char *name,
|
||||
struct vec3 *val);
|
||||
EXPORT void obs_data_get_autoselect_vec4(obs_data_t data, const char *name,
|
||||
struct vec4 *val);
|
||||
EXPORT void obs_data_get_autoselect_quat(obs_data_t data, const char *name,
|
||||
struct quat *val);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* OBS-specific functions */
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QStandardItem>
|
||||
#include "qt-wrappers.hpp"
|
||||
#include "properties-view.hpp"
|
||||
#include "obs-app.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
@ -172,6 +173,39 @@ static void AddComboItem(QComboBox *combo, obs_property_t prop,
|
|||
item->setFlags(Qt::NoItemFlags);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
switch (format) {
|
||||
case OBS_COMBO_FORMAT_INT:
|
||||
return to_string(get_int(data, name));
|
||||
case OBS_COMBO_FORMAT_FLOAT:
|
||||
return to_string(get_double(data, name));
|
||||
case OBS_COMBO_FORMAT_STRING:
|
||||
return get_string(data, name);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static string from_obs_data(obs_data_t data, const char *name,
|
||||
obs_combo_format format)
|
||||
{
|
||||
return from_obs_data<obs_data_getint, obs_data_getdouble,
|
||||
obs_data_getstring>(data, name, format);
|
||||
}
|
||||
|
||||
static string 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,
|
||||
obs_data_get_autoselect_string>(data, name, format);
|
||||
}
|
||||
|
||||
QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning)
|
||||
{
|
||||
const char *name = obs_property_name(prop);
|
||||
|
@ -187,24 +221,13 @@ QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning)
|
|||
if (type == OBS_COMBO_TYPE_EDITABLE)
|
||||
combo->setEditable(true);
|
||||
|
||||
if (format == OBS_COMBO_FORMAT_INT) {
|
||||
int val = (int)obs_data_getint(settings, name);
|
||||
string valString = to_string(val);
|
||||
idx = combo->findData(QT_UTF8(valString.c_str()));
|
||||
string value = from_obs_data(settings, name, format);
|
||||
|
||||
} else if (format == OBS_COMBO_FORMAT_FLOAT) {
|
||||
double val = obs_data_getdouble(settings, name);
|
||||
string valString = to_string(val);
|
||||
idx = combo->findData(QT_UTF8(valString.c_str()));
|
||||
|
||||
} else if (format == OBS_COMBO_FORMAT_STRING) {
|
||||
const char *val = obs_data_getstring(settings, name);
|
||||
|
||||
if (type == OBS_COMBO_TYPE_EDITABLE)
|
||||
combo->lineEdit()->setText(val);
|
||||
if (format == OBS_COMBO_FORMAT_STRING &&
|
||||
type == OBS_COMBO_TYPE_EDITABLE)
|
||||
combo->lineEdit()->setText(QT_UTF8(value.c_str()));
|
||||
else
|
||||
idx = combo->findData(QT_UTF8(val));
|
||||
}
|
||||
idx = combo->findData(QT_UTF8(value.c_str()));
|
||||
|
||||
if (type == OBS_COMBO_TYPE_EDITABLE)
|
||||
return NewWidget(prop, combo,
|
||||
|
@ -213,6 +236,22 @@ QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning)
|
|||
if (idx != -1)
|
||||
combo->setCurrentIndex(idx);
|
||||
|
||||
if (obs_data_has_autoselect(settings, name)) {
|
||||
string autoselect =
|
||||
from_obs_data_autoselect(settings, name, format);
|
||||
int id = combo->findData(QT_UTF8(autoselect.c_str()));
|
||||
|
||||
if (id != -1 && id != idx) {
|
||||
QString actual = combo->itemText(id);
|
||||
QString selected = combo->itemText(idx);
|
||||
QString combined = QTStr(
|
||||
"Basic.PropertiesWindow.AutoSelectFormat");
|
||||
combo->setItemText(idx,
|
||||
combined.arg(selected).arg(actual));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QAbstractItemModel *model = combo->model();
|
||||
warning = idx != -1 &&
|
||||
model->flags(model->index(idx, 0)) == Qt::NoItemFlags;
|
||||
|
|
Loading…
Reference in New Issue