[glom/feature_choices_show_all] Choices: Fix !show-all lists.



commit ed1a56b121539c37abc22f1e13af610c928b625f
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Aug 6 16:40:34 2010 +0200

    Choices: Fix !show-all lists.
    
    	* glom/mode_data/datawidget/combochoices.[h|cc]:
      refresh_data_from_database_with_foreign_key(): Add a document parameter,
      used to update the cached choices information if necessary.
    	* glom/mode_data/flowtablewithfields.cc: set_field_value(): Adapted.

 ChangeLog                                 |    9 ++++++
 glom/mode_data/datawidget/combochoices.cc |   39 +++++++++++++++++++++++++++-
 glom/mode_data/datawidget/combochoices.h  |    2 +-
 glom/mode_data/flowtablewithfields.cc     |    2 +-
 4 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1d0101f..5eb32f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-08-06  Murray Cumming  <murrayc murrayc com>
 
+	Choices: Fix !show-all lists.
+
+	* glom/mode_data/datawidget/combochoices.[h|cc]:
+  refresh_data_from_database_with_foreign_key(): Add a document parameter,
+  used to update the cached choices information if necessary.
+	* glom/mode_data/flowtablewithfields.cc: set_field_value(): Adapted.
+
+2010-08-06  Murray Cumming  <murrayc murrayc com>
+
 	Document loading: Show an error dialog even for unexpected errors.
 
 	* glom/application.cc: on_document_load(): Don't just fail silently when
diff --git a/glom/mode_data/datawidget/combochoices.cc b/glom/mode_data/datawidget/combochoices.cc
index cce338a..df6ff7d 100644
--- a/glom/mode_data/datawidget/combochoices.cc
+++ b/glom/mode_data/datawidget/combochoices.cc
@@ -51,11 +51,46 @@ ComboChoices::~ComboChoices()
 {
 }
 
-bool ComboChoices::refresh_data_from_database_with_foreign_key(const Gnome::Gda::Value& foreign_key_value)
+bool ComboChoices::refresh_data_from_database_with_foreign_key(const Document* document, const Gnome::Gda::Value& foreign_key_value)
 {
+  //Get the choice information, then cache it:
   if(!m_related_relationship || !m_related_field)
   {
-    std::cerr << G_STRFUNC << ": !m_related_relationship or !m_related_field." << std::endl;
+    sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+    if(!layout_item)
+    {
+      return false;
+    }
+
+    //TODO: Avoid repeating this tedious code in so many places:
+    const FieldFormatting& format = layout_item->get_formatting_used();
+    Glib::ustring choice_field, choice_second;
+    format.get_choices_related(m_related_relationship, choice_field, choice_second, m_related_show_all);
+
+    if(!m_related_relationship)
+    {
+      std::cerr << G_STRFUNC << ": !m_related_relationship." << std::endl;
+      return false;
+    }
+
+    const Glib::ustring to_table = m_related_relationship->get_to_table();
+
+    m_related_field = sharedptr<LayoutItem_Field>::create();
+    sharedptr<const Field> field_details = document->get_field(to_table, choice_field);
+    m_related_field->set_full_field_details(field_details);
+
+    m_related_field_second.clear();
+    if(!choice_second.empty())
+    {
+      m_related_field_second = sharedptr<LayoutItem_Field>::create();
+      field_details = document->get_field(to_table, choice_second);
+      m_related_field_second->set_full_field_details(field_details);
+    }
+  }
+
+  if(!m_related_field)
+  {
+    std::cerr << G_STRFUNC << ": !m_related_field." << std::endl;
     return false;
   }
 
diff --git a/glom/mode_data/datawidget/combochoices.h b/glom/mode_data/datawidget/combochoices.h
index c9f8010..2af9778 100644
--- a/glom/mode_data/datawidget/combochoices.h
+++ b/glom/mode_data/datawidget/combochoices.h
@@ -60,7 +60,7 @@ public:
    *
    * @param foreign_key_value: The value that should be found in this table.
    */
-  bool refresh_data_from_database_with_foreign_key(const Gnome::Gda::Value& foreign_key_value);
+  bool refresh_data_from_database_with_foreign_key(const Document* document, const Gnome::Gda::Value& foreign_key_value);
 
 protected:
   void init();
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index e1612f3..8569903 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -817,7 +817,7 @@ void FlowTableWithFields::set_field_value(const sharedptr<const LayoutItem_Field
     if(widget)
     {
       //g_warning("FlowTableWithFields::set_field_value: foreign_key_value=%s", value.to_string().c_str());
-      widget->refresh_data_from_database_with_foreign_key(value /* foreign key value */);
+      widget->refresh_data_from_database_with_foreign_key(get_document(), value /* foreign key value */);
     }
   }
 }



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