Commit 06e7d989 authored by Murray Cumming's avatar Murray Cumming

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
parent 383bfa8d
......@@ -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)
......
......@@ -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.
*/
......
......@@ -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());
}
......
......@@ -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();
......
......@@ -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
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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);
}
);
}
......
......@@ -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;
......
......@@ -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(
......
......@@ -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))
{
......
......@@ -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)
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 */);
}
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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.
*
......
......@@ -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;
......
......@@ -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().
......
......@@ -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
{
......
......@@ -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