ecore: fix bugs from composite models

Fix type error while getting boolean property from Efl.Model_Composite_Boolean.

Fix properties_get methods for all composite models.

Now properly call property.changed events when it is needed.

Use EINA_VALUE_TYPE_BOOL instead of EINA_VALUE_TYPE_UCHAR.

Remove some memory leaks.
This commit is contained in:
Vitor Sousa 2018-11-06 10:42:36 -02:00 committed by Cedric BAIL
parent c4af12164f
commit 3f2560a821
7 changed files with 90 additions and 16 deletions

View File

@ -126,6 +126,7 @@ lib/ecore/efl_model_container_private.h \
lib/ecore/efl_model_composite.c \
lib/ecore/efl_model_composite_boolean.c \
lib/ecore/efl_model_composite_selection.c \
lib/ecore/efl_model_composite_private.h \
lib/ecore/efl_model_accessor_view.c \
lib/ecore/efl_model_accessor_view_private.h \
lib/ecore/efl_linear_interpolator.c \

View File

@ -5,6 +5,7 @@
#include <Efl_Core.h>
#include "efl_model_composite_boolean_children.eo.h"
#include "efl_model_composite_private.h"
typedef struct _Efl_Model_Composite_Boolean_Data Efl_Model_Composite_Boolean_Data;
typedef struct _Efl_Model_Composite_Boolean_Children_Data Efl_Model_Composite_Boolean_Children_Data;
@ -71,16 +72,11 @@ static Eina_Iterator *
_efl_model_composite_boolean_children_efl_model_properties_get(const Eo *obj,
Efl_Model_Composite_Boolean_Children_Data *pd)
{
Eina_Iterator *its;
Eina_Iterator *itr;
its = efl_model_properties_get(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS));
itr = eina_hash_iterator_key_new(pd->parent->values);
if (!its) return itr;
if (!itr) return its;
return eina_multi_iterator_new(its, itr);
EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS,
eina_hash_iterator_key_new(pd->parent->values),
"child.index");
return props;
}
static Eina_Value *
@ -109,9 +105,9 @@ _efl_model_composite_boolean_children_efl_model_property_get(const Eo *obj,
if ((pd->index >> 3) >= v->buffer_count)
flag = v->default_value;
else
flag = v->buffer[pd->index >> 3] & (1 << pd->index & 0x7);
flag = v->buffer[pd->index >> 3] & (((unsigned char)1) << (pd->index & 0x7));
return eina_value_uchar_new(!!flag);
return eina_value_bool_new(!!flag);
}
static Eina_Future *
@ -139,7 +135,7 @@ _efl_model_composite_boolean_children_efl_model_property_set(Eo *obj,
return efl_model_property_set(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS),
property, value);
eina_value_setup(&b, EINA_VALUE_TYPE_UCHAR);
eina_value_setup(&b, EINA_VALUE_TYPE_BOOL);
if (!eina_value_convert(value, &b))
return eina_future_rejected(efl_loop_future_scheduler_get(obj),
EFL_MODEL_ERROR_UNKNOWN);
@ -165,12 +161,16 @@ _efl_model_composite_boolean_children_efl_model_property_set(Eo *obj,
// It is assumed that during slice get the buffer is properly sized
if (flag)
v->buffer[pd->index >> 3] |= 1 << (pd->index & 0x7);
v->buffer[pd->index >> 3] |= ((unsigned char)1) << (pd->index & 0x7);
else
v->buffer[pd->index >> 3] &= ~(1 << (pd->index & 0x7));
v->buffer[pd->index >> 3] &= ~(((unsigned char)1) << (pd->index & 0x7));
// Calling "properties,changed" event
efl_model_properties_changed(obj, property);
// Return fulfilled future
return eina_future_resolved(efl_loop_future_scheduler_get(obj),
eina_value_uchar_init(!!flag));
eina_value_bool_init(!!flag));
}
/**************** efl_model_composite_boolean **************/
@ -225,6 +225,8 @@ _boolean_value_free(void *data)
free(value->buffer);
value->buffer = NULL;
value->buffer_count = 0;
free(value);
}
static Eo *

View File

