[glom] Document: fill_layout_field_details(): Handle choices layouts too.



commit 15f9e3a01f4035c6c07c5f14d4792fcc5135c2f9
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Oct 1 16:37:07 2010 +0200

    Document: fill_layout_field_details(): Handle choices layouts too.
    
    * glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
    set_choices_related(): Take non-const parameters.
    Added a non-const version of get_choices_related() so we can update the
    full field details later.
    * glom/libglom/document/document.cc: fill_layout_field_details():
    Also try to update the field details in the choices lists.

 ChangeLog                                          |   11 ++++
 .../data_structure/layout/fieldformatting.cc       |   12 ++++-
 .../data_structure/layout/fieldformatting.h        |    5 +-
 glom/libglom/document/document.cc                  |   50 ++++++++++++++++++-
 4 files changed, 72 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8f7629b..0285701 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-10-01  Murray Cumming  <murrayc murrayc com>
+
+	Document: fill_layout_field_details(): Handle choices layouts too.
+
+	* glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
+	set_choices_related(): Take non-const parameters.
+	Added a non-const version of get_choices_related() so we can update the 
+	full field details later.
+	* glom/libglom/document/document.cc: fill_layout_field_details():
+	Also try to update the field details in the choices lists.
+
 2010-09-29  Murray Cumming  <murrayc murrayc com>
 
 	Fix the build with the latest gtkmm 3 API.
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index 8a9d91e..18c7493 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -243,7 +243,7 @@ void FieldFormatting::set_has_related_choices(bool val)
   m_choices_related = val;
 }
 
