[glom] Box_Data_Portal: Use m_portal via get_portal().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Box_Data_Portal: Use m_portal via get_portal().
- Date: Fri, 18 Mar 2016 20:58:20 +0000 (UTC)
commit 59fb983e3800a3da9cc897865ddc0eb76eef4bb8
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Mar 18 15:26:58 2016 +0100
Box_Data_Portal: Use m_portal via get_portal().
glom/mode_data/box_data_calendar_related.cc | 39 ++++++++------
glom/mode_data/box_data_list_related.cc | 56 ++++++++++++++------
glom/mode_data/box_data_portal.cc | 73 +++++++++++++++++---------
3 files changed, 110 insertions(+), 58 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index d5d5838..4591ebd 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -85,8 +85,9 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
m_parent_table = parent_table;
- if(m_portal)
- LayoutWidgetBase::m_table_name = m_portal->get_table_used(Glib::ustring() /* parent table_name, not
used. */);
+ 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();
@@ -96,8 +97,8 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
if(show_title)
{
Glib::ustring title;
- if(m_portal)
- title = item_get_title(m_portal);
+ if(portal)
+ title = item_get_title(portal);
m_Label.set_markup(UiUtils::bold_message(title));
m_Label.show();
@@ -115,11 +116,11 @@ bool Box_Data_Calendar_Related::init_db_details(const Glib::ustring& parent_tabl
m_calendar.set_margin_top(0);
}
- if(m_portal)
+ if(portal)
{
auto document = get_document();
m_key_field = DbUtils::get_fields_for_table_one_field(document,
- LayoutWidgetBase::m_table_name, m_portal->get_to_field_used());
+ LayoutWidgetBase::m_table_name, portal->get_to_field_used());
}
else
m_key_field.reset();
@@ -141,7 +142,8 @@ void Box_Data_Calendar_Related::create_layout()
bool Box_Data_Calendar_Related::fill_from_database()
{
- if(!m_portal)
+ const auto portal = get_portal();
+ if(!portal)
return false;
bool result = false;
@@ -170,13 +172,13 @@ bool Box_Data_Calendar_Related::fill_from_database()
Gnome::Gda::Value date_end_value(date_end);
//Add a WHERE clause for this date range:
- auto relationship = m_portal->get_relationship();
+ auto relationship = portal->get_relationship();
Glib::ustring where_clause_to_table_name = relationship->get_to_table();
- auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(m_portal);
+ auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(portal);
const auto date_field_name = derived_portal->get_date_field()->get_name();
- auto relationship_related = m_portal->get_related_relationship();
+ auto relationship_related = portal->get_related_relationship();
if(relationship_related)
{
//Adjust the WHERE clause appropriately for the extra JOIN:
@@ -297,11 +299,13 @@ void Box_Data_Calendar_Related::on_record_added(const Gnome::Gda::Value& primary
{
std::shared_ptr<Field> field_primary_key; //TODO: = m_calendar.get_key_field();
+ const auto portal = get_portal();
+
//Create the link by setting the foreign key
- if(m_key_field && m_portal)
+ if(m_key_field && portal)
{
auto builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
- const auto target_table = m_portal->get_table_used(Glib::ustring() /* not relevant */);
+ const auto target_table = portal->get_table_used(Glib::ustring() /* not relevant */);
builder->set_table(target_table);
builder->add_field_value_as_value(m_key_field->get_name(), m_key_value);
builder->set_where(
@@ -328,7 +332,8 @@ Box_Data_Calendar_Related::type_vecConstLayoutFields Box_Data_Calendar_Related::
{
type_vecConstLayoutFields layout_fields = Box_Data_Portal::get_fields_to_show();
- auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(m_portal);
+ const auto portal = get_portal();
+ const auto derived_portal = std::dynamic_pointer_cast<const LayoutItem_CalendarPortal>(portal);
if(!derived_portal)
{
std::cerr << G_STRFUNC << ": The portal is not a LayoutItem_CalendarPortal.\n";
@@ -388,7 +393,8 @@ void Box_Data_Calendar_Related::prepare_layout_dialog(Dialog_Layout* dialog)
auto related_dialog = dynamic_cast<Dialog_Layout_Calendar_Related*>(dialog);
g_assert(related_dialog);
- auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(m_portal);
+ const auto portal = get_portal();
+ const auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(portal);
if(derived_portal && derived_portal->get_has_relationship_name())
{
related_dialog->init_with_portal(m_layout_name, m_layout_platform, get_document(), derived_portal);
@@ -408,7 +414,8 @@ void Box_Data_Calendar_Related::on_calendar_month_changed()
Glib::ustring Box_Data_Calendar_Related::on_calendar_details(guint year, guint month, guint day)
{
- auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(m_portal);
+ const auto portal = get_portal();
+ const auto derived_portal = std::dynamic_pointer_cast<LayoutItem_CalendarPortal>(portal);
if(!derived_portal)
{
//std::cout << "debug: " << G_STRFUNC << ": date_field is NULL\n";
@@ -453,7 +460,7 @@ Glib::ustring Box_Data_Calendar_Related::on_calendar_details(guint year, guint m
//We iterate over the original list of items from the portal,
//instead of the ones used by the query (m_FieldsShown),
//because we really don't want to show the extra fields (at the end) to the user:
- LayoutGroup::type_list_items items = m_portal->get_items();
+ LayoutGroup::type_list_items items = portal->get_items();
for(const auto& layout_item : items)
{
if(!layout_item)
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 665bbd4..55f05e8 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -60,9 +60,11 @@ Box_Data_List_Related::Box_Data_List_Related()
void Box_Data_List_Related::enable_buttons()
{
+ const auto portal = get_portal();
const bool view_details_possible =
get_has_suitable_record_to_view_details() &&
- (m_portal->get_navigation_type() != LayoutItem_Portal::navigation_type::NONE);
+ portal &&
+ (portal->get_navigation_type() != LayoutItem_Portal::navigation_type::NONE);
// Don't allow the user to go to a record in a hidden table.
// Unless we are on Maemo - then we want to allow editing in a separate window only.
@@ -79,8 +81,9 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
{
m_parent_table = parent_table;
- if(m_portal)
- LayoutWidgetBase::m_table_name = m_portal->get_table_used(Glib::ustring() /* parent table_name, not
used. */);
+ 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();
@@ -94,8 +97,9 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
if(show_title)
{
Glib::ustring title;
- if(m_portal)
- title = item_get_title(m_portal);
+ const auto portal = get_portal();
+ if(portal)
+ title = item_get_title(portal);
m_Label.set_markup(UiUtils::bold_message(title));
m_Label.show();
@@ -119,10 +123,10 @@ bool Box_Data_List_Related::init_db_details(const Glib::ustring& parent_table, b
m_AddDel.set_margin_top(0);
}
- if(m_portal)
+ if(portal)
{
m_key_field = DbUtils::get_fields_for_table_one_field(get_document(),
- LayoutWidgetBase::m_table_name, m_portal->get_to_field_used());
+ LayoutWidgetBase::m_table_name, portal->get_to_field_used());
}
else
m_key_field.reset();
@@ -175,8 +179,9 @@ bool Box_Data_List_Related::fill_from_database()
}
//Prevent addition of new records if that is what the relationship specifies:
- if(allow_add && m_portal && m_portal->get_relationship())
- allow_add = m_portal->get_relationship()->get_auto_create();
+ const auto portal = get_portal();
+ if(allow_add && portal && portal->get_relationship())
+ allow_add = portal->get_relationship()->get_auto_create();
m_AddDel.set_allow_add(allow_add);
@@ -209,8 +214,15 @@ void Box_Data_List_Related::on_adddel_user_requested_edit(const Gtk::TreeModel::
void Box_Data_List_Related::on_adddel_record_changed()
{
+ const auto portal = get_portal();
+ if(!portal)
+ {
+ std::cerr << G_STRFUNC << ": portal is null.\n";
+ return;
+ }
+
//Let parent respond:
- signal_portal_record_changed().emit(m_portal->get_relationship_name());
+ signal_portal_record_changed().emit(portal->get_relationship_name());
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -303,7 +315,8 @@ void Box_Data_List_Related::on_adddel_record_added(const Gtk::TreeModel::iterato
auto field_primary_key = m_AddDel.get_key_field();
//Create the link by setting the foreign key
- if(m_key_field && m_portal)
+ const auto portal = get_portal();
+ if(m_key_field && portal)
{
make_record_related(primary_key_value);
@@ -360,7 +373,14 @@ void Box_Data_List_Related::prepare_layout_dialog(Dialog_Layout* dialog)
auto related_dialog = dynamic_cast<Dialog_Layout_List_Related*>(dialog);
g_assert(related_dialog);
- related_dialog->init_with_portal(m_layout_name, m_layout_platform, get_document(), m_portal,
m_parent_table);
+ const auto portal = get_portal();
+ if(!portal)
+ {
+ std::cerr << G_STRFUNC << ": portal is null.\n";
+ return;
+ }
+
+ related_dialog->init_with_portal(m_layout_name, m_layout_platform, get_document(), portal, m_parent_table);
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
@@ -386,8 +406,9 @@ Document::type_list_layout_groups Box_Data_List_Related::create_layout_get_layou
//Do not use get_data_layout_groups(m_layout_name).
//instead do this:
- if(m_portal)
- result.emplace_back(m_portal);
+ const auto portal = get_portal();
+ if(portal)
+ result.emplace_back(portal);
return result;
}
@@ -409,12 +430,13 @@ void Box_Data_List_Related::create_layout()
//m_AddDel.set_columns_count(m_Fields.size());
m_AddDel.set_table_name(Base_DB_Table::m_table_name);
-
- if(m_portal)
+
+ const auto portal = get_portal();
+ if(portal)
{
gulong rows_count_min = 0;
gulong rows_count_max = 0;
- m_portal->get_rows_count(rows_count_min, rows_count_max);
+ portal->get_rows_count(rows_count_min, rows_count_max);
if(rows_count_min) //0 is a silly value.
m_AddDel.set_height_rows(rows_count_min, rows_count_max);
}
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index 494ffbb..c4d3202 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -68,13 +68,14 @@ void Box_Data_Portal::make_record_related(const Gnome::Gda::Value& related_recor
std::cerr << G_STRFUNC << ": m_key_value was empty.\n";
}
-
- if(!m_portal)
+ const auto portal = get_portal();
+ if (!portal)
{
- std::cerr << G_STRFUNC << ": m_portal was null.\n";
+ std::cerr << G_STRFUNC << ": portal is null\n";
+ return;
}
- const auto target_table = m_portal->get_table_used(Glib::ustring() /* not relevant */);
+ const auto target_table = portal->get_table_used(Glib::ustring() /* not relevant */);
auto builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builder->set_table(target_table);
builder->add_field_value_as_value(m_key_field->get_name(), m_key_value);
@@ -104,8 +105,9 @@ bool Box_Data_Portal::init_db_details(const std::shared_ptr<const LayoutItem_Por
Glib::ustring Box_Data_Portal::get_title(const Glib::ustring& locale) const
{
- if(m_portal)
- return m_portal->get_title_or_name(locale);
+ auto portal = get_portal();
+ if(portal)
+ return portal->get_title_or_name(locale);
else
{
//Note to translators: This text is shown instead of a table title, when the table has not yet been
chosen.
@@ -116,8 +118,9 @@ Glib::ustring Box_Data_Portal::get_title(const Glib::ustring& locale) const
Glib::ustring Box_Data_Portal::get_title_singular(const Glib::ustring& locale) const
{
Glib::ustring relationship_title;
- if(m_portal && m_portal->get_has_relationship_name())
- relationship_title = m_portal->get_title_singular_used(Glib::ustring() /* parent title - not relevant
*/, locale);
+ const auto portal = get_portal();
+ if(portal && portal->get_has_relationship_name())
+ relationship_title = portal->get_title_singular_used(Glib::ustring() /* parent title - not relevant */,
locale);
else
{
//Note to translators: This text is shown instead of a table title, when the table has not yet been
chosen.
@@ -132,13 +135,13 @@ bool Box_Data_Portal::refresh_data_from_database_with_foreign_key(const Gnome::G
m_key_value = foreign_key_value;
//std::cout << "debug: " << G_STRFUNC << ": m_key_value=" << m_key_value.to_string() << std::endl;
-
- if(m_key_field && m_portal)
+ const auto portal = get_portal();
+ if(m_key_field && portal)
{
if(!Conversions::value_is_empty(m_key_value))
{
FoundSet found_set;
- set_found_set_where_clause_for_portal(found_set, m_portal, m_key_value);
+ set_found_set_where_clause_for_portal(found_set, portal, m_key_value);
//std::cout << "debug: " << G_STRFUNC << ": where_clause=" << found_set.m_where_clause << std::endl;
return Box_Data::refresh_data_from_database_with_where_clause(found_set);
@@ -177,33 +180,48 @@ std::shared_ptr<const Field> Box_Data_Portal::get_key_field() const
//TODO: refactor: Remove this because it is never called?
void Box_Data_Portal::on_record_deleted(const Gnome::Gda::Value& /* primary_key_value */)
{
+ const auto portal = get_portal();
+ if (!portal)
+ {
+ std::cerr << G_STRFUNC << ": portal is null\n";
+ return;
+ }
+
//Allow the parent record (Details view) to recalculate aggregations:
- signal_portal_record_changed().emit(m_portal->get_relationship_name());
+ signal_portal_record_changed().emit(portal->get_relationship_name());
}
void Box_Data_Portal::on_record_added(const Gnome::Gda::Value& /* primary_key_value */, const
Gtk::TreeModel::iterator& /* row */)
{
+ const auto portal = get_portal();
+ if (!portal)
+ {
+ std::cerr << G_STRFUNC << ": portal is null\n";
+ return;
+ }
+
//Allow the parent record (Details view) to recalculate aggregations:
- signal_portal_record_changed().emit(m_portal->get_relationship_name());
+ signal_portal_record_changed().emit(portal->get_relationship_name());
}
Box_Data_Portal::type_vecConstLayoutFields Box_Data_Portal::get_fields_to_show() const
{
const auto document = get_document();
- if(document && m_portal)
+ const auto portal = get_portal();
+ if(document && portal)
{
Document::type_list_const_layout_groups mapGroups;
- mapGroups.emplace_back(m_portal);
+ mapGroups.emplace_back(portal);
- auto relationship = m_portal->get_relationship();
+ auto relationship = portal->get_relationship();
if(relationship)
{
- auto result = Utils::get_table_fields_to_show_for_sequence(document,
m_portal->get_table_used(Glib::ustring() /* not relevant */), mapGroups);
+ auto result = Utils::get_table_fields_to_show_for_sequence(document,
portal->get_table_used(Glib::ustring() /* not relevant */), mapGroups);
//If the relationship does not allow editing, then mark all these fields as non-editable:
//TODO: Prevent this in some other way:
/*
- if(!(m_portal->get_relationship_used_allows_edit()))
+ if(!(portal->get_relationship_used_allows_edit()))
{
for(const auto& item : result)
{
@@ -232,8 +250,11 @@ void Box_Data_Portal::on_dialog_layout_hide()
bool Box_Data_Portal::get_has_suitable_record_to_view_details() const
{
- if(!m_portal)
+ const auto portal = get_portal();
+ if (!portal)
+ {
return false;
+ }
const auto document = get_document();
if(!document)
@@ -241,7 +262,7 @@ bool Box_Data_Portal::get_has_suitable_record_to_view_details() const
Glib::ustring navigation_table_name;
std::shared_ptr<const UsesRelationship> navigation_relationship; //Ignored.
- m_portal->get_suitable_table_to_view_details(navigation_table_name, navigation_relationship, document);
+ portal->get_suitable_table_to_view_details(navigation_table_name, navigation_relationship, document);
return !(navigation_table_name.empty());
}
@@ -252,7 +273,8 @@ void Box_Data_Portal::get_suitable_record_to_view_details(const Gnome::Gda::Valu
table_name = Glib::ustring();
table_primary_key_value = Gnome::Gda::Value();
- if(!m_portal)
+ const auto portal = get_portal();
+ if(!portal)
return;
const auto document = get_document();
@@ -261,7 +283,7 @@ void Box_Data_Portal::get_suitable_record_to_view_details(const Gnome::Gda::Valu
Glib::ustring navigation_table_name;
std::shared_ptr<const UsesRelationship> navigation_relationship;
- m_portal->get_suitable_table_to_view_details(navigation_table_name, navigation_relationship, document);
+ portal->get_suitable_table_to_view_details(navigation_table_name, navigation_relationship, document);
//if(navigation_relationship && navigation_relationship->get_relationship())
// std::cout << "debug: navigation_relationship=" <<
navigation_relationship->get_relationship()->get_name() << std::endl;
@@ -290,7 +312,7 @@ void Box_Data_Portal::get_suitable_record_to_view_details(const Gnome::Gda::Valu
fieldsToGet.emplace_back(layout_item);
//For instance "invoice_line_id" if this is a portal to an "invoice_lines" table:
- const auto related_table = m_portal->get_table_used(Glib::ustring() /* not relevant */);
+ const auto related_table = portal->get_table_used(Glib::ustring() /* not relevant */);
auto key_field = get_field_primary_key_for_table(related_table);
//std::cout << "DEBUG: related table=" << related_table << ", whose primary_key=" << key_field->get_name()
<< ", with value=" << primary_key_value.to_string() << "getting value for: " <<
layout_item->get_layout_display_name() << std::endl;
@@ -343,8 +365,9 @@ Document::type_list_layout_groups Box_Data_Portal::create_layout_get_layout()
{
Document::type_list_layout_groups result;
- if(m_portal)
- result.emplace_back(m_portal);
+ const auto portal = get_portal();
+ if(portal)
+ result.emplace_back(portal);
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]