[glom/maemo5] DbAddDel: Expand an appropriate column.



commit d7ef137dce1298d7e7c69a0c93fcc5402239e78c
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 6 17:42:54 2009 +0200

    DbAddDel: Expand an appropriate column.
    
    * glom/libglom/data_structure/layout/layoutitem.[h|cc]: get_display_width():
    Remove the bool return and just return the value, because 0 already means no
    specified width.
    * glom/libglom/document/document.cc:
    * glom/mode_design/layout/dialog_layout_details.cc:
    * glom/print_layout/canvas_layout_item.cc: Adapt.
    
    * glom/utility_widgets/db_adddel/db_adddel.[h|cc]:
    Added get_column_to_expand() to choose the last expandable (text, no specified
    width) column.
    treeview_append_column(): Add a bool expand property and use it.
    construct_specified_columns(): Expand the expandable column, to avoid
    wasting space or expanding an inappropriate column.

 ChangeLog                                        |   18 +++++
 glom/libglom/data_structure/layout/layoutitem.cc |    7 +--
 glom/libglom/data_structure/layout/layoutitem.h  |    2 +-
 glom/libglom/document/document.cc                |    3 +-
 glom/mode_design/layout/dialog_layout_details.cc |    2 +-
 glom/print_layout/canvas_layout_item.cc          |    3 +-
 glom/utility_widgets/db_adddel/db_adddel.cc      |   74 ++++++++++++++++++----
 glom/utility_widgets/db_adddel/db_adddel.h       |    5 +-
 8 files changed, 90 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5494e6e..45f9aac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-10-06  Murray Cumming  <murrayc murrayc com>
+
+	DbAddDel: Expand an appropriate column.
+	
+	* glom/libglom/data_structure/layout/layoutitem.[h|cc]: get_display_width(): 
+	Remove the bool return and just return the value, because 0 already means no 
+	specified width.
+	* glom/libglom/document/document.cc:
+	* glom/mode_design/layout/dialog_layout_details.cc:
+	* glom/print_layout/canvas_layout_item.cc: Adapt.
+	
+	* glom/utility_widgets/db_adddel/db_adddel.[h|cc]:
+	Added get_column_to_expand() to choose the last expandable (text, no specified 
+	width) column.
+	treeview_append_column(): Add a bool expand property and use it.
+	construct_specified_columns(): Expand the expandable column, to avoid 
+	wasting space or expanding an inappropriate column.
+
 2009-10-05  Murray Cumming  <murrayc murrayc com>
 
 	Maemo: Allow editing of hidden tables (only) via its details window.
diff --git a/glom/libglom/data_structure/layout/layoutitem.cc b/glom/libglom/data_structure/layout/layoutitem.cc
index 8b3f9d7..5614b6b 100644
--- a/glom/libglom/data_structure/layout/layoutitem.cc
+++ b/glom/libglom/data_structure/layout/layoutitem.cc
@@ -145,12 +145,9 @@ Glib::ustring LayoutItem::get_report_part_id() const
   return "unexpected_report_part_id"; //This should never be used.
 }
 
-bool LayoutItem::get_display_width(guint& width) const
+guint LayoutItem::get_display_width() const
 {
-  //Initialize output variable:
-  width = m_display_width;
-
-  return (m_display_width != 0); //Tell the caller whether a display width has even been specified.
+  return m_display_width;
 }
 
 void LayoutItem::set_display_width(guint value)
diff --git a/glom/libglom/data_structure/layout/layoutitem.h b/glom/libglom/data_structure/layout/layoutitem.h
index 1ac2038..5ec3d52 100644
--- a/glom/libglom/data_structure/layout/layoutitem.h
+++ b/glom/libglom/data_structure/layout/layoutitem.h
@@ -54,7 +54,7 @@ public:
    */
   virtual Glib::ustring get_report_part_id() const;
 
