glom r1909 - in trunk: . glom glom/libglom/document glom/mode_data glom/utility_widgets



Author: murrayc
Date: Fri Feb 20 13:39:24 2009
New Revision: 1909
URL: http://svn.gnome.org/viewvc/glom?rev=1909&view=rev

Log:
2009-02-20  Murray Cumming  <murrayc murrayc com>

* glom/libglom/document/document_glom.[h|cc]:
get_field_used_in_relationship_to_one(): Make this take a
LayoutItem_Field instead of just a field name.
* glom/utlity_widgets/datawidget.cc: Constructor: adapt, so we add
Open and Find buttons for related fields too when appropriate.
* glom/base_db.cc: Adapt to API change.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/libglom/document/document_glom.cc
   trunk/glom/libglom/document/document_glom.h
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/utility_widgets/datawidget.cc

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Fri Feb 20 13:39:24 2009
@@ -2963,7 +2963,7 @@
     sharedptr<const LayoutItem_Field> field = sharedptr<const LayoutItem_Field>::cast_dynamic(*iter);
     if(field && !(field->get_has_relationship_name()))
     {
-      sharedptr<Relationship> relationship = document->get_field_used_in_relationship_to_one(parent_table_name, field->get_name());
+      sharedptr<const Relationship> relationship = document->get_field_used_in_relationship_to_one(parent_table_name, field);
       if(relationship)
       {
         const Glib::ustring table_name = relationship->get_to_table();

Modified: trunk/glom/libglom/document/document_glom.cc
==============================================================================
--- trunk/glom/libglom/document/document_glom.cc	(original)
+++ trunk/glom/libglom/document/document_glom.cc	Fri Feb 20 13:39:24 2009
@@ -3672,30 +3672,41 @@
   return false;
 }
 
-sharedptr<Relationship> Document_Glom::get_field_used_in_relationship_to_one(const Glib::ustring& table_name, const Glib::ustring& field_name) const
+sharedptr<Relationship> Document_Glom::get_field_used_in_relationship_to_one(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& layout_field) const
 {
   sharedptr<Relationship> result;
 
-  type_tables::const_iterator iterFind = m_tables.find(table_name);
-  if(iterFind != m_tables.end())
+  if(!layout_field)
+  {
+    std::cerr << "Document::get_field_used_in_relationship_to_one(): layout_field was null" << std::endl;
+    return result; 
+  }
+
+  const Glib::ustring table_used = layout_field->get_table_used(table_name);
+  type_tables::const_iterator iterFind = m_tables.find(table_used);
+  if(iterFind == m_tables.end())
+  {
+    std::cerr << "Document::get_field_used_in_relationship_to_one(): table not found:" << table_used << std::endl;
+    return result; 
+  }
+
+  //Look at each relationship:
+  const Glib::ustring field_name = layout_field->get_name();
+  for(type_vecRelationships::const_iterator iterRel = iterFind->second.m_relationships.begin(); iterRel != iterFind->second.m_relationships.end(); ++iterRel)
   {
-    //Look at each relationship:
-    for(type_vecRelationships::const_iterator iterRel = iterFind->second.m_relationships.begin(); iterRel != iterFind->second.m_relationships.end(); ++iterRel)
+    sharedptr<Relationship> relationship = *iterRel;
+    if(relationship)
     {
-      sharedptr<Relationship> relationship = *iterRel;
-      if(relationship)
+      //If the relationship uses the field
+      if(relationship->get_from_field() == field_name)
       {
-        //If the relationship uses the field
-        if(relationship->get_from_field() == field_name)
+        //if the to_table is not hidden:
+        if(!get_table_is_hidden(relationship->get_to_table()))
         {
-          //if the to_table is not hidden:
-          if(!get_table_is_hidden(relationship->get_to_table()))
+          //TODO_Performance: The use of this convenience method means we get the full relationship information again:
+          if(get_relationship_is_to_one(table_name, relationship->get_name()))
           {
-            //TODO_Performance: The use of this convenience method means we get the full relationship information again:
-            if(get_relationship_is_to_one(table_name, relationship->get_name()))
-            {
-              result = relationship;
-            }
+           result = relationship;
           }
         }
       }

Modified: trunk/glom/libglom/document/document_glom.h
==============================================================================
--- trunk/glom/libglom/document/document_glom.h	(original)
+++ trunk/glom/libglom/document/document_glom.h	Fri Feb 20 13:39:24 2009
@@ -173,8 +173,7 @@
   /** Returns whether the field is the from-field in a to-one relationship.
    * @see get_relationship_is_to_one(). Ignores hidden tables.
    */
-  sharedptr<Relationship> get_field_used_in_relationship_to_one(const Glib::ustring& table_name, const Glib::ustring& field_name) const;
-
+  sharedptr<Relationship> get_field_used_in_relationship_to_one(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& layout_field) const;
 
   typedef std::vector< sharedptr<Field> > type_vecFields;
   type_vecFields get_table_fields(const Glib::ustring& table_name) const;

Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc	(original)
+++ trunk/glom/mode_data/box_data_details.cc	Fri Feb 20 13:39:24 2009
@@ -641,7 +641,7 @@
   if(Conversions::value_is_empty(field_value))
     return; //Ignore empty ID fields.
 
-  sharedptr<Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layout_field->get_name());
+  sharedptr<const Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layout_field);
   if(relationship)
   {
     signal_requested_related_details().emit(relationship->get_to_table(), field_value);

Modified: trunk/glom/utility_widgets/datawidget.cc
==============================================================================
--- trunk/glom/utility_widgets/datawidget.cc	(original)
+++ trunk/glom/utility_widgets/datawidget.cc	Fri Feb 20 13:39:24 2009
@@ -195,7 +195,8 @@
     apply_formatting(*m_child, field->get_formatting_used());
     
     bool child_added = false; //Don't use an extra container unless necessary.
-    const bool field_used_in_relationship_to_one = document->get_field_used_in_relationship_to_one(table_name, field->get_name());
+    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;
 
     Gtk::HBox* hbox_parent = 0; //Only used if there are extra widgets.
 
@@ -838,10 +839,10 @@
 
     //Discover the related table, in the relationship that uses this ID field:
     Glib::ustring related_table_name;
-    sharedptr<LayoutItem_Field> layoutField = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+    sharedptr<const LayoutItem_Field> layoutField = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
     if(layoutField)
     {
-      sharedptr<Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layoutField->get_name());
+      sharedptr<const Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layoutField);
       if(relationship)
         related_table_name = relationship->get_to_table();
     }
@@ -851,7 +852,7 @@
     dialog->init_db_details(related_table_name, get_document()->get_active_layout_platform());
 
 
-    int response = dialog->run();
+    const int response = dialog->run();
     dialog->hide();
     if(response == Gtk::RESPONSE_OK)
     {



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