[glom] Box_Data_Portal: Separate the 2 init_db_details*() methods.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Box_Data_Portal: Separate the 2 init_db_details*() methods.
- Date: Mon, 21 Mar 2016 20:49:52 +0000 (UTC)
commit bbd0b7220e6a9684ecc35ec838e61c3c13bea5d4
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Mar 21 21:49:33 2016 +0100
Box_Data_Portal: Separate the 2 init_db_details*() methods.
And avoid duplication in the derived classes.
glom/mode_data/box_data_calendar_related.cc | 31 ----------------
glom/mode_data/box_data_calendar_related.h | 4 --
glom/mode_data/box_data_list_related.cc | 52 +++++++++++---------------
glom/mode_data/box_data_list_related.h | 2 +
glom/mode_data/box_data_portal.cc | 29 +++++++++++++--
glom/mode_data/box_data_portal.h | 5 ++-
6 files changed, 52 insertions(+), 71 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 48a4c05..ce5288c 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -72,37 +72,6 @@ void Box_Data_Calendar_Related::enable_buttons()
//m_calendar.set_allow_view_details(view_details_possible); //Don't allow the user to go to a record in a
hidden table.
}
-bool Box_Data_Calendar_Related::init_db_details_without_portal(const Glib::ustring &parent_table)
-{
- //std::cout << "debug: " << G_STRFUNC << ": " << parent_table << std::endl;
-
- set_parent_table(parent_table);
-
- const auto portal = get_portal();
- if(portal)
- LayoutWidgetBase::m_table_name = portal->get_table_used(Glib::ustring() /* parent table_name, not used.
*/);
- else
- LayoutWidgetBase::m_table_name = Glib::ustring();
-
- Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;
-
- if(portal)
- {
- auto document = get_document();
- m_key_field = DbUtils::get_fields_for_table_one_field(document,
- LayoutWidgetBase::m_table_name, portal->get_to_field_used());
- }
- else
- m_key_field.reset();
-
- enable_buttons();
-
- FoundSet found_set;
- found_set.m_table_name = LayoutWidgetBase::m_table_name;
- return Box_Data::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout() and
fill_from_database().
-}
-
-
void Box_Data_Calendar_Related::show_title_in_ui(const Glib::ustring& title)
{
if (!title.empty()) {
diff --git a/glom/mode_data/box_data_calendar_related.h b/glom/mode_data/box_data_calendar_related.h
index b010281..992122e 100644
--- a/glom/mode_data/box_data_calendar_related.h
+++ b/glom/mode_data/box_data_calendar_related.h
@@ -40,10 +40,6 @@ public:
Box_Data_Calendar_Related();
virtual ~Box_Data_Calendar_Related();
- /** Use this if no portal is yet defined, so the user can use the context menu to define a portal.
- */
- bool init_db_details_without_portal(const Glib::ustring &parent_table) override;
-
private:
bool fill_from_database() override;
type_vecConstLayoutFields get_fields_to_show() const override;
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 2d74e01..6c62b2f 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -71,47 +71,39 @@ void Box_Data_List_Related::enable_buttons()
m_AddDel.set_allow_view_details(view_details_possible);
}
-bool Box_Data_List_Related::init_db_details_without_portal(const Glib::ustring &parent_table)
+bool Box_Data_List_Related::init_db_details(const std::shared_ptr<const LayoutItem_Portal>& portal, bool
show_title = true)
{
- set_parent_table(parent_table);
-
- const auto portal = get_portal();
- if(portal)
- LayoutWidgetBase::m_table_name = portal->get_table_used(Glib::ustring() /* parent table_name, not used.
*/);
- else
- LayoutWidgetBase::m_table_name = Glib::ustring();
-
- if(LayoutWidgetBase::m_table_name.empty())
- {
- std::cerr << G_STRFUNC << ": LayoutWidgetBase::m_table_name is null\n";
- }
-
- Base_DB_Table::m_table_name = LayoutWidgetBase::m_table_name;
-
- if(portal)
- {
- m_key_field = DbUtils::get_fields_for_table_one_field(get_document(),
- LayoutWidgetBase::m_table_name, portal->get_to_field_used());
- }
- else
- m_key_field.reset();
-
-
//Prevent impossible multiple related records:
const bool single_related = (m_key_field && (m_key_field->get_unique_key() ||
m_key_field->get_primary_key()));
m_AddDel.set_allow_only_one_related_record(single_related);
- enable_buttons();
+ const auto table_name = portal->get_table_used(Glib::ustring() /* parent table_name, not used. */);
+ const auto table_privs = Privs::get_current_privs(table_name);
+ m_AddDel.set_allow_view(table_privs.m_view);
//TODO: Use m_found_set?
FoundSet found_set;
- found_set.m_table_name = LayoutWidgetBase::m_table_name;
+ found_set.m_table_name = table_name;
+ m_AddDel.set_found_set(found_set);
- const auto table_privs = Privs::get_current_privs(found_set.m_table_name);
- m_AddDel.set_allow_view(table_privs.m_view);
+ const auto result = Box_Data_Portal::init_db_details(portal, show_title);
+ enable_buttons();
+ return result;
+}
+bool Box_Data_List_Related::init_db_details_without_portal(const Glib::ustring& parent_table)
+{
+ //Prevent impossible multiple related records:
+ m_AddDel.set_allow_only_one_related_record(false);
+ m_AddDel.set_allow_view(false);
+
+ //TODO: Use m_found_set?
+ FoundSet found_set;
m_AddDel.set_found_set(found_set);
- return Box_Data_ManyRecords::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout()
and fill_from_database().
+
+ enable_buttons();
+
+ return Box_Data_Portal::init_db_details_without_portal(parent_table);
}
void Box_Data_List_Related::show_title_in_ui(const Glib::ustring& title)
diff --git a/glom/mode_data/box_data_list_related.h b/glom/mode_data/box_data_list_related.h
index ee4fcc9..b46fa7f 100644
--- a/glom/mode_data/box_data_list_related.h
+++ b/glom/mode_data/box_data_list_related.h
@@ -33,6 +33,8 @@ class Box_Data_List_Related : public Box_Data_Portal
public:
Box_Data_List_Related();
+ bool init_db_details(const std::shared_ptr<const LayoutItem_Portal>& portal, bool show_title) override;
+
/** Use this if no portal is yet defined, so the user can use the context menu to define a portal.
*/
bool init_db_details_without_portal(const Glib::ustring &parent_table) override;
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index e1b06f1..057877a 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -21,6 +21,7 @@
#include <glom/mode_data/box_data_portal.h>
#include <libglom/data_structure/glomconversions.h>
#include <libglom/db_utils.h>
+#include <libglom/privs.h>
#include <libglom/sql_utils.h>
#include <libglom/utils.h>
#include <libglom/layout_utils.h>
@@ -97,9 +98,12 @@ bool Box_Data_Portal::init_db_details(const std::shared_ptr<const LayoutItem_Por
auto portal_stored = glom_sharedptr_clone(portal);
set_layout_item(portal_stored, "" /* TODO */);
- Glib::ustring parent_table;
- if(portal_stored)
- parent_table = portal_stored->get_from_table();
+ const auto table_name = portal->get_table_used(Glib::ustring() /* parent table_name, not used. */);
+ LayoutWidgetBase::m_table_name = table_name;
+ Base_DB_Table::m_table_name = table_name;
+
+ m_key_field = DbUtils::get_fields_for_table_one_field(get_document(),
+ table_name, portal->get_to_field_used());
Glib::ustring title;
if(show_title && portal_stored) {
@@ -107,7 +111,24 @@ bool Box_Data_Portal::init_db_details(const std::shared_ptr<const LayoutItem_Por
}
show_title_in_ui(title);
- return init_db_details_without_portal(parent_table);
+ //TODO: Use m_found_set?
+ FoundSet found_set;
+ found_set.m_table_name = table_name;
+ return Box_Data_ManyRecords::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout()
and fill_from_database().
+}
+
+bool Box_Data_Portal::init_db_details_without_portal(const Glib::ustring& parent_table)
+{
+ set_layout_item(std::shared_ptr<LayoutItem_Portal>(), "" /* TODO */);
+ set_parent_table(parent_table);
+
+ LayoutWidgetBase::m_table_name = Glib::ustring();
+ Base_DB_Table::m_table_name = Glib::ustring();
+ m_key_field.reset();
+
+ //TODO: Use m_found_set?
+ FoundSet found_set;
+ return Box_Data_ManyRecords::init_db_details(found_set, "" /* layout_platform */); //Calls create_layout()
and fill_from_database().
}
Glib::ustring Box_Data_Portal::get_title(const Glib::ustring& locale) const
diff --git a/glom/mode_data/box_data_portal.h b/glom/mode_data/box_data_portal.h
index 17295fb..646a723 100644
--- a/glom/mode_data/box_data_portal.h
+++ b/glom/mode_data/box_data_portal.h
@@ -46,11 +46,12 @@ public:
/**
* @param portal: The full portal details
*/
- bool init_db_details(const std::shared_ptr<const LayoutItem_Portal>& portal, bool show_title = true);
+ virtual bool init_db_details(const std::shared_ptr<const LayoutItem_Portal>& portal, bool show_title =
true);
+ //TODO: Remove this? It might only be called when portal is unexectedly null.
/** Use this if no portal is yet defined, so the user can use the context menu to define a portal.
*/
- virtual bool init_db_details_without_portal(const Glib::ustring& parent_table) = 0;
+ virtual bool init_db_details_without_portal(const Glib::ustring& parent_table);
/** Update a portal if a relevant value in its parent table has changed.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]