[glom/feature_choices_show_all: 1/3] Field Formatting: Related Choices: Add a Show All checkbox.



commit 86ccc046a8163ea3e7acd4af6966c7ffcece279e
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Aug 2 17:29:31 2010 +0200

    Field Formatting: Related Choices: Add a Show All checkbox.
    
    * glom/glom_developer.glade:
    * glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
    * glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
    Add a Show All checkbox to the Related Choices section, so the developer
    may choose to restrict the choices depending on the relationship. The default
    (the previous behaviour) is to show all records from the related table.
    * glom/libglom/document/document.cc: save_before_layout_item_formatting(),
    save_after_layout_item_formatting(): Store the new bool in the document.
    * glom/libglom/utils.cc:
    * glom/mode_data/datawidget/datawidget.cc:
    * glom/utility_widgets/db_adddel/db_adddel.cc: Adapt the code to build, though
    the behaviour has not changed yet.

 ChangeLog                                          |   17 +++++++++++++++++
 glom/glom_developer.glade                          |   19 +++++++++++++++++++
 .../data_structure/layout/fieldformatting.cc       |   16 +++++++++++-----
 .../data_structure/layout/fieldformatting.h        |    5 +++--
 glom/libglom/document/document.cc                  |   17 ++++++++++++++---
 glom/libglom/utils.cc                              |    8 +++++++-
 glom/mode_data/datawidget/datawidget.cc            |    3 ++-
 .../layout/layout_item_dialogs/box_formatting.cc   |   12 ++++++++++--
 .../layout/layout_item_dialogs/box_formatting.h    |    1 +
 glom/utility_widgets/db_adddel/db_adddel.cc        |    3 ++-
 10 files changed, 86 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f126e8c..9049ccc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2010-08-02  Murray Cumming  <murrayc murrayc com>
+
+	Field Formatting: Related Choices: Add a Show All checkbox.
+
+	* glom/glom_developer.glade:
+	* glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
+	* glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
+	Add a Show All checkbox to the Related Choices section, so the developer 
+	may choose to restrict the choices depending on the relationship. The default 
+	(the previous behaviour) is to show all records from the related table.
+	* glom/libglom/document/document.cc: save_before_layout_item_formatting(), 
+	save_after_layout_item_formatting(): Store the new bool in the document.
+	* glom/libglom/utils.cc:
+	* glom/mode_data/datawidget/datawidget.cc: 
+	* glom/utility_widgets/db_adddel/db_adddel.cc: Adapt the code to build, though 
+	the behaviour has not changed yet.
+
 2010-07-27  Murray Cumming  <murrayc murrayc com>
 
 	Fix the tests build after the merge.
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index c199df7..cab328c 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -6818,6 +6818,25 @@ Which user should be added to this group?</property>
                                     <property name="y_options"></property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="checkbutton_choices_related_show_all">
+                                    <property name="label" translatable="yes">Show all records</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="tooltip_text" translatable="yes">If this option is selected then the choices will list values from all records in the related table. If this option is not selected then the choices will list values only from related records.</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                    <property name="top_attach">3</property>
+                                    <property name="bottom_attach">4</property>
+                                  </packing>
+                                </child>
                               </object>
                             </child>
                           </object>
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index 9644914..cbb9201 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -35,7 +35,8 @@ FieldFormatting::FieldFormatting()
   m_choices_related(false),
   m_text_format_multiline(false),
   m_text_multiline_height_lines(MULTILINE_TEXT_DEFAULT_HEIGHT_LINES),
-  m_horizontal_alignment(HORIZONTAL_ALIGNMENT_AUTO)
+  m_horizontal_alignment(HORIZONTAL_ALIGNMENT_AUTO),
+  m_choices_related_show_all(false)
 {
 }
 
@@ -54,7 +55,8 @@ FieldFormatting::FieldFormatting(const FieldFormatting& src)
   m_text_color_background(src.m_text_color_background),
   m_horizontal_alignment(src.m_horizontal_alignment),
   m_choices_related_field(src.m_choices_related_field),
-  m_choices_related_field_second(src.m_choices_related_field_second)
+  m_choices_related_field_second(src.m_choices_related_field_second),
+  m_choices_related_show_all(src.m_choices_related_show_all)
 {
 }
 
@@ -78,7 +80,8 @@ bool FieldFormatting::operator==(const FieldFormatting& src) const
     (m_text_font == src.m_text_font) &&
     (m_text_color_foreground == src.m_text_color_foreground) &&
     (m_text_color_background == src.m_text_color_background) && 
-    (m_horizontal_alignment == src.m_horizontal_alignment);
+    (m_horizontal_alignment == src.m_horizontal_alignment) &&
+    (m_choices_related_show_all == src.m_choices_related_show_all);
 }
 
 
@@ -95,6 +98,7 @@ FieldFormatting& FieldFormatting::operator=(const FieldFormatting& src)
   m_choices_related = src.m_choices_related;
   m_choices_related_field = src.m_choices_related_field;
   m_choices_related_field_second = src.m_choices_related_field_second;
+  m_choices_related_show_all = src.m_choices_related_show_all;
 
   m_text_format_multiline = src.m_text_format_multiline;
   m_text_multiline_height_lines = src.m_text_multiline_height_lines;
@@ -231,22 +235,24 @@ void FieldFormatting::set_has_related_choices(bool val)
   m_choices_related = val;
 }
 
-void FieldFormatting::get_choices(sharedptr<const Relationship>& relationship, Glib::ustring& field, Glib::ustring& field_second) const
+void FieldFormatting::get_choices(sharedptr<const Relationship>& relationship, Glib::ustring& field, Glib::ustring& field_second, bool& show_all) const
 {
   relationship = get_relationship();
 
   field = m_choices_related_field;
   field_second = m_choices_related_field_second;
+  show_all = m_choices_related_show_all;
 
   //g_warning("FieldFormatting::get_choices, %s, %s, %s", m_choices_related_relationship->c_str(), m_choices_related_field.c_str(), m_choices_related_field_second.c_str());
 }
 
-void FieldFormatting::set_choices(const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second)
+void FieldFormatting::set_choices(const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all)
 {
   set_relationship(relationship);
 
   m_choices_related_field = field;
   m_choices_related_field_second = field_second;
+  m_choices_related_show_all = show_all;
 }
 
 void FieldFormatting::change_field_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new)
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index e709128..c9aa272 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -65,8 +65,8 @@ public:
    */
   void set_choices_restricted(bool val = true, bool as_radio_buttons = false);
 
