[libgda] Simplified implementation of GdaDataProxy's iterator
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Simplified implementation of GdaDataProxy's iterator
- Date: Sun, 15 Apr 2012 19:50:19 +0000 (UTC)
commit 3d786cd861ec74a24b1db877431405633a081e28
Author: Vivien Malerba <malerba gnome-db org>
Date: Sun Apr 15 21:36:07 2012 +0200
Simplified implementation of GdaDataProxy's iterator
libgda/gda-data-model-iter.c | 53 +++++++++++++++-------------
libgda/gda-data-proxy.c | 39 +--------------------
tests/multi-threading/check_threaded_cnc.c | 18 ++-------
3 files changed, 33 insertions(+), 77 deletions(-)
---
diff --git a/libgda/gda-data-model-iter.c b/libgda/gda-data-model-iter.c
index ca3036f..0a48e5b 100644
--- a/libgda/gda-data-model-iter.c
+++ b/libgda/gda-data-model-iter.c
@@ -329,6 +329,9 @@ model_reset_cb (GdaDataModel *model, GdaDataModelIter *iter)
gint i, nbcols;
GSList *list;
nbcols = gda_data_model_get_n_columns (model);
+ if (GDA_IS_DATA_PROXY (model))
+ nbcols = nbcols / 2;
+
for (i = 0, list = ((GdaSet*) iter)->holders;
(i < nbcols) && list;
i++, list = list->next) {
@@ -520,45 +523,42 @@ gda_data_model_iter_set_property (GObject *object,
if (iter->priv) {
switch (param_id) {
case PROP_DATA_MODEL: {
- GdaDataModel *model;
gint col, ncols;
+ GdaDataModel *model;
GObject* ptr = g_value_get_object (value);
g_return_if_fail (ptr && GDA_IS_DATA_MODEL (ptr));
model = GDA_DATA_MODEL (ptr);
-
- /* REM: model is actually set in the next property's code
- * (there is no break statement) */
- /*
- ncols = gda_data_model_get_n_columns (model);
- for (col = 0; col < ncols; col++)
- define_holder_for_data_model_column (model, col, iter);
- */
- }
- case PROP_FORCED_MODEL: {
- GdaDataModel* ptr = g_value_get_object (value);
- g_return_if_fail (GDA_IS_DATA_MODEL (ptr));
-
if (iter->priv->data_model) {
- if (iter->priv->data_model == GDA_DATA_MODEL (ptr))
+ if (iter->priv->data_model == model)
return;
- g_signal_handler_disconnect (iter->priv->data_model, iter->priv->model_changes_signals [0]);
- g_signal_handler_disconnect (iter->priv->data_model, iter->priv->model_changes_signals [1]);
- g_signal_handler_disconnect (iter->priv->data_model, iter->priv->model_changes_signals [2]);
+ g_signal_handler_disconnect (iter->priv->data_model,
+ iter->priv->model_changes_signals [0]);
+ g_signal_handler_disconnect (iter->priv->data_model,
+ iter->priv->model_changes_signals [1]);
+ g_signal_handler_disconnect (iter->priv->data_model,
+ iter->priv->model_changes_signals [2]);
g_object_remove_weak_pointer (G_OBJECT (iter->priv->data_model),
(gpointer*) &(iter->priv->data_model));
}
- iter->priv->data_model = GDA_DATA_MODEL (ptr);
+ iter->priv->data_model = model;
g_object_add_weak_pointer (G_OBJECT (iter->priv->data_model),
(gpointer*) &(iter->priv->data_model));
- iter->priv->model_changes_signals [0] = g_signal_connect (G_OBJECT (ptr), "row-updated",
- G_CALLBACK (model_row_updated_cb), iter);
- iter->priv->model_changes_signals [1] = g_signal_connect (G_OBJECT (ptr), "row-removed",
- G_CALLBACK (model_row_removed_cb), iter);
- iter->priv->model_changes_signals [2] = g_signal_connect (G_OBJECT (ptr), "reset",
+
+ iter->priv->model_changes_signals [0] = g_signal_connect (G_OBJECT (model), "row-updated",
+ G_CALLBACK (model_row_updated_cb),
+ iter);
+ iter->priv->model_changes_signals [1] = g_signal_connect (G_OBJECT (model), "row-removed",
+ G_CALLBACK (model_row_removed_cb),
+ iter);
+ iter->priv->model_changes_signals [2] = g_signal_connect (G_OBJECT (model), "reset",
G_CALLBACK (model_reset_cb), iter);
- model_reset_cb (iter->priv->data_model, iter);
+ model_reset_cb (GDA_DATA_MODEL (ptr), iter);
+ break;
+ }
+ case PROP_FORCED_MODEL: {
+ g_warning ("Deprecated property, not to be used");
break;
}
case PROP_CURRENT_ROW:
@@ -590,7 +590,10 @@ gda_data_model_iter_get_property (GObject *object,
if (iter->priv) {
switch (param_id) {
case PROP_DATA_MODEL:
+ g_value_set_object (value, G_OBJECT (iter->priv->data_model));
+ break;
case PROP_FORCED_MODEL:
+ g_warning ("Deprecated property, not to be used");
g_value_set_object (value, G_OBJECT (iter->priv->data_model));
break;
case PROP_CURRENT_ROW:
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index 1ba946a..27514d6 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -71,7 +71,6 @@ static gint gda_data_proxy_get_n_columns (GdaDataModel *model)
static GdaColumn *gda_data_proxy_describe_column (GdaDataModel *model, gint col);
static const GValue *gda_data_proxy_get_value_at (GdaDataModel *model, gint col, gint row, GError **error);
static GdaValueAttribute gda_data_proxy_get_attributes_at (GdaDataModel *model, gint col, gint row);
-static GdaDataModelIter *gda_data_proxy_create_iter (GdaDataModel *model);
static GdaDataModelAccessFlags gda_data_proxy_get_access_flags(GdaDataModel *model);
@@ -704,7 +703,7 @@ gda_data_proxy_data_model_init (GdaDataModelIface *iface)
iface->i_get_value_at = gda_data_proxy_get_value_at;
iface->i_get_attributes_at = gda_data_proxy_get_attributes_at;
- iface->i_create_iter = gda_data_proxy_create_iter;
+ iface->i_create_iter = NULL;
iface->i_iter_at_row = NULL;
iface->i_iter_next = NULL;
iface->i_iter_prev = NULL;
@@ -3692,42 +3691,6 @@ gda_data_proxy_find_row_from_values (GdaDataModel *model, GSList *values, gint *
return found ? proxy_row : -1;
}
-
-static GdaDataModelIter *
-gda_data_proxy_create_iter (GdaDataModel *model)
-{
- GdaDataProxy *proxy;
- GdaDataModelIter *iter, *iter2;
-
- g_return_val_if_fail (GDA_IS_DATA_PROXY (model), FALSE);
- proxy = GDA_DATA_PROXY (model);
- g_return_val_if_fail (proxy->priv, FALSE);
-
- gda_mutex_lock (proxy->priv->mutex);
-
- iter = gda_data_model_create_iter (proxy->priv->model);
- g_object_set (G_OBJECT (iter), "forced-model", proxy, NULL);
-
- iter2 = gda_data_model_create_iter (proxy->priv->model);
- if (iter2) {
- GSList *plist1, *plist2;
-
- plist1 = GDA_SET (iter)->holders;
- plist2 = GDA_SET (iter2)->holders;
- for (; plist1 && plist2; plist1 = plist1->next, plist2 = plist2->next)
- gda_attributes_manager_copy (gda_holder_attributes_manager, (gpointer) plist2->data,
- gda_holder_attributes_manager, (gpointer) plist1->data);
- if (plist1 || plist2)
- g_warning ("Proxy iterator does not have the same length as proxied model's iterator: %d/%d",
- g_slist_length (GDA_SET (iter)->holders),
- g_slist_length (GDA_SET (iter2)->holders));
- g_object_unref (iter2);
- }
- gda_mutex_unlock (proxy->priv->mutex);
-
- return iter;
-}
-
static GdaDataModelAccessFlags
gda_data_proxy_get_access_flags (GdaDataModel *model)
{
diff --git a/tests/multi-threading/check_threaded_cnc.c b/tests/multi-threading/check_threaded_cnc.c
index 0aaefc2..21af52f 100644
--- a/tests/multi-threading/check_threaded_cnc.c
+++ b/tests/multi-threading/check_threaded_cnc.c
@@ -174,18 +174,13 @@ test_select (GdaConnection *cnc, GdaConnection *tcnc)
failures ++;
}
else {
- GdaDataModel *m1, *m2;
- g_object_get (G_OBJECT (titer), "data-model", &m1, "forced-model", &m2, NULL);
+ GdaDataModel *m1;
+ g_object_get (G_OBJECT (titer), "data-model", &m1, NULL);
if (m1 != tmodel) {
g_print ("ERROR: \"data-model\" property of created iterator is wrong\n");
failures ++;
}
- if (m2 != tmodel) {
- g_print ("ERROR: \"forced-model\" property of created iterator is wrong\n");
- failures ++;
- }
g_object_unref (m1);
- g_object_unref (m2);
/* check iter's contents */
guint ncols;
@@ -340,18 +335,13 @@ test_select_cursor (GdaConnection *cnc, GdaConnection *tcnc)
}
else {
/* iter's properties */
- GdaDataModel *m1, *m2;
- g_object_get (G_OBJECT (titer), "data-model", &m1, "forced-model", &m2, NULL);
+ GdaDataModel *m1;
+ g_object_get (G_OBJECT (titer), "data-model", &m1, NULL);
if (m1 != tmodel) {
g_print ("ERROR: \"data-model\" property of created iterator is wrong\n");
failures ++;
}
- if (m2 != tmodel) {
- g_print ("ERROR: \"forced-model\" property of created iterator is wrong\n");
- failures ++;
- }
g_object_unref (m1);
- g_object_unref (m2);
/* check iter's contents */
guint ncols;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]