[glom] Print Layout: Show contents of System Preferences in Fields.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Print Layout: Show contents of System Preferences in Fields.
- Date: Wed, 21 Sep 2011 14:59:57 +0000 (UTC)
commit 818490f07290f5b14289c028989c2ddcbad962a3
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Sep 21 16:59:49 2011 +0200
Print Layout: Show contents of System Preferences in Fields.
* glom/base_db.cc: get_field_value_in_database(): Only complain about
a missing key if the relationship needs one.
* glom/libglom/document/document.cc:
* glom/print_layout/canvas_layout_item.cc: set_db_data(): Show an
empty image if there is no pixbuf.
* glom/print_layout/canvas_print_layout.[h|cc]: Added
fill_with_data_system_preferences() to show details from the system
preferences, if appropriate. This is possible because we do not need a
specific record to show values from the one record in System Preferences.
add_canvas_layout_item(), on_context_menu_edit(): Call it.
ChangeLog | 15 ++++++++++
glom/base_db.cc | 17 ++++++++++-
glom/libglom/document/document.cc | 2 +-
glom/print_layout/canvas_layout_item.cc | 8 +++--
glom/print_layout/canvas_print_layout.cc | 44 ++++++++++++++++++++++++++++-
glom/print_layout/canvas_print_layout.h | 6 ++++
6 files changed, 84 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ae1924c..6527bea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2011-09-21 Murray Cumming <murrayc murrayc com>
+ Print Layout: Show contents of System Preferences in Fields.
+
+ * glom/base_db.cc: get_field_value_in_database(): Only complain about
+ a missing key if the relationship needs one.
+ * glom/libglom/document/document.cc:
+ * glom/print_layout/canvas_layout_item.cc: set_db_data(): Show an
+ empty image if there is no pixbuf.
+ * glom/print_layout/canvas_print_layout.[h|cc]: Added
+ fill_with_data_system_preferences() to show details from the system
+ preferences, if appropriate. This is possible because we do not need a
+ specific record to show values from the one record in System Preferences.
+ add_canvas_layout_item(), on_context_menu_edit(): Call it.
+
+2011-09-21 Murray Cumming <murrayc murrayc com>
+
Details: Avoid warning when using System Preferences fields.
* glom/libglom/document/document.cc: get_field_used_in_relationship_to_one():
diff --git a/glom/base_db.cc b/glom/base_db.cc
index bad14ed..27c2a2b 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1207,11 +1207,24 @@ Gnome::Gda::Value Base_DB::get_field_value_in_database(const LayoutFieldInRecord
return result;
}
+ //Check that there is a key value, if there should be one:
+ //System Preferences, for instance, should not need a key to identify the record:
if(!(field_in_record.m_key))
{
- std::cerr << G_STRFUNC << ": field_in_record.m_key is empty." << std::endl;
- return result;
+ Glib::ustring to_field;
+ if(field_in_record.m_field &&
+ field_in_record.m_field->get_relationship())
+ {
+ to_field = field_in_record.m_field->get_relationship()->get_to_field();
+ }
+
+ if(!to_field.empty())
+ {
+ std::cerr << G_STRFUNC << ": field_in_record.m_key is empty." << std::endl;
+ return result;
+ }
}
+
type_vecConstLayoutFields list_fields;
sharedptr<const LayoutItem_Field> layout_item = field_in_record.m_field;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index b90fc66..7bbf76f 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -578,7 +578,7 @@ sharedptr<TableInfo> Document::create_table_system_preferences(type_vec_fields&
bool Document::get_relationship_is_system_properties(const sharedptr<const Relationship>& relationship)
{
- return relationship->get_name() == GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES;
+ return relationship && (relationship->get_name() == GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES);
}
sharedptr<Relationship> Document::get_relationship(const Glib::ustring& table_name, const Glib::ustring& relationship_name) const
diff --git a/glom/print_layout/canvas_layout_item.cc b/glom/print_layout/canvas_layout_item.cc
index 104a1f7..02c5395 100644
--- a/glom/print_layout/canvas_layout_item.cc
+++ b/glom/print_layout/canvas_layout_item.cc
@@ -287,7 +287,7 @@ Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_
//Show as many rows as can fit in the height.
double row_height = 0;
const int max_rows = get_rows_count_for_portal(portal, row_height);
- std::cout << "DEBUG: max_rows=" << max_rows << ", row_height=" << row_height << std::endl;
+ //std::cout << "DEBUG: max_rows=" << max_rows << ", row_height=" << row_height << std::endl;
const LayoutGroup::type_list_items child_items = portal->get_items();
@@ -410,7 +410,7 @@ void CanvasLayoutItem::set_db_data(const Gnome::Gda::Value& value)
if(text_value.empty() && sharedptr<const LayoutItem_FieldSummary>::cast_dynamic(field) && (field_type == Field::TYPE_NUMERIC))
{
//Use get_text_for_gda_value() instead of "0" so we get the correct numerical formatting:
- Gnome::Gda::Value value = Conversions::parse_value(0);
+ const Gnome::Gda::Value value = Conversions::parse_value(0);
text_value = Conversions::get_text_for_gda_value(field_type, value, field->get_formatting_used().m_numeric_format);
}
@@ -430,8 +430,10 @@ void CanvasLayoutItem::set_db_data(const Gnome::Gda::Value& value)
canvas_item->get_width_height(width, height);
Glib::RefPtr<Gdk::Pixbuf> pixbuf = Utils::get_pixbuf_for_gda_value(value);
- if(pixbuf) //TODO: Remove this if() check when goocanvas has my patch to avoid crashes when this is NULL.
+ if(pixbuf)
canvas_item->set_image(pixbuf);
+ else
+ canvas_item->set_image_empty();
break;
}
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 8ddcf02..3105931 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -192,6 +192,8 @@ void Canvas_PrintLayout::add_canvas_layout_item(const Glib::RefPtr<CanvasLayoutI
#endif //GLOM_ENABLE_CLIENT_ONLY
item->set_outline_visible(m_outline_visibility);
+
+ fill_with_data_system_preferences(item, get_document());
}
void Canvas_PrintLayout::remove_canvas_layout_item(const Glib::RefPtr<CanvasLayoutItem>& item)
@@ -268,7 +270,7 @@ void Canvas_PrintLayout::setup_context_menu()
sigc::mem_fun(*this, &Canvas_PrintLayout::on_context_menu_insert_text) );
*/
- m_action_edit = Gtk::Action::create("ContextMenuEdit", Gtk::Stock::EDIT);
+ m_action_edit = Gtk::Action::create("ContextMenuEdit", Gtk::Stock::EDIT);
m_context_menu_action_group->add(m_action_edit);
m_action_formatting = Gtk::Action::create("ContextMenuFormatting", _("_Formatting"));
m_context_menu_action_group->add(m_action_formatting);
@@ -406,6 +408,7 @@ void Canvas_PrintLayout::on_context_menu_edit()
field_chosen->set_formatting_use_default(false);
m_context_item->set_layout_item(field_chosen);
+ fill_with_data_system_preferences(m_context_item, get_document());
}
}
else
@@ -657,6 +660,43 @@ void Canvas_PrintLayout::fill_with_data(const FoundSet& found_set)
fill_with_data(m_items_group, found_set);
}
+void Canvas_PrintLayout::fill_with_data_system_preferences(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, Document* document)
+{
+ sharedptr<LayoutItem_Field> layoutitem_field =
+ sharedptr<LayoutItem_Field>::cast_dynamic(
+ canvas_item->get_layout_item());
+ if(!layoutitem_field)
+ return;
+
+ bool empty = true;
+ if(!layoutitem_field->get_name().empty())
+ {
+ const sharedptr<const Relationship> 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))
+ empty = false;
+ }
+
+ if(!empty)
+ {
+ LayoutFieldInRecord field_in_record;
+ field_in_record.m_field = layoutitem_field;
+ field_in_record.m_table_name = m_table_name;
+ const Gnome::Gda::Value value = get_field_value_in_database(
+ field_in_record, 0 /* TODO: parent window */);
+ if(!Glom::Conversions::value_is_empty(value))
+ canvas_item->set_db_data(value);
+ }
+}
+
+
void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set)
{
//A map of the text representation (e.g. field_name or relationship::field_name) to the index:
@@ -700,7 +740,7 @@ void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& ca
sharedptr<const Relationship> relationship = layoutitem_portal->get_relationship();
if(relationship)
{
- sharedptr<Field> from_field = get_fields_for_table_one_field(relationship->get_from_table(), relationship->get_from_field());
+ const sharedptr<Field> from_field = get_fields_for_table_one_field(relationship->get_from_table(), relationship->get_from_field());
const Gnome::Gda::Value from_key_value = get_field_value_in_database(from_field, found_set, 0 /* TODO: window */);
fill_with_data_portal(canvas_item, from_key_value);
}
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index bae82dc..19ab6ab 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -62,6 +62,12 @@ public:
void remove_canvas_layout_item(const Glib::RefPtr<CanvasLayoutItem>& item);
+ /** If the item is a field from the System Preferences table,
+ * show the content instead of the field name,
+ * because it will be the same for all records.
+ */
+ void fill_with_data_system_preferences(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, Document* document);
+
void fill_with_data(const FoundSet& found_set);
virtual void set_grid_gap(double gap = 20.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]