-  void get_choices(sharedptr<const Relationship>& relationship_name, Glib::ustring& field, Glib::ustring& field_second) const;
-  void set_choices(const sharedptr<const Relationship>& relationship_name, const Glib::ustring& field, const Glib::ustring& field_second);
+  void get_choices(sharedptr<const Relationship>& relationship_name, Glib::ustring& field, Glib::ustring& field_second, bool& show_all) const;
+  void set_choices(const sharedptr<const Relationship>& relationship_name, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all);
 
   /** Get whether the text should be displayed with multiple lines in the
    * details view. Text is displayed with a single line in the list view.
@@ -161,6 +161,7 @@ private:
   HorizontalAlignment m_horizontal_alignment;
 
   Glib::ustring m_choices_related_field, m_choices_related_field_second;
+  bool m_choices_related_show_all;
 };
 
 } //namespace Glom
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index dffb483..1c97b8f 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -198,6 +198,7 @@ namespace Glom
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP "choices_related_relationship"
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD "choices_related_field"
 #define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND "choices_related_second"
+#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL "choices_related_show_all"
 
 #define GLOM_NODE_TRANSLATIONS_SET "trans_set"
 #define GLOM_NODE_TRANSLATION "trans"
@@ -1992,10 +1993,17 @@ void Document::load_after_layout_item_formatting(const xmlpp::Element* element,
     const Glib::ustring relationship_name = get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP);
     if(!relationship_name.empty())
     {
+      bool show_all = get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL);
+      if(get_document_format_version() < 6)
+      {
+        show_all = true; //This was the behaviour before this checkbox existed.
+      }
+      
       sharedptr<Relationship> relationship = get_relationship(table_name, relationship_name);
       format.set_choices(relationship,
         get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD),
-        get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND) );
+        get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND),
+        show_all);
       //Full details are updated in filled-in ().
     }
   }
@@ -2994,11 +3002,13 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
 
     sharedptr<const Relationship> choice_relationship;
     Glib::ustring choice_field, choice_second;
-    format.get_choices(choice_relationship, choice_field, choice_second);
+    bool choice_show_all = false;
+    format.get_choices(choice_relationship, choice_field, choice_second, choice_show_all);
 
     set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP, glom_get_sharedptr_name(choice_relationship));
     set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD, choice_field);
     set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND, choice_second);
+    set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL, choice_show_all);
   }
 }
 
@@ -4189,8 +4199,9 @@ guint Document::get_latest_known_document_format_version()
   // Version 3: (Glom 1.10). Support for the old one-big-string example_rows format was removed, and we now use (unquoted) non-postgres libgda escaping.
   // Version 4: (Glom 1.12). Portal navigation options were simplified, with a "none" option. network_sharing was added, defaulting to off.
   // Version 5: (Glom 1.14). Extra layout item formatting options were added, plus a startup script.
+  // Version 6: (Glom 1.16). Extra show_all option for choices that show related records.
 
-  return 5;
+  return 6;
 }
 
 std::vector<Glib::ustring> Document::get_library_module_names() const
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 295e671..e2fcb11 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -468,7 +468,13 @@ Utils::type_list_values_with_second Utils::get_choice_values(const sharedptr<con
 
   sharedptr<const Relationship> choice_relationship;
   Glib::ustring choice_field, choice_second;
-  field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
+  bool choice_show_all = false; //TODO: Use this.
+  if(!choice_show_all)
+  {
+    std::cerr << G_STRFUNC << ": Not fully implemented. TODO: Restrict values to related records." << std::endl;
+  }
+  
+  field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second, choice_show_all);
   if(!choice_relationship)
   {
     //std::cout <<" debug: field has no choices: " << field->get_name() << std::endl;
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index fee40b6..11a3145 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -129,7 +129,8 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
       {
         sharedptr<const Relationship> choice_relationship;
         Glib::ustring choice_field, choice_second;
-        field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
+        bool show_all = false; //TODO: Use this.
+        field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second, show_all);
         if(choice_relationship && !choice_field.empty())
         {
           const Glib::ustring to_table = choice_relationship->get_to_table();
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 2ea2f5c..974e7e8 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -57,6 +57,10 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_checkbutton_choices_restricted_as_radio_buttons(0),
   m_adddel_choices_custom(0),
   m_col_index_custom_choices(0),
+  m_combo_choices_relationship(0),
+  m_combo_choices_field(0),
+  m_combo_choices_field_second(0),
+  m_checkbutton_choices_related_show_all(0),
   m_for_print_layout(false),
   m_show_numeric(true),
   m_show_choices(true)
@@ -119,6 +123,7 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   builder->get_widget_derived("combobox_choices_related_relationship", m_combo_choices_relationship);
   builder->get_widget_derived("combobox_choices_related_field", m_combo_choices_field);
   builder->get_widget_derived("combobox_choices_related_field_second", m_combo_choices_field_second);
+  builder->get_widget("checkbutton_choices_related_show_all", m_checkbutton_choices_related_show_all);
   builder->get_widget("radiobutton_choices_custom", m_radiobutton_choices_custom);
   builder->get_widget("radiobutton_choices_related", m_radiobutton_choices_related);
 
@@ -233,12 +238,14 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
 
     sharedptr<const Relationship> choices_relationship;
     Glib::ustring choices_field, choices_field_second;
-    format.get_choices(choices_relationship, choices_field, choices_field_second);
+    bool choices_show_all = false;
+    format.get_choices(choices_relationship, choices_field, choices_field_second, choices_show_all);
 
     m_combo_choices_relationship->set_selected_relationship(choices_relationship);
     on_combo_choices_relationship_changed(); //Fill the combos so we can set their active items.
     m_combo_choices_field->set_selected_field(choices_field);
     m_combo_choices_field_second->set_selected_field(choices_field_second);
+    m_checkbutton_choices_related_show_all->set_active(choices_show_all);
 
     //Custom choices:
     m_adddel_choices_custom->remove_all();
@@ -308,7 +315,8 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
     sharedptr<Relationship> choices_relationship = m_combo_choices_relationship->get_selected_relationship();
     m_format.set_choices(choices_relationship,
       m_combo_choices_field->get_selected_field_name(),
-      m_combo_choices_field_second->get_selected_field_name() );
+      m_combo_choices_field_second->get_selected_field_name(),
+      m_checkbutton_choices_related_show_all->get_active());
 
     //Custom choices:
     FieldFormatting::type_list_values list_choice_values;
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index ebe72d7..21db584 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -99,6 +99,7 @@ private:
   ComboBox_Relationship* m_combo_choices_relationship;
   ComboBox_Fields* m_combo_choices_field;
   ComboBox_Fields* m_combo_choices_field_second;
+  Gtk::CheckButton* m_checkbutton_choices_related_show_all;
 
   mutable FieldFormatting m_format;
 
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index c775f97..2465aca 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -833,7 +833,8 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
       {
         sharedptr<const Relationship> choice_relationship;
         Glib::ustring choice_field, choice_second;
-        item_field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
+        bool choice_show_all; //TODO: Use this.
+        item_field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second, choice_show_all);
 
         if(choice_relationship && !choice_field.empty())
         {



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