[glom] Details: Do not navigate past the last row.



commit ecf0ccc7c8d5218d53a73111d8346d0bb9eec4da
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jul 8 11:53:29 2011 +0200

    Details: Do not navigate past the last row.
    
    * glom/mode_data/datawidget/treemodel_db.[h|cc]: get_last_row():
    Document that this never returns the placeholder row, and make sure that it
    does not. There was a typo that --ed the wrong variable.
    * glom/mode_data/db_adddel/db_adddel.[h|cc]: get_last_row():
    Document that this never returns the placeholder row.
    get_is_placeholder_row(): Remove an illogical call to is_last_row().
    get_count(): Remove an illogical check to see whether the last row is the
    placeholder row.
    * glom/utility_widgets/adddel/adddel.h: get_last_row(): Document that this
      similarly-APIed widget has different behaviour.
    
      This stops the user from being taken to an empty record when clicking Last,
      or when clicking Next to the end.
      Bug #526115 comment #25 (Michael Hasselmann)

 ChangeLog                                 |   19 +++++++++++++++++++
 glom/mode_data/datawidget/treemodel_db.cc |   14 +++++++++++---
 glom/mode_data/datawidget/treemodel_db.h  |    3 ++-
 glom/mode_data/db_adddel/db_adddel.cc     |    8 +-------
 glom/mode_data/db_adddel/db_adddel.h      |   14 +++++++++++++-
 glom/utility_widgets/adddel/adddel.h      |    5 +++++
 6 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c8f8cf3..933bdc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2011-07-08  Murray Cumming  <murrayc murrayc com>
 
+	Details: Do not navigate past the last row.
+
+	* glom/mode_data/datawidget/treemodel_db.[h|cc]: get_last_row(): 
+	Document that this never returns the placeholder row, and make sure that it 
+	does not. There was a typo that --ed the wrong variable.
+	* glom/mode_data/db_adddel/db_adddel.[h|cc]: get_last_row(): 
+	Document that this never returns the placeholder row.
+	get_is_placeholder_row(): Remove an illogical call to is_last_row().
+	get_count(): Remove an illogical check to see whether the last row is the 
+	placeholder row.
+	* glom/utility_widgets/adddel/adddel.h: get_last_row(): Document that this 
+  similarly-APIed widget has different behaviour.
+  
+  This stops the user from being taken to an empty record when clicking Last, 
+  or when clicking Next to the end.
+  Bug #526115 comment #25 (Michael Hasselmann)
+
+2011-07-08  Murray Cumming  <murrayc murrayc com>
+
 	DbAddDel: Remove unnecessary virtual keywords. 
 
 	* glom/mode_data/db_adddel/db_adddel.h: These methods are not meant to 
