[glom] TranslatableItem: Make get_title() virtual.



commit dafddac88747cccba6975ceefb0c878a0b6385c3
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 11 15:38:06 2011 +0200

    TranslatableItem: Make get_title() virtual.
    
    * glom/libglom/data_structure/translatable_item.h: Make get_title()
    virtual, like get_title_or_name() already is, so we can make get_title()
    useful generically via the base class.
    * glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
    * glom/libglom/data_structure/layout/layoutitem_portal.[h|cc]:
    * glom/libglom/data_structure/layout/report_parts/layoutitem_fields
    ummary.[h|cc]: Add get_title() overrides.
    * glom/mode_data/box_data_calendar_related.cc:
    * glom/mode_data/box_data_list_related.cc:
    * glom/print_layout/print_layout_utils.cc: Use get_title() instead of
    get_title_or_name(), to avoid showing names of intentionally title-less
    groups and notebooks.

 ChangeLog                                          |   17 +++++++++++
 .../data_structure/layout/layoutitem_field.cc      |   29 ++++++++++++++++++-
 .../data_structure/layout/layoutitem_field.h       |    6 ++++
 .../data_structure/layout/layoutitem_portal.cc     |    9 ++++++
 .../data_structure/layout/layoutitem_portal.h      |    1 +
 .../layout/report_parts/layoutitem_fieldsummary.cc |    7 +++++
 .../layout/report_parts/layoutitem_fieldsummary.h  |    1 +
 glom/libglom/data_structure/translatable_item.h    |    2 +-
 glom/mode_data/box_data_calendar_related.cc        |    7 +----
 glom/mode_data/box_data_list_related.cc            |    7 +----
 glom/print_layout/print_layout_utils.cc            |    4 ++-
 11 files changed, 74 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6419df6..f29bb69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2011-10-11  Murray Cumming  <murrayc murrayc com>
 
+	TranslatableItem: Make get_title() virtual.
+
+	* glom/libglom/data_structure/translatable_item.h: Make get_title()
+	virtual, like get_title_or_name() already is, so we can make get_title()
+	useful generically via the base class.
+	* glom/libglom/data_structure/layout/layoutitem_field.[h|cc]:
+	* glom/libglom/data_structure/layout/layoutitem_portal.[h|cc]:
+	* glom/libglom/data_structure/layout/report_parts/layoutitem_fields
+	ummary.[h|cc]: Add get_title() overrides.
+	* glom/mode_data/box_data_calendar_related.cc:
+	* glom/mode_data/box_data_list_related.cc:
+	* glom/print_layout/print_layout_utils.cc: Use get_title() instead of 
+	get_title_or_name(), to avoid showing names of intentionally title-less 
+	groups and notebooks.
+
+2011-10-11  Murray Cumming  <murrayc murrayc com>
+
 	LayoutItem_Portal: Make get_title_or_name() useful.
 
 	* glom/libglom/data_structure/layout/layoutitem_portal.[h|cc]:
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc b/glom/libglom/data_structure/layout/layoutitem_field.cc
index 3329425..638a1cd 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -115,7 +115,7 @@ Glib::ustring LayoutItem_Field::get_name() const
   return LayoutItem_WithFormatting::get_name();
 }
 
-Glib::ustring LayoutItem_Field::get_title_or_name_no_custom() const
+Glib::ustring LayoutItem_Field::get_title_no_custom() const
 {
   //Use the field's default title:
   if(m_field_cache_valid && m_field)
@@ -126,6 +126,31 @@ Glib::ustring LayoutItem_Field::get_title_or_name_no_custom() const
     return get_name(); //We ignore TranslatableItem::get_title() for LayoutItem_Field.
 }
 
+
+Glib::ustring LayoutItem_Field::get_title_or_name_no_custom() const
+{
+  //Use the field's default title:
+  if(m_field_cache_valid && m_field)
+  {
+    return m_field->get_title();
+  }
+
+  return Glib::ustring();
+}
+
+Glib::ustring LayoutItem_Field::get_title() const
+{
+  //Use the custom title (overriding the field's default title), if there is one:
+  //This may even be empty if the developer specifies that.
+  if(m_title_custom && m_title_custom->get_use_custom_title())
+  {
+    return m_title_custom->get_title();
+  }
+
+  //Use the field's default title:
+  return get_title_no_custom();
+}
+
 Glib::ustring LayoutItem_Field::get_title_or_name() const
 {
   //Use the custom title (overriding the field's default title), if there is one:
@@ -136,7 +161,7 @@ Glib::ustring LayoutItem_Field::get_title_or_name() const
   }
 
   //Use the field's default title:
-  return get_title_or_name_no_custom();
+  return get_title_no_custom();
 }
 
 bool LayoutItem_Field::get_editable_and_allowed() const
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h b/glom/libglom/data_structure/layout/layoutitem_field.h
index a53ad63..3d378a3 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -86,6 +86,10 @@ public:
   /** Get the user-visible title for the field, in the user's current locale.
    * This returns the name if no title is set.
    */
+  virtual Glib::ustring get_title() const;
+
+  /** Get the user-visible title for the field, in the user's current locale.
+   */
   virtual Glib::ustring get_title_or_name() const;
 
   Glib::ustring get_title_or_name_no_custom() const;
@@ -155,6 +159,8 @@ public:
 
 private:
 
+  Glib::ustring get_title_no_custom() const;
+
   //This is just a cache, filled in by looking at the database structure:
   sharedptr<const Field> m_field;
   bool m_field_cache_valid; //Whetehr m_field is up-to-date.
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.cc b/glom/libglom/data_structure/layout/layoutitem_portal.cc
index d197c73..86a3562 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.cc
@@ -417,4 +417,13 @@ Glib::ustring LayoutItem_Portal::get_title_or_name() const
   return title;
 }
 
+Glib::ustring LayoutItem_Portal::get_title() const
+{
+  Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */);
+  if(title.empty()) //TODO: This prevents "" as a real title.
+   title = _("Undefined Table");
+
+  return title;
+}
+
 } //namespace Glom
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.h b/glom/libglom/data_structure/layout/layoutitem_portal.h
index 6106e6a..dd2044d 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.h
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.h
@@ -47,6 +47,7 @@ public:
 
   virtual LayoutItem* clone() const;
 
+  virtual Glib::ustring get_title() const;
   virtual Glib::ustring get_title_or_name() const;
   virtual Glib::ustring get_part_type_name() const;
 
diff --git a/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc b/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc
index 345f791..f656658 100644
--- a/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc
+++ b/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc
@@ -66,6 +66,13 @@ Glib::ustring LayoutItem_FieldSummary::get_title_or_name() const
   return get_summary_type_name(m_summary_type) + ": " + field_title; //TODO: Allow a more human-readable title for summary headings.
 }
 
+Glib::ustring LayoutItem_FieldSummary::get_title() const
+{
+  const Glib::ustring field_title = get_full_field_details()->get_title();
+
+  return get_summary_type_name(m_summary_type) + ": " + field_title; //TODO: Allow a more human-readable title for summary headings.
+}
+
 Glib::ustring LayoutItem_FieldSummary::get_part_type_name() const
 {
   //Translators: This is the name of a UI element (a layout part name).
diff --git a/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h b/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h
index beaa902..9bdc16c 100644
--- a/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h
+++ b/glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h
@@ -61,6 +61,7 @@ public:
 
   void set_field(const sharedptr<LayoutItem_Field>& field);
 
+  virtual Glib::ustring get_title() const;
   virtual Glib::ustring get_title_or_name() const;
 
   virtual Glib::ustring get_layout_display_name() const;
diff --git a/glom/libglom/data_structure/translatable_item.h b/glom/libglom/data_structure/translatable_item.h
index 775844c..ba6d43c 100644
--- a/glom/libglom/data_structure/translatable_item.h
+++ b/glom/libglom/data_structure/translatable_item.h
@@ -55,7 +55,7 @@ public:
 
   /** Get the title's translation for the current locale.
    */
-  Glib::ustring get_title() const;
+  virtual Glib::ustring get_title() const;
 
   /** Get the title's translation for the specifed locale.
    */
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 12b53cf..eb67d6e 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -91,12 +91,7 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
   {
     Glib::ustring title;
     if(m_portal)
-      title = m_portal->get_title_or_name();
-    else
-    {
-      //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
-      title = _("Undefined Table");
-    }
+      title = m_portal->get_title();
 
     m_Label.set_markup(Utils::bold_message(title));
     m_Label.show();
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 95bebb9..3c598d3 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -86,12 +86,7 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
   {
     Glib::ustring title;
     if(m_portal)
-      title = m_portal->get_title_or_name();
-    else
-    {
-      //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
-      title = _("Undefined Table");
-    }
+      title = m_portal->get_title();
 
     m_Label.set_markup(Utils::bold_message(title));
     m_Label.show();
diff --git a/glom/print_layout/print_layout_utils.cc b/glom/print_layout/print_layout_utils.cc
index a412183..d64e92a 100644
--- a/glom/print_layout/print_layout_utils.cc
+++ b/glom/print_layout/print_layout_utils.cc
@@ -80,7 +80,9 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
   const double field_height = ITEM_HEIGHT;
   const double gap = GRID_GAP;
 
-  const Glib::ustring title = layout_group->get_title_or_name();
+  //Show the group's title
+  //(but do not fall back to the name, because unnamed groups are really wanted sometimes.)
+  const Glib::ustring title = layout_group->get_title();
   if(!title.empty())
   {
     sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::create();



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