[glom/ownership] More not taking a shared_ptr<> when the function doesn't share ownership.



commit 06e7d9897d46de864c5adf0966741a1faafa5b79
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Feb 9 17:57:13 2016 +0100

    More not taking a shared_ptr<> when the function doesn't share ownership.
    
    As suggested by:
    
    Bjarne Stroustrup: 2015: Writing Good C++14:
    video: https://www.youtube.com/watch?v=1OEu9C51K2A
    slide: 
https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Stroustrup%20-%20CppCon%202015%20keynote.pdf
    
    C++ Core Guidelines:
    "F.7: For general use, take T* or T& arguments rather than smart pointers":
     
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#f7-for-general-use-take-t-or-t-arguments-rather-than-smart-pointers

 glom/base_db.cc                                    |   50 ++++++-------
 glom/base_db.h                                     |    6 +-
 glom/base_db_table_data.cc                         |   14 ++--
 glom/base_db_table_data.h                          |    2 +-
 glom/import_csv/dialog_import_csv_progress.cc      |    8 +-
 glom/import_csv/dialog_import_csv_progress.h       |    4 +-
 .../data_structure/layout/layoutitem_field.cc      |    6 +-
 .../data_structure/layout/layoutitem_field.h       |   12 ++--
 glom/libglom/utils.cc                              |   10 +-
 glom/libglom/utils.h                               |    4 +-
 glom/mode_data/box_data.cc                         |    2 +-
 glom/mode_data/box_data_details.cc                 |   28 ++++---
 glom/mode_data/box_data_details.h                  |    6 +-
 glom/mode_data/box_data_list.cc                    |   10 +-
 glom/mode_data/box_data_list.h                     |    6 +-
 glom/mode_data/box_data_list_related.cc            |    4 +-
 glom/mode_data/datawidget/cellcreation.cc          |    5 +-
 glom/mode_data/datawidget/cellrenderer_dblist.cc   |    2 +-
 glom/mode_data/datawidget/cellrenderer_dblist.h    |    2 +-
 glom/mode_data/datawidget/combo.cc                 |    2 +-
 glom/mode_data/datawidget/combo.h                  |    2 +-
 .../mode_data/datawidget/combo_as_radio_buttons.cc |    2 +-
 glom/mode_data/datawidget/combo_as_radio_buttons.h |    2 +-
 glom/mode_data/datawidget/combochoices.cc          |    2 +-
 glom/mode_data/datawidget/combochoices.h           |    2 +-
 .../datawidget/combochoiceswithtreemodel.cc        |    4 +-
 .../datawidget/combochoiceswithtreemodel.h         |    2 +-
 glom/mode_data/datawidget/datawidget.cc            |    2 +-
 glom/mode_data/db_adddel/db_adddel.cc              |   78 ++++++++-----------
 glom/mode_data/db_adddel/db_adddel.h               |   25 +++---
 glom/mode_data/flowtablewithfields.cc              |   34 ++++-----
 glom/mode_data/flowtablewithfields.h               |   20 +++---
 glom/mode_design/layout/dialog_choose_field.cc     |    4 +-
 tests/test_layout_item_field.cc                    |   70 +++++++++---------
 tests/test_selfhosting_new_then_choices.cc         |    2 +-
 35 files changed, 214 insertions(+), 220 deletions(-)
---
diff --git a/glom/base_db.cc b/glom/base_db.cc
index e1ddd49..12269ea 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -60,24 +60,18 @@ namespace Glom
  */
 template
 <typename T_Container>
-auto find_if_layout_item_is_equal(T_Container& container, const typename T_Container::value_type& 
layout_item) -> decltype(container.begin())
+auto find_if_layout_item_is_equal(T_Container& container, const typename 
T_Container::value_type::element_type& layout_item) -> decltype(container.begin())
 {
+  //TODO: Try to capture layout_item in the lambda as const &.
   return Utils::find_if(container,
     [&layout_item](const typename T_Container::value_type& element)
     {
       //Assume that element is a shared_ptr<>.
 
-      if(!layout_item && !element)
-        return true;
+      if(!element)
+        return false; //layout_item cannot (should not) be null because it is a reference.
 
-      if(element && layout_item)
-      {
-        return layout_item->is_same_field(element);
-        //std::cout << "          debug: name1=" << layout_item->get_name() << ", name2=" << 
element->get_name() << ", result=" << result << std::endl;
-        //return result;
-      }
-      else
-        return false;
+      return layout_item.is_same_field(*element);
     }
   );
 }
@@ -885,7 +879,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
           layout_item->set_full_field_details(field);
 
           //show it:
-          set_entered_field_data(layout_item, calc_progress_refreshed.m_value ); //TODO: If this record is 
shown.
+          set_entered_field_data(*layout_item, calc_progress_refreshed.m_value ); //TODO: If this record is 
shown.
 
           //Add it to the database (even if it is not shown in the view)
           //Using true for the last parameter means we use existing calculations where possible,
@@ -910,13 +904,13 @@ Base_DB::type_map_fields Base_DB::get_record_field_values_for_calculation(const
   return DbUtils::get_record_field_values(document, table_name, primary_key, primary_key_value);
 }
 
-void Base_DB::set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& /* field */, const 
Gnome::Gda::Value& /* value */)
+void Base_DB::set_entered_field_data(const LayoutItem_Field& /* field */, const Gnome::Gda::Value& /* value 
*/)
 {
   //Override this.
 }
 
 
-void Base_DB::set_entered_field_data(const Gtk::TreeModel::iterator& /* row */, const std::shared_ptr<const 
LayoutItem_Field>& /* field */, const Gnome::Gda::Value& /* value */)
+void Base_DB::set_entered_field_data(const Gtk::TreeModel::iterator& /* row */, const LayoutItem_Field& /* 
field */, const Gnome::Gda::Value& /* value */)
 {
   //Override this.
 }
@@ -1104,25 +1098,29 @@ void Base_DB::do_calculations(const LayoutFieldInRecord& field_changed, bool fir
 
   //Recalculate fields that are triggered by a change of this field's value, not including calculations that 
these calculations use.
 
-  for(const auto& field : get_calculated_fields(field_changed.m_table_name, field_changed.m_field))
+  const auto field_info_changed = field_changed.m_field;
+  if(field_info_changed)
   {
-    if(field)
-    {
-      //std::cout << "debug: recalcing field: " << field->get_name() << std::endl;
-      //TODO: What if the field is in another table?
-      LayoutFieldInRecord triggered_field(field, field_changed.m_table_name, field_changed.m_key, 
field_changed.m_key_value);
-      calculate_field(triggered_field); //And any dependencies.
+      for(const auto& field : get_calculated_fields(field_changed.m_table_name, *field_info_changed))
+      {
+        if(field)
+        {
+          //std::cout << "debug: recalcing field: " << field->get_name() << std::endl;
+          //TODO: What if the field is in another table?
+          LayoutFieldInRecord triggered_field(field, field_changed.m_table_name, field_changed.m_key, 
field_changed.m_key_value);
+          calculate_field(triggered_field); //And any dependencies.
 
-      //Calculate anything that depends on this.
-      do_calculations(triggered_field, false /* recurse, reusing m_FieldsCalculationInProgress */);
-    }
+          //Calculate anything that depends on this.
+          do_calculations(triggered_field, false /* recurse, reusing m_FieldsCalculationInProgress */);
+        }
+      }
   }
 
   if(first_calc_field)
     clear_fields_calculation_in_progress();
 }
 
-Base_DB::type_list_const_field_items Base_DB::get_calculated_fields(const Glib::ustring& table_name, const 
std::shared_ptr<const LayoutItem_Field>& field)
+Base_DB::type_list_const_field_items Base_DB::get_calculated_fields(const Glib::ustring& table_name, const 
LayoutItem_Field& field)
 {
   //std::cout << "debug: Base_DB::get_calculated_fields field=" << field->get_name() << std::endl;
 
@@ -1266,7 +1264,7 @@ void Base_DB::do_lookups(const LayoutFieldInRecord& field_in_record, const Gtk::
         LayoutFieldInRecord field_in_record_to_set(layout_item, field_in_record.m_table_name /* parent table 
*/, field_in_record.m_key, field_in_record.m_key_value);
 
         //Add it to the view:
-        set_entered_field_data(row, layout_item, value_converted);
+        set_entered_field_data(row, *layout_item, value_converted);
         //m_AddDel.set_value(row, layout_item, value_converted);
 
         //Add it to the database (even if it is not shown in the view)
diff --git a/glom/base_db.h b/glom/base_db.h
index 14da782..9be6c1c 100644
--- a/glom/base_db.h
+++ b/glom/base_db.h
@@ -123,8 +123,8 @@ protected:
   std::shared_ptr<Field> get_field_primary_key_for_table(const Glib::ustring& table_name) const;
 
   //Methods to be overridden by derived classes:
-  virtual void set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value&  value);
-  virtual void set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value);
+  virtual void set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value&  value);
+  virtual void set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& field, 
const Gnome::Gda::Value& value);
 
 
   class FieldInRecord
@@ -230,7 +230,7 @@ protected:
 
   /** Get the fields whose values should be recalculated when @a field_name changes.
    */
-  type_list_const_field_items get_calculated_fields(const Glib::ustring& table_name, const 
std::shared_ptr<const LayoutItem_Field>& field);
+  type_list_const_field_items get_calculated_fields(const Glib::ustring& table_name, const LayoutItem_Field& 
field);
 
   /** Get the fields used, if any, in the calculation of this field.
    */
diff --git a/glom/base_db_table_data.cc b/glom/base_db_table_data.cc
index 8b6d567..4bc7184 100644
--- a/glom/base_db_table_data.cc
+++ b/glom/base_db_table_data.cc
@@ -36,7 +36,7 @@ Base_DB_Table_Data::Base_DB_Table_Data()
 {
 }
 
-Gnome::Gda::Value Base_DB_Table_Data::get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& 
/* field */) const
+Gnome::Gda::Value Base_DB_Table_Data::get_entered_field_data(const LayoutItem_Field& /* field */) const
 {
   //Override this to use Field::set_data() too.
 
@@ -112,7 +112,7 @@ bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Val
         else
         {
           if(use_entered_data)
-            value = get_entered_field_data(layout_item);
+            value = get_entered_field_data(*layout_item);
         }
 
         if(Conversions::value_is_empty(value)) //This deals with empty strings too.
@@ -194,7 +194,7 @@ bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Val
       for(const auto& layout_item : fieldsToAdd)
       {
         //TODO_Performance: We just set this with set_entered_field_data() above. Maybe we could just 
remember it.
-        const auto field_value = get_entered_field_data(layout_item);
+        const auto field_value = get_entered_field_data(*layout_item);
 
         const LayoutFieldInRecord field_in_record(layout_item, m_table_name, fieldPrimaryKey, 
primary_key_value);
 
@@ -245,7 +245,7 @@ bool Base_DB_Table_Data::add_related_record_for_field(const std::shared_ptr<cons
     dialog.run();
 
     //Clear the field again, discarding the entered data.
-    set_entered_field_data(layout_item_parent, Gnome::Gda::Value());
+    set_entered_field_data(*layout_item_parent, Gnome::Gda::Value());
 
     return false;
   }
@@ -267,7 +267,7 @@ bool Base_DB_Table_Data::add_related_record_for_field(const std::shared_ptr<cons
       dialog.run();
 
       //Clear the field again, discarding the entered data.
-      set_entered_field_data(layout_item_parent, Gnome::Gda::Value());
+      set_entered_field_data(*layout_item_parent, Gnome::Gda::Value());
 
       return false;
     }
@@ -299,7 +299,7 @@ bool Base_DB_Table_Data::add_related_record_for_field(const std::shared_ptr<cons
         item_from_key->set_name(relationship->get_from_field());
 
         //Show the new from key in the parent table's layout:
-        set_entered_field_data(item_from_key, primary_key_value);
+        set_entered_field_data(*item_from_key, primary_key_value);
 
         //Set it in the database too:
         auto document = get_document();
@@ -526,7 +526,7 @@ void Base_DB_Table_Data::refresh_related_fields(const LayoutFieldInRecord& field
             //std::cout << "debug: " << G_STRFUNC << ": value_as_string=" << value.to_string()  << std::endl;
 
             //m_AddDel.set_value(row, layout_item, value);
-            set_entered_field_data(row, layout_item, value);
+            set_entered_field_data(row, *layout_item, value);
             //g_warning("addedel size=%d", m_AddDel.get_count());
           }
 
diff --git a/glom/base_db_table_data.h b/glom/base_db_table_data.h
index b9e7326..62bf6eb 100644
--- a/glom/base_db_table_data.h
+++ b/glom/base_db_table_data.h
@@ -51,7 +51,7 @@ protected:
    */
   bool record_new(bool use_entered_data = true, const Gnome::Gda::Value& primary_key_value = 
Gnome::Gda::Value());
 
-  virtual Gnome::Gda::Value get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) 
const;
+  virtual Gnome::Gda::Value get_entered_field_data(const LayoutItem_Field& field) const;
 
   //Gets the row being edited, for derived classes that have rows.
   virtual Gtk::TreeModel::iterator get_row_selected();
diff --git a/glom/import_csv/dialog_import_csv_progress.cc b/glom/import_csv/dialog_import_csv_progress.cc
index c928eab..4960cf9 100644
--- a/glom/import_csv/dialog_import_csv_progress.cc
+++ b/glom/import_csv/dialog_import_csv_progress.cc
@@ -259,18 +259,18 @@ void Dialog_Import_CSV_Progress::on_response(int /* response_id */)
   clear();
 }
 
-Gnome::Gda::Value Dialog_Import_CSV_Progress::get_entered_field_data(const std::shared_ptr<const 
LayoutItem_Field>& field) const
+Gnome::Gda::Value Dialog_Import_CSV_Progress::get_entered_field_data(const LayoutItem_Field& field) const
 {
-  const auto iter = m_current_row_values.find(field->get_name());
+  const auto iter = m_current_row_values.find(field.get_name());
   if(iter == m_current_row_values.end())
     return Gnome::Gda::Value();
 
   return iter->second;
 }
 
-void Dialog_Import_CSV_Progress::set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& 
field, const Gnome::Gda::Value&  value)
+void Dialog_Import_CSV_Progress::set_entered_field_data(const LayoutItem_Field& field, const 
Gnome::Gda::Value&  value)
 {
-  m_current_row_values[field->get_name()] = value;
+  m_current_row_values[field.get_name()] = value;
 }
 
 std::shared_ptr<Field> Dialog_Import_CSV_Progress::get_field_primary_key() const
diff --git a/glom/import_csv/dialog_import_csv_progress.h b/glom/import_csv/dialog_import_csv_progress.h
index f87b273..9ae7196 100644
--- a/glom/import_csv/dialog_import_csv_progress.h
+++ b/glom/import_csv/dialog_import_csv_progress.h
@@ -57,8 +57,8 @@ private:
 
   void on_response(int response_id) override; // From Gtk::Dialog
 
-  Gnome::Gda::Value get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) const 
override; // from Base_DB_Table_Data
-  void set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& 
 value) override; // from Base_DB
+  Gnome::Gda::Value get_entered_field_data(const LayoutItem_Field& field) const override; // from 
Base_DB_Table_Data
+  void set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value&  value) override; // 
from Base_DB
 
   std::shared_ptr<Field> get_field_primary_key() const override; // from Base_DB_Table_Data
   Gnome::Gda::Value get_primary_key_value_selected() const override; // from Base_DB_Table_Data
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc 
b/glom/libglom/data_structure/layout/layoutitem_field.cc
index b655e54..b6d0b60 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -333,16 +333,16 @@ void LayoutItem_Field::set_title_custom(const std::shared_ptr<CustomTitle>& titl
   m_title_custom = title;
 }
 
-bool LayoutItem_Field::is_same_field(const std::shared_ptr<const LayoutItem_Field>& field) const
+bool LayoutItem_Field::is_same_field(const LayoutItem_Field& field) const
 {
   //Don't use auto here because we really want to call
   //UsesRelationship::operator==(), not LayoutItem_Field::operator==().
   const UsesRelationship* uses_a = this;
-  const UsesRelationship* uses_b = &(*field);
+  const UsesRelationship* uses_b = &field; //TODO: Avoid this.
   if(!uses_a || !uses_b)
     return false; //Shouldn't happen.
     
-  return (get_name() == field->get_name()) &&
+  return (get_name() == field.get_name()) &&
          (*uses_a == *uses_b);
 }
 
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h 
b/glom/libglom/data_structure/layout/layoutitem_field.h
index 292152c..0ae439e 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -141,7 +141,7 @@ public:
 
   /** Compare the name, relationship, and related_relationship.
    */
-  bool is_same_field(const std::shared_ptr<const LayoutItem_Field>& field) const;
+  bool is_same_field(const LayoutItem_Field& field) const;
 
 private:
 
@@ -166,15 +166,15 @@ private:
  */
 template
 <typename T_Container>
-bool find_if_layout_item_field_is_same_field_exists(T_Container& container, const std::shared_ptr<const 
LayoutItem_Field>& layout_item)
+bool find_if_layout_item_field_is_same_field_exists(T_Container& container, const LayoutItem_Field& 
layout_item)
 {
   return Utils::find_if_exists(container,
-    [&layout_item](const typename T_Container::value_type& element)
+      [&layout_item](const auto& element)
     {
       //Assume that element is a shared_ptr<>.
 
-      if(!layout_item && !element)
-        return true;
+      if(!element)
+        return false; //layout_item cannot (should not) be null because it's a reference.
 
       //Allow this to be used on a container of LayoutItems,
       //as well as just of LayoutItem_Fields.
@@ -182,7 +182,7 @@ bool find_if_layout_item_field_is_same_field_exists(T_Container& container, cons
       if(!element_field)
         return false;
 
-      return layout_item && layout_item->is_same_field(element_field);
+      return layout_item.is_same_field(*element_field);
     }
   );
 }
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 833343f..a38d9e2 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -505,13 +505,13 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_key(const Glib
     std::shared_ptr<const Relationship>(), sort_clause, limit);
 }
 
