[glom] Box_Data_List/Calender_Related: Move some code into show_title_in_ui().



commit 401677715668e5ca7b25e59e102cd24de19d55df
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Mar 21 12:48:40 2016 +0100

    Box_Data_List/Calender_Related: Move some code into show_title_in_ui().

 glom/mode_data/box_data_calendar_related.cc |   43 +++++++++++---------
 glom/mode_data/box_data_calendar_related.h  |    5 +-
 glom/mode_data/box_data_list_related.cc     |   58 ++++++++++++++------------
 glom/mode_data/box_data_list_related.h      |    2 +
 glom/mode_data/box_data_portal.h            |    3 +-
 5 files changed, 61 insertions(+), 50 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 0760673..0d91dbe 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -93,27 +93,11 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
   Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;
 
   //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 title;
-    if(portal)
-      title = item_get_title(portal);
-
-    m_Label.set_markup(UiUtils::bold_message(title));
-    m_Label.show();
-
-    m_calendar.set_margin_start(Utils::to_utype(UiUtils::DefaultSpacings::LARGE));
-    m_calendar.set_margin_top(Utils::to_utype(UiUtils::DefaultSpacings::SMALL));
-  }
-  else
-  {
-    m_Label.set_markup(Glib::ustring());
-    m_Label.hide();
-
-    //The box itself has padding of 6.
-    m_calendar.set_margin_start(0);
-    m_calendar.set_margin_top(0);
+  Glib::ustring title;
+  if(show_title && portal) {
+    title = item_get_title(portal);
   }
+  show_title_in_ui(title);
 
   if(portal)
   {
@@ -132,6 +116,25 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
 }
 
 
+void Box_Data_Calendar_Related::show_title_in_ui(const Glib::ustring& title)
+{
+  if (!title.empty()) {
+    m_Label.set_markup(UiUtils::bold_message(title));
+    m_Label.show();
+
+    m_calendar.set_margin_start(Utils::to_utype(UiUtils::DefaultSpacings::LARGE));
+    m_calendar.set_margin_top(Utils::to_utype(UiUtils::DefaultSpacings::SMALL));
+  }
+  else {
+    m_Label.set_markup(Glib::ustring());
+    m_Label.hide();
+
+    //The box itself has padding of 6.
+    m_calendar.set_margin_start(0);
+    m_calendar.set_margin_top(0);
+  }
+}
+
 void Box_Data_Calendar_Related::create_layout()
 {
   Box_Data::create_layout();
diff --git a/glom/mode_data/box_data_calendar_related.h b/glom/mode_data/box_data_calendar_related.h
index d687d3b..c0b680c 100644
--- a/glom/mode_data/box_data_calendar_related.h
+++ b/glom/mode_data/box_data_calendar_related.h
@@ -53,8 +53,9 @@ private:
   bool fill_from_database() override;
   type_vecConstLayoutFields get_fields_to_show() const override;
   void create_layout() override;
-    
-    
+  void show_title_in_ui(const Glib::ustring& title) override;
+
+
   //Implementations of pure virtual methods from Base_DB_Table_Data:
   void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value) override;
     
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index d68f0a8..f630ca9 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -91,36 +91,14 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
   {
     std::cerr << G_STRFUNC << ": LayoutWidgetBase::m_table_name is null\n";
   }
-  
-  Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;
-
-  if(show_title)
-  {
-    Glib::ustring title;
-    if(portal)
-      title = item_get_title(portal);
-
-    m_Label.set_markup(UiUtils::bold_message(title));
-    m_Label.show();
-
-    if(!(m_Frame.get_label_widget()))
-      m_Frame.set_label_widget(m_Label);
-
-    m_AddDel.set_margin_start(Utils::to_utype(UiUtils::DefaultSpacings::LARGE));
-    m_AddDel.set_margin_top(Utils::to_utype(UiUtils::DefaultSpacings::SMALL));
 
-  }
-  else
-  {
-    m_Label.set_markup(Glib::ustring());
-    m_Label.hide();
-    if(m_Frame.get_label_widget())
-      m_Frame.unset_label(); //Otherwise the allocation is calculated wrong due to GtkFrame bug: 
https://bugzilla.gnome.org/show_bug.cgi?id=662915
+  Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;
 
-    //The box itself has padding of 6:
-    m_AddDel.set_margin_start(0);
-    m_AddDel.set_margin_top(0);
+  Glib::ustring title;
+  if(show_title && portal) {
+    title = item_get_title(portal);
   }
+  show_title_in_ui(title);
 
   if(portal)
   {
@@ -148,6 +126,32 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
   return Box_Data_ManyRecords::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout() 
and fill_from_database().
 }
 
+void Box_Data_List_Related::show_title_in_ui(const Glib::ustring& title)
+{
+  if(!title.empty())
+  {
+    m_Label.set_markup(UiUtils::bold_message(title));
+    m_Label.show();
+
+    if(!(m_Frame.get_label_widget()))
+      m_Frame.set_label_widget(m_Label);
+
+    m_AddDel.set_margin_start(Utils::to_utype(UiUtils::DefaultSpacings::LARGE));
+    m_AddDel.set_margin_top(Utils::to_utype(UiUtils::DefaultSpacings::SMALL));
+  }
+  else
+  {
+    m_Label.set_markup(Glib::ustring());
+    m_Label.hide();
+    if(m_Frame.get_label_widget())
+      m_Frame.unset_label(); //Otherwise the allocation is calculated wrong due to GtkFrame bug: 
https://bugzilla.gnome.org/show_bug.cgi?id=662915
+
+    //The box itself has padding of 6:
+    m_AddDel.set_margin_start(0);
+    m_AddDel.set_margin_top(0);
+  }
+}
+
 bool Box_Data_List_Related::fill_from_database()
 {
   bool result = false;
diff --git a/glom/mode_data/box_data_list_related.h b/glom/mode_data/box_data_list_related.h
index 1bf1551..a8a869e 100644
--- a/glom/mode_data/box_data_list_related.h
+++ b/glom/mode_data/box_data_list_related.h
@@ -47,6 +47,8 @@ public:
 protected:
   bool fill_from_database() override;
 
+  void show_title_in_ui(const Glib::ustring& title) override;
+
   //Signal handlers:
   void on_adddel_record_changed();
   void on_adddel_user_requested_edit(const Gtk::TreeModel::iterator& row);
diff --git a/glom/mode_data/box_data_portal.h b/glom/mode_data/box_data_portal.h
index adca728..b08e678 100644
--- a/glom/mode_data/box_data_portal.h
+++ b/glom/mode_data/box_data_portal.h
@@ -109,11 +109,12 @@ protected:
   void on_dialog_layout_hide() override;
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
-protected:
   virtual Document::type_list_layout_groups create_layout_get_layout();
 
   void make_record_related(const Gnome::Gda::Value& related_record_primary_key_value);
 
+  virtual void show_title_in_ui(const Glib::ustring& title) = 0;
+
   /** Get the title of the relationship used by the portal.
    */
   Glib::ustring get_title(const Glib::ustring& locale) const;


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