[glom] libglom::layout_field_should_have_navigation(): Return Relationship not bool.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] libglom::layout_field_should_have_navigation(): Return Relationship not bool.
- Date: Tue, 27 Sep 2011 10:07:25 +0000 (UTC)
commit cb515a74e3204ec8744bd96ed7101bc766007383
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Sep 27 12:05:40 2011 +0200
libglom::layout_field_should_have_navigation(): Return Relationship not bool.
* glom/libglom/db_utils.[h|cc]: layout_field_should_have_navigation():
Make field_used_in_relationship_to_one() be a Relationship so it can
be used for actual navigation.
Also require that the LayoutItem_Field has full field information, instead
of updating it, so that it can be const.
* glom/mode_data/datawidget/datawidget.cc: Constructor: Adapted.
* glom/mode_data/box_data_details.cc:
on_flowtable_field_open_details_requested(): Use it here instead of the
copy/pasted code.
ChangeLog | 14 ++++++++++++++
glom/libglom/db_utils.cc | 11 ++++-------
glom/libglom/db_utils.h | 9 +++++++--
glom/mode_data/box_data_details.cc | 22 ++++++++++++++--------
glom/mode_data/datawidget/datawidget.cc | 6 +++++-
5 files changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8cc9393..e1119f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2011-09-27 Murray Cumming <murrayc murrayc com>
+ libglom::layout_field_should_have_navigation(): Return Relationship not bool.
+
+ * glom/libglom/db_utils.[h|cc]: layout_field_should_have_navigation():
+ Make field_used_in_relationship_to_one() be a Relationship so it can
+ be used for actual navigation.
+ Also require that the LayoutItem_Field has full field information, instead
+ of updating it, so that it can be const.
+ * glom/mode_data/datawidget/datawidget.cc: Constructor: Adapted.
+ * glom/mode_data/box_data_details.cc:
+ on_flowtable_field_open_details_requested(): Use it here instead of the
+ copy/pasted code.
+
+2011-09-27 Murray Cumming <murrayc murrayc com>
+
Add libglom::layout_field_should_have_navigation().
* glom/mode_data/datawidget/datawidget.cc: Constructor: Moved decision code
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index 4b89292..2176403 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1624,10 +1624,10 @@ void layout_item_fill_field_details(Document* document, const Glib::ustring& par
layout_item->set_full_field_details( document->get_field(table_name, layout_item->get_name()) );
}
-bool layout_field_should_have_navigation(const Glib::ustring& table_name, const sharedptr<LayoutItem_Field>& layout_item, const Document* document, bool& field_used_in_relationship_to_one)
+bool layout_field_should_have_navigation(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& layout_item, const Document* document, sharedptr<Relationship>& field_used_in_relationship_to_one)
{
//Initialize output parameter:
- field_used_in_relationship_to_one = false;
+ field_used_in_relationship_to_one = sharedptr<Relationship>();
if(!document)
{
@@ -1646,16 +1646,13 @@ bool layout_field_should_have_navigation(const Glib::ustring& table_name, const
std::cerr << G_STRFUNC << ": layout_item was null." << std::endl;
return false;
}
-
- layout_item->set_full_field_details(
- document->get_field(layout_item->get_table_used(table_name), layout_item->get_name()) ); //Otherwise get_primary_key() returns false always.
-
//Check whether the field controls a relationship,
//meaning it identifies a record in another table.
- field_used_in_relationship_to_one =
+ sharedptr<const Relationship> const_relationship =
document->get_field_used_in_relationship_to_one(table_name, layout_item);
//std::cout << "DEBUG: table_name=" << table_name << ", table_used=" << field->get_table_used(table_name) << ", field=" << field->get_name() << ", field_used_in_relationship_to_one=" << field_used_in_relationship_to_one << std::endl;
+ field_used_in_relationship_to_one = sharedptr<Relationship>::cast_const(const_relationship); //This is just because we can't seem to have a sharedptr<const Relationship>& output parameter.
//Check whether the field identifies a record in another table
//just because it is a primary key in that table:
diff --git a/glom/libglom/db_utils.h b/glom/libglom/db_utils.h
index 5c013bd..a3439df 100644
--- a/glom/libglom/db_utils.h
+++ b/glom/libglom/db_utils.h
@@ -105,12 +105,17 @@ Gnome::Gda::Value get_next_auto_increment_value(const Glib::ustring& table_name,
void layout_item_fill_field_details(Document* document, const Glib::ustring& parent_table_name, sharedptr<LayoutItem_Field>& layout_item);
+
+//TODO: It would be nice to use sharedptr<const Relationship>& instead of sharedptr<Relationship>&,
+//but it does not seem possible to pass a sharedptr<const Relationship> for a sharedptr<const Relationship>&.
+
/** Decides whether a field should have an Open button next to it,
* allowing the user to navigate to a related record.
*
- * @param field_used_in_relationship_to_one Whether the field identifies a single record, so a Find button would also make sense, to choose the ID, in editing mode.
+ * @param layout_item A field on a layout. This must have full field details.
+ * @param field_used_in_relationship_to_one A relationship, if the field identifies a single record, so a Find button would also make sense, to choose the ID, in editing mode.
*/
-bool layout_field_should_have_navigation(const Glib::ustring& table_name, const sharedptr<LayoutItem_Field>& layout_item, const Document* document, bool& field_used_in_relationship_to_one);
+bool layout_field_should_have_navigation(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& layout_item, const Document* document, sharedptr<Relationship>& field_used_in_relationship_to_one);
} //namespace DbUtils
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index b4f578b..8bfb30a 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -642,22 +642,28 @@ void Box_Data_Details::on_flowtable_field_open_details_requested(const sharedptr
if(Conversions::value_is_empty(field_value))
return; //Ignore empty ID fields.
+ //Updating doesn't seem necessary. The field details seem to be full already.
+ //Update the field details from the document:
+ ////sharedptr<LayoutItem_Field> unconst_field = sharedptr<LayoutItem_Field>::cast_const(layout_field); //A hack, because layout_field_should_have_navigation() needs to get full field details.
+ //unconst_field->set_full_field_details(
+ // document->get_field(field->get_table_used(table_name), field->get_name()) ); //Otherwise get_primary_key() returns false always.
+
+ sharedptr<Relationship> field_used_in_relationship_to_one;
+ const bool has_open_button =
+ DbUtils::layout_field_should_have_navigation(m_table_name, layout_field, get_document(),
+ field_used_in_relationship_to_one);
+
//If it's a simple field that is part of a relationship,
//identifying a related record.
- sharedptr<const Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layout_field);
- if(relationship)
+ if(field_used_in_relationship_to_one)
{
- signal_requested_related_details().emit(relationship->get_to_table(), field_value);
+ signal_requested_related_details().emit(field_used_in_relationship_to_one->get_to_table(), field_value);
return;
}
//If it is a related field that is a primary key,
//meaning it identifies a record in another table:
- sharedptr<const Field> field_info = layout_field->get_full_field_details();
- const bool field_is_related_primary_key =
- layout_field->get_has_relationship_name() &&
- field_info && field_info->get_primary_key();
- if(field_is_related_primary_key)
+ if(has_open_button)
{
signal_requested_related_details().emit(layout_field->get_table_used(m_table_name), field_value);
}
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index 839df6a..4b13036 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -176,7 +176,11 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
bool child_added = false; //Don't use an extra container unless necessary.
- bool field_used_in_relationship_to_one = false;
+ //Update the field details from the document:
+ field->set_full_field_details(
+ document->get_field(field->get_table_used(table_name), field->get_name()) ); //Otherwise get_primary_key() returns false always.
+
+ sharedptr<Relationship> field_used_in_relationship_to_one;
const bool add_open_button =
DbUtils::layout_field_should_have_navigation(table_name, field, document,
field_used_in_relationship_to_one);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]