[glom] Add libglom::layout_field_should_have_navigation().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Add libglom::layout_field_should_have_navigation().
- Date: Tue, 27 Sep 2011 09:32:38 +0000 (UTC)
commit 2664eb95399c3e05ebd575063c553e58cda5a490
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Sep 27 11:29:52 2011 +0200
Add libglom::layout_field_should_have_navigation().
* glom/mode_data/datawidget/datawidget.cc: Constructor: Moved decision code
from here to here:
* glom/libglom/db_utils.[h|cc]: Added layout_field_should_have_navigation().
ChangeLog | 8 +++++
glom/libglom/db_utils.cc | 44 +++++++++++++++++++++++++++++++
glom/libglom/db_utils.h | 7 +++++
glom/mode_data/datawidget/datawidget.cc | 27 +++++-------------
4 files changed, 67 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c318312..8cc9393 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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
+ from here to here:
+ * glom/libglom/db_utils.[h|cc]: Added layout_field_should_have_navigation().
+
2011-09-26 Murray Cumming <murrayc murrayc com>
Document: Use CSS3 formatting for colors, via Gdk::RGBA.
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index a340aac..4b89292 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1624,6 +1624,50 @@ 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)
+{
+ //Initialize output parameter:
+ field_used_in_relationship_to_one = false;
+
+ if(!document)
+ {
+ std::cerr << G_STRFUNC << ": document was null." << std::endl;
+ return false;
+ }
+
+ if(table_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": table_name was empty." << std::endl;
+ return false;
+ }
+
+ if(!layout_item)
+ {
+ 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 =
+ 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;
+
+ //Check whether the field identifies a record in another table
+ //just because it is a primary key in that table:
+ const sharedptr<const Field> field_info = layout_item->get_full_field_details();
+ const bool field_is_related_primary_key =
+ layout_item->get_has_relationship_name() &&
+ field_info && field_info->get_primary_key();
+ //std::cout << "DEBUG: field->get_has_relationship_name()=" << field->get_has_relationship_name() << ", field_info->get_primary_key()=" << field_info->get_primary_key() << ", field_is_related_primary_key=" << field_is_related_primary_key << std::endl;
+
+ return field_used_in_relationship_to_one || field_is_related_primary_key;
+}
+
} //namespace DbUtils
diff --git a/glom/libglom/db_utils.h b/glom/libglom/db_utils.h
index c1e9b5f..5c013bd 100644
--- a/glom/libglom/db_utils.h
+++ b/glom/libglom/db_utils.h
@@ -105,6 +105,13 @@ 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);
+/** 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.
+ */
+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);
+
} //namespace DbUtils
} //namespace Glom
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index 8ad5d4c..839df6a 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -35,6 +35,7 @@
#include <glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
+#include <libglom/db_utils.h>
#include <glibmm/i18n.h>
@@ -175,26 +176,14 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
bool child_added = false; //Don't use an extra container unless necessary.
- //Check whether the field controls a relationship,
- //meaning it identifies a record in another table.
- const bool field_used_in_relationship_to_one = document->get_field_used_in_relationship_to_one(table_name, field);
- //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;
-
- //Check whether the field identifies a record in another table
- //just because it is a primary key in that table:
- bool field_is_related_primary_key = false;
- if(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<const Field> field_info = field->get_full_field_details();
- field_is_related_primary_key =
- field->get_has_relationship_name() &&
- field_info && field_info->get_primary_key();
- //std::cout << "DEBUG: field->get_has_relationship_name()=" << field->get_has_relationship_name() << ", field_info->get_primary_key()=" << field_info->get_primary_key() << ", field_is_related_primary_key=" << field_is_related_primary_key << std::endl;
-
+ bool field_used_in_relationship_to_one = false;
+ const bool add_open_button =
+ DbUtils::layout_field_should_have_navigation(table_name, field, document,
+ field_used_in_relationship_to_one);
Gtk::Box* hbox_parent = 0; //Only used if there are extra widgets.
- const bool with_extra_widgets = field_used_in_relationship_to_one || field_is_related_primary_key || (glom_type == Field::TYPE_DATE);
+ const bool with_extra_widgets = field_used_in_relationship_to_one || add_open_button || (glom_type == Field::TYPE_DATE);
if(with_extra_widgets)
{
hbox_parent = Gtk::manage( new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) ); //We put the child (and any extra stuff) in this:
@@ -217,7 +206,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
button_date->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_choose_date));
}
- if((field_used_in_relationship_to_one || field_is_related_primary_key) && hbox_parent)
+ if(hbox_parent && add_open_button)
{
//Add a button for related record navigation:
m_button_go_to_details = Gtk::manage(new Gtk::Button(Gtk::Stock::OPEN));
@@ -225,7 +214,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
hbox_parent->pack_start(*m_button_go_to_details, Gtk::PACK_SHRINK);
m_button_go_to_details->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_open_details));
- //Add a button to make it easier to choose an ID for this field.
+ //Add an additional button to make it easier to choose an ID for this field.
//Don't add this for simple related primary key fields, because they
//can generally not be edited via another table's layout.
if(field_used_in_relationship_to_one)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]