[glom/feature_choices_show_all] List view: When a value is edited, update other instances of the same field.



commit 7e2bd06eb03038072a8d007c4b5921d42167fe3b
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Aug 5 16:36:04 2010 +0200

    List view: When a value is edited, update other instances of the same field.
    
    * glom/utility_widgets/db_adddel/db_adddel.[h|cc]:
    get_data_model_column_index(): Add a including_specified_field_layout bool
    parameter, used in a new set_value() method overload that has a
    set_specified_field_layout bool parameter.
    user_changed(): Call set_value() to show the new value in any other
    instances of the same field.
    The details view already does this.

 ChangeLog                                   |   12 ++++++++++++
 glom/utility_widgets/db_adddel/db_adddel.cc |   17 ++++++++++++++---
 glom/utility_widgets/db_adddel/db_adddel.h  |    7 +++++--
 3 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0cc35d3..e0237bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-05  Murray Cumming  <murrayc murrayc com>
+
+	List view: When a value is edited, update other instances of the same field.
+
+	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]:
+	get_data_model_column_index(): Add a including_specified_field_layout bool 
+	parameter, used in a new set_value() method overload that has a 
+	set_specified_field_layout bool parameter.
+	user_changed(): Call set_value() to show the new value in any other 
+	instances of the same field.
+	The details view already does this.
+
 2010-08-04  Murray Cumming  <murrayc murrayc com>>
 
 	Simplified some code.
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 66dca4c..e1cb37e 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -1206,6 +1206,11 @@ bool DbAddDel::refresh_from_database_blank()
 
 void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value)
 {
+  set_value(iter, layout_item, value, true /* including the specified field */);
+}
+
+void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value, bool set_specified_field_layout)
+{
   //g_warning("DbAddDel::set_value begin");
 
   InnerIgnore innerIgnore(this);
@@ -1217,7 +1222,7 @@ void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<c
     Gtk::TreeModel::Row treerow = *iter;
     if(treerow)
     {
-      type_list_indexes list_indexes = get_data_model_column_index(layout_item);
+      const type_list_indexes list_indexes = get_data_model_column_index(layout_item, set_specified_field_layout);
       for(type_list_indexes::const_iterator iter = list_indexes.begin(); iter != list_indexes.end(); ++iter)
       {
         const guint treemodel_col = *iter + get_count_hidden_system_columns();
@@ -1310,7 +1315,7 @@ void DbAddDel::set_columns_ready()
   construct_specified_columns();
 }
 
-DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const sharedptr<const LayoutItem_Field>& layout_item_field) const
+DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const sharedptr<const LayoutItem_Field>& layout_item_field, bool including_specified_field_layout) const
 {
   //TODO_Performance: Replace all this looping by a cache/map:
 
@@ -1325,7 +1330,8 @@ DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const sharedpt
     sharedptr<const LayoutItem_Field> field = sharedptr<const LayoutItem_Field>::cast_dynamic(iter->m_item); //TODO_Performance: This would be unnecessary if !layout_item_field
     if(field)
     {
-      if(field && field->is_same_field(layout_item_field))
+      if(field->is_same_field(layout_item_field) 
+        && (including_specified_field_layout || field != layout_item_field))
       {
         list_indexes.push_back(data_model_column_index);
       }
@@ -2537,7 +2543,12 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
         set_entered_field_data(row, layout_field, value_old);
       }
       else
+      {
+        //Display the same value in other instances of the same field:
+        set_value(row, layout_field, field_value, false /* don't set the actually-edited cell */);
+        
         signal_record_changed().emit();
+      }
     }
     catch(const Glib::Exception& ex)
     {
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 61ca867..ef99b1b 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -265,6 +265,7 @@ public:
 
 private:
   
+  void set_value(const Gtk::TreeModel::iterator& iter, const sharedptr<const LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value, bool set_specified_field_layout);
   
   //Overrides of Base_DB/Base_DB_Table methods:
   virtual void set_entered_field_data(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
@@ -287,8 +288,10 @@ private:
   ///Return the column indexes of any columns that display this field.
   virtual type_list_indexes get_column_index(const sharedptr<const LayoutItem>& layout_item) const;
 
-  ///Return the query column index of any columns that display this field:
-  type_list_indexes get_data_model_column_index(const sharedptr<const LayoutItem_Field>& layout_item_field) const;
+  /** Return the query column index of any columns that display this field:
+   * @param including_specified_field_layout If false, then don't return the actual layout item itself.
+   */
+  type_list_indexes get_data_model_column_index(const sharedptr<const LayoutItem_Field>& layout_item_field, bool including_specified_field_layout = true) const;
 
 protected:
   virtual void setup_menu();



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