@ -0,0 +1,39 @@
#define EFL_MODEL_COMPOSITE_PROPERTIES(name, dyn, sta, ...) \
EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(name, NULL, NULL, (dyn), sta, ##__VA_ARGS__)
#define EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(name, obj, klass, dyn, sta, ...) \
Eina_Iterator *name; \
do \
{ \
static const char *static_props__[] = { \
sta, \
##__VA_ARGS__ \
}; \
name = _efl_model_composite_properties_mix( \
((obj) ? efl_model_properties_get(efl_super((obj), (klass))) : NULL), \
(dyn), \
EINA_C_ARRAY_ITERATOR_NEW(static_props__)); \
} \
while (0)
static inline Eina_Iterator *
_efl_model_composite_properties_mix(Eina_Iterator *super, Eina_Iterator *dyn, Eina_Iterator *sta)
{
Eina_Iterator *its[3];
int i = 0;
if (sta) its[i++] = sta;
if (dyn) its[i++] = dyn;
if (super) its[i++] = super;
switch (i)
{
case 1: return its[0];
case 2: return eina_multi_iterator_new(its[0], its[1]);
case 3: return eina_multi_iterator_new(its[0], its[1], its[2]);
default: return NULL;
};
}

View File

@ -9,6 +9,7 @@
#include "efl_model_composite_selection.eo.h"
#include "efl_model_accessor_view_private.h"
#include "efl_model_composite_private.h"
typedef struct _Efl_Model_Composite_Selection_Data Efl_Model_Composite_Selection_Data;
typedef struct _Efl_Model_Composite_Selection_Children_Data Efl_Model_Composite_Selection_Children_Data;
@ -186,6 +187,17 @@ _unselect_slice_then(void *data EINA_UNUSED,
return v;
}
static Eina_Iterator *
_efl_model_composite_selection_efl_model_properties_get(const Eo *obj,
Efl_Model_Composite_Selection_Data *pd EINA_UNUSED)
{
EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS,
NULL,
"selected", "exclusive");
return props;
}
static Eina_Future *
_efl_model_composite_selection_efl_model_property_set(Eo *obj,
Efl_Model_Composite_Selection_Data *pd,
@ -196,13 +208,18 @@ _efl_model_composite_selection_efl_model_property_set(Eo *obj,
if (!strcmp("exclusive", property))
{
Eina_Bool exclusive = pd->exclusive;
Eina_Bool changed;
vf = eina_value_bool_init(exclusive);
eina_value_convert(value, &vf);
eina_value_bool_get(&vf, &exclusive);
changed = (!pd->exclusive != !exclusive);
pd->exclusive = !!exclusive;
if (changed)
efl_model_properties_changed(obj, "exclusive");
return eina_future_resolved(efl_loop_future_scheduler_get(obj), vf);
}
@ -291,6 +308,17 @@ _untangle_array(void *data,
return va;
}
static Eina_Iterator *
_efl_model_composite_selection_children_efl_model_properties_get(const Eo *obj,
Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED)
{
EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
obj, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS,
NULL,
"selected");
return props;
}
static Eina_Future *
_efl_model_composite_selection_children_efl_model_property_set(Eo *obj,
Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED,

View File

@ -5,6 +5,7 @@ class Efl.Model_Composite_Selection (Efl.Model_Composite_Boolean)
Efl.Object.constructor;
Efl.Model.children_slice_get;
Efl.Model.property { get; set; }
Efl.Model.properties { get; }
}
events {
/* FIXME: The object is emitted in the event_info. This is redundant. */

View File

@ -3,5 +3,7 @@ class Efl.Model_Composite_Selection_Children (Efl.Model_Composite_Boolean_Childr
[[Efl model composite selection children class]]
implements {
Efl.Model.property { set; }
Efl.Model.properties { get; }
}
/* FIXME: emitting Efl.Model_Composite_Selection.Selected. Use a default selection event! */
}

View File

@ -153,6 +153,7 @@ ecore_src = [
'efl_model_composite.c',
'efl_model_composite_boolean.c',
'efl_model_composite_selection.c',
'efl_model_composite_private.h',
'efl_model_accessor_view.c',
'efl_model_accessor_view_private.h',
'efl_linear_interpolator.c',