-Utils::type_list_values_with_second Utils::get_choice_values_all(const std::shared_ptr<const Document>& 
document, const std::shared_ptr<const LayoutItem_Field>& field)
+Utils::type_list_values_with_second Utils::get_choice_values_all(const std::shared_ptr<const Document>& 
document, const LayoutItem_Field& field)
 {
   return get_choice_values(document, field,
     Gnome::Gda::Value() /* means get all with no WHERE clause */);
 }
 
-Utils::type_list_values_with_second Utils::get_choice_values(const std::shared_ptr<const Document>& 
document, const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& foreign_key_value)
+Utils::type_list_values_with_second Utils::get_choice_values(const std::shared_ptr<const Document>& 
document, const LayoutItem_Field& field, const Gnome::Gda::Value& foreign_key_value)
 {
   //TODO: Reduce duplication between this and get_choice_values(field).
 
@@ -526,7 +526,7 @@ Utils::type_list_values_with_second Utils::get_choice_values(const std::shared_p
   }
   */
 
-  const Formatting& format = field->get_formatting_used();
+  const Formatting& format = field.get_formatting_used();
   std::shared_ptr<const Relationship> choice_relationship;
   std::shared_ptr<const LayoutItem_Field> layout_choice_first;
   std::shared_ptr<const LayoutGroup> layout_choice_extra;
@@ -1486,7 +1486,7 @@ LayoutGroup::type_list_const_items Utils::get_layout_items_plus_primary_key(cons
   pk_layout_item->set_hidden();
   pk_layout_item->set_full_field_details(field_primary_key);
   
-  if(find_if_layout_item_field_is_same_field_exists(items, pk_layout_item))
+  if(find_if_layout_item_field_is_same_field_exists(items, *pk_layout_item))
     return items; //It is already in the list:
 
   LayoutGroup::type_list_const_items items_plus_pk = items;
@@ -1514,7 +1514,7 @@ LayoutGroup::type_list_items Utils::get_layout_items_plus_primary_key(const Layo
   pk_layout_item->set_hidden();
   pk_layout_item->set_full_field_details(field_primary_key);
   
-  if(find_if_layout_item_field_is_same_field_exists(items, pk_layout_item))
+  if(find_if_layout_item_field_is_same_field_exists(items, *pk_layout_item))
     return items; //It is already in the list:
 
   LayoutGroup::type_list_items items_plus_pk = items;
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index 501e8ed..737f6b4 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -135,9 +135,9 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_update_with_where_clause(
 
 typedef std::vector<Gnome::Gda::Value> type_list_values;
 typedef std::vector< std::pair<Gnome::Gda::Value, type_list_values> > type_list_values_with_second; //TODO: 
Rename this now that we have more than just 1 extra field.
-type_list_values_with_second get_choice_values_all(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& field);
+type_list_values_with_second get_choice_values_all(const std::shared_ptr<const Document>& document, const 
LayoutItem_Field& field);
 
-type_list_values_with_second get_choice_values(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& foreign_key_value);
+type_list_values_with_second get_choice_values(const std::shared_ptr<const Document>& document, const 
LayoutItem_Field& field, const Gnome::Gda::Value& foreign_key_value);
 
 /// Get the full query string suitable for use with std::cout.
 std::string sqlbuilder_get_full_query(
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index 47cdc8c..a360776 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -100,7 +100,7 @@ Gnome::Gda::SqlExpr Box_Data::get_find_where_clause() const
   //Look at each field entry and build e.g. 'Name = "Bob"'
   for(const auto& item : m_FieldsShown)
   {
-    const auto data = get_entered_field_data(item);
+    const auto data = get_entered_field_data(*item);
 
     if(!Conversions::value_is_empty(data))
     {
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 97dd640..006ac8e 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -306,7 +306,7 @@ bool Box_Data_Details::fill_from_database()
         bool index_primary_key_found = false;
         unsigned int index_primary_key = 0; //Arbitrary default.
         //g_warning("primary_key name = %s", m_field_primary_key->get_name().c_str());
-        if(!find_if_layout_item_field_is_same_field_exists(fieldsToGet, layout_item_pk))
+        if(!find_if_layout_item_field_is_same_field_exists(fieldsToGet, *layout_item_pk))
         {
           fieldsToGet.emplace_back(layout_item_pk);
           index_primary_key = fieldsToGet.size() - 1;
@@ -389,7 +389,7 @@ bool Box_Data_Details::fill_from_database()
                 value = Conversions::get_empty_value(layout_item->get_glom_type());
               }
 
-              m_FlowTable.set_field_value(layout_item, value);
+              m_FlowTable.set_field_value(*layout_item, value);
             }
           }
         }
@@ -493,17 +493,17 @@ void Box_Data_Details::on_button_nav_last()
     signal_nav_last().emit();
 }
 
-Gnome::Gda::Value Box_Data_Details::get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& 
field) const
+Gnome::Gda::Value Box_Data_Details::get_entered_field_data(const LayoutItem_Field& field) const
 {
   return m_FlowTable.get_field_value(field);
 }
 
-void Box_Data_Details::set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value)
+void Box_Data_Details::set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value)
 {
   m_FlowTable.set_field_value(field, value);
 }
 
-void Box_Data_Details::set_entered_field_data(const Gtk::TreeModel::iterator& /* row */, const 
std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value)
+void Box_Data_Details::set_entered_field_data(const Gtk::TreeModel::iterator& /* row */, const 
LayoutItem_Field& field, const Gnome::Gda::Value& value)
 {
   set_entered_field_data(field, value);
 }
@@ -747,7 +747,7 @@ void Box_Data_Details::on_flowtable_field_edited(const std::shared_ptr<const Lay
           auto layout_item = std::make_shared<LayoutItem_Field>();
           layout_item->set_full_field_details( document->get_field(relationship->get_from_table(), 
relationship->get_from_field()) );
 
-          primary_key_value = get_entered_field_data(layout_item);
+          primary_key_value = get_entered_field_data(*layout_item);
 
           //Note: This just uses an existing record if one already exists:
           Gnome::Gda::Value primary_key_value_used;
@@ -775,14 +775,14 @@ void Box_Data_Details::on_flowtable_field_edited(const std::shared_ptr<const Lay
     {
       //Revert to the value in the database:
       const auto value_old = get_field_value_in_database(field_in_record, window);
-      set_entered_field_data(layout_field, value_old);
+      set_entered_field_data(*layout_field, value_old);
 
       return;
     }
 
     //Set the value in all instances of this field in the layout (The field might be on the layout more than 
once):
     //We don't need to set the value in the layout_field itself, as this is where the value comes from.
-    m_FlowTable.set_other_field_value(layout_field, field_value);
+    m_FlowTable.set_other_field_value(*layout_field, field_value);
 
     //Update the field in the record (the record with this primary key):
 
@@ -807,7 +807,7 @@ void Box_Data_Details::on_flowtable_field_edited(const std::shared_ptr<const Lay
         //Update failed.
         //Replace with correct values.
         const auto value_old = get_field_value_in_database(field_in_record, window);
-        set_entered_field_data(layout_field, value_old);
+        set_entered_field_data(*layout_field, value_old);
       }
       else
       {
@@ -873,7 +873,7 @@ void Box_Data_Details::on_flowtable_field_edited(const std::shared_ptr<const Lay
         {
           //Revert to a blank value:
           const auto value_old = 
Conversions::get_empty_value(layout_field->get_full_field_details()->get_glom_type());
-          set_entered_field_data(layout_field, value_old);
+          set_entered_field_data(*layout_field, value_old);
         }
         else
         {
@@ -900,7 +900,13 @@ void Box_Data_Details::on_flowtable_field_choices_changed(const std::shared_ptr<
   if(m_ignore_signals)
     return;
 
-  m_FlowTable.update_choices(layout_field);
+  if(!layout_field)
+  {
+      std::cerr << G_STRFUNC << ": layout_field is null.\n";
+      return;
+  }
+
+  m_FlowTable.update_choices(*layout_field);
 }
 
 void Box_Data_Details::on_userlevel_changed(AppState::userlevels user_level)
diff --git a/glom/mode_data/box_data_details.h b/glom/mode_data/box_data_details.h
index 75ed1da..3c6f18f 100644
--- a/glom/mode_data/box_data_details.h
+++ b/glom/mode_data/box_data_details.h
@@ -82,9 +82,9 @@ protected:
   void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value) override;
   Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const override; //Actual 
primary key value of this record.
 
-  Gnome::Gda::Value get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) const 
override;
-  void set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& 
value) override;
-  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value) override;
+  Gnome::Gda::Value get_entered_field_data(const LayoutItem_Field& field) const override;
+  void set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value) override;
+  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& field, const 
Gnome::Gda::Value& value) override;
 
 
   bool fill_from_database() override;