-void FieldFormatting::set_choices_related(const sharedptr<const Relationship>& relationship, const sharedptr<const LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all)
+void FieldFormatting::set_choices_related(const sharedptr<const Relationship>& relationship, const sharedptr<LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all)
 {
   set_relationship(relationship);
 
@@ -261,6 +261,16 @@ void FieldFormatting::get_choices_related(sharedptr<const Relationship>& relatio
   show_all = m_choices_related_show_all;
 }
 
+
+void FieldFormatting::get_choices_related(sharedptr<const Relationship>& relationship, sharedptr<LayoutItem_Field>& field, sharedptr<LayoutGroup>& extra_layout, bool& show_all)
+{
+  relationship = get_relationship();
+
+  field = m_choices_related_field;
+  extra_layout = m_choices_extra_layout_group;
+  show_all = m_choices_related_show_all;
+}
+
 sharedptr<const Relationship> FieldFormatting::get_choices_related_relationship(bool& show_all) const
 {
   show_all = m_choices_related_show_all;
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index 44e4dd9..b2104bd 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -69,8 +69,9 @@ public:
    */
   void set_choices_restricted(bool val = true, bool as_radio_buttons = false);
 
+  void get_choices_related(sharedptr<const Relationship>& relationship_name, sharedptr<LayoutItem_Field>& field, sharedptr<LayoutGroup>& extra_layout, bool& show_all);
   void get_choices_related(sharedptr<const Relationship>& relationship_name, sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutGroup>& extra_layout, bool& show_all) const;
-  void set_choices_related(const sharedptr<const Relationship>& relationship_name, const sharedptr<const LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all);
+  void set_choices_related(const sharedptr<const Relationship>& relationship_name, const sharedptr<LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all);
 
   //Just for convenience:
   sharedptr<const Relationship> get_choices_related_relationship(bool& show_all) const;
@@ -168,7 +169,7 @@ private:
   Glib::ustring m_text_color_foreground, m_text_color_background;
   HorizontalAlignment m_horizontal_alignment;
 
-  sharedptr<const LayoutItem_Field> m_choices_related_field;
+  sharedptr<LayoutItem_Field> m_choices_related_field;
   sharedptr<LayoutGroup> m_choices_extra_layout_group;
   bool m_choices_related_show_all;
 };
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 1afe216..0f53bb9 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1388,16 +1388,51 @@ void Document::set_tables(const type_listTableInfo& tables)
 
 void Document::fill_layout_field_details(const Glib::ustring& parent_table_name, const sharedptr<LayoutGroup>& layout_group) const
 {
+  if(!layout_group)
+    return;
+
   //Get the full field information for the LayoutItem_Fields in this group:
 
   for(LayoutGroup::type_list_items::iterator iter = layout_group->m_list_items.begin(); iter != layout_group->m_list_items.end(); ++iter)
   {
     sharedptr<LayoutItem> layout_item = *iter;
 
+    //Check custom Field Formatting:
+    sharedptr<LayoutItem_WithFormatting> layout_withformatting = 
+      sharedptr<LayoutItem_WithFormatting>::cast_dynamic(layout_item);
+    if(layout_withformatting)
+    {
+      sharedptr<const Relationship> choice_relationship;
+      sharedptr<LayoutItem_Field> choice_layout_first;
+      sharedptr<LayoutGroup> choice_extra_layouts;
+      bool choice_show_all = false;
+      layout_withformatting->m_formatting.get_choices_related(choice_relationship, choice_layout_first, choice_extra_layouts, choice_show_all);
+      
+      const Glib::ustring table_name = (choice_relationship ? choice_relationship->get_to_table() : Glib::ustring());
+      if(choice_layout_first)
+        choice_layout_first->set_full_field_details( get_field(table_name, choice_layout_first->get_name()) );
+      fill_layout_field_details(parent_table_name, choice_extra_layouts); //recurse
+    }
+
     sharedptr<LayoutItem_Field> layout_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
     if(layout_field)
     {
-      layout_field->set_full_field_details( get_field(layout_field->get_table_used(parent_table_name), layout_field->get_name()) );
+      const sharedptr<Field> field = get_field(layout_field->get_table_used(parent_table_name), layout_field->get_name());
+      layout_field->set_full_field_details(field);
+      if(field)
+      {
+        //Check default Field Formatting:
+        sharedptr<const Relationship> choice_relationship;
+        sharedptr<LayoutItem_Field> choice_layout_first;
+        sharedptr<LayoutGroup> choice_extra_layouts;
+        bool choice_show_all = false;
+        field->m_default_formatting.get_choices_related(choice_relationship, choice_layout_first, choice_extra_layouts, choice_show_all);
+        
+        const Glib::ustring table_name = (choice_relationship ? choice_relationship->get_to_table() : Glib::ustring());
+        if(choice_layout_first)
+          choice_layout_first->set_full_field_details( get_field(table_name, choice_layout_first->get_name()) );
+        fill_layout_field_details(parent_table_name, choice_extra_layouts); //recurse
+      }
     }
     else
     {
@@ -2082,7 +2117,16 @@ void Document::load_after_layout_item_field(const xmlpp::Element* element, const
   load_after_layout_item_usesrelationship(element, table_name, item);
 
   //Needed to decide what formatting to load/save:
-  item->set_full_field_details( get_field(item->get_table_used(table_name), name) );
+  const sharedptr<const Field> field = get_field(item->get_table_used(table_name), name);
+  
+  // This is not unusual, because tables often refer to tables that have not been loaded yet.
+  // Code should sometimes check this before returning the layout items.
+  //
+  //if(!field)
+  //{
+  //  std::cerr << G_STRFUNC << ": Could not find field details for field=" << name << ", table=" << table_name << std::endl;
+  //}
+  item->set_full_field_details(field);
 
   item->set_editable( get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_EDITABLE) );
 
@@ -2154,7 +2198,7 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
     const xmlpp::Element* element = dynamic_cast<const xmlpp::Element*>(*iter);
     if(element)
     {
-      if(element->get_name() == GLOM_NODE_DATA_LAYOUT_ITEM)
+      if(element->get_name() == GLOM_NODE_DATA_LAYOUT_ITEM) //TODO: Rename this to GLOM_NODE_DATA_LAYOUT_ITEM_FIELD
       {
         sharedptr<LayoutItem_Field> item = sharedptr<LayoutItem_Field>::create();
         //item.set_full_field_details_empty();



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