-  bool get_display_width(guint& width) const;
+  guint get_display_width() const;
   void set_display_width(guint value);
 
   /// This is used only for the print layouts.
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 5290bdd..faa3b35 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -3185,8 +3185,7 @@ void Document::save_before_layout_group(xmlpp::Element* node, const sharedptr<co
       if(nodeItem)
       {
         //Attributes that any layout item could have:
-        guint column_width = 0;
-        item->get_display_width(column_width);
+        const guint column_width = item->get_display_width();
         set_node_attribute_value_as_decimal(nodeItem, GLOM_ATTRIBUTE_LAYOUT_ITEM_COLUMN_WIDTH, column_width);
 
         if(with_print_layout_positions)
diff --git a/glom/mode_design/layout/dialog_layout_details.cc b/glom/mode_design/layout/dialog_layout_details.cc
index c495f1b..f2813bc 100644
--- a/glom/mode_design/layout/dialog_layout_details.cc
+++ b/glom/mode_design/layout/dialog_layout_details.cc
@@ -1268,7 +1268,7 @@ void Dialog_Layout_Details::on_cell_data_column_width(Gtk::CellRenderer* rendere
         const bool editable = (layout_field || layout_button || layout_text); //Only these have column widths that can be edited.
         renderer_text->property_editable() = editable;
       
-        layout_item->get_display_width(column_width);
+        column_width = layout_item->get_display_width();
       }
 
       Glib::ustring text; 
diff --git a/glom/print_layout/canvas_layout_item.cc b/glom/print_layout/canvas_layout_item.cc
index 4bfe695..b2ed8ae 100644
--- a/glom/print_layout/canvas_layout_item.cc
+++ b/glom/print_layout/canvas_layout_item.cc
@@ -329,8 +329,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
                 if(cell)
                 {
                   //Make sure that the width is sensible:
-                  guint width = 0;
-                  layout_item->get_display_width(width);
+                  guint width = layout_item->get_display_width();
                   width = std::max(width, (guint)10);
                   cell->set_width_height(width, row_height);
                   std::cout << "DEBUG: width=" << width << std::endl;
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 14fef85..6eb83ef 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -1056,6 +1056,10 @@ void DbAddDel::construct_specified_columns()
   bool no_columns_used = true;
   int data_model_column_index = 0;
   
+  guint column_to_expand = 0;
+  const bool has_expandable_column = get_column_to_expand(column_to_expand);
+  //std::cout << "DEBUG: column_to_expand=" << column_to_expand  << ", has=" << has_expandable_column << std::endl;
+  
   for(type_vecModelColumns::iterator iter = vecModelColumns.begin(); iter != vecModelColumns.end(); ++iter)
   {
     const DbAddDelColumnInfo& column_info = m_ColumnTypes[model_column_index];
@@ -1082,7 +1086,12 @@ void DbAddDel::construct_specified_columns()
       if(pCellRenderer)
       {
         //Get the index of the field in the query, if it is a field:
-        treeview_append_column(column_name, *pCellRenderer, model_column_index, item_data_model_column_index);
+        //std::cout << "debug: model_column_index=" << model_column_index << ", item_data_model_column_index=" << item_data_model_column_index << std::endl;
+        const bool expand = column_to_expand && (column_to_expand == model_column_index);
+        treeview_append_column(column_name, 
+          *pCellRenderer, 
+          model_column_index, item_data_model_column_index, 
+          expand);
 
         if(column_info.m_editable)
         {
@@ -1897,7 +1906,44 @@ void DbAddDel::on_treeview_columns_changed()
 }
 #endif //GLOM_ENABLE_MAEMO
 
-guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRenderer& cellrenderer, int model_column_index, int data_model_column_index)
+bool DbAddDel::get_column_to_expand(guint& column_to_expand) const
+{
+  //Initialize output parameter:
+  column_to_expand = 0;
+  bool result = false;
+  
+  //Discover the right-most text column: 
+  guint i = 0;
+  for(type_ColumnTypes::const_iterator iter = m_ColumnTypes.begin(); iter != m_ColumnTypes.end(); ++iter)
+  {
+    sharedptr<LayoutItem> layout_item = iter->m_item;
+           
+    sharedptr<LayoutItem_Field> layout_item_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
+    if(layout_item_field)
+    {  
+      //Only text columns should expand.
+      //Number fields are right-aligned, so expansion is annoying.
+      //Time and date fields don't vary their width much.
+      if(layout_item_field->get_glom_type() == Field::TYPE_TEXT)
+      {
+        //Check that no specific width has been specified:
+        const guint column_width = layout_item_field->get_display_width();
+        if(!column_width) //TODO: Ignore these on maemo?
+        {
+          column_to_expand = i;
+          result = true;
+        }
+        
+      }
+    }
+    
+    ++i;
+  }
+  
+  return result;
+}
+
+guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRenderer& cellrenderer, int model_column_index, int data_model_column_index, bool expand)
 {
   #ifndef GLOM_ENABLE_MAEMO
   DbTreeViewColumnGlom* pViewColumn = Gtk::manage( new DbTreeViewColumnGlom(Utils::string_escape_underscores(title), cellrenderer) );
@@ -1906,7 +1952,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
   guint cols_count = m_TreeView.append_column(*pViewColumn);
   #else
   Glib::RefPtr<Hildon::TouchSelectorColumn> pViewColumn = touch_selector_get_column();
-  pViewColumn->pack_start(cellrenderer, false);
+  pViewColumn->pack_start(cellrenderer, expand);
   g_assert(pViewColumn);
   guint cols_count = get_columns_count();
   #endif //GLOM_ENABLE_MAEMO
@@ -1929,18 +1975,22 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
   pViewColumn->set_resizable();
   #endif //GLOM_ENABLE_MAEMO
   
-  guint column_width = 0;
-  if(!layout_item->get_display_width(column_width))
+  guint column_width = -1; //Means expand.
+  if(!expand)
   {
-    //TODO: Choose a width based on the first 100 values.
-    if(layout_item_field)
+    column_width = layout_item->get_display_width();
+    if(!column_width)
     {
-     column_width = Utils::get_suitable_field_width_for_widget(*this, layout_item_field);
-     column_width = column_width / 3;
-     //std::cout << "DEBUG: column_width=" << column_width << std::endl;
+      //TODO: Choose a width based on the first 100 values.
+      if(layout_item_field)
+      {
+       column_width = Utils::get_suitable_field_width_for_widget(*this, layout_item_field);
+       column_width = column_width / 3;
+       //std::cout << "DEBUG: column_width=" << column_width << std::endl;
+      }
+      else
+        column_width = 100; //TODO: Don't save this default in the document.
     }
-    else
-     column_width = 100;
   }
 
   #ifdef GLOM_ENABLE_MAEMO
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index 8ec3bf1..416e209 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -366,7 +366,7 @@ private:
   guint get_count_hidden_system_columns() const;
 
   //The column_id is extra information that we can use later to discover what the column shows, even when columns have been reordered.
-  guint treeview_append_column(const Glib::ustring& title, Gtk::CellRenderer& cellrenderer, int model_column_index, int data_model_column_index);
+  guint treeview_append_column(const Glib::ustring& title, Gtk::CellRenderer& cellrenderer, int model_column_index, int data_model_column_index, bool expand);
 
   /** Show a model that gives a visual hint to the developer,
    * when he has not yet specified fields to show.
@@ -507,6 +507,9 @@ private:
     
 private:
   
+  /// Discover the right-most text column, so we can make it expand.
+  bool get_column_to_expand(guint& column_to_expand) const;
+  
   //TODO_refactor: Give these better names, and document them:
   bool start_new_record();
   void user_changed(const Gtk::TreeModel::iterator& row, guint col);



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