[glom] Details: Align widgets in other columns too.



commit d883aec00dcefbc237b59e01e6c54056fa47add2
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Mar 7 22:45:13 2010 +0100

    Details: Align widgets in other columns too.
    
    * glom/utility_widgets/flowtable.[h|cc]: Added get_columns_count().
    * glom/mode_data/flowtablewithfields.[h|cc]: apply_size_group_to_label():
    Change this to apply_size_groups_to_label().
    align_child_group_labels(): Create a size group for each possible column,
    and call apply_size_groups_to_label() with them.

 ChangeLog                             |   10 ++++++
 glom/mode_data/flowtablewithfields.cc |   56 +++++++++++++++++++++++---------
 glom/mode_data/flowtablewithfields.h  |   17 +++++++--
 glom/utility_widgets/flowtable.cc     |    5 +++
 glom/utility_widgets/flowtable.h      |    2 +
 5 files changed, 70 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 546101f..bdf0f4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-03-07  Murray Cumming  <murrayc murrayc com>
+
+  Details: Align widgets in other columns too.
+  
+	* glom/utility_widgets/flowtable.[h|cc]: Added get_columns_count().
+	* glom/mode_data/flowtablewithfields.[h|cc]: apply_size_group_to_label():
+	Change this to apply_size_groups_to_label().
+	align_child_group_labels(): Create a size group for each possible column, 
+	and call apply_size_groups_to_label() with them.
+
 2010-03-06  Murray Cumming  <murrayc murrayc com>
 
 	Details: Align widgets in the first columns of neighbouring layout groups.
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 5572b53..df0d5da 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -1246,7 +1246,7 @@ void FlowTableWithFields::on_flowtable_requested_related_details(const Glib::ust
   signal_requested_related_details().emit(table_name, primary_key_value);
 }
 