diff --git a/glom/mode_data/box_data_list.cc b/glom/mode_data/box_data_list.cc
index 0eb5d91..55cf9c6 100644
--- a/glom/mode_data/box_data_list.cc
+++ b/glom/mode_data/box_data_list.cc
@@ -345,19 +345,19 @@ Gnome::Gda::Value Box_Data_List::get_primary_key_value_first() const
   return Gnome::Gda::Value();
 }
 
-Gnome::Gda::Value Box_Data_List::get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& 
field) const
+Gnome::Gda::Value Box_Data_List::get_entered_field_data(const LayoutItem_Field& field) const
 {
   return m_AddDel.get_value_selected(field);
 }
 
-void Box_Data_List::set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value)
+void Box_Data_List::set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value)
 {
-  return m_AddDel.set_value_selected(field, value);
+  m_AddDel.set_value_selected(field, value);
 }
 
-void Box_Data_List::set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value)
+void Box_Data_List::set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& 
field, const Gnome::Gda::Value& value)
 {
-  return m_AddDel.set_value(row, field, value);
+  m_AddDel.set_value(row, field, value);
 }
 
 bool Box_Data_List::get_showing_multiple_records() const
diff --git a/glom/mode_data/box_data_list.h b/glom/mode_data/box_data_list.h
index 27dbd4c..37e5ac9 100644
--- a/glom/mode_data/box_data_list.h
+++ b/glom/mode_data/box_data_list.h
@@ -43,9 +43,9 @@ public:
   Gnome::Gda::Value get_primary_key_value_selected() const override;
   void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value) override;
 
-  Gnome::Gda::Value get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) const 
override;
-  void set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& 
value) override;
-  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value) override;
+  Gnome::Gda::Value get_entered_field_data(const LayoutItem_Field& field) const override;
+  void set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value) override;
+  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& field, const 
Gnome::Gda::Value& value) override;
 
   Gtk::TreeModel::iterator get_row_selected() override;
 
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 8eaffca..ef293c5 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -281,7 +281,7 @@ void Box_Data_List_Related::on_adddel_record_added(const Gtk::TreeModel::iterato
     //m_key_field is the field in this table that must match another field in the parent table.
     auto layout_item = std::make_shared<LayoutItem_Field>();
     layout_item->set_full_field_details(m_key_field);
-    key_value = m_AddDel.get_value(row, layout_item);
+    key_value = m_AddDel.get_value(row, *layout_item);
   }
 
 
@@ -312,7 +312,7 @@ void Box_Data_List_Related::on_adddel_record_added(const Gtk::TreeModel::iterato
 
       //TODO: Although the to-field value is visible on the new related record, get_value() returns NULL so 
you can't immediately navigate to the new record:
       //std::cout << "debug: " << G_STRFUNC << ": setting field=" << layout_item->get_name() << 
"m_key_value=" << m_key_value.to_string() << std::endl;
-      m_AddDel.set_value(row, layout_item, m_key_value);
+      m_AddDel.set_value(row, *layout_item, m_key_value);
     }
     else
       std::cerr << G_STRFUNC << ": m_key_field is NULL" << std::endl;
diff --git a/glom/mode_data/datawidget/cellcreation.cc b/glom/mode_data/datawidget/cellcreation.cc
index 52e1244..34e664b 100644
--- a/glom/mode_data/datawidget/cellcreation.cc
+++ b/glom/mode_data/datawidget/cellcreation.cc
@@ -65,6 +65,9 @@ static void apply_formatting(Gtk::CellRenderer* renderer, const std::shared_ptr<
     text_renderer->property_background() = bg;
 }
 
+//This really needs to take the layout_item as a std::shared_ptr<>,
+//because we might need to call set_layout_item(layout_item) on the newly-created cell.
+//TODO: And it should be non-const too.
 Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_item, const Glib::ustring& 
table_name, const std::shared_ptr<const Document>& document, guint fixed_cell_height)
 {
   Gtk::CellRenderer* cell = nullptr;
@@ -235,7 +238,7 @@ Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_i
         //TODO: Update this when the relationship's field value changes:
         if(choice_show_all) //Otherwise it must change whenever the relationships's ID value changes.
         {
-          pCellRendererDbList->set_choices_related(document, item_field, Gnome::Gda::Value() /* TODO: Makes 
no sense */);
+          pCellRendererDbList->set_choices_related(document, *item_field, Gnome::Gda::Value() /* TODO: Makes 
no sense */);
         }
       }
     }
diff --git a/glom/mode_data/datawidget/cellrenderer_dblist.cc 
b/glom/mode_data/datawidget/cellrenderer_dblist.cc
index acc4aca..b097f7e 100644
--- a/glom/mode_data/datawidget/cellrenderer_dblist.cc
+++ b/glom/mode_data/datawidget/cellrenderer_dblist.cc
@@ -49,7 +49,7 @@ void CellRendererDbList::set_choices_fixed(const Formatting::type_list_values& l
   //The other cells are added in on_editing_started().
 }
 
-void CellRendererDbList::set_choices_related(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value)
+void CellRendererDbList::set_choices_related(const std::shared_ptr<const Document>& document, const 
LayoutItem_Field& layout_field, const Gnome::Gda::Value& foreign_key_value)
 {
   ComboChoicesWithTreeModel::set_choices_related(document, layout_field, foreign_key_value);
 
diff --git a/glom/mode_data/datawidget/cellrenderer_dblist.h b/glom/mode_data/datawidget/cellrenderer_dblist.h
index a91a9e3..487f2dc 100644
--- a/glom/mode_data/datawidget/cellrenderer_dblist.h
+++ b/glom/mode_data/datawidget/cellrenderer_dblist.h
@@ -43,7 +43,7 @@ public:
   void set_choices_fixed(const Formatting::type_list_values& list_values, bool restricted = false) override;
 
   //This creates a db-based tree model, with appropriate cell renderers:
-  void set_choices_related(const std::shared_ptr<const Document>& document, const std::shared_ptr<const 
LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value) override;
+  void set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value) override;
 
   void set_restrict_values_to_list(bool val = true);
 
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index bfcb058..bc3285c 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -150,7 +150,7 @@ void ComboGlom::set_choices_fixed(const Formatting::type_list_values& list_value
   }
 }
 
-void ComboGlom::set_choices_related(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value)
+void ComboGlom::set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value)
 {
   ComboChoicesWithTreeModel::set_choices_related(document, layout_field, foreign_key_value);
 
diff --git a/glom/mode_data/datawidget/combo.h b/glom/mode_data/datawidget/combo.h
index 566327c..fd64b3b 100644
--- a/glom/mode_data/datawidget/combo.h
+++ b/glom/mode_data/datawidget/combo.h
@@ -51,7 +51,7 @@ public:
   void set_choices_fixed(const Formatting::type_list_values& list_values, bool restricted = false) override;
 
   //This creates a db-based tree model, with appropriate cell renderers:
-  void set_choices_related(const std::shared_ptr<const Document>& document, const std::shared_ptr<const 
LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value) override;
+  void set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value) override;
 
   void set_read_only(bool read_only = true) override;
 
diff --git a/glom/mode_data/datawidget/combo_as_radio_buttons.cc 
b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
index f07ccd0..1952d57 100644
--- a/glom/mode_data/datawidget/combo_as_radio_buttons.cc
+++ b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
@@ -145,7 +145,7 @@ void ComboAsRadioButtons::set_choices_fixed(const Formatting::type_list_values&
   }
 }
 
-void ComboAsRadioButtons::set_choices_related(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value)
+void ComboAsRadioButtons::set_choices_related(const std::shared_ptr<const Document>& document, const 
LayoutItem_Field& layout_field, const Gnome::Gda::Value& foreign_key_value)
 {
   const Utils::type_list_values_with_second list_values =
     Utils::get_choice_values(document, layout_field, foreign_key_value);
diff --git a/glom/mode_data/datawidget/combo_as_radio_buttons.h 
b/glom/mode_data/datawidget/combo_as_radio_buttons.h
index abd7afa..1f00bfd 100644
--- a/glom/mode_data/datawidget/combo_as_radio_buttons.h
+++ b/glom/mode_data/datawidget/combo_as_radio_buttons.h
@@ -52,7 +52,7 @@ public:
 
   void set_choices_fixed(const Formatting::type_list_values& list_values, bool restricted = false) override;
 
-  void set_choices_related(const std::shared_ptr<const Document>& document, const std::shared_ptr<const 
LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value) override;
+  void set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value) override;
 
   void set_read_only(bool read_only = true) override;
 
