[glom/glom-1-18] LayoutItem_Portal: Make get_title_or_name() useful.



commit 9a2d97cf4c4b77bc084ea0bb2f6f88d5b0a467f0
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 11 15:02:21 2011 +0200

    LayoutItem_Portal: Make get_title_or_name() useful.
    
    * glom/libglom/data_structure/layout/layoutitem_portal.[h|cc]:
    Add an override for get_title_or_nam(), so that callers do not need to
    special-case portals compared to other groups.
    * glom/mode_data/box_data_calendar_related.cc:
    * glom/mode_data/box_data_list_related.cc:
    * glom/mode_data/box_data_portal.cc:
    * glom/mode_data/flowtablewithfields.cc:
    * glom/print_layout/print_layout_utils.cc: Use get_title_or_name()
    instead of more complicated code.
    
    Conflicts:
    
    	ChangeLog
    	glom/mode_data/box_data_list_related.cc
    	glom/print_layout/print_layout_utils.cc

 ChangeLog                                          |   14 ++++++++++++++
 .../data_structure/layout/layoutitem_portal.cc     |   12 ++++++++++++
 .../data_structure/layout/layoutitem_portal.h      |    1 +
 glom/mode_data/box_data_calendar_related.cc        |   10 +++++-----
 glom/mode_data/box_data_list_related.cc            |   12 ++++++------
 glom/mode_data/box_data_portal.cc                  |   10 +++-------
 glom/mode_data/flowtablewithfields.cc              |   11 +++--------
 7 files changed, 44 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d20958..891050c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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]:
+	Add an override for get_title_or_nam(), so that callers do not need to 
+	special-case portals compared to other groups.
+	* glom/mode_data/box_data_calendar_related.cc:
+	* glom/mode_data/box_data_list_related.cc:
+	* glom/mode_data/box_data_portal.cc:
+	* glom/mode_data/flowtablewithfields.cc:
+	* glom/print_layout/print_layout_utils.cc: Use get_title_or_name() 
+	instead of more complicated code.
+
 2011-10-06  Murray Cumming  <murrayc murrayc com>
 
 	TreeModelDb: fill_values_if_necessary(): Avoid a crash.
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.cc b/glom/libglom/data_structure/layout/layoutitem_portal.cc
index 8597b3b..67b4c5a 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.cc
@@ -358,4 +358,16 @@ sharedptr<const LayoutItem_Field> LayoutItem_Portal::get_field_identifies_non_hi
   return result;
 }
 
+Glib::ustring LayoutItem_Portal::get_title_or_name() const
+{
+  Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */);
+  if(title.empty())
+    title = get_relationship_name_used();
+  
+  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 23b81e4..f4bd0f1 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_or_name() const;
   virtual Glib::ustring get_part_type_name() const;
 
   virtual void change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index c812c72..0bdbc53 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -89,16 +89,16 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
   //TODO: This is duplicated in box_data_related_list.cc and box_data_portal.cc. Just use code from the base class?
   if(show_title)
   {
-    Glib::ustring relationship_title;
-    if(m_portal && m_portal->get_has_relationship_name())
-      relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
+    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.
-      relationship_title = _("Undefined Table");
+      title = _("Undefined Table");
     }
 
-    m_Label.set_markup(Utils::bold_message(relationship_title));
+    m_Label.set_markup(Utils::bold_message(title));
     m_Label.show();
 
     m_Alignment.set_padding(Utils::DEFAULT_SPACING_SMALL /* top */, 0, Utils::DEFAULT_SPACING_LARGE /* left */, 0);
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 62b810e..86f0699 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -87,16 +87,16 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
 
   if(show_title)
   {
-    Glib::ustring relationship_title;
-    if(m_portal && m_portal->get_has_relationship_name())
-      relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
+    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.
-      relationship_title = _("Undefined Table");
+      title = _("Undefined Table");
     }
-  
-    m_Label.set_markup(Utils::bold_message(relationship_title));
+
+    m_Label.set_markup(Utils::bold_message(title));
     m_Label.show();
 
     m_Alignment.set_padding(Utils::DEFAULT_SPACING_SMALL /* top */, 0, Utils::DEFAULT_SPACING_LARGE /* left */, 0);
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index 217ad95..1384a62 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -254,17 +254,13 @@ bool Box_Data_Portal::init_db_details(const sharedptr<const LayoutItem_Portal>&
 
 Glib::ustring Box_Data_Portal::get_title() const
 {
-  //TODO: This same code is in box_data_related_list.cc. Remove the duplication.
-  Glib::ustring relationship_title;
-  if(m_portal && m_portal->get_has_relationship_name())
-    relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
+  if(m_portal)
+    return 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.
-    relationship_title = _("Undefined Table");
+    return _("Undefined Table");
   }
-
-  return relationship_title;
 }
 
 Glib::ustring Box_Data_Portal::get_title_singular() const
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 33c5221..698e8d6 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -374,13 +374,12 @@ void FlowTableWithFields::add_layout_notebook_at_position(const sharedptr<Layout
       Gtk::Label* tab_label = Gtk::manage(new Gtk::Label());
       tab_label->show();
 #endif
+
+      tab_label->set_label(group->get_title_or_name());
+
       sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::cast_dynamic(group);
       if(portal)
       {
-        const Glib::ustring tab_title = glom_get_sharedptr_title_or_name(portal->get_relationship());
-        //tab_label->set_markup(Utils::bold_message(tab_title));
-        tab_label->set_label(tab_title);
-
         //Add a Related Records list for this portal:
         Box_Data_List_Related* portal_box = create_related(portal, false /* no label, because it's in the tab instead. */);
         //portal_box->set_border_width(Glom::Utils::DEFAULT_SPACING_SMALL); It has "padding" around the Alignment instead.
@@ -391,10 +390,6 @@ void FlowTableWithFields::add_layout_notebook_at_position(const sharedptr<Layout
       }
       else
       {
-        const Glib::ustring tab_title = group->get_title_or_name();
-        //tab_label->set_markup(Utils::bold_message(tab_title));
-        tab_label->set_label(tab_title);
-
         //Add a FlowTable for this group:
         FlowTableWithFields* flow_table = Gtk::manage( new FlowTableWithFields() );
         add_view(flow_table); //Allow these sub-flowtables to access the document too.



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