-void FlowTableWithFields::apply_size_group_to_labels(const Glib::RefPtr<Gtk::SizeGroup>& size_group)
+void FlowTableWithFields::apply_size_groups_to_labels(const type_vec_sizegroups& size_groups)
 {
   //Remove widgets from any existing size group:
   for(type_listFields::iterator iter = m_listFields.begin(); iter != m_listFields.end(); ++iter)
@@ -1257,16 +1257,13 @@ void FlowTableWithFields::apply_size_group_to_labels(const Glib::RefPtr<Gtk::Siz
     if(!label || !previous_size_group)
       continue;
       
-    if(previous_size_group != size_group)
-    {
-      previous_size_group->remove_widget(*label);
-      info.m_first_in_sizegroup.clear();
-    }
+    previous_size_group->remove_widget(*label);
+    info.m_first_in_sizegroup.clear();
   }
   
-  m_size_group = size_group;
+  m_vec_size_groups = size_groups;
   
-  if(!size_group)
+  if(m_vec_size_groups.empty())
     return;
      
   for(type_listFields::iterator iter = m_listFields.begin(); iter != m_listFields.end(); ++iter)
@@ -1285,10 +1282,13 @@ void FlowTableWithFields::apply_size_group_to_labels(const Glib::RefPtr<Gtk::Siz
     //TODO: Use a different SizeGroup for items in 2nd columns?
     guint column = 0;
     const bool column_allocated = get_column_for_first_widget(*label_parent, column);
-    if(!column_allocated || (column > 0))
+    if(!column_allocated)
+      
+    if(column >= m_vec_size_groups.size())
       continue;
-    
-    if(info.m_first_in_sizegroup != size_group)
+      
+    Glib::RefPtr<Gtk::SizeGroup> size_group = m_vec_size_groups[column];
+    if(size_group && (info.m_first_in_sizegroup != size_group))
     {
       size_group->add_widget(*label);
       info.m_first_in_sizegroup = size_group; //Remember it so we can remove it later.
@@ -1302,17 +1302,41 @@ void FlowTableWithFields::align_child_group_labels()
   if(m_sub_flow_tables.size() < 2)
     return;
     
-  //Create a size group and tell all groups to use is for their labels:
-  Glib::RefPtr<Gtk::SizeGroup> size_group = 
-    Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
+  //Create a size group for each column and tell all groups to use them for their labels:
+  const guint max_columns = get_sub_flowtables_max_columns();
+  type_vec_sizegroups vec_sizegroups(max_columns);
+  for(guint i = 0; i < max_columns; ++i)
+  {
+    vec_sizegroups[i] = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
+  }
+   
   for(type_sub_flow_tables::iterator iter = m_sub_flow_tables.begin(); iter != m_sub_flow_tables.end(); ++iter)
   {
     FlowTableWithFields* subtable = *iter;
     if(subtable)
-      subtable->apply_size_group_to_labels(size_group);
+      subtable->apply_size_groups_to_labels(vec_sizegroups);
   }
 }
 
+guint FlowTableWithFields::get_sub_flowtables_max_columns() const
+{
+  guint result = get_columns_count();
+  
+  for(type_sub_flow_tables::const_iterator iter = m_sub_flow_tables.begin(); iter != m_sub_flow_tables.end(); ++iter)
+  {
+    const FlowTableWithFields* subtable = *iter;
+    if(subtable)
+    {
+      const guint count = subtable->get_columns_count();
+      if(count > result)
+          result = count;
+    }
+  }
+  
+  return result;
+}
+  
+
 void FlowTableWithFields::on_size_allocate(Gtk::Allocation& allocation)
 {
   FlowTable::on_size_allocate(allocation);
@@ -1326,7 +1350,7 @@ void FlowTableWithFields::on_size_allocate(Gtk::Allocation& allocation)
   //so this should be able to work:
   if(m_columns_allocated_changed)
   {
-    apply_size_group_to_labels(m_size_group);
+    apply_size_groups_to_labels(m_vec_size_groups);
     
     //Prevent unnecessary repeated (endless?) size allocation requested:
     m_columns_allocated_changed = false;
diff --git a/glom/mode_data/flowtablewithfields.h b/glom/mode_data/flowtablewithfields.h
index e54424d..8cb7c38 100644
--- a/glom/mode_data/flowtablewithfields.h
+++ b/glom/mode_data/flowtablewithfields.h
@@ -103,11 +103,14 @@ public:
 
   virtual void remove_all();
   
-  /** Apply the size group to all field labels.
+  typedef std::vector< Glib::RefPtr<Gtk::SizeGroup> > type_vec_sizegroups;
+    
+  /** Apply the size groups to all field labels.
    * By calling this method on multiple FlowTables, the field widgets in 
    * different groups can then align.
+   * @param size_groups A vector containing a size group for each possible column.
    */
-  void apply_size_group_to_labels(const Glib::RefPtr<Gtk::SizeGroup>& size_group);
+  void apply_size_groups_to_labels(const type_vec_sizegroups& size_group);
   
   /** Create a size group and make all the labels in child flowtables use it,
    * making them align.
@@ -163,6 +166,11 @@ private:
     
   /// Get portals whose relationships have @a from_key as the from_key.
   type_portals get_portals(const sharedptr<const LayoutItem_Field>& from_key);
+  
+  /** Examine this flow table and all child flow tables, discovering which 
+   * has the most columns.
+   */
+  guint get_sub_flowtables_max_columns() const;
 
   //int get_suitable_width(Field::glom_field_type field_type);
 
@@ -260,8 +268,9 @@ private:
   
   Glib::ustring m_table_name;
   
-  //Size group shared by this widget's sibling FlowTables.
-  Glib::RefPtr<Gtk::SizeGroup> m_size_group;
+  //Size groups shared by this widget's sibling FlowTables,
+  //with one group for each column.
+  type_vec_sizegroups m_vec_size_groups;
 
   type_signal_field_edited m_signal_field_edited;
   type_signal_field_open_details_requested m_signal_field_open_details_requested;
diff --git a/glom/utility_widgets/flowtable.cc b/glom/utility_widgets/flowtable.cc
index 2e08514..396f7e4 100644
--- a/glom/utility_widgets/flowtable.cc
+++ b/glom/utility_widgets/flowtable.cc
@@ -370,6 +370,11 @@ void FlowTable::set_columns_count(guint value)
   m_columns_count = value;
 }
 
+guint FlowTable::get_columns_count() const
+{
+  return m_columns_count;
+}
+
 void FlowTable::get_item_requested_width(const FlowTableItem& item, int& first, int& second) const
 {
   //Initialize output paramters:
diff --git a/glom/utility_widgets/flowtable.h b/glom/utility_widgets/flowtable.h
index 04b990d..87010bf 100644
--- a/glom/utility_widgets/flowtable.h
+++ b/glom/utility_widgets/flowtable.h
@@ -43,6 +43,8 @@ public:
   virtual void remove(Gtk::Widget& first); //override
 
   void set_columns_count(guint value);
+  
+  guint get_columns_count() const;
 
   /** Sets the padding to put between the columns of widgets.
    */



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