Re: DND in TreeView



On Wed, 2009-03-25 at 13:02 +0800, Deng Xiyue wrote: 
> So, with the given test program, what I'm experiencing is:
> 
> 1. If I drag the last row in a TreeView to other place within the same
> TreeView, no delete signal is emitted, only insert signal got signaled.
> 
> 2. If I drag any row (that is not the last row) to the last position,
> the insert signal always returns the path that evaluates to be row 0,
> which is the first row. That way, I cannot distinguish whether the row
> is dragged to the first row or the last row.  Note that there are some
> assertion message when dragging to to last position.

Okay.  I think that what you're experiencing is a side effect of when
rows are inserted and deleted in the tree model (this can be very
tricky).  I think that you should use the path in the signal handlers
instead of attempting to get an iterator to get the rows that have been
inserted/deleted.  The patch I've attached exemplifies how to do that.
You'll probably have to make adjustment to the row numbers based on
whether an insertion or a deletion has taken place (I'm not sure).

If you have to get an iterator, you should make sure you're working with
the right row because as the Gtk::Path[1] docs say, it is not guaranteed
that a path will always yield a vaild TreeModel::iterator.  HTH.

[1]
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreePath.html 

-- 
José Alburquerque
--- treemodel_bug_test.cc	2009-03-25 14:13:44.000000000 -0400
+++ treemodel_bug_test-orig.cc	2009-03-24 23:43:00.000000000 -0400
@@ -103,9 +103,6 @@
 
 void ExampleWindow::on_row_deleted(Gtk::TreeModel::Path const& path)
 {
-  std::cout << "on_row_deleted() called.  path = '" << path.to_string() <<
-    "'." << std::endl;
-
   Gtk::TreeModel::iterator iter_deleted =
     m_refTreeModel->get_iter(path);
   if (iter_deleted)
@@ -128,14 +125,11 @@
 void ExampleWindow::on_row_inserted(Gtk::TreeModel::Path const& path,
                                               Gtk::TreeModel::iterator const& iter)
 {
-  std::cout << "on_row_inserted() called.  path = '" << path.to_string() <<
-    "'." << std::endl;
-
   Gtk::TreeModel::iterator iter_inserted =
     m_refTreeModel->get_iter(path);
   if (iter_inserted)
     {
-      Gtk::TreeModel::Row row = *(iter_inserted);
+      Gtk::TreeModel::Row row = *(++iter_inserted);
       inserted_pos_ = row[m_Columns.m_col_id];
       std::cout << "Inserted row: " << inserted_pos_ << std::endl;
     }


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