glom r1910 - in trunk: . glom glom/libglom glom/mode_data glom/utility_widgets



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

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

* glom/utlity_widgets/datawidget.cc: Constructor: Show the Open button,
(but not Find) for related fields that are primary keys, so we can
navigate to that record.
* glom/mode_data/box_data_details.cc:
on_flowtable_field_open_details_requested(): Navigate to the
appropriate record in the appropriate table for this type of Open
button.
* glom/base_db.cc: fill_full_field_details(): Avoid crashes.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/libglom/connectionpool.cc
   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:29 2009
@@ -1824,8 +1824,19 @@
 
 void Base_DB::fill_full_field_details(const Glib::ustring& parent_table_name, sharedptr<LayoutItem_Field>& layout_item)
 {
+  if(!layout_item)
+  {
+    std::cerr << "Base_DB::fill_full_field_details(): layout_item was null." << std::endl;
+  }
+
   const Glib::ustring table_name = layout_item->get_table_used(parent_table_name);
 
+  Document_Glom* document = get_document();
+  if(!document)
+  {
+    std::cerr << "Base_DB::fill_full_field_details(): document was null." << std::endl;
+  }
+
   layout_item->set_full_field_details( get_document()->get_field(table_name, layout_item->get_name()) );
 }
 

Modified: trunk/glom/libglom/connectionpool.cc
==============================================================================
--- trunk/glom/libglom/connectionpool.cc	(original)
+++ trunk/glom/libglom/connectionpool.cc	Fri Feb 20 13:39:29 2009
@@ -852,7 +852,7 @@
 
   //If we crash while running (unlikely, hopefully), then try to cleanup.
   //Comment this out if you want to see the backtrace in a debugger.
-  previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
+  //previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
 
   return true;
 }

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:29 2009
@@ -641,10 +641,24 @@
   if(Conversions::value_is_empty(field_value))
     return; //Ignore empty ID fields.
 
+  //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)
   {
     signal_requested_related_details().emit(relationship->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)
+  {
+    signal_requested_related_details().emit(layout_field->get_table_used(m_table_name), 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:29 2009
@@ -195,12 +195,27 @@
     apply_formatting(*m_child, field->get_formatting_used());
     
     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;
+    //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;
+
 
     Gtk::HBox* hbox_parent = 0; //Only used if there are extra widgets.
 
-    const bool with_extra_widgets = field_used_in_relationship_to_one || (glom_type == Field::TYPE_DATE);
+    const bool with_extra_widgets = field_used_in_relationship_to_one || field_is_related_primary_key || (glom_type == Field::TYPE_DATE);
     if(with_extra_widgets)
     {
       hbox_parent = Gtk::manage( new Gtk::HBox() ); //We put the child (and any extra stuff) in this:
@@ -222,18 +237,24 @@
       button_date->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_choose_date));
     }
 
-    if(field_used_in_relationship_to_one && hbox_parent)
+    if((field_used_in_relationship_to_one || field_is_related_primary_key) && hbox_parent)
     {
-      //Add buttons for related record navigation:
+      //Add a button for related record navigation:
       Gtk::Button* button_go_to_details = Gtk::manage(new Gtk::Button(Gtk::Stock::OPEN));
       button_go_to_details->set_tooltip_text(_("Open the record identified by this ID, in the other table."));
       hbox_parent->pack_start(*button_go_to_details);
       button_go_to_details->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_open_details));
 
-      Gtk::Button* button_select = Gtk::manage(new Gtk::Button(Gtk::Stock::FIND));
-      button_select->set_tooltip_text(_("Enter search criteria to identify records in the other table, to choose an ID for this field."));
-      hbox_parent->pack_start(*button_select);
-      button_select->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_select_id));
+      //Add a 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)
+      {
+        Gtk::Button* button_select = Gtk::manage(new Gtk::Button(Gtk::Stock::FIND));
+        button_select->set_tooltip_text(_("Enter search criteria to identify records in the other table, to choose an ID for this field."));
+        hbox_parent->pack_start(*button_select);
+        button_select->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_select_id));
+      }
     }
 
     if(!child_added)



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