diff --git a/glom/mode_data/datawidget/treemodel_db.cc b/glom/mode_data/datawidget/treemodel_db.cc
index 95055d9..7ed78f4 100644
--- a/glom/mode_data/datawidget/treemodel_db.cc
+++ b/glom/mode_data/datawidget/treemodel_db.cc
@@ -881,15 +881,23 @@ bool DbTreeModel::row_was_removed(const type_datamodel_row_index& datamodel_row)
 
 Gtk::TreeModel::iterator DbTreeModel::get_last_row()
 {
+  std::cout << "debug: " << G_STRFUNC << std::endl;
   iterator result;
 
   //Find the last non-removed row:
-  int rows_count = get_internal_rows_count();
+  const int rows_count = get_internal_rows_count();
   if(rows_count)
   {
+    std::cout << "rows_count=" << rows_count << std::endl;
+   
     type_datamodel_row_index row = rows_count - 1;
-    --rows_count; //Ignore the placeholder.
+    
+    if(row > 0) //This should always be true, because there is always a placeholder.
+      --row; //Ignore the placeholder.
 
+    std::cout << "row=" << row << std::endl;
+   
+   
     //Step backwards until we find one that is not removed.
     while((m_map_rows.find(row) != m_map_rows.end()) && m_map_rows[row].m_removed)
     {
@@ -899,7 +907,7 @@ Gtk::TreeModel::iterator DbTreeModel::get_last_row()
         return result; //failed, because there are no non-removed row.
     }
 
-    //g_warning("DbTreeModel::get_last_row(): returning row=%d", row);
+    std::cout << G_STRFUNC << ": returning row=" << row << std::endl;
     create_iterator(row, result);
   }
 
diff --git a/glom/mode_data/datawidget/treemodel_db.h b/glom/mode_data/datawidget/treemodel_db.h
index ee741c9..5f71159 100644
--- a/glom/mode_data/datawidget/treemodel_db.h
+++ b/glom/mode_data/datawidget/treemodel_db.h
@@ -105,7 +105,8 @@ public:
   void set_key_value(const TreeModel::iterator& iter, const DbValue& value);
   DbValue get_key_value(const TreeModel::iterator& iter) const;
 
-  /** Get the last row - usually the placeholder.
+  /** Get the last row.
+   * This will never return the placeholder row. 
    */
   TreeModel::iterator get_last_row();
 
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index 5dbcb33..d9bb2d6 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -554,8 +554,7 @@ guint DbAddDel::get_count() const
   //Take account of the extra blank for new entries:
   if(get_allow_user_actions()) //If it has the extra row.
   {
-    if(get_is_placeholder_row(get_last_row()))
-      --iCount;
+    --iCount;
   }
 
   return iCount;
@@ -1942,11 +1941,6 @@ bool DbAddDel::get_is_placeholder_row(const Gtk::TreeModel::iterator& iter) cons
 {
   //g_warning("DbAddDel::get_is_placeholder_row()");
 
-  if(!get_is_last_row(iter))
-  {
-    return false;
-  }
-
   if(!iter)
     return false;
 
diff --git a/glom/mode_data/db_adddel/db_adddel.h b/glom/mode_data/db_adddel/db_adddel.h
index 0ce25d4..cdc49b2 100644
--- a/glom/mode_data/db_adddel/db_adddel.h
+++ b/glom/mode_data/db_adddel/db_adddel.h
@@ -131,6 +131,12 @@ public:
   virtual void set_value_selected(const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value);
 
   bool get_is_first_row(const Gtk::TreeModel::iterator& iter) const;
+
+  /** Check whether the row is the last (non-placeholder) row.
+   * This will also return true if @a iter is the placeholder row,
+   * but this should be used to identify the last real row.
+   * @see get_is_placeholder_row()
+   */
   bool get_is_last_row(const Gtk::TreeModel::iterator& iter) const;
 
   /** @result Whether this is a blank row where date for a new row should be entered
@@ -236,8 +242,14 @@ public:
   typedef sigc::signal<void> type_signal_sort_clause_changed;
   type_signal_sort_clause_changed signal_sort_clause_changed();
 
-
+  /** Get the last row.
+   * This will never return the placeholder row. 
+   */
   Gtk::TreeModel::iterator get_last_row();
+  
+  /** Get the last row.
+   * This will never return the placeholder row. 
+   */
   Gtk::TreeModel::iterator get_last_row() const;
 
   void set_open_button_title(const Glib::ustring& title);
diff --git a/glom/utility_widgets/adddel/adddel.h b/glom/utility_widgets/adddel/adddel.h
index 67de1aa..cc7519a 100644
--- a/glom/utility_widgets/adddel/adddel.h
+++ b/glom/utility_widgets/adddel/adddel.h
@@ -206,7 +206,12 @@ public:
 
   bool get_model_column_index(guint view_column_index, guint& model_column_index);
 
+  /** Get the last row. This will generally be the placeholder row.
+   */
   Gtk::TreeModel::iterator get_last_row();
+
+  /** Get the last row. This will generally be the placeholder row.
+   */
   Gtk::TreeModel::iterator get_last_row() const;
 
 protected:



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