diff --git a/glom/mode_data/datawidget/combochoices.cc b/glom/mode_data/datawidget/combochoices.cc
index 8e011b4..c3a2201 100644
--- a/glom/mode_data/datawidget/combochoices.cc
+++ b/glom/mode_data/datawidget/combochoices.cc
@@ -64,7 +64,7 @@ bool ComboChoices::refresh_data_from_database_with_foreign_key(const std::shared
   return true;
 }
 
-void ComboChoices::set_choices_related(const std::shared_ptr<const Document>& /* document */, const 
std::shared_ptr<const LayoutItem_Field>& /* layout_field */, const Gnome::Gda::Value& /* foreign_key_value */)
+void ComboChoices::set_choices_related(const std::shared_ptr<const Document>& /* document */, const 
LayoutItem_Field& /* layout_field */, const Gnome::Gda::Value& /* foreign_key_value */)
 {
   /* TODO:
   type_list_values_with_second list_values;
diff --git a/glom/mode_data/datawidget/combochoices.h b/glom/mode_data/datawidget/combochoices.h
index 503423b..6a9808a 100644
--- a/glom/mode_data/datawidget/combochoices.h
+++ b/glom/mode_data/datawidget/combochoices.h
@@ -56,7 +56,7 @@ public:
    *
    * See also refresh_data_from_database_with_foreign_key().
    */
-  virtual void set_choices_related(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value) = 0;
+  virtual void set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value) = 0;
 
   /** Update a choices widget's list of related choices if a relevant value in its parent table has changed.
    *
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc 
b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index e20af7f..5908c84 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -228,7 +228,7 @@ void ComboChoicesWithTreeModel::set_choices_fixed(const Formatting::type_list_va
   //then sets up the view, using the model.
 }
 
-void ComboChoicesWithTreeModel::set_choices_related(const std::shared_ptr<const Document>& document, const 
std::shared_ptr<const LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value)
+void ComboChoicesWithTreeModel::set_choices_related(const std::shared_ptr<const Document>& document, const 
LayoutItem_Field& layout_field, const Gnome::Gda::Value& foreign_key_value)
 {
   if(!document)
   {
@@ -236,7 +236,7 @@ void ComboChoicesWithTreeModel::set_choices_related(const std::shared_ptr<const
     return;
   }
 
-  const auto format = layout_field->get_formatting_used();
+  const auto format = layout_field.get_formatting_used();
   std::shared_ptr<const Relationship> choice_relationship;
   std::shared_ptr<const LayoutItem_Field> layout_choice_first;
   std::shared_ptr<const LayoutGroup> layout_choice_extra;
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.h 
b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
index 3d4b6d2..31f7a09 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
@@ -43,7 +43,7 @@ public:
   void set_choices_fixed(const Formatting::type_list_values& list_values, bool restricted = false) override;
 
   //This creates a db-based tree model, with appropriate cell renderers:
-  void set_choices_related(const std::shared_ptr<const Document>& document, const std::shared_ptr<const 
LayoutItem_Field>& layout_field, const Gnome::Gda::Value& foreign_key_value) override;
+  void set_choices_related(const std::shared_ptr<const Document>& document, const LayoutItem_Field& 
layout_field, const Gnome::Gda::Value& foreign_key_value) override;
 
 
   //Not named get_model(), to avoid clashing with ComboBox::get_model().
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index ecce444..86e5d3e 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -131,7 +131,7 @@ DataWidget::DataWidget(const std::shared_ptr<LayoutItem_Field>& field, const Gli
         combo = create_combo_widget_for_field(field);
         combo->set_layout_item( get_layout_item(), table_name);
 
-        combo->set_choices_related(document, field, Gnome::Gda::Value() /* no ID means show all related 
records */);
+        combo->set_choices_related(document, *field, Gnome::Gda::Value() /* no ID means show all related 
records */);
       }
       else
       {
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index 2d5b234..84bdbc4 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -325,7 +325,7 @@ Gtk::TreeModel::iterator DbAddDel::get_item_placeholder()
    return Gtk::TreeModel::iterator();
 }
 
-Gnome::Gda::Value DbAddDel::get_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const 
LayoutItem_Field>& layout_item) const
+Gnome::Gda::Value DbAddDel::get_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& 
layout_item) const
 {
   Gnome::Gda::Value value;
 
@@ -360,7 +360,7 @@ Gnome::Gda::Value DbAddDel::get_value_key_selected() const
     return Gnome::Gda::Value();
 }
 
-Gnome::Gda::Value DbAddDel::get_value_selected(const std::shared_ptr<const LayoutItem_Field>& layout_item) 
const
+Gnome::Gda::Value DbAddDel::get_value_selected(const LayoutItem_Field& layout_item) const
 {
   return get_value(get_item_selected(), layout_item);
 }
@@ -424,10 +424,10 @@ bool DbAddDel::select_item(const Gtk::TreeModel::iterator& iter, bool start_edit
       break;
   }
 
-  return select_item(iter, layout_item, start_editing);
+  return select_item(iter, *layout_item, start_editing);
 }
 
-bool DbAddDel::select_item(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const LayoutItem>& 
layout_item, bool start_editing)
+bool DbAddDel::select_item(const Gtk::TreeModel::iterator& iter, const LayoutItem& layout_item, bool 
start_editing)
 {
   if(!m_refListStore)
     return false;
@@ -804,12 +804,12 @@ bool DbAddDel::refresh_from_database_blank()
   return true;
 }
 
-void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const 
LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value)
+void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& layout_item, const 
Gnome::Gda::Value& value)
 {
   set_value(iter, layout_item, value, true /* including the specified field */);
 }
 
-void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const 
LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value, bool set_specified_field_layout)
+void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& layout_item, const 
Gnome::Gda::Value& value, bool set_specified_field_layout)
 {
   //g_warning("DbAddDel::set_value begin");
 
@@ -846,7 +846,7 @@ void DbAddDel::set_value(const Gtk::TreeModel::iterator& iter, const std::shared
   //g_warning("DbAddDel::set_value end");
 }
 
-void DbAddDel::set_value_selected(const std::shared_ptr<const LayoutItem_Field>& layout_item, const 
Gnome::Gda::Value& value)
+void DbAddDel::set_value_selected(const LayoutItem_Field& layout_item, const Gnome::Gda::Value& value)
 {
   set_value(get_item_selected(), layout_item, value);
 }
@@ -883,7 +883,7 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
     return;
   }
 
-  cell->set_choices_related(get_document(), layout_field, foreign_key_value);
+  cell->set_choices_related(get_document(), *layout_field, foreign_key_value);
 }
 
 void DbAddDel::remove_all_columns()
@@ -939,15 +939,12 @@ FoundSet DbAddDel::get_found_set() const
   return m_found_set;
 }
 
-DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const std::shared_ptr<const 
LayoutItem_Field>& layout_item_field, bool including_specified_field_layout) const
+DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const LayoutItem_Field& layout_item_field, 
bool including_specified_field_layout) const
 {
   //TODO_Performance: Replace all this looping by a cache/map:
 
   type_list_indexes list_indexes;
 
-  if(!layout_item_field)
-    return list_indexes;
-
   guint data_model_column_index = 0;
   for(const auto& item : m_column_items)
   {
@@ -955,7 +952,7 @@ DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const std::sha
     if(field)
     {
       if(field->is_same_field(layout_item_field)
-        && (including_specified_field_layout || field != layout_item_field))
+        && (including_specified_field_layout || *field != layout_item_field))
       {
         list_indexes.emplace_back(data_model_column_index);
       }
@@ -967,29 +964,23 @@ DbAddDel::type_list_indexes DbAddDel::get_data_model_column_index(const std::sha
   return list_indexes;
 }
 
-DbAddDel::type_list_indexes DbAddDel::get_column_index(const std::shared_ptr<const LayoutItem>& layout_item) 
const
+DbAddDel::type_list_indexes DbAddDel::get_column_index(const LayoutItem& layout_item) const
 {
   //TODO_Performance: Replace all this looping by a cache/map:
 
   type_list_indexes list_indexes;
 
-  if(!layout_item)
-  {
-    std::cerr << G_STRFUNC << ": layout_item was null." << std::endl;
-    return list_indexes;
-  }
-
-  auto layout_item_field = std::dynamic_pointer_cast<const LayoutItem_Field>(layout_item);
+  auto layout_item_field = dynamic_cast<const LayoutItem_Field*>(&layout_item);
 
   guint i = 0;
   for(const auto& item : m_column_items)
   {
     const auto field = std::dynamic_pointer_cast<const LayoutItem_Field>(item); //TODO_Performance: This 
would be unnecessary if !layout_item_field
-    if(field && layout_item_field && field->is_same_field(layout_item_field))
+    if(field && layout_item_field && field->is_same_field(*layout_item_field))
     {
       list_indexes.emplace_back(i);
     }
-    else if(*(item) == *(layout_item))
+    else if(*(item) == layout_item)
     {
       list_indexes.emplace_back(i);
     }
@@ -1000,14 +991,11 @@ DbAddDel::type_list_indexes DbAddDel::get_column_index(const std::shared_ptr<con
   return list_indexes;
 }
 
-DbAddDel::type_list_indexes DbAddDel::get_choice_index(const std::shared_ptr<const LayoutItem_Field>& 
from_key)
+DbAddDel::type_list_indexes DbAddDel::get_choice_index(const LayoutItem_Field& from_key)
 {
   type_list_indexes result;
 
-  if(!from_key)
-    return result;
-
-  const auto from_key_name = from_key->get_name();
+  const auto from_key_name = from_key.get_name();
 
   guint index = 0;
   for(const auto& item : m_column_items)
@@ -2074,7 +2062,7 @@ bool DbAddDel::start_new_record()
 
   if(fieldToEdit)
   {
-    select_item(iter, fieldToEdit, true /* start_editing */);
+    select_item(iter, *fieldToEdit, true /* start_editing */);
   }
   else
   {
@@ -2128,8 +2116,8 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
           if(primary_key_field)
           {
             //Get the value of the corresponding key in the current table (that identifies the record in the 
table that we will change)
-            auto layout_item = std::make_shared<LayoutItem_Field>();
-            layout_item->set_full_field_details( document->get_field(relationship->get_from_table(), 
relationship->get_from_field()) );
+            LayoutItem_Field layout_item;
+            layout_item.set_full_field_details( document->get_field(relationship->get_from_table(), 
relationship->get_from_field()) );
 
             primary_key_value = get_value_selected(layout_item);
 
@@ -2155,7 +2143,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
       }
 
       //Update the field in the record (the record with this primary key):
-      const auto field_value = get_value(row, layout_field);
+      const auto field_value = get_value(row, *layout_field);
       //std::cout << "debug: " << G_STRFUNC << ": field_value = " << field_value.to_string() << std::endl;
       //const std::shared_ptr<const Field>& field = layout_field->m_field;
       //const Glib::ustring strFieldName = layout_field->get_name();
@@ -2167,7 +2155,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
       {
         //Revert to the value in the database:
         const auto value_old = get_field_value_in_database(field_in_record, window);
-        set_entered_field_data(row, layout_field, value_old);
+        set_entered_field_data(row, *layout_field, value_old);
 
         return; //The value has been reverted to the value in the database.
       }
@@ -2179,12 +2167,12 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
         //Update failed.
         //Replace with correct values.
         const auto value_old = get_field_value_in_database(field_in_record, window);
-        set_entered_field_data(row, layout_field, value_old);
+        set_entered_field_data(row, *layout_field, value_old);
       }
       else
       {
         //Display the same value in other instances of the same field:
-        set_value(row, layout_field, field_value, false /* don't set the actually-edited cell */);
+        set_value(row, *layout_field, field_value, false /* don't set the actually-edited cell */);
 
         signal_record_changed().emit();
       }
@@ -2198,7 +2186,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
       {
         LayoutFieldInRecord field_in_record(layout_field, m_found_set.m_table_name /* parent */, 
primary_key_field, primary_key_value);
         const auto value_old = get_field_value_in_database(field_in_record, window);
-        set_entered_field_data(row, layout_field, value_old);
+        set_entered_field_data(row, *layout_field, value_old);
       }
     }
     catch(const std::exception& ex)
@@ -2210,7 +2198,7 @@ void DbAddDel::user_changed(const Gtk::TreeModel::iterator& row, guint col)
       {
         LayoutFieldInRecord field_in_record(layout_field, m_found_set.m_table_name /* parent */, 
primary_key_field, primary_key_value);
         const auto value_old = get_field_value_in_database(field_in_record, window);
-        set_entered_field_data(row, layout_field, value_old);
+        set_entered_field_data(row, *layout_field, value_old);
       }
     }
   }
@@ -2272,8 +2260,8 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
     //This only works when the primary key is already stored: primary_key_value = get_value_key(row);
     //primary_key_value = get_value_key_selected();
 
-    auto layout_field = std::make_shared<LayoutItem_Field>();
-    layout_field->set_full_field_details(primary_key_field);
+    LayoutItem_Field layout_field;
+    layout_field.set_full_field_details(primary_key_field);
     primary_key_value = get_value_selected(layout_field);
     std::cout << "DEBUG: get_value_key_selected(): " << primary_key_value.to_string() << std::endl;
   }
@@ -2298,7 +2286,7 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
   {
     //Revert to a blank value.
     primary_key_value = 
Conversions::get_empty_value(layout_field->get_full_field_details()->get_glom_type());
-    set_entered_field_data(row, layout_field, primary_key_value);
+    set_entered_field_data(row, *layout_field, primary_key_value);
     return;
   }
 
@@ -2320,8 +2308,8 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
   //If it's an auto-increment, then get the value and show it:
   if(primary_key_field->get_auto_increment())
   {
-    auto layout_item = std::make_shared<LayoutItem_Field>();
-    layout_item->set_full_field_details(primary_key_field);
+    LayoutItem_Field layout_item;
+    layout_item.set_full_field_details(primary_key_field);
     set_value(row, layout_item, primary_key_value);
   }
 
@@ -2349,18 +2337,18 @@ void DbAddDel::user_requested_delete(const Gtk::TreeModel::iterator& rowStart, c
 }
 
 //An override of the Base_DB method:
-void DbAddDel::set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value)
+void DbAddDel::set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value)
 {
   return set_value_selected(field, value);
 }
 
 //An override of the Base_DB method:
-void DbAddDel::set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value)
+void DbAddDel::set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& field, 
const Gnome::Gda::Value& value)
 {
   return set_value(row, field, value);
 }
 
-Gnome::Gda::Value DbAddDel::get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) 
const
+Gnome::Gda::Value DbAddDel::get_entered_field_data(const LayoutItem_Field& field) const
 {
   return get_value_selected(field);
 }
diff --git a/glom/mode_data/db_adddel/db_adddel.h b/glom/mode_data/db_adddel/db_adddel.h
index e095ab3..1bf1f60 100644
--- a/glom/mode_data/db_adddel/db_adddel.h
+++ b/glom/mode_data/db_adddel/db_adddel.h
@@ -87,7 +87,7 @@ public:
 
   void remove_item(const Gtk::TreeModel::iterator& iter);
 
-  Gnome::Gda::Value get_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const 
LayoutItem_Field>& layout_item) const;
+  Gnome::Gda::Value get_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& layout_item) 
const;
 
   /** Get the row's hidden key
    */
@@ -100,7 +100,7 @@ public:
   /** @param col A value returned from add_column().
    * @result The value on the selected row.
    */
-  Gnome::Gda::Value get_value_selected(const std::shared_ptr<const LayoutItem_Field>& layout_item) const;
+  Gnome::Gda::Value get_value_selected(const LayoutItem_Field& layout_item) const;
   Gnome::Gda::Value get_value_key_selected() const;
 
   Gtk::TreeModel::iterator get_item_selected();
@@ -112,7 +112,7 @@ public:
    * @param start_editing Whether editing should start in the cell.
    * @result Whether the row was successfully selected.
    */
-  bool select_item(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const LayoutItem>& 
layout_item, bool start_editing = false);  //bool indicates success.
+  bool select_item(const Gtk::TreeModel::iterator& iter, const LayoutItem& layout_item, bool start_editing = 
false);  //bool indicates success.
   bool select_item(const Gtk::TreeModel::iterator& iter, bool start_editing = false);
 
   guint get_count() const;
@@ -122,13 +122,13 @@ public:
    * @param layout_item Describes the column(s) whose values should be changed.
    * @param value The new value.
    */
-  virtual void set_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const 
LayoutItem_Field>& layout_item, const Gnome::Gda::Value& value);
+  virtual void set_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& layout_item, const 
Gnome::Gda::Value& value);
 
   /**
    * @param col A value returned from add_column().
    * @param value The new value.
    */
-  virtual void set_value_selected(const std::shared_ptr<const LayoutItem_Field>& layout_item, const 
Gnome::Gda::Value& value);
+  virtual void set_value_selected(const LayoutItem_Field& layout_item, const Gnome::Gda::Value& value);
 
   bool get_is_first_row(const Gtk::TreeModel::iterator& iter) const;
 
@@ -267,12 +267,12 @@ public:
 
 private:
 
-  void set_value(const Gtk::TreeModel::iterator& iter, const std::shared_ptr<const LayoutItem_Field>& 
layout_item, const Gnome::Gda::Value& value, bool set_specified_field_layout);
+  void set_value(const Gtk::TreeModel::iterator& iter, const LayoutItem_Field& layout_item, const 
Gnome::Gda::Value& value, bool set_specified_field_layout);
 
   //Overrides of Base_DB/Base_DB_Table methods:
-  void set_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& 
value) override;
-  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const std::shared_ptr<const 
LayoutItem_Field>& field, const Gnome::Gda::Value& value) override;
-  Gnome::Gda::Value get_entered_field_data(const std::shared_ptr<const LayoutItem_Field>& field) const 
override;
+  void set_entered_field_data(const LayoutItem_Field& field, const Gnome::Gda::Value& value) override;
+  void set_entered_field_data(const Gtk::TreeModel::iterator& row, const LayoutItem_Field& field, const 
Gnome::Gda::Value& value) override;
+  Gnome::Gda::Value get_entered_field_data(const LayoutItem_Field& field) const override;
   Gtk::TreeModel::iterator get_row_selected() override;
 
   //Implementations of pure virtual methods from Base_DB_Table_Data:
@@ -288,15 +288,16 @@ private:
 
   typedef std::list<guint> type_list_indexes;
   ///Return the column indexes of any columns that display this field.
-  type_list_indexes get_column_index(const std::shared_ptr<const LayoutItem>& layout_item) const;
+  type_list_indexes get_column_index(const LayoutItem& layout_item) const;
 
+  //TODO: Make this const?
   /// Get indexes of any columns with choices with !show_all relationships that have @a from_key as the 
from_key.
-  type_list_indexes get_choice_index(const std::shared_ptr<const LayoutItem_Field>& from_key);
+  type_list_indexes get_choice_index(const LayoutItem_Field& from_key);
 
   /** Return the query column index of any columns that display this field:
    * @param including_specified_field_layout If false, then don't return the actual layout item itself.
    */
-  type_list_indexes get_data_model_column_index(const std::shared_ptr<const LayoutItem_Field>& 
layout_item_field, bool including_specified_field_layout = true) const;
+  type_list_indexes get_data_model_column_index(const LayoutItem_Field& layout_item_field, bool 
including_specified_field_layout = true) const;
 
 protected:
   void setup_menu(Gtk::Widget* widget);
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 58e673c..47f39e6 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -105,9 +105,9 @@ void FlowTableWithFields::add_layout_item(const std::shared_ptr<LayoutItem>& ite
     if(field_details)
     {
       if(field_details->get_auto_increment())
-        set_field_editable(field, false);
+        set_field_editable(*field, false);
       else
-        set_field_editable(field, field->get_editable_and_allowed());
+        set_field_editable(*field, field->get_editable_and_allowed());
     }
   }
   else
@@ -671,12 +671,12 @@ void FlowTableWithFields::remove_field(const Glib::ustring& id)
   }
 }
 
-void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value)
+void FlowTableWithFields::set_field_value(const LayoutItem_Field& field, const Gnome::Gda::Value& value)
 {
   set_field_value(field, value, true);
 }
 
-void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value, bool set_specified_field_layout)
+void FlowTableWithFields::set_field_value(const LayoutItem_Field& field, const Gnome::Gda::Value& value, 
bool set_specified_field_layout)
 {
   //Set widgets which should show the value of this field:
   for(const auto& item : get_field(field, set_specified_field_layout))
@@ -709,12 +709,12 @@ void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem
   }
 }
 
-void FlowTableWithFields::set_other_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const 
Gnome::Gda::Value& value)
+void FlowTableWithFields::set_other_field_value(const LayoutItem_Field& field, const Gnome::Gda::Value& 
value)
 {
   set_field_value(field, value, false);
 }
 
-Gnome::Gda::Value FlowTableWithFields::get_field_value(const std::shared_ptr<const LayoutItem_Field>& field) 
const
+Gnome::Gda::Value FlowTableWithFields::get_field_value(const LayoutItem_Field& field) const
 {
   const type_list_const_widgets list_widgets = get_field(field, true);
   for(const auto& list_widget : list_widgets)
@@ -732,7 +732,7 @@ Gnome::Gda::Value FlowTableWithFields::get_field_value(const std::shared_ptr<con
   return Gnome::Gda::Value(); //null.
 }
 
-void FlowTableWithFields::set_field_editable(const std::shared_ptr<const LayoutItem_Field>& field, bool 
editable)
+void FlowTableWithFields::set_field_editable(const LayoutItem_Field& field, bool editable)
 {
   for(const auto& item : get_field(field, true))
   {
@@ -744,7 +744,7 @@ void FlowTableWithFields::set_field_editable(const std::shared_ptr<const LayoutI
   }
 }
 
-void FlowTableWithFields::update_choices(const std::shared_ptr<const LayoutItem_Field>& field)
+void FlowTableWithFields::update_choices(const LayoutItem_Field& field)
 {
   for(const auto& item : get_field(field, true))
   {
@@ -771,11 +771,11 @@ void FlowTableWithFields::update_choices(const std::shared_ptr<const LayoutItem_
 }
 
 
-FlowTableWithFields::type_portals FlowTableWithFields::get_portals(const std::shared_ptr<const 
LayoutItem_Field>& from_key)
+FlowTableWithFields::type_portals FlowTableWithFields::get_portals(const LayoutItem_Field& from_key)
 {
   type_portals result;
 
-  const auto from_key_name = from_key->get_name();
+  const auto from_key_name = from_key.get_name();
 
   //Check the single-item widgets:
   for(const auto& pPortalUI : m_portals)
@@ -814,13 +814,11 @@ FlowTableWithFields::type_portals FlowTableWithFields::get_portals(const std::sh
   return result;
 }
 
-FlowTableWithFields::type_choice_widgets FlowTableWithFields::get_choice_widgets(const std::shared_ptr<const 
LayoutItem_Field>& from_key)
+FlowTableWithFields::type_choice_widgets FlowTableWithFields::get_choice_widgets(const LayoutItem_Field& 
from_key)
 {
   type_choice_widgets result;
-  if(!from_key)
-    return result;
 
-  const auto from_key_name = from_key->get_name();
+  const auto from_key_name = from_key.get_name();
 
   //Check the single-item widgets:
   for(const auto& the_pair : m_listFields)
@@ -875,11 +873,11 @@ namespace
   // Get the direct widgets represesenting a given layout item
   // from a flowtable, without considering subflowtables:
   template<typename InputIterator, typename OutputIterator>
-  static void get_direct_fields(InputIterator begin, InputIterator end, OutputIterator out, const 
std::shared_ptr<const LayoutItem_Field>& layout_item, bool include_item)
+  static void get_direct_fields(InputIterator begin, InputIterator end, OutputIterator out, const 
LayoutItem_Field& layout_item, bool include_item)
   {
     for(InputIterator iter = begin; iter != end; ++iter)
     {
-      if(iter->m_field->is_same_field(layout_item) && (include_item || iter->m_field != layout_item))
+      if(iter->m_field->is_same_field(layout_item) && (include_item || *(iter->m_field) != layout_item))
       {
         if(iter->m_checkbutton)
           *out++ = iter->m_checkbutton;
@@ -890,7 +888,7 @@ namespace
   }
 }
 
-FlowTableWithFields::type_list_const_widgets FlowTableWithFields::get_field(const std::shared_ptr<const 
LayoutItem_Field>& layout_item, bool include_item) const
+FlowTableWithFields::type_list_const_widgets FlowTableWithFields::get_field(const LayoutItem_Field& 
layout_item, bool include_item) const
 {
   type_list_const_widgets result;
 
@@ -913,7 +911,7 @@ FlowTableWithFields::type_list_const_widgets FlowTableWithFields::get_field(cons
   return result;
 }
 
-FlowTableWithFields::type_list_widgets FlowTableWithFields::get_field(const std::shared_ptr<const 
LayoutItem_Field>& layout_item, bool include_item)
+FlowTableWithFields::type_list_widgets FlowTableWithFields::get_field(const LayoutItem_Field& layout_item, 
bool include_item)
 {
   type_list_widgets result;
 
diff --git a/glom/mode_data/flowtablewithfields.h b/glom/mode_data/flowtablewithfields.h
index 70a27f7..16a0895 100644
--- a/glom/mode_data/flowtablewithfields.h
+++ b/glom/mode_data/flowtablewithfields.h
@@ -91,22 +91,22 @@ public:
    */
   void add_layout_group_or_derived(const std::shared_ptr<LayoutGroup>& group, bool with_indent = true);
 
-  void set_field_editable(const std::shared_ptr<const LayoutItem_Field>& field, bool editable = true);
+  void set_field_editable(const LayoutItem_Field& field, bool editable = true);
 
-  Gnome::Gda::Value get_field_value(const std::shared_ptr<const LayoutItem_Field>& field) const;
+  Gnome::Gda::Value get_field_value(const LayoutItem_Field& field) const;
 
   /** Set the displayed @a value in any instances of the specified @a field.
    */
-  void set_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
+  void set_field_value(const LayoutItem_Field& field, const Gnome::Gda::Value& value);
 
   /** Set the displayed @a value in any instances of the field other than the specified @a layout_field.
    */
-  void set_other_field_value(const std::shared_ptr<const LayoutItem_Field>& layout_field, const 
Gnome::Gda::Value& value);
+  void set_other_field_value(const LayoutItem_Field& layout_field, const Gnome::Gda::Value& value);
 
   /** Refresh the list of related records in choice combo boxes, 
    * in any instance of the specified field.
    */
-  void update_choices(const std::shared_ptr<const LayoutItem_Field>& field);
+  void update_choices(const LayoutItem_Field& field);
 
   typedef std::list<Gtk::Widget*> type_list_widgets;
   typedef std::list<const Gtk::Widget*> type_list_const_widgets;
@@ -178,23 +178,23 @@ public:
 
 private:
 
-  void set_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value, 
bool set_specified_field_layout);
+  void set_field_value(const LayoutItem_Field& field, const Gnome::Gda::Value& value, bool 
set_specified_field_layout);
 
   // If include_item is set, then the output list will contain field's widget,
   // otherwise not.
-  type_list_widgets get_field(const std::shared_ptr<const LayoutItem_Field>& field, bool include_item);
-  type_list_const_widgets get_field(const std::shared_ptr<const LayoutItem_Field>& field, bool include_item) 
const;
+  type_list_widgets get_field(const LayoutItem_Field& field, bool include_item);
+  type_list_const_widgets get_field(const LayoutItem_Field& field, bool include_item) const;
 
   typedef std::list<Box_Data_Portal*> type_portals;
 
   /// Get portals whose relationships have @a from_key as the from_key.
-  type_portals get_portals(const std::shared_ptr<const LayoutItem_Field>& from_key);
+  type_portals get_portals(const LayoutItem_Field& from_key);
 
 
   typedef std::list<DataWidgetChildren::ComboChoices*> type_choice_widgets;
 
   /// Get choice widgets with !show_all relationships that have @a from_key as the from_key.
-  type_choice_widgets get_choice_widgets(const std::shared_ptr<const LayoutItem_Field>& from_key);
+  type_choice_widgets get_choice_widgets(const LayoutItem_Field& from_key);
 
   /** Examine this flow table and all child flow tables, discovering which
    * has the most columns.
diff --git a/glom/mode_design/layout/dialog_choose_field.cc b/glom/mode_design/layout/dialog_choose_field.cc
index 5ba0588..ec0fa8d 100644
--- a/glom/mode_design/layout/dialog_choose_field.cc
+++ b/glom/mode_design/layout/dialog_choose_field.cc
@@ -252,11 +252,11 @@ Dialog_ChooseField::type_list_field_items Dialog_ChooseField::get_fields_chosen(
       
     Gtk::TreeModel::Row row = *tree_iter;
     std::shared_ptr<Field> field_details = row[m_ColumnsFields.m_col_field];
-    field->set_full_field_details(field_details); 
+    field->set_full_field_details(field_details);
       
     // Start with the original LayoutItem_Field, 
     // to preserve extra information such as Translations:
-    if(m_start_field && m_start_field->is_same_field(field))
+    if(m_start_field && m_start_field->is_same_field(*field))
       field = m_start_field; 
     else
       field = std::make_shared<LayoutItem_Field>();
diff --git a/tests/test_layout_item_field.cc b/tests/test_layout_item_field.cc
index ccb48ac..0a69efa 100644
--- a/tests/test_layout_item_field.cc
+++ b/tests/test_layout_item_field.cc
@@ -26,9 +26,9 @@
 static
 bool test_compare_empty_instances()
 {
-  auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
-  auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
-  if(!layout_item1->is_same_field(layout_item2))
+  Glom::LayoutItem_Field layout_item1;
+  Glom::LayoutItem_Field layout_item2;
+  if(!layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with empty instances." << 
std::endl;
     return false;
@@ -40,11 +40,11 @@ bool test_compare_empty_instances()
 static
 bool test_compare_same_named_instances()
 {
-  auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
-  auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
-  layout_item1->set_name("one");
-  layout_item2->set_name("two");
-  if(layout_item1->is_same_field(layout_item2))
+  Glom::LayoutItem_Field layout_item1;
+  Glom::LayoutItem_Field layout_item2;
+  layout_item1.set_name("one");
+  layout_item2.set_name("two");
+  if(layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with named field instances." 
<< std::endl;
     return false;
@@ -56,12 +56,12 @@ bool test_compare_same_named_instances()
 static
 bool test_compare_same_named_instances_unrelated_differences()
 {
-  auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
-  auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
-  layout_item1->set_name("one");
-  layout_item2->set_name("one");
-  layout_item2->set_hidden(); //is_same_field() should ignore this.
-  if(!layout_item1->is_same_field(layout_item2))
+  Glom::LayoutItem_Field layout_item1;
+  Glom::LayoutItem_Field layout_item2;
+  layout_item1.set_name("one");
+  layout_item2.set_name("one");
+  layout_item2.set_hidden(); //is_same_field() should ignore this.
+  if(!layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with named field instances 
with unrelated differences." << std::endl;
     return false;
@@ -74,27 +74,27 @@ bool test_compare_same_named_instances_unrelated_differences()
 static
 bool test_compare_same_named_instances_with_relationship()
 {
-  auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
-  auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
-  layout_item1->set_name("one");
-  layout_item2->set_name("one");
+  Glom::LayoutItem_Field layout_item1;
+  Glom::LayoutItem_Field layout_item2;
+  layout_item1.set_name("one");
+  layout_item2.set_name("one");
 
   auto relationship1 = std::make_shared<Glom::Relationship>();
   relationship1->set_name("relationship1");
-  layout_item1->set_relationship(relationship1);
+  layout_item1.set_relationship(relationship1);
 
   auto relationship2 = std::make_shared<Glom::Relationship>();
   relationship2->set_name("relationship2");
-  layout_item2->set_relationship(relationship2);
+  layout_item2.set_relationship(relationship2);
 
-  if(layout_item1->is_same_field(layout_item2))
+  if(layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with 
different relationships." << std::endl;
     return false;
   }
 
-  layout_item2->set_relationship(relationship1);
-  if(!layout_item1->is_same_field(layout_item2))
+  layout_item2.set_relationship(relationship1);
+  if(!layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with 
same relationships." << std::endl;
     return false;
@@ -106,21 +106,21 @@ bool test_compare_same_named_instances_with_relationship()
 static
 bool test_compare_same_named_instances_with_related_relationship()
 {
-  auto layout_item1 = std::make_shared<Glom::LayoutItem_Field>();
-  auto layout_item2 = std::make_shared<Glom::LayoutItem_Field>();
-  layout_item1->set_name("one");
-  layout_item2->set_name("one");
+  Glom::LayoutItem_Field layout_item1;
+  Glom::LayoutItem_Field layout_item2;
+  layout_item1.set_name("one");
+  layout_item2.set_name("one");
 
   auto relationship1 = std::make_shared<Glom::Relationship>();
   relationship1->set_name("relationship1");
-  layout_item1->set_relationship(relationship1);
-  layout_item2->set_relationship(relationship1);
+  layout_item1.set_relationship(relationship1);
+  layout_item2.set_relationship(relationship1);
 
   auto relationship_related1 = std::make_shared<Glom::Relationship>();
   relationship_related1->set_name("relationship_related1");
-  layout_item1->set_related_relationship(relationship_related1);
+  layout_item1.set_related_relationship(relationship_related1);
 
-  if(layout_item1->is_same_field(layout_item2))
+  if(layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with 
different (one unset) related relationships." << std::endl;
     return false;
@@ -128,16 +128,16 @@ bool test_compare_same_named_instances_with_related_relationship()
 
   auto relationship_related2 = std::make_shared<Glom::Relationship>();
   relationship_related2->set_name("relationship_related2");
-  layout_item2->set_related_relationship(relationship_related2);
+  layout_item2.set_related_relationship(relationship_related2);
 
-  if(layout_item1->is_same_field(layout_item2))
+  if(layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with 
different related relationships." << std::endl;
     return false;
   }
 
-  layout_item2->set_related_relationship(relationship_related1);
-  if(!layout_item1->is_same_field(layout_item2))
+  layout_item2.set_related_relationship(relationship_related1);
+  if(!layout_item1.is_same_field(layout_item2))
   {
     std::cerr << G_STRFUNC << ": Glom::LayoutItem_Field::is_same_field() failed with field instances with 
same related relationships." << std::endl;
     return false;
diff --git a/tests/test_selfhosting_new_then_choices.cc b/tests/test_selfhosting_new_then_choices.cc
index 40b3fdb..f2eca8a 100644
--- a/tests/test_selfhosting_new_then_choices.cc
+++ b/tests/test_selfhosting_new_then_choices.cc
@@ -54,7 +54,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
   }
 
   const Glom::Utils::type_list_values_with_second values_with_second = 
-    Glom::Utils::get_choice_values_all(document, field_with_choice);
+    Glom::Utils::get_choice_values_all(document, *field_with_choice);
   if(values_with_second.size() != 3)
   {
     std::cerr << G_STRFUNC << ": Failure: There were an unexpected number of choices." << std::endl;


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