Re: Fixing the GtkTreeModel::row-deleted inconsistency



On Tuesday 15 May 2007 10:37, Kristian Rietveld wrote:
> It depends what you mean with "remove the row from the model".  If that
> means unlinking the row from the model's data structures, then there's
> not a nice way anymore to retrieve an iterator to access that row.  And
> if _get_iter() is still supposed to be working, all other model methods
> should also work: you are much better off not removing the row in that
> case :)

Yes, I meant unlink it from the model. Think about something like this:

gboolean
gtk_list_store_remove (GtkListStore *list_store,
		       GtkTreeIter  *iter)
{
  GtkTreePath *path;
  GtkSequencePtr ptr, next;

  g_return_val_if_fail (GTK_IS_LIST_STORE (list_store), FALSE);
  g_return_val_if_fail (VALID_ITER (iter, list_store), FALSE);

  path = gtk_list_store_get_path (GTK_TREE_MODEL (list_store), iter);

  ptr = iter->user_data;
  next = _gtk_sequence_ptr_next (ptr);
  
- _gtk_tree_data_list_free (_gtk_sequence_ptr_get_data (ptr), 
list_store->column_headers);
+ list_store->removed_data = (GtkTreeDataList *) _gtk_sequence_ptr_get_data 
(ptr);
  _gtk_sequence_remove (iter->user_data);

  list_store->length--;
  
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (list_store), path);
+ _gtk_tree_data_list_free (list_store->removed_data, 
list_store->column_headers);
+ list_store->removed_data = NULL;
  gtk_tree_path_free (path);

  if (_gtk_sequence_ptr_is_end (next))
    {
      iter->stamp = 0;
      return FALSE;
    }
  else
    {
      iter->stamp = list_store->stamp;
      iter->user_data = next;
      return TRUE;
    }
}

/* This new API method gets values from the very last deleted row: no needs 
for an iter arg */
void
gtk_list_store_get_removed_value (GtkListStore *list_store,
				  gint          column,
				  GValue       *value)
{
  GtkTreeDataList *list;

  g_return_if_fail (GTK_IS_LIST_STORE (list_store));
  g_return_if_fail (column < list_store->n_columns);
  g_return_if_fail (list_store->removed_data != NULL);
		    
  list = list_store->removed_data;

  while (tmp_column-- > 0 && list)
    list = list->next;

  if (list == NULL)
    g_value_init (value, list_store->column_headers[column]);
  else
    _gtk_tree_data_list_node_to_value (list,
				       list_store->column_headers[column],
				       value);
}

Of course, this solution needs a private field in the _GtkTreeStore struct and 
a new API function, but it does not break anything and provides what needed.

Anyway, I think moving gtk_tree_model_row_deleted() at the top is a better 
solution, but if you want backward compatibility, well, what can you do?

> I think row-deleted does specifiy you the subject, one of its arguments
> is the path ...

Yes, but if I need some data from the model I must duplicate it.

I don't want to bother, I only want to highlight that the row-deleted signal 
(from an application developer's point of view) is, at this moment, quite 
useless. But maybe I'm short in fantasy ...

-- Nicola



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]