Commit 383bfa8d authored by Murray Cumming's avatar Murray Cumming

Don't take a shared_ptr<> when the method does not share ownership.

As suggested by recent talks 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 44e021ab
......@@ -590,9 +590,9 @@ std::shared_ptr<TableInfo> Document::create_table_system_preferences(type_vec_fi
return prefs_table_info;
}
bool Document::get_relationship_is_system_properties(const std::shared_ptr<const Relationship>& relationship)
bool Document::get_relationship_is_system_properties(const Relationship& relationship)
{
return relationship && (relationship->get_name() == GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES);
return (relationship.get_name() == GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES);
}
std::shared_ptr<Relationship> Document::get_relationship(const Glib::ustring& table_name, const Glib::ustring& relationship_name) const
......
......@@ -488,7 +488,7 @@ public:
static std::shared_ptr<TableInfo> create_table_system_preferences();
static std::shared_ptr<TableInfo> create_table_system_preferences(type_vec_fields& fields);
static std::shared_ptr<Relationship> create_relationship_system_preferences(const Glib::ustring& table_name);
static bool get_relationship_is_system_properties(const std::shared_ptr<const Relationship>& relationship);
static bool get_relationship_is_system_properties(const Relationship& relationship);
#endif //SWIG
/// Failure codes that could be returned by load_after()
......
......@@ -178,7 +178,7 @@ DataWidget::DataWidget(const std::shared_ptr<LayoutItem_Field>& field, const Gli
if(m_child)
{
//Use the text formatting:
apply_formatting(*m_child, field);
apply_formatting(*m_child, *field);
bool child_added = false; //Don't use an extra container unless necessary.
......
......@@ -378,7 +378,7 @@ private:
void refresh_cell_choices_data_from_database_with_foreign_key(guint model_index, const Gnome::Gda::Value& foreign_key_value);
static void apply_formatting(Gtk::CellRenderer* renderer, const std::shared_ptr<const LayoutItem_WithFormatting>& layout_item);
static void apply_formatting(Gtk::CellRenderer* renderer, const LayoutItem_WithFormatting& layout_item);
typedef Gtk::Box type_base;
......
......@@ -563,7 +563,7 @@ void FlowTableWithFields::add_button(const std::shared_ptr<LayoutItem_Button>& l
add_widgets(*widget_to_add, expand);
apply_formatting(*button, layoutitem_button);
apply_formatting(*button, *layoutitem_button);
}
void FlowTableWithFields::add_textobject(const std::shared_ptr<LayoutItem_Text>& layoutitem_text, const Glib::ustring& table_name)
......@@ -580,7 +580,7 @@ void FlowTableWithFields::add_textobject(const std::shared_ptr<LayoutItem_Text>&
label->set_valign(Gtk::ALIGN_CENTER);
label->show();
apply_formatting(*label, layoutitem_text);
apply_formatting(*label, *layoutitem_text);
add_layoutwidgetbase(label);
......
......@@ -158,6 +158,9 @@ void ComboBox_Relationship::set_relationships(const std::shared_ptr<Document>& d
//Fill the model:
for(const auto& rel : document->get_relationships(parent_table_name, true /* plus system properties */))
{
if(!rel)
continue;
auto tree_iter = m_model->append();
Gtk::TreeModel::Row row = *tree_iter;
......@@ -165,7 +168,7 @@ void ComboBox_Relationship::set_relationships(const std::shared_ptr<Document>& d
row[m_model_columns.m_separator] = false;
//Children:
if(show_related_relationships && !Document::get_relationship_is_system_properties(rel))
if(show_related_relationships && !Document::get_relationship_is_system_properties(*rel))
{
for(const auto& sub_rel : document->get_relationships(rel->get_to_table(), false /* plus system properties */))
{
......
......@@ -59,21 +59,18 @@ std::shared_ptr<LayoutItem> CanvasLayoutItem::get_layout_item()
return m_layout_item;
}
void CanvasLayoutItem::apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const std::shared_ptr<const LayoutItem_WithFormatting>& layout_item)
void CanvasLayoutItem::apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const LayoutItem_WithFormatting& layout_item)
{
if(!canvas_item)
return;
if(!layout_item)
return;
//Horizontal alignment:
const Formatting::HorizontalAlignment alignment =
layout_item->get_formatting_used_horizontal_alignment();
layout_item.get_formatting_used_horizontal_alignment();
const Pango::Alignment x_align = (alignment == Formatting::HorizontalAlignment::LEFT ? Pango::ALIGN_LEFT : Pango::ALIGN_RIGHT);
canvas_item->property_alignment() = x_align;
const auto formatting = layout_item->get_formatting_used();
const auto formatting = layout_item.get_formatting_used();
Glib::ustring font = formatting.get_text_format_font();
if(font.empty())
......@@ -163,7 +160,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
auto canvas_item = CanvasTextMovable::create();
canvas_item->property_line_width() = 0;
apply_formatting(canvas_item, text);
apply_formatting(canvas_item, *text);
canvas_item->set_text(text->get_text(AppWindow::get_current_locale()));
child = canvas_item;
......@@ -227,7 +224,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
{
auto canvas_item = CanvasTextMovable::create();
canvas_item->property_line_width() = 0;
apply_formatting(canvas_item, field);
apply_formatting(canvas_item, *field);
Glib::ustring name = field->get_name();
if(name.empty())
......
......@@ -82,7 +82,7 @@ private:
/// Create the appropriate inner canvas item to represent the layout item.
static Glib::RefPtr<CanvasItemMovable> create_canvas_item_for_layout_item(const std::shared_ptr<LayoutItem>& layout_item);
static void apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const std::shared_ptr<const LayoutItem_WithFormatting>& layout_item);
static void apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, const LayoutItem_WithFormatting& layout_item);
static void add_portal_rows_if_necessary(const Glib::RefPtr<CanvasTableMovable>& canvas_table, const std::shared_ptr<LayoutItem_Portal>& portal, guint rows_count);
......
......@@ -702,20 +702,20 @@ void Canvas_PrintLayout::fill_with_data_system_preferences(const Glib::RefPtr<Ca
std::dynamic_pointer_cast<LayoutItem_Field>(canvas_item->get_layout_item());
if(!layoutitem_field)
return;
bool empty = true;
if(!layoutitem_field->get_name().empty())
{
const auto relationship =
layoutitem_field->get_relationship();
if(!document)
{
std::cerr << G_STRFUNC << ": document is null" << std::endl;
return;
}
if(document->get_relationship_is_system_properties(relationship))
const auto relationship =
layoutitem_field->get_relationship();
if(relationship && document->get_relationship_is_system_properties(*relationship))
empty = false;
}
......
......@@ -81,7 +81,7 @@ void LayoutWidgetBase::set_read_only(bool /* read_only */)
{
}
void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const std::shared_ptr<const LayoutItem_WithFormatting>& layout_item)
void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const LayoutItem_WithFormatting& layout_item)
{
auto widget_to_change = &widget;
......@@ -104,15 +104,12 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const std::shared_p
return;
}
if(!layout_item)
return;
//Set justification on labels and text views:
//Assume that people want left/right justification of multi-line text if they chose
//left/right alignment of the text itself.
{
const Formatting::HorizontalAlignment alignment =
layout_item->get_formatting_used_horizontal_alignment(true /* for details view */);
layout_item.get_formatting_used_horizontal_alignment(true /* for details view */);
const Gtk::Justification justification =
(alignment == Formatting::HorizontalAlignment::LEFT ? Gtk::JUSTIFY_LEFT : Gtk::JUSTIFY_RIGHT);
const Gtk::Align x_align =
......@@ -146,7 +143,7 @@ void LayoutWidgetBase::apply_formatting(Gtk::Widget& widget, const std::shared_p
}
}
const auto formatting = layout_item->get_formatting_used();
const auto formatting = layout_item.get_formatting_used();
//Use the text formatting:
const auto font_desc = formatting.get_text_format_font();
......
......@@ -81,7 +81,7 @@ protected:
virtual AppWindow* get_appwindow() const; // = 0;
static void apply_formatting(Gtk::Widget& widget, const std::shared_ptr<const LayoutItem_WithFormatting>& layout_item);
static void apply_formatting(Gtk::Widget& widget, const LayoutItem_WithFormatting& layout_item);
protected: //TODO: Add accessor?
std::shared_ptr<LayoutItem> m_pLayoutItem;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment