[glom] Initial support for multiple show-also fields in related choices.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Initial support for multiple show-also fields in related choices.
- Date: Wed, 8 Sep 2010 10:21:21 +0000 (UTC)
commit a738dd306a8d402af9e3faf55431020a6e8e72b6
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Sep 8 12:21:15 2010 +0200
Initial support for multiple show-also fields in related choices.
* glom/glom_developer.glade: Formatting box: related choices:
Replace the second-field combo with a label and an edit button, to
open a layout dialog allowing multiple items (fields).
* glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
Add the code for that.
* glom/mode_design/fields/dialog_fielddefinition.cc: Handle changes to
the extra layout group in BoxFormatting.
* glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
Added a get_has_related_choices() with a has_second& parameter.
Added a get_choices_related_relationship() convenience method.
set/get_choices_related(): Change the field_second string parameter to
a full LayoutGroup, allowing multiple items (fields).
* glom/libglom/data_structure/layout/layoutgroup.[h|cc]:
Added a get_items_recursive() convenience method.
Adapt to the FieldFormatting change.
* glom/libglom/document/document.cc:
load_after_layout_item_formatting(), save_before_layout_item_formatting():
For the related choices extra fields, save an entire layout group instead of
just a field name, supporting the deprecated way for documents with the
old file format version.
* glom/libglom/utils.[h|cc]: get_choice_values(): Do not take
the first and second fields as parameters. Instead get the information from
the layout item. Support multiple fields, via the new layout group.
Added get_list_of_layout_items_for_display() to show a preview of the
layout group (list of fields) in the label in BoxFormatting.
* glom/mode_data/flowtablewithfields.cc: Adapt to the FieldFormatting change.
* glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc:
update_labels(): Improve this code, using the new
Utils::get_list_of_layout_items_for_display() method.
* glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Adapt to these changes.
* glom/mode_data/datawidget/combo.[h|cc]:
* glom/mode_data/datawidget/combo_as_radio_buttons.cc:
* glom/mode_data/datawidget/combochoices.[h|cc]:
* glom/mode_data/datawidget/combochoiceswithtreemodel.cc:
* glom/mode_data/datawidget/comboentry.[h|cc]:
set_choices_related(): Don't take the extra fields as a parameter. Instead
discover them from the layout item.
set_choices_with_second(): Change the list_value's parameter type to support
multiple second values.
refresh_data_from_database_with_foreign_key(): Adapt the to the use of a
layout group instead of second field name, though this currently only uses the first field.
* glom/mode_data/datawidget/datawidget.cc: Adapt to the combo API changes.
* glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc: Make
some code slightly more robust. Not really a related change.
ChangeLog | 52 +++++++
glom/glom_developer.glade | 24 +++-
.../data_structure/layout/fieldformatting.cc | 73 +++-------
.../data_structure/layout/fieldformatting.h | 17 ++-
glom/libglom/data_structure/layout/layoutgroup.cc | 34 ++++-
glom/libglom/data_structure/layout/layoutgroup.h | 15 +-
glom/libglom/document/document.cc | 84 +++++++++---
glom/libglom/utils.cc | 72 ++++++++--
glom/libglom/utils.h | 16 ++-
glom/mode_data/datawidget/combo.cc | 13 ++-
glom/mode_data/datawidget/combo.h | 2 +-
.../mode_data/datawidget/combo_as_radio_buttons.cc | 63 ++++++---
glom/mode_data/datawidget/combochoices.cc | 144 +++-----------------
glom/mode_data/datawidget/combochoices.h | 15 +--
.../datawidget/combochoiceswithtreemodel.cc | 37 +++++-
glom/mode_data/datawidget/comboentry.cc | 12 ++-
glom/mode_data/datawidget/comboentry.h | 2 +-
glom/mode_data/datawidget/datawidget.cc | 7 +-
glom/mode_data/flowtablewithfields.cc | 5 +-
glom/mode_design/fields/dialog_fielddefinition.cc | 15 +-
.../layout/layout_item_dialogs/box_formatting.cc | 116 +++++++++++++---
.../layout/layout_item_dialogs/box_formatting.h | 20 ++-
.../layout_item_dialogs/dialog_fieldslist.cc | 13 ++-
.../layout/layout_item_dialogs/dialog_group_by.cc | 18 +--
glom/utility_widgets/db_adddel/db_adddel.cc | 65 ++++++---
glom/utility_widgets/db_adddel/db_adddel.h | 2 +-
po/ChangeLog | 6 +
po/POTFILES.in | 2 +-
28 files changed, 581 insertions(+), 363 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1ffaabf..6cb6bfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,55 @@
+2010-09-08 Murray Cumming <murrayc murrayc com>
+
+ Initial support for multiple show-also fields in related choices.
+
+ * glom/glom_developer.glade: Formatting box: related choices:
+ Replace the second-field combo with a label and an edit button, to
+ open a layout dialog allowing multiple items (fields).
+ * glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
+ Add the code for that.
+ * glom/mode_design/fields/dialog_fielddefinition.cc: Handle changes to
+ the extra layout group in BoxFormatting.
+
+ * glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
+ Added a get_has_related_choices() with a has_second& parameter.
+ Added a get_choices_related_relationship() convenience method.
+ set/get_choices_related(): Change the field_second string parameter to
+ a full LayoutGroup, allowing multiple items (fields).
+ * glom/libglom/data_structure/layout/layoutgroup.[h|cc]:
+ Added a get_items_recursive() convenience method.
+ Adapt to the FieldFormatting change.
+ * glom/libglom/document/document.cc:
+ load_after_layout_item_formatting(), save_before_layout_item_formatting():
+ For the related choices extra fields, save an entire layout group instead of
+ just a field name, supporting the deprecated way for documents with the
+ old file format version.
+ * glom/libglom/utils.[h|cc]: get_choice_values(): Do not take
+ the first and second fields as parameters. Instead get the information from
+ the layout item. Support multiple fields, via the new layout group.
+ Added get_list_of_layout_items_for_display() to show a preview of the
+ layout group (list of fields) in the label in BoxFormatting.
+ * glom/mode_data/flowtablewithfields.cc: Adapt to the FieldFormatting change.
+ * glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc:
+ update_labels(): Improve this code, using the new
+ Utils::get_list_of_layout_items_for_display() method.
+ * glom/utility_widgets/db_adddel/db_adddel.[h|cc]: Adapt to these changes.
+
+ * glom/mode_data/datawidget/combo.[h|cc]:
+ * glom/mode_data/datawidget/combo_as_radio_buttons.cc:
+ * glom/mode_data/datawidget/combochoices.[h|cc]:
+ * glom/mode_data/datawidget/combochoiceswithtreemodel.cc:
+ * glom/mode_data/datawidget/comboentry.[h|cc]:
+ set_choices_related(): Don't take the extra fields as a parameter. Instead
+ discover them from the layout item.
+ set_choices_with_second(): Change the list_value's parameter type to support
+ multiple second values.
+ refresh_data_from_database_with_foreign_key(): Adapt the to the use of a
+ layout group instead of second field name, though this currently only uses the first field.
+ * glom/mode_data/datawidget/datawidget.cc: Adapt to the combo API changes.
+
+ * glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc: Make
+ some code slightly more robust. Not really a related change.
+
2010-09-07 Murray Cumming <murrayc murrayc com>
Dialog_Properties: Remove the unnecessary virtual keywords.
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index 322a238..c5bada8 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -6727,8 +6727,30 @@ Which user should be added to this group?</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
- <object class="GtkComboBox" id="combobox_choices_related_field_second">
+ <object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label_choices_related_extra_fields">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">label</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_choices_related_extra_fields">
+ <property name="label">gtk-edit</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index bb081db..8a9d91e 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -56,7 +56,7 @@ FieldFormatting::FieldFormatting(const FieldFormatting& src)
m_text_color_background(src.m_text_color_background),
m_horizontal_alignment(src.m_horizontal_alignment),
m_choices_related_field(src.m_choices_related_field),
- m_choices_related_field_second(src.m_choices_related_field_second),
+ m_choices_extra_layout_group(src.m_choices_extra_layout_group),
m_choices_related_show_all(src.m_choices_related_show_all)
{
}
@@ -75,7 +75,7 @@ bool FieldFormatting::operator==(const FieldFormatting& src) const
(m_choices_custom == src.m_choices_custom) &&
(m_choices_related == src.m_choices_related) &&
(m_choices_related_field == src.m_choices_related_field) &&
- (m_choices_related_field_second == src.m_choices_related_field_second) &&
+ (m_choices_extra_layout_group == src.m_choices_extra_layout_group) &&
(m_text_format_multiline == src.m_text_format_multiline) &&
(m_text_multiline_height_lines == src.m_text_multiline_height_lines) &&
(m_text_font == src.m_text_font) &&
@@ -98,7 +98,7 @@ FieldFormatting& FieldFormatting::operator=(const FieldFormatting& src)
m_choices_custom = src.m_choices_custom;
m_choices_related = src.m_choices_related;
m_choices_related_field = src.m_choices_related_field;
- m_choices_related_field_second = src.m_choices_related_field_second;
+ m_choices_extra_layout_group = src.m_choices_extra_layout_group;
m_choices_related_show_all = src.m_choices_related_show_all;
m_text_format_multiline = src.m_text_format_multiline;
@@ -190,7 +190,7 @@ FieldFormatting::HorizontalAlignment FieldFormatting::get_horizontal_alignment()
bool FieldFormatting::get_has_choices() const
{
- return ( m_choices_related && get_has_relationship_name() && !m_choices_related_field.empty() ) ||
+ return ( m_choices_related && get_has_relationship_name() && m_choices_related_field ) ||
( m_choices_custom && !m_choices_custom_list.empty() );
}
@@ -231,73 +231,40 @@ bool FieldFormatting::get_has_related_choices() const
return m_choices_related;
}
-void FieldFormatting::set_has_related_choices(bool val)
+bool FieldFormatting::get_has_related_choices(bool& show_all, bool& with_second) const
{
- m_choices_related = val;
+ show_all = m_choices_related_show_all;
+ with_second = m_choices_extra_layout_group;
+ return m_choices_related;
}
-void FieldFormatting::get_choices_related(sharedptr<const Relationship>& relationship, Glib::ustring& field, Glib::ustring& field_second, bool& show_all) const
+void FieldFormatting::set_has_related_choices(bool val)
{
- relationship = get_relationship();
-
- field = m_choices_related_field;
- field_second = m_choices_related_field_second;
- show_all = m_choices_related_show_all;
-
- //g_warning("FieldFormatting::get_choices, %s, %s, %s", m_choices_related_relationship->c_str(), m_choices_related_field.c_str(), m_choices_related_field_second.c_str());
+ m_choices_related = val;
}
-void FieldFormatting::set_choices_related(const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all)
+void FieldFormatting::set_choices_related(const sharedptr<const Relationship>& relationship, const sharedptr<const LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all)
{
set_relationship(relationship);
m_choices_related_field = field;
- m_choices_related_field_second = field_second;
+ m_choices_extra_layout_group = extra_layout;
m_choices_related_show_all = show_all;
}
-void FieldFormatting::get_choices_related(const Document* document, sharedptr<const Relationship>& relationship, sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutItem_Field>& field_second, bool& show_all) const
+void FieldFormatting::get_choices_related(sharedptr<const Relationship>& relationship, sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutGroup>& extra_layout, bool& show_all) const
{
- //Initialize output parameters:
- field.clear();
- field_second.clear();
-
- Glib::ustring choice_field, choice_second;
- get_choices_related(relationship, choice_field, choice_second, show_all);
-
- if(!relationship)
- return;
-
- if(choice_field.empty())
- return;
-
- const Glib::ustring to_table = relationship->get_to_table();
-
- sharedptr<LayoutItem_Field> temp = sharedptr<LayoutItem_Field>::create();
- sharedptr<const Field> field_details = document->get_field(to_table, choice_field);
- temp->set_full_field_details(field_details);
- field = temp;
+ relationship = get_relationship();
- if(!choice_second.empty())
- {
- sharedptr<LayoutItem_Field> temp = sharedptr<LayoutItem_Field>::create();
- sharedptr<const Field> field_details = document->get_field(to_table, choice_second);
- temp->set_full_field_details(field_details);
- field_second = temp;
- }
+ field = m_choices_related_field;
+ extra_layout = m_choices_extra_layout_group;
+ show_all = m_choices_related_show_all;
}
-void FieldFormatting::change_field_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new)
+sharedptr<const Relationship> FieldFormatting::get_choices_related_relationship(bool& show_all) const
{
- //Update choices:
- if(get_has_relationship_name() && get_table_used(Glib::ustring()) == table_name)
- {
- if(m_choices_related_field == field_name)
- m_choices_related_field = field_name_new;
-
- if(m_choices_related_field_second == field_name)
- m_choices_related_field_second = field_name_new;
- }
+ show_all = m_choices_related_show_all;
+ return get_relationship();
}
} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index b9e5a55..44e4dd9 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -30,8 +30,8 @@
namespace Glom
{
-class Document;
class LayoutItem_Field;
+class LayoutGroup;
//TODO: This should probably be renamed to Formatting, because it is used for static text items too.
class FieldFormatting : public UsesRelationship //The UsesRelationship base has the relationship for the choices.
@@ -48,6 +48,7 @@ public:
bool get_has_choices() const;
bool get_has_related_choices() const;
+ bool get_has_related_choices(bool& show_all, bool& with_second) const;
void set_has_related_choices(bool val = true);
bool get_has_custom_choices() const;
@@ -68,11 +69,14 @@ public:
*/
void set_choices_restricted(bool val = true, bool as_radio_buttons = false);
- void get_choices_related(sharedptr<const Relationship>& relationship_name, Glib::ustring& field, Glib::ustring& field_second, bool& show_all) const;
- void set_choices_related(const sharedptr<const Relationship>& relationship_name, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all);
+ void get_choices_related(sharedptr<const Relationship>& relationship_name, sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutGroup>& extra_layout, bool& show_all) const;
+ void set_choices_related(const sharedptr<const Relationship>& relationship_name, const sharedptr<const LayoutItem_Field>& field, const sharedptr<LayoutGroup>& extra_layout, bool show_all);
+
+ //Just for convenience:
+ sharedptr<const Relationship> get_choices_related_relationship(bool& show_all) const;
+
- void get_choices_related(const Document* document, sharedptr<const Relationship>& relationship_name, sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutItem_Field>& field_second, bool& show_all) const;
/** Get whether the text should be displayed with multiple lines in the
* details view. Text is displayed with a single line in the list view.
@@ -148,8 +152,6 @@ public:
void set_horizontal_alignment(HorizontalAlignment alignment);
HorizontalAlignment get_horizontal_alignment() const;
- void change_field_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
-
NumericFormat m_numeric_format; //Only used for numeric fields.
private:
@@ -166,7 +168,8 @@ private:
Glib::ustring m_text_color_foreground, m_text_color_background;
HorizontalAlignment m_horizontal_alignment;
- Glib::ustring m_choices_related_field, m_choices_related_field_second;
+ sharedptr<const LayoutItem_Field> m_choices_related_field;
+ sharedptr<LayoutGroup> m_choices_extra_layout_group;
bool m_choices_related_show_all;
};
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc b/glom/libglom/data_structure/layout/layoutgroup.cc
index 9e37b24..2220877 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -149,7 +149,7 @@ void LayoutGroup::add_item(const sharedptr<LayoutItem>& item, const sharedptr<co
//std::vector::insert() adds before rather than after:
// jhs: We want to add after rather than before - at least for dnd
//++iter;
-
+
m_list_items.insert(iter, item);
}
@@ -157,7 +157,7 @@ void LayoutGroup::remove_item (const sharedptr<LayoutItem>& item)
{
sharedptr<LayoutItem> unconst = sharedptr<LayoutItem>::cast_const(item);
type_list_items::iterator iter = std::find(m_list_items.begin(), m_list_items.end(), unconst);
- m_list_items.erase(iter);
+ m_list_items.erase(iter);
}
LayoutGroup::type_list_items LayoutGroup::get_items()
@@ -179,6 +179,26 @@ LayoutGroup::type_list_const_items LayoutGroup::get_items() const
return result;
}
+LayoutGroup::type_list_const_items LayoutGroup::get_items_recursive() const
+{
+ type_list_const_items result;
+
+ for(type_list_items::const_iterator iter = m_list_items.begin(); iter != m_list_items.end(); ++iter)
+ {
+ const sharedptr<const LayoutItem> item = *iter;
+ sharedptr<const LayoutGroup> group = sharedptr<const LayoutGroup>::cast_dynamic(item);
+ if(group)
+ {
+ const type_list_const_items sub_result = group->get_items_recursive();
+ result.insert(result.end(), sub_result.begin(), sub_result.end());
+ }
+ else
+ result.push_back(item);
+ }
+
+ return result;
+}
+
void LayoutGroup::remove_relationship(const sharedptr<const Relationship>& relationship)
{
LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin();
@@ -193,7 +213,7 @@ void LayoutGroup::remove_relationship(const sharedptr<const Relationship>& relat
if(*(uses_rel->get_relationship()) == *relationship) //TODO_Performance: Slow if there are lots of translations.
{
m_list_items.erase(iterItem);
- iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
+ iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
continue;
}
}
@@ -222,7 +242,7 @@ void LayoutGroup::remove_field(const Glib::ustring& field_name)
if(field_item->get_name() == field_name)
{
m_list_items.erase(iterItem);
- iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
+ iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
continue;
}
}
@@ -257,7 +277,7 @@ void LayoutGroup::remove_field(const Glib::ustring& table_name, const Glib::ustr
if(field_item->get_name() == field_name)
{
m_list_items.erase(iterItem);
- iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
+ iterItem = m_list_items.begin(); //Start again, because we changed the container.AddDel
continue;
}
}
@@ -330,8 +350,6 @@ void LayoutGroup::change_field_item_name(const Glib::ustring& table_name, const
if(field_item->get_name() == field_name)
field_item->set_name(field_name_new); //Change it.
}
-
- field_item->m_formatting.change_field_name(table_name, field_name, field_name_new);
}
else
{
@@ -424,7 +442,7 @@ void LayoutGroup::set_columns_count(guint columns_count)
{
m_columns_count = columns_count;
}
-
+
double LayoutGroup::get_border_width() const
{
return m_border_width;
diff --git a/glom/libglom/data_structure/layout/layoutgroup.h b/glom/libglom/data_structure/layout/layoutgroup.h
index d44fe6f..f95395c 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.h
+++ b/glom/libglom/data_structure/layout/layoutgroup.h
@@ -58,14 +58,14 @@ public:
/** Add the item after the specified existing item.
* @param item The item to add.
- * @param position The item after which the item should be added.
+ * @param position The item after which the item should be added.
*/
void add_item(const sharedptr<LayoutItem>& item, const sharedptr<const LayoutItem>& position);
-
+
/** Remove a layout item from the group
* @param item The item to remove.
*/
- void remove_item (const sharedptr<LayoutItem>& item);
+ void remove_item (const sharedptr<LayoutItem>& item);
/** Remove any instance of the field (from the current table) from the layout.
*/
@@ -94,13 +94,17 @@ public:
guint get_columns_count() const;
void set_columns_count(guint columns_count);
-
+
typedef std::vector< sharedptr<LayoutItem> > type_list_items;
type_list_items get_items();
typedef std::vector< sharedptr<const LayoutItem> > type_list_const_items;
type_list_const_items get_items() const;
+ /** Get the items recursively, depth-first, not returning any groups.
+ */
+ type_list_const_items get_items_recursive() const;
+
virtual Glib::ustring get_part_type_name() const;
virtual Glib::ustring get_report_part_id() const;
@@ -118,6 +122,3 @@ private:
} //namespace Glom
#endif //GLOM_DATASTRUCTURE_LAYOUTGROUP_H
-
-
-
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 112fbb2..6860a65 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -197,7 +197,8 @@ namespace Glom
#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED "choices_related"
#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP "choices_related_relationship"
#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD "choices_related_field"
-#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND "choices_related_second"
+#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_EXTRA_LAYOUT "choices_related_extra_layout"
+#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND "choices_related_second" //deprecated
#define GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL "choices_related_show_all"
#define GLOM_NODE_TRANSLATIONS_SET "trans_set"
@@ -930,13 +931,6 @@ void Document::change_field_name(const Glib::ustring& table_name, const Glib::us
}
}
- //Look at all field formatting:
- for(type_vec_fields::iterator iterFields = iter->second.m_fields.begin(); iterFields != iter->second.m_fields.end(); ++iterFields)
- {
- (*iterFields)->m_default_formatting.change_field_name(table_name, strFieldNameOld, strFieldNameNew);
- }
-
-
const bool is_parent_table = (iter->second.m_info->get_name() == table_name);
//Look at each layout:
@@ -1993,17 +1987,59 @@ void Document::load_after_layout_item_formatting(const xmlpp::Element* element,
const Glib::ustring relationship_name = get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP);
if(!relationship_name.empty())
{
+ sharedptr<const Relationship> relationship = get_relationship(table_name, relationship_name);
+
bool show_all = get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL);
if(get_document_format_version() < 6)
{
show_all = true; //This was the behaviour before this checkbox existed.
}
-
- sharedptr<Relationship> relationship = get_relationship(table_name, relationship_name);
+
+ const Glib::ustring field_first = get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD);
+ sharedptr<LayoutItem_Field> layout_field_first = sharedptr<LayoutItem_Field>::create();
+ layout_field_first->set_name(field_first);
+
+ sharedptr<LayoutGroup> extra_layouts;
+
+ //Previous versions just saved a single extra field name, instead of a whole set of layoutgroups:
+ if(m_document_format_version < 6)
+ {
+ //The deprecated way:
+ const Glib::ustring field_second = get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND);
+ if(!field_second.empty())
+ {
+ extra_layouts = sharedptr<LayoutGroup>::create();
+ sharedptr<LayoutItem_Field> item = sharedptr<LayoutItem_Field>::create();
+ item->set_name(field_second);
+ extra_layouts->add_item(item);
+ }
+ }
+ else
+ {
+ //Get the extra layout for related choices:
+ xmlpp::Element* nodeExtraLayout = get_node_child_named(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_EXTRA_LAYOUT);
+ if(nodeExtraLayout)
+ {
+ std::cout << "debuga1" << std::endl;
+ xmlpp::Element* nodeGroups = get_node_child_named(nodeExtraLayout, GLOM_NODE_DATA_LAYOUT_GROUPS);
+ if(nodeGroups)
+ {
+
+ sharedptr<LayoutGroup> layout_group = sharedptr<LayoutGroup>::create();
+ load_after_layout_group(nodeGroups, relationship->get_to_table(), layout_group);
+ if(layout_group && !(layout_group->m_list_items.empty()))
+ {
+ //We actually want the sub-group:
+ extra_layouts = sharedptr<LayoutGroup>::cast_dynamic( layout_group->m_list_items[0] );
+ }
+ }
+ }
+ }
+
format.set_choices_related(relationship,
- get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD),
- get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND),
+ layout_field_first, extra_layouts,
show_all);
+
//Full details are updated in filled-in ().
}
}
@@ -3001,14 +3037,26 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED, format.get_has_related_choices() );
sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
+ sharedptr<const LayoutItem_Field> choice_layout_first;
+ sharedptr<const LayoutGroup> choice_extra_layouts;
bool choice_show_all = false;
- format.get_choices_related(choice_relationship, choice_field, choice_second, choice_show_all);
+ format.get_choices_related(choice_relationship, choice_layout_first, choice_extra_layouts, choice_show_all);
+
+ Glib::ustring choice_field;
+ if(choice_layout_first)
+ choice_field = choice_layout_first->get_name();
set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_RELATIONSHIP, glom_get_sharedptr_name(choice_relationship));
set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_FIELD, choice_field);
- set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SECOND, choice_second);
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_SHOW_ALL, choice_show_all);
+
+ //Save the extra fields to show for related choices:
+ if(choice_extra_layouts)
+ {
+ xmlpp::Element* nodeExtraLayout = nodeItem->add_child(GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED_EXTRA_LAYOUT);
+ xmlpp::Element* nodeGroups = nodeExtraLayout->add_child(GLOM_NODE_DATA_LAYOUT_GROUPS);
+ save_before_layout_group(nodeGroups, choice_extra_layouts);
+ }
}
}
@@ -3921,7 +3969,7 @@ sharedptr<const Relationship> Document::get_field_used_in_relationship_to_one(co
if(!layout_field)
{
std::cerr << G_STRFUNC << ": layout_field was null" << std::endl;
- return result;
+ return result;
}
const Glib::ustring table_used = layout_field->get_table_used(table_name);
@@ -3929,7 +3977,7 @@ sharedptr<const Relationship> Document::get_field_used_in_relationship_to_one(co
if(iterFind == m_tables.end())
{
std::cerr << G_STRFUNC << ": table not found:" << table_used << std::endl;
- return result;
+ return result;
}
//Look at each relationship:
@@ -4199,7 +4247,7 @@ guint Document::get_latest_known_document_format_version()
// Version 3: (Glom 1.10). Support for the old one-big-string example_rows format was removed, and we now use (unquoted) non-postgres libgda escaping.
// Version 4: (Glom 1.12). Portal navigation options were simplified, with a "none" option. network_sharing was added, defaulting to off.
// Version 5: (Glom 1.14). Extra layout item formatting options were added, plus a startup script.
- // Version 6: (Glom 1.16). Extra show_all option for choices that show related records.
+ // Version 6: (Glom 1.16). Extra show_all option for choices that show related records. Extra related choice fields are now a layout group instead of just a second field name.
return 6;
}
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index e4669a2..2691fa0 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -480,19 +480,14 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_key(const Glib
sharedptr<const Relationship>(), sort_clause, limit);
}
-Utils::type_list_values_with_second Utils::get_choice_values_all(const Document* document, const sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutItem_Field>& layout_choice_first, sharedptr<const LayoutItem_Field>& layout_choice_second)
+Utils::type_list_values_with_second Utils::get_choice_values_all(const Document* document, const sharedptr<const LayoutItem_Field>& field)
{
return get_choice_values(document, field,
- Gnome::Gda::Value() /* means get all with no WHERE clause */,
- layout_choice_first, layout_choice_second);
+ Gnome::Gda::Value() /* means get all with no WHERE clause */);
}
-Utils::type_list_values_with_second Utils::get_choice_values(const Document* document, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& foreign_key_value, sharedptr<const LayoutItem_Field>& layout_choice_first, sharedptr<const LayoutItem_Field>& layout_choice_second)
+Utils::type_list_values_with_second Utils::get_choice_values(const Document* document, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& foreign_key_value)
{
- //Initialize output parameters:
- layout_choice_first = sharedptr<LayoutItem_Field>();
- layout_choice_second = sharedptr<LayoutItem_Field>();
-
//TODO: Reduce duplication between this and get_choice_values(field).
type_list_values_with_second result;
@@ -508,9 +503,10 @@ Utils::type_list_values_with_second Utils::get_choice_values(const Document* doc
const FieldFormatting& format = field->get_formatting_used();
sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
+ sharedptr<const LayoutItem_Field> layout_choice_first;
+ sharedptr<const LayoutGroup> layout_choice_extra;
bool choice_show_all = false;
- format.get_choices_related(document, choice_relationship, layout_choice_first, layout_choice_second, choice_show_all);
+ format.get_choices_related(choice_relationship, layout_choice_first, layout_choice_extra, choice_show_all);
if(!choice_relationship)
{
@@ -520,11 +516,22 @@ Utils::type_list_values_with_second Utils::get_choice_values(const Document* doc
Utils::type_vecConstLayoutFields fields;
fields.push_back(layout_choice_first);
- if(layout_choice_second)
- fields.push_back(layout_choice_second);
+
+ if(layout_choice_extra)
+ {
+ const LayoutGroup::type_list_const_items extra_fields = layout_choice_extra->get_items_recursive();
+ for(LayoutGroup::type_list_const_items::const_iterator iter = extra_fields.begin();
+ iter != extra_fields.end(); ++iter)
+ {
+ const sharedptr<const LayoutItem> item = *iter;
+ const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
+ if(item_field)
+ fields.push_back(item_field); //TODO: Don't ignore other usable items such as static text.
+ }
+ }
const Glib::ustring to_table = choice_relationship->get_to_table();
- sharedptr<Field> to_field = document->get_field(to_table, choice_relationship->get_to_field());
+ const sharedptr<const Field> to_field = document->get_field(to_table, choice_relationship->get_to_field());
if(!to_field)
{
@@ -571,11 +578,19 @@ Utils::type_list_values_with_second Utils::get_choice_values(const Document* doc
for(guint row = 0; row < count; ++row)
{
- std::pair<Gnome::Gda::Value, Gnome::Gda::Value> itempair;
+ std::pair<Gnome::Gda::Value, type_list_values> itempair;
itempair.first = datamodel->get_value_at(0, row);
- if(layout_choice_second && (cols_count > 1))
- itempair.second = datamodel->get_value_at(1, row);
+ if(layout_choice_extra && (cols_count > 1))
+ {
+ type_list_values list_values;
+ for(guint i = 1; i < cols_count; ++i)
+ {
+ list_values.push_back(datamodel->get_value_at(1, row));
+ }
+
+ itempair.second = list_values;
+ }
result.push_back(itempair);
}
@@ -1124,5 +1139,30 @@ Glib::ustring Utils::get_directory_child_with_suffix(const Glib::ustring& uri_di
return Glib::ustring();
}
+Glib::ustring Utils::get_list_of_layout_items_for_display(const LayoutGroup::type_list_items& list_layout_fields)
+{
+ Glib::ustring result;
+ for(LayoutGroup::type_list_items::const_iterator iter = list_layout_fields.begin(); iter != list_layout_fields.end(); ++iter)
+ {
+ const sharedptr<LayoutItem> item = *iter;
+ if(item)
+ {
+ if(!result.empty())
+ result += ", ";
+
+ result += item->get_layout_display_name();
+ }
+ }
+
+ return result;
+}
+
+Glib::ustring Utils::get_list_of_layout_items_for_display(const sharedptr<const LayoutGroup>& layout_group)
+{
+ if(layout_group)
+ return get_list_of_layout_items_for_display(layout_group->m_list_items);
+ else
+ return Glib::ustring();
+}
} //namespace Glom
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index 13339c6..4415e08 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -111,11 +111,11 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_with_key(
Gnome::Gda::SqlExpr get_find_where_clause_quick(const Document* document, const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search);
+typedef std::list<Gnome::Gda::Value> type_list_values;
+typedef std::list< 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 Document* document, const sharedptr<const LayoutItem_Field>& field);
-typedef std::list< std::pair<Gnome::Gda::Value, Gnome::Gda::Value> > type_list_values_with_second;
-type_list_values_with_second get_choice_values_all(const Document* document, const sharedptr<const LayoutItem_Field>& field, sharedptr<const LayoutItem_Field>& layout_choice_first, sharedptr<const LayoutItem_Field>& layout_choice_second);
-
-type_list_values_with_second get_choice_values(const Document* document, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& foreign_key_value, sharedptr<const LayoutItem_Field>& layout_choice_first, sharedptr<const LayoutItem_Field>& layout_choice_second);
+type_list_values_with_second get_choice_values(const Document* document, const sharedptr<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(
@@ -177,6 +177,14 @@ bool delete_directory(const std::string& uri);
*/
Glib::ustring get_directory_child_with_suffix(const Glib::ustring& uri_directory, const std::string& suffix, bool recursive);
+/** Get a string to display to the user, as a representation of a list of layout items.
+ */
+Glib::ustring get_list_of_layout_items_for_display(const LayoutGroup::type_list_items& list_layout_fields);
+
+/** Get a string to display to the user, as a representation of a list of layout items.
+ */
+Glib::ustring get_list_of_layout_items_for_display(const sharedptr<const LayoutGroup>& layout_group);
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 6283ece..fe0d980 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -73,10 +73,17 @@ ComboGlom::~ComboGlom()
{
}
-void ComboGlom::set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all)
+void ComboGlom::set_choices_related(const Document* document)
{
+ //TODO: Remove duplication with ComboEntry:
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ bool choice_show_all = false;
+ bool choice_has_second = false;
+ layout_item->get_formatting_used().get_has_related_choices(choice_show_all, choice_has_second);
+
//Add the extra cell if necessary:
- if(!m_cell_second && !field_second.empty())
+ if(!m_cell_second && choice_has_second)
{
#ifndef GLOM_ENABLE_MAEMO
//We don't use this convenience method, because we want more control over the renderer.
@@ -99,7 +106,7 @@ void ComboGlom::set_choices_related(const Document* document, const sharedptr<co
#endif //GLOM_ENABLE_MAEMO
}
- ComboChoicesWithTreeModel::set_choices_related(document, relationship, field, field_second, show_all);
+ ComboChoicesWithTreeModel::set_choices_related(document);
}
void ComboGlom::check_for_change()
diff --git a/glom/mode_data/datawidget/combo.h b/glom/mode_data/datawidget/combo.h
index c48c96c..830cb5c 100644
--- a/glom/mode_data/datawidget/combo.h
+++ b/glom/mode_data/datawidget/combo.h
@@ -72,7 +72,7 @@ public:
virtual Gnome::Gda::Value get_value() const;
- virtual void set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all);
+ virtual void set_choices_related(const Document* document);
private:
void init();
diff --git a/glom/mode_data/datawidget/combo_as_radio_buttons.cc b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
index 2a31a4b..ed96c1d 100644
--- a/glom/mode_data/datawidget/combo_as_radio_buttons.cc
+++ b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
@@ -47,11 +47,6 @@ ComboAsRadioButtons::ComboAsRadioButtons()
void ComboAsRadioButtons::init()
{
- if(m_related_field_second)
- {
- //TODO
- }
-
//if(m_glom_type == Field::TYPE_NUMERIC)
// get_entry()->set_alignment(1.0); //Align numbers to the right.
}
@@ -59,7 +54,7 @@ void ComboAsRadioButtons::init()
void ComboAsRadioButtons::set_choices_with_second(const type_list_values_with_second& list_values)
{
//Clear existing buttons:
- for(type_map_buttons::iterator iter = m_map_buttons.begin();
+ for(type_map_buttons::iterator iter = m_map_buttons.begin();
iter != m_map_buttons.end(); ++iter)
{
Gtk::RadioButton* button = iter->second;
@@ -67,21 +62,49 @@ void ComboAsRadioButtons::set_choices_with_second(const type_list_values_with_se
}
m_map_buttons.clear();
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ const FieldFormatting& format = layout_item->get_formatting_used();
+ sharedptr<const Relationship> choice_relationship;
+ sharedptr<const LayoutItem_Field> layout_choice_first;
+ sharedptr<const LayoutGroup> layout_choice_extra;
+ bool choice_show_all = false;
+ format.get_choices_related(choice_relationship, layout_choice_first, layout_choice_extra, choice_show_all);
+
+ LayoutGroup::type_list_const_items extra_fields;
+ if(layout_choice_extra)
+ extra_fields = layout_choice_extra->get_items_recursive();
+
//Add new buttons:
Gtk::RadioButton::Group group;
for(type_list_values_with_second::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
{
- sharedptr<const LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
- if(layout_item)
+ if(layout_choice_first)
{
- const Glib::ustring value_first = Conversions::get_text_for_gda_value(layout_item->get_glom_type(), iter->first, layout_item->get_formatting_used().m_numeric_format);
+ const Glib::ustring value_first = Conversions::get_text_for_gda_value(layout_choice_first->get_glom_type(), iter->first, layout_choice_first->get_formatting_used().m_numeric_format);
Glib::ustring title = value_first;
- if(m_related_field_second)
+
+ const type_list_values extra_values = iter->second;
+ if(layout_choice_extra && !extra_values.empty())
{
- const Glib::ustring value_second = Conversions::get_text_for_gda_value(m_related_field_second->get_glom_type(), iter->second, m_related_field_second->get_formatting_used().m_numeric_format);
- title += " - " + value_second; //TODO: Find a better way to join them?
+ type_list_values::const_iterator iterValues = extra_values.begin();
+ for(LayoutGroup::type_list_const_items::const_iterator iterExtra = extra_fields.begin();
+ iterExtra != extra_fields.end(); ++iterExtra)
+ {
+ const sharedptr<const LayoutItem> item = *iterExtra;
+ const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
+ if(item_field && (iterValues != extra_values.end()))
+ {
+ const Gnome::Gda::Value value = *iterValues; //TODO: Use a vector instead?
+ const Glib::ustring value_second = Conversions::get_text_for_gda_value(item_field->get_glom_type(), value, item_field->get_formatting_used().m_numeric_format);
+
+ title += " - " + value_second; //TODO: Find a better way to join them?
+ }
+
+ ++iterValues;
+ }
}
-
+
Gtk::RadioButton* button = new Gtk::RadioButton(group, title);
m_map_buttons[value_first] = button;
pack_start(*button);
@@ -93,13 +116,13 @@ void ComboAsRadioButtons::set_choices_with_second(const type_list_values_with_se
button->signal_button_press_event().connect(
sigc::mem_fun(*this, &ComboAsRadioButtons::on_radiobutton_button_press_event), false);
}
- }
+ }
}
void ComboAsRadioButtons::set_choices(const FieldFormatting::type_list_values& list_values)
{
//Clear existing buttons:
- for(type_map_buttons::iterator iter = m_map_buttons.begin();
+ for(type_map_buttons::iterator iter = m_map_buttons.begin();
iter != m_map_buttons.end(); ++iter)
{
Gtk::RadioButton* button = iter->second;
@@ -115,7 +138,7 @@ void ComboAsRadioButtons::set_choices(const FieldFormatting::type_list_values& l
if(layout_item)
{
const Glib::ustring value_first = Conversions::get_text_for_gda_value(layout_item->get_glom_type(), *iter, layout_item->get_formatting_used().m_numeric_format);
-
+
Gtk::RadioButton* button = new Gtk::RadioButton(group, value_first);
m_map_buttons[value_first] = button;
pack_start(*button);
@@ -123,20 +146,20 @@ void ComboAsRadioButtons::set_choices(const FieldFormatting::type_list_values& l
button->signal_toggled().connect(
sigc::mem_fun(*this, &ComboAsRadioButtons::on_radiobutton_toggled));
}
- }
+ }
}
ComboAsRadioButtons::~ComboAsRadioButtons()
{
- for(type_map_buttons::iterator iter = m_map_buttons.begin();
+ for(type_map_buttons::iterator iter = m_map_buttons.begin();
iter != m_map_buttons.end(); ++iter)
{
Gtk::RadioButton* button = iter->second;
delete button;
}
- m_map_buttons.clear();
+ m_map_buttons.clear();
}
void ComboAsRadioButtons::check_for_change()
@@ -224,7 +247,7 @@ Glib::ustring ComboAsRadioButtons::get_text() const
return iter->first;
}
}
-
+
return Glib::ustring();
}
diff --git a/glom/mode_data/datawidget/combochoices.cc b/glom/mode_data/datawidget/combochoices.cc
index 3d6f00f..b77420e 100644
--- a/glom/mode_data/datawidget/combochoices.cc
+++ b/glom/mode_data/datawidget/combochoices.cc
@@ -38,7 +38,6 @@ namespace DataWidgetChildren
{
ComboChoices::ComboChoices()
-: m_related_show_all(false)
{
init();
}
@@ -53,33 +52,10 @@ ComboChoices::~ComboChoices()
bool ComboChoices::refresh_data_from_database_with_foreign_key(const Document* document, const Gnome::Gda::Value& foreign_key_value)
{
- //Get the choice information, then cache it:
- if(!m_related_relationship || !m_related_field)
- {
- sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
- if(!layout_item)
- {
- return false;
- }
-
- //TODO: Avoid repeating this tedious code in so many places:
- const FieldFormatting& format = layout_item->get_formatting_used();
- format.get_choices_related(document, m_related_relationship, m_related_field, m_related_field_second, m_related_show_all);
-
- if(!m_related_relationship)
- {
- std::cerr << G_STRFUNC << ": !m_related_relationship." << std::endl;
- return false;
- }
- }
-
- if(!m_related_field)
- {
- std::cerr << G_STRFUNC << ": !m_related_field." << std::endl;
- return false;
- }
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
- if(Conversions::value_is_empty(foreign_key_value))
+ if(!layout_item || Conversions::value_is_empty(foreign_key_value))
{
//Clear the choices list:
type_list_values_with_second list_values;
@@ -87,110 +63,32 @@ bool ComboChoices::refresh_data_from_database_with_foreign_key(const Document* d
return true;
}
- if(m_related_show_all)
- {
- //The list should be set in set_choices_related() instead.
- std::cerr << G_STRFUNC << ": Called with m_related_show_all=true." << std::endl;
- return false;
- }
-
- Utils::type_vecConstLayoutFields fields;
- fields.push_back(m_related_field);
- if(m_related_field_second)
- fields.push_back(m_related_field_second);
-
- //std::cout << G_STRFUNC << "debug: m_related_field=" << m_related_field->get_name() << ", m_related_field_second" << m_related_field_second->get_name() << std::endl;
-
- if(!m_related_to_field)
- {
- std::cerr << G_STRFUNC << ": m_related_to_field is null." << std::endl;
- }
-
- //TODO: Support related relationships (in the UI too):
- Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Utils::build_sql_select_with_key(
- m_related_relationship->get_to_table(),
- fields,
- m_related_to_field,
- foreign_key_value);
-
- if(!builder)
- {
- std::cerr << G_STRFUNC << ": builder is null." << std::endl;
- return false;
- }
-
- //TODO: builder->select_order_by(choice_field_id);
-
- //Connect to database and get the related values:
- sharedptr<SharedConnection> connection = ConnectionPool::get_instance()->connect();
-
- if(!connection)
- {
- std::cerr << G_STRFUNC << ": connection is null." << std::endl;
- return false;
- }
-
- const std::string sql_query =
- Utils::sqlbuilder_get_full_query(builder);
- //std::cout << "get_choice_values: Executing SQL: " << sql_query << std::endl;
- Glib::RefPtr<Gnome::Gda::DataModel> datamodel = connection->get_gda_connection()->statement_execute_select(sql_query);
-
- if(datamodel)
- {
- type_list_values_with_second list_values;
-
- const guint count = datamodel->get_n_rows();
- const guint cols_count = datamodel->get_n_columns();
- //std::cout << " result: count=" << count << std::endl;
- for(guint row = 0; row < count; ++row)
- {
-
- std::pair<Gnome::Gda::Value, Gnome::Gda::Value> itempair;
- itempair.first = datamodel->get_value_at(0, row);
-
- if(m_related_field_second && (cols_count > 1))
- itempair.second = datamodel->get_value_at(1, row);
-
- list_values.push_back(itempair);
- }
-
- const Gnome::Gda::Value old_value = get_value();
- set_choices_with_second(list_values);
- set_value(old_value); //Try to preserve the value, even in iter-based ComboBoxes.
- }
- else
- {
- std::cerr << G_STRFUNC << ": Error while executing SQL" << std::endl <<
- " " << sql_query << std::endl;
- return false;
- }
+ const Utils::type_list_values_with_second list_values = Utils::get_choice_values(document, layout_item, foreign_key_value);
+ const Gnome::Gda::Value old_value = get_value();
+ set_choices_with_second(list_values);
+ set_value(old_value); //Try to preserve the value, even in iter-based ComboBoxes.
return true;
}
-void ComboChoices::set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& /* field */, const Glib::ustring& /* field_second */, bool show_all)
+void ComboChoices::set_choices_related(const Document* document)
{
- //Note that field_second is used in derived classes.
-
- m_related_relationship = relationship;
- m_related_show_all = show_all;
-
- m_related_field.clear();
- m_related_field_second.clear();
- if(m_related_relationship)
- {
- const Glib::ustring to_table = m_related_relationship->get_to_table();
- m_related_to_field = document->get_field(to_table, m_related_relationship->get_to_field());
- }
-
type_list_values_with_second list_values;
- //Set the values now because if it will be the same regardless of the foreign key value.
- //Otherwise show them when refresh_data_from_database_with_foreign_key() is called.
- if(relationship && show_all)
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ if(layout_item)
{
- sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
- list_values = Utils::get_choice_values_all(document, layout_item, m_related_field, m_related_field_second);
+ bool choice_show_all = false;
+ const sharedptr<const Relationship> choice_relationship =
+ layout_item->get_formatting_used().get_choices_related_relationship(choice_show_all);
+
+ //Set the values now because if it will be the same regardless of the foreign key value.
+ //Otherwise show them when refresh_data_from_database_with_foreign_key() is called.
+ if(choice_relationship && choice_show_all)
+ {
+ list_values = Utils::get_choice_values_all(document, layout_item);
+ }
}
const Gnome::Gda::Value old_value = get_value();
diff --git a/glom/mode_data/datawidget/combochoices.h b/glom/mode_data/datawidget/combochoices.h
index 762e80b..6c885d0 100644
--- a/glom/mode_data/datawidget/combochoices.h
+++ b/glom/mode_data/datawidget/combochoices.h
@@ -50,11 +50,8 @@ public:
/**
* See also refresh_data_from_database_with_foreign_key().
- * @param relationship Just to save some extra lookup in the format, from get_layout_item().
- * @param field Just to save some extra lookup in the format, from get_layout_item().
- * @param field_second Just to save some extra lookup in the format, from get_layout_item().
*/
- virtual void set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all);
+ virtual void set_choices_related(const Document* document);
/** Update a choices widget's list of related choices if a relevant value in its parent table has changed.
*
@@ -65,17 +62,11 @@ public:
protected:
void init();
- typedef std::list< std::pair<Gnome::Gda::Value, Gnome::Gda::Value> > type_list_values_with_second;
+ typedef std::list<Gnome::Gda::Value> type_list_values;
+ typedef std::list< std::pair<Gnome::Gda::Value, type_list_values> > type_list_values_with_second;
virtual void set_choices_with_second(const type_list_values_with_second& list_values) = 0;
//Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
-
- //These are used if it is related choices:
- sharedptr<const Relationship> m_related_relationship;
- sharedptr<const Field> m_related_to_field; //To avoid retrieving it each time.
- sharedptr<const LayoutItem_Field> m_related_field;
- sharedptr<const LayoutItem_Field> m_related_field_second;
- bool m_related_show_all;
};
} //namespace DataWidetChildren
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index 6cf8ac6..5726b7d 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -53,19 +53,46 @@ void ComboChoicesWithTreeModel::set_choices_with_second(const type_list_values_w
{
m_refModel->clear();
+ //TODO: Remove duplication with ComboEntry:
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ const FieldFormatting& format = layout_item->get_formatting_used();
+ sharedptr<const Relationship> choice_relationship;
+ sharedptr<const LayoutItem_Field> layout_choice_first;
+ sharedptr<const LayoutGroup> layout_choice_extra;
+ bool choice_show_all = false;
+ format.get_choices_related(choice_relationship, layout_choice_first, layout_choice_extra, choice_show_all);
+
+ LayoutGroup::type_list_const_items extra_fields;
+ if(layout_choice_extra)
+ extra_fields = layout_choice_extra->get_items_recursive();
+
for(type_list_values_with_second::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
{
Gtk::TreeModel::iterator iterTree = m_refModel->append();
Gtk::TreeModel::Row row = *iterTree;
- sharedptr<const LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
- if(layout_item)
+ if(layout_choice_first)
{
- row[m_Columns.m_col_first] = Conversions::get_text_for_gda_value(layout_item->get_glom_type(), iter->first, layout_item->get_formatting_used().m_numeric_format);
+ row[m_Columns.m_col_first] = Conversions::get_text_for_gda_value(layout_choice_first->get_glom_type(), iter->first, layout_choice_first->get_formatting_used().m_numeric_format);
- if(m_related_field_second)
+ //TODO: Support multiple extra fields:
+ //For now, use only the first extra field:
+ const type_list_values extra_values = iter->second;
+ if(layout_choice_extra && !extra_values.empty())
{
- row[m_Columns.m_col_second] = Conversions::get_text_for_gda_value(m_related_field_second->get_glom_type(), iter->second, m_related_field_second->get_formatting_used().m_numeric_format);
+ for(LayoutGroup::type_list_const_items::const_iterator iterExtra = extra_fields.begin();
+ iterExtra != extra_fields.end(); ++iterExtra)
+ {
+ const sharedptr<const LayoutItem> item = *iterExtra;
+ const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
+ if(item_field)
+ {
+ const Gnome::Gda::Value value = *(extra_values.begin()); //TODO: Use a vector instead?
+ row[m_Columns.m_col_second] = Conversions::get_text_for_gda_value(item_field->get_glom_type(), value, item_field->get_formatting_used().m_numeric_format);
+ break;
+ }
+ }
}
}
}
diff --git a/glom/mode_data/datawidget/comboentry.cc b/glom/mode_data/datawidget/comboentry.cc
index 051fc65..5188330 100644
--- a/glom/mode_data/datawidget/comboentry.cc
+++ b/glom/mode_data/datawidget/comboentry.cc
@@ -112,9 +112,15 @@ ComboEntry::~ComboEntry()
{
}
-void ComboEntry::set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all)
+void ComboEntry::set_choices_related(const Document* document)
{
- if(!m_cell_second && !field_second.empty())
+ sharedptr<LayoutItem_Field> layout_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ bool choice_show_all = false;
+ bool choice_has_second = false;
+ layout_item->get_formatting_used().get_has_related_choices(choice_show_all, choice_has_second);
+
+ if(!m_cell_second && choice_has_second) //Use a more efficient way of discovering if there is a second column.
{
#ifndef GLOM_ENABLE_MAEMO
//We don't use this convenience method, because we want more control over the renderer.
@@ -135,7 +141,7 @@ void ComboEntry::set_choices_related(const Document* document, const sharedptr<c
#endif //GLOM_ENABLE_MAEMO
}
- ComboChoicesWithTreeModel::set_choices_related(document, relationship, field, field_second, show_all);
+ ComboChoicesWithTreeModel::set_choices_related(document);
}
void ComboEntry::set_layout_item(const sharedptr<LayoutItem>& layout_item, const Glib::ustring& table_name)
diff --git a/glom/mode_data/datawidget/comboentry.h b/glom/mode_data/datawidget/comboentry.h
index bbff22f..87fa061 100644
--- a/glom/mode_data/datawidget/comboentry.h
+++ b/glom/mode_data/datawidget/comboentry.h
@@ -71,7 +71,7 @@ public:
virtual void set_read_only(bool read_only = true);
- virtual void set_choices_related(const Document* document, const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second, bool show_all);
+ virtual void set_choices_related(const Document* document);
private:
void init();
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index a5051f3..fcb0185 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -130,12 +130,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
combo = create_combo_widget_for_field(field);
combo->set_layout_item( get_layout_item(), table_name);
- sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
- bool choice_show_all = false;
- field->get_formatting_used().get_choices_related(choice_relationship, choice_field, choice_second, choice_show_all);
-
- combo->set_choices_related(document, choice_relationship, choice_field, choice_second, choice_show_all);
+ combo->set_choices_related(document);
}
else
{
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 8569903..3a5460e 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -930,10 +930,9 @@ FlowTableWithFields::type_choice_widgets FlowTableWithFields::get_choice_widgets
const FieldFormatting& format = field->get_formatting_used();
- sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
bool choice_show_all = false;
- format.get_choices_related(choice_relationship, choice_field, choice_second, choice_show_all);
+ const sharedptr<const Relationship> choice_relationship =
+ format.get_choices_related_relationship(choice_show_all);
if(choice_show_all)
continue; //"Show All" choices don't use the ID field values.
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc b/glom/mode_design/fields/dialog_fielddefinition.cc
index 5d17274..de5a404 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -45,7 +45,7 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
builder->get_widget("checkbutton_unique", m_pCheck_Unique);
builder->get_widget("checkbutton_primarykey", m_pCheck_PrimaryKey);
- builder->get_widget("checkbutton_autoincrement", m_pCheck_AutoIncrement);
+ builder->get_widget("checkbutton_autoincrement", m_pCheck_AutoIncrement);
builder->get_widget("hbox_default_value_simple", m_pBox_DefaultValueSimple);
@@ -97,6 +97,10 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
on_foreach_connect(*m_pBox_ValueTab);
on_foreach_connect(*m_box_formatting);
+ //Plus an extra signal for the related extra show-also fields:
+ m_box_formatting->signal_modified().connect(
+ sigc::mem_fun(*this, &Dialog_FieldDefinition::on_anything_changed));
+
Dialog_Properties::set_modified(false);
show_all_children();
@@ -160,7 +164,7 @@ void Dialog_FieldDefinition::set_field(const sharedptr<const Field>& field, cons
if(!pLabel->get_text().empty())
m_pBox_DefaultValueSimple->pack_start(*pLabel);
- m_pBox_DefaultValueSimple->pack_end(*m_pDataWidget_DefaultValueSimple, Gtk::PACK_EXPAND_WIDGET);
+ m_pBox_DefaultValueSimple->pack_end(*m_pDataWidget_DefaultValueSimple, Gtk::PACK_EXPAND_WIDGET);
m_pDataWidget_DefaultValueSimple->set_value(default_value);
m_pDataWidget_DefaultValueSimple->show();
@@ -220,7 +224,7 @@ sharedptr<Field> Dialog_FieldDefinition::get_field() const
// const_cast is necessary and save here for the window (jhs)
sharedptr<SharedConnection> sharedcnc = connect_to_server(const_cast<Dialog_FieldDefinition*>(this));
Glib::RefPtr<Gnome::Gda::Connection> cnc = sharedcnc->get_gda_connection();
-
+
//Get the field info from the widgets:
Glib::RefPtr<Gnome::Gda::Column> fieldInfo = field->get_field_info(); //Preserve previous information.
@@ -372,7 +376,7 @@ void Dialog_FieldDefinition::on_button_edit_calculation()
//TODO: Share a global instance, to make this quicker?
Dialog_FieldCalculation* dialog = 0;
Utils::get_glade_widget_derived_with_warning(dialog);
-
+
add_view(dialog); //Give it access to the document.
m_Field->set_calculation( m_pTextView_Calculation->get_buffer()->get_text() );
@@ -389,6 +393,3 @@ void Dialog_FieldDefinition::on_button_edit_calculation()
}
} //namespace Glom
-
-
-
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 94126ef..2f46482 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -18,8 +18,12 @@
* Boston, MA 02111-1307, USA.
*/
+
#include "box_formatting.h"
+#include <glom/utils_ui.h>
+#include <glom/glade_utils.h>
#include <libglom/data_structure/glomconversions.h>
+#include <glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.h>
#include <glibmm/i18n.h>
namespace Glom
@@ -59,8 +63,10 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
m_col_index_custom_choices(0),
m_combo_choices_relationship(0),
m_combo_choices_field(0),
- m_combo_choices_field_second(0),
+ m_label_choices_extra_fields(0),
+ m_button_choices_extra_fields(0),
m_checkbutton_choices_related_show_all(0),
+ m_dialog_choices_extra_fields(0),
m_for_print_layout(false),
m_show_numeric(true),
m_show_choices(true)
@@ -115,7 +121,7 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
m_combo_format_text_horizontal_alignment->set_model(m_model_alignment);
m_combo_format_text_horizontal_alignment->pack_start(m_columns_alignment.m_col_title);
-
+
//Choices:
builder->get_widget("vbox_choices", m_vbox_choices);
@@ -126,11 +132,12 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
m_adddel_choices_custom->set_auto_add();
builder->get_widget("checkbutton_choices_restrict", m_checkbutton_choices_restricted);
- builder->get_widget("checkbutton_choices_restrict_as_radio_buttons", m_checkbutton_choices_restricted_as_radio_buttons);
+ builder->get_widget("checkbutton_choices_restrict_as_radio_buttons", m_checkbutton_choices_restricted_as_radio_buttons);
builder->get_widget_derived("combobox_choices_related_relationship", m_combo_choices_relationship);
builder->get_widget_derived("combobox_choices_related_field", m_combo_choices_field);
- builder->get_widget_derived("combobox_choices_related_field_second", m_combo_choices_field_second);
+ builder->get_widget("label_choices_related_extra_fields", m_label_choices_extra_fields);
+ builder->get_widget("button_choices_related_extra_fields", m_button_choices_extra_fields);
builder->get_widget("checkbutton_choices_related_show_all", m_checkbutton_choices_related_show_all);
builder->get_widget("radiobutton_choices_custom", m_radiobutton_choices_custom);
builder->get_widget("radiobutton_choices_related", m_radiobutton_choices_related);
@@ -143,12 +150,24 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
m_checkbox_format_text_color_background->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
m_checkbox_format_color_negatives->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
m_checkbutton_choices_restricted->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
+ m_button_choices_extra_fields->signal_clicked().connect( sigc::mem_fun(*this, &Box_Formatting::on_button_choices_extra) );
+
+ if(!m_dialog_choices_extra_fields)
+ {
+ Utils::get_glade_widget_derived_with_warning(m_dialog_choices_extra_fields);
+ add_view(m_dialog_choices_extra_fields); //Give it access to the document.
+ }
show_all_children();
}
Box_Formatting::~Box_Formatting()
{
+ if(m_dialog_choices_extra_fields)
+ {
+ remove_view(m_dialog_choices_extra_fields); //Give it access to the document.
+ delete m_dialog_choices_extra_fields;
+ }
}
void Box_Formatting::set_is_for_print_layout()
@@ -156,7 +175,7 @@ void Box_Formatting::set_is_for_print_layout()
m_for_print_layout = true;
m_show_choices = false;
- //Add labels (because we will hide the checkboxes):
+ //Add labels (because we will hide the checkboxes):
Gtk::Label* label = Gtk::manage(new Gtk::Label(_("Font")));
label->show();
m_hbox_font->pack_start(*label, Gtk::PACK_SHRINK);
@@ -165,7 +184,7 @@ void Box_Formatting::set_is_for_print_layout()
m_hbox_color_foreground->pack_start(*label, Gtk::PACK_SHRINK);
label = Gtk::manage(new Gtk::Label(_("Background Color")));
label->show();
- m_hbox_color_background->pack_start(*label, Gtk::PACK_SHRINK);
+ m_hbox_color_background->pack_start(*label, Gtk::PACK_SHRINK);
enforce_constraints();
}
@@ -200,9 +219,9 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
format.m_numeric_format.m_alt_foreground_color_for_negatives );
//Text formatting
- const FieldFormatting::HorizontalAlignment alignment =
+ const FieldFormatting::HorizontalAlignment alignment =
format.get_horizontal_alignment();
- Gtk::TreeModel::Children children = m_model_alignment->children();
+ Gtk::TreeModel::Children children = m_model_alignment->children();
for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter)
{
Gtk::TreeModel::Row row = *iter;
@@ -245,14 +264,30 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
m_combo_choices_relationship->set_relationships(vecRelationships);
sharedptr<const Relationship> choices_relationship;
- Glib::ustring choices_field, choices_field_second;
+ sharedptr<const LayoutItem_Field> choices_field;
+ sharedptr<const LayoutGroup> choices_field_extras;
bool choices_show_all = false;
- format.get_choices_related(choices_relationship, choices_field, choices_field_second, choices_show_all);
+ format.get_choices_related(choices_relationship, choices_field, choices_field_extras, choices_show_all);
m_combo_choices_relationship->set_selected_relationship(choices_relationship);
on_combo_choices_relationship_changed(); //Fill the combos so we can set their active items.
- m_combo_choices_field->set_selected_field(choices_field);
- m_combo_choices_field_second->set_selected_field(choices_field_second);
+ m_combo_choices_field->set_selected_field(choices_field ? choices_field->get_name() : Glib::ustring());
+
+ //Show the list of fields in a label:
+ const Glib::ustring text_extra_fields =
+ Utils::get_list_of_layout_items_for_display(choices_field_extras);
+ m_label_choices_extra_fields->set_text(text_extra_fields);
+
+ //Update the contents of the dialog that will be shown if Edit is clicked:
+ const Glib::ustring related_to_table =
+ (choices_relationship ? choices_relationship->get_to_table() : Glib::ustring());
+ if(choices_field_extras)
+ m_dialog_choices_extra_fields->set_fields(related_to_table, choices_field_extras->m_list_items);
+ else
+ m_dialog_choices_extra_fields->set_fields(related_to_table, LayoutGroup::type_list_items());
+
+
+
m_checkbutton_choices_related_show_all->set_active(choices_show_all);
//Custom choices:
@@ -284,7 +319,7 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
m_format.m_numeric_format.m_currency_symbol = m_entry_currency_symbol->get_entry()->get_text();
- m_format.m_numeric_format.m_alt_foreground_color_for_negatives =
+ m_format.m_numeric_format.m_alt_foreground_color_for_negatives =
m_checkbox_format_color_negatives->get_active();
//Text formatting:
@@ -317,13 +352,18 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
if(m_field)
{
m_format.set_choices_restricted(
- m_checkbutton_choices_restricted->get_active(),
+ m_checkbutton_choices_restricted->get_active(),
m_checkbutton_choices_restricted_as_radio_buttons->get_active());
- sharedptr<Relationship> choices_relationship = m_combo_choices_relationship->get_selected_relationship();
+ const sharedptr<const Relationship> choices_relationship = m_combo_choices_relationship->get_selected_relationship();
+ sharedptr<LayoutItem_Field> layout_choice_first = sharedptr<LayoutItem_Field>::create();
+ layout_choice_first->set_name(m_combo_choices_field->get_selected_field_name());
+
+ sharedptr<LayoutGroup> layout_choice_extra = sharedptr<LayoutGroup>::create();
+ layout_choice_extra->m_list_items = m_dialog_choices_extra_fields->get_fields();
+
m_format.set_choices_related(choices_relationship,
- m_combo_choices_field->get_selected_field_name(),
- m_combo_choices_field_second->get_selected_field_name(),
+ layout_choice_first, layout_choice_extra,
m_checkbutton_choices_related_show_all->get_active());
//Custom choices:
@@ -364,10 +404,19 @@ void Box_Formatting::on_combo_choices_relationship_changed()
//Show the list of formats from this relationship:
if(relationship)
{
- Document::type_vec_fields vecFields = pDocument->get_table_fields(relationship->get_to_table());
-
+ const Document::type_vec_fields vecFields = pDocument->get_table_fields(relationship->get_to_table());
m_combo_choices_field->set_fields(vecFields);
- m_combo_choices_field_second->set_fields(vecFields, true /* with_none_item */); //We add a "None" item so this GtkComboBox can be cleared by the user.
+
+ //Update the show-all dialog's list:
+ //If the related table name has changed then the list of fields will probably
+ //be ignored, clearing the list, but we try to preserve it if possible:
+ const LayoutGroup::type_list_items list_fields = m_dialog_choices_extra_fields->get_fields();
+ m_dialog_choices_extra_fields->set_fields(relationship->get_to_table(), list_fields);
+
+ //Update the label:
+ const Glib::ustring text_extra_fields =
+ Utils::get_list_of_layout_items_for_display(m_dialog_choices_extra_fields->get_fields());
+ m_label_choices_extra_fields->set_text(text_extra_fields);
}
}
}
@@ -432,7 +481,7 @@ void Box_Formatting::enforce_constraints()
//Radio buttons only make sense when the items are restricted, instead of free-form:
m_checkbutton_choices_restricted_as_radio_buttons->set_sensitive(
m_checkbutton_choices_restricted->get_active());
-
+
if(m_show_numeric)
m_vbox_numeric_format->show();
else
@@ -449,4 +498,29 @@ void Box_Formatting::on_checkbox()
enforce_constraints();
}
+void Box_Formatting::on_button_choices_extra()
+{
+ if(!m_dialog_choices_extra_fields)
+ return;
+
+ const int response = Glom::Utils::dialog_run_with_help(m_dialog_choices_extra_fields);
+ m_dialog_choices_extra_fields->hide();
+ if(response == Gtk::RESPONSE_OK && m_dialog_choices_extra_fields->get_modified())
+ {
+ //Update the label:
+ const Glib::ustring text_extra_fields =
+ Utils::get_list_of_layout_items_for_display(m_dialog_choices_extra_fields->get_fields());
+ m_label_choices_extra_fields->set_text(text_extra_fields);
+
+ //Tell the parent (which connects directly to all other (regular) widgets):
+ m_signal_modified.emit();
+ }
+}
+
+
+Box_Formatting::type_signal_modified Box_Formatting::signal_modified()
+{
+ return m_signal_modified;
+}
+
} //namespace Glom
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index 21db584..350756f 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -28,10 +28,13 @@
#include <glom/mode_design/comboentry_currency.h>
#include <glom/mode_design/layout/combobox_relationship.h>
#include <glom/mode_design/layout/combobox_fields.h>
+#include <glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.h>
namespace Glom
{
+class Dialog_FieldsList;
+
class Box_Formatting
: public Gtk::VBox,
public View_Composite_Glom
@@ -47,7 +50,7 @@ public:
* @param format The starting information.
*/
void set_formatting(const FieldFormatting& format, bool show_numeric = true, bool show_choices = true);
-
+
/**
* @param format The starting information.
* @param table_name The field's table.
@@ -56,14 +59,18 @@ public:
void set_formatting(const FieldFormatting& format, const Glib::ustring& table_name, const sharedptr<const Field>& field);
bool get_formatting(FieldFormatting& format) const;
- //When used for print layout items,
+ //When used for print layout items,
//we hide some stuff:
void set_is_for_print_layout();
+ typedef sigc::signal<void> type_signal_modified;
+ type_signal_modified signal_modified();
+
private:
//Signal handlers:
void on_combo_choices_relationship_changed();
void on_checkbox();
+ void on_button_choices_extra();
void enforce_constraints();
@@ -98,21 +105,26 @@ private:
guint m_col_index_custom_choices;
ComboBox_Relationship* m_combo_choices_relationship;
ComboBox_Fields* m_combo_choices_field;
- ComboBox_Fields* m_combo_choices_field_second;
+ Gtk::Label* m_label_choices_extra_fields;
+ Gtk::Button* m_button_choices_extra_fields;
Gtk::CheckButton* m_checkbutton_choices_related_show_all;
+ Dialog_FieldsList* m_dialog_choices_extra_fields;
+
mutable FieldFormatting m_format;
Glib::ustring m_table_name;
sharedptr<const Field> m_field;
- //We show different options when
+ //We show different options when
//showing this on a print layout.
bool m_for_print_layout;
bool m_show_numeric;
bool m_show_choices;
+ type_signal_modified m_signal_modified;
+
class AlignmentColumns: public Gtk::TreeModelColumnRecord
{
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc
index cdc0de1..ee4d42f 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc
@@ -120,6 +120,8 @@ void Dialog_FieldsList::set_fields(const Glib::ustring& table_name, const Layout
for(LayoutGroup::type_list_items::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
{
sharedptr<const LayoutItem_Field> item = sharedptr<const LayoutItem_Field>::cast_dynamic(*iter);
+ if(!item)
+ continue;
Gtk::TreeModel::iterator iterTree = m_model_fields->append();
Gtk::TreeModel::Row row = *iterTree;
@@ -277,7 +279,16 @@ void Dialog_FieldsList::on_cell_data_name(Gtk::CellRenderer* renderer, const Gtk
Gtk::TreeModel::Row row = *iter;
sharedptr<const LayoutItem_Field> item = row[m_ColumnsFields.m_col_layout_item]; //TODO_performance: Reduce copying.
- renderer_text->property_markup() = item->get_layout_display_name();
+ if(item)
+ {
+ renderer_text->property_markup() = item->get_layout_display_name();
+ }
+ else
+ {
+ //Though this really shouldn't even be in the model:
+ renderer_text->property_markup() = Glib::ustring();
+ }
+
renderer_text->property_editable() = false; //Names can never be edited.
}
}
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
index 0089315..147b550 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
@@ -209,22 +209,8 @@ void Dialog_GroupBy::update_labels()
m_label_sort_by->set_text( Glib::ustring() );
//Secondary Fields:
- Glib::ustring text_secondary_fields;
- if(m_layout_item->m_group_secondary_fields)
- {
- const LayoutGroup::type_list_items& map_items = m_layout_item->m_group_secondary_fields->m_list_items;
- for(LayoutGroup::type_list_items::const_iterator iter = map_items.begin(); iter != map_items.end(); ++iter)
- {
- if(*iter)
- {
- if(!text_secondary_fields.empty())
- text_secondary_fields += ", ";
-
- text_secondary_fields += (*iter)->get_layout_display_name();
- }
- }
- }
-
+ const Glib::ustring text_secondary_fields =
+ Utils::get_list_of_layout_items_for_display(m_layout_item->m_group_secondary_fields);
m_label_secondary_fields->set_text(text_secondary_fields);
}
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index fe0fb23..fd5315b 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -832,25 +832,24 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
else if(item_field && item_field->get_formatting_used().get_has_related_choices())
{
sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
+ sharedptr<const LayoutItem_Field> choice_field;
+ sharedptr<const LayoutGroup> choice_extras;
bool choice_show_all;
- item_field->get_formatting_used().get_choices_related(choice_relationship, choice_field, choice_second, choice_show_all);
+ item_field->get_formatting_used().get_choices_related(choice_relationship, choice_field, choice_extras, choice_show_all);
- if(choice_relationship && !choice_field.empty())
+ if(choice_relationship && choice_field)
{
const Glib::ustring to_table = choice_relationship->get_to_table();
- const bool use_second = !choice_second.empty();
+ const bool use_second = choice_extras;
pCellRendererCombo->set_use_second(use_second);
//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.
{
- Document* document = get_document();
- sharedptr<const LayoutItem_Field> layout_field_first;
- sharedptr<const LayoutItem_Field> layout_field_second;
- Utils::type_list_values_with_second list_values = Utils::get_choice_values_all(document, item_field, layout_field_first, layout_field_second);
- set_cell_choices(pCellRendererCombo, layout_field_first, layout_field_second, list_values);
+ const Utils::type_list_values_with_second list_values =
+ Utils::get_choice_values_all(get_document(), item_field);
+ set_cell_choices(pCellRendererCombo, choice_field, choice_extras, list_values);
}
}
}
@@ -1237,7 +1236,7 @@ void DbAddDel::set_value_selected(const sharedptr<const LayoutItem_Field>& layou
set_value(get_item_selected(), layout_item, value);
}
-void DbAddDel::set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first, const sharedptr<const LayoutItem_Field>& layout_choice_second, const Utils::type_list_values_with_second& list_values)
+void DbAddDel::set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first, const sharedptr<const LayoutGroup>& layout_choice_extras, const Utils::type_list_values_with_second& list_values)
{
if(!cell)
return;
@@ -1251,11 +1250,34 @@ void DbAddDel::set_cell_choices(CellRendererList* cell, const sharedptr<const La
Conversions::get_text_for_gda_value(
layout_choice_first->get_glom_type(), iter->first, layout_choice_first->get_formatting_used().m_numeric_format);
+ //TODO: Support multiple extra fields:
+ //For now, use only the first extra field:
+ sharedptr<const LayoutItem_Field> layout_choice_second;
+ if(layout_choice_extras)
+ {
+ const LayoutGroup::type_list_const_items extra_fields
+ = layout_choice_extras->get_items_recursive();
+
+ for(LayoutGroup::type_list_const_items::const_iterator iterExtra = extra_fields.begin();
+ iterExtra != extra_fields.end(); ++iterExtra)
+ {
+ const sharedptr<const LayoutItem> item = *iterExtra;
+ const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
+ if(item_field)
+ {
+ layout_choice_second = item_field;
+ break;
+ }
+ }
+ }
+
Glib::ustring second;
- if(layout_choice_second)
+ const Utils::type_list_values extra_values = iter->second;
+ if(layout_choice_second && !extra_values.empty())
{
+ const Gnome::Gda::Value value = *(extra_values.begin()); //TODO: Use a vector instead?
second = Conversions::get_text_for_gda_value(
- layout_choice_second->get_glom_type(), iter->second, layout_choice_second->get_formatting_used().m_numeric_format);
+ layout_choice_second->get_glom_type(), value, layout_choice_second->get_formatting_used().m_numeric_format);
}
cell->append_list_item(first, second);
@@ -1294,14 +1316,16 @@ void DbAddDel::refresh_cell_choices_data_from_database_with_foreign_key(guint mo
return;
}
+ const Utils::type_list_values_with_second list_values =
+ Utils::get_choice_values(get_document(), layout_field, foreign_key_value);
+ sharedptr<const Relationship> choice_relationship;
sharedptr<const LayoutItem_Field> layout_choice_first;
- sharedptr<const LayoutItem_Field> layout_choice_second;
- Utils::type_list_values_with_second list_values =
- Utils::get_choice_values(get_document(), layout_field, foreign_key_value,
- layout_choice_first, layout_choice_second);
-
- set_cell_choices(cell, layout_choice_first, layout_choice_second, list_values);
+ sharedptr<const LayoutGroup> layout_choice_extras;
+ bool choice_show_all = false;
+ layout_field->get_formatting_used().get_choices_related(choice_relationship, layout_choice_first, layout_choice_extras, choice_show_all);
+
+ set_cell_choices(cell, layout_choice_first, layout_choice_extras, list_values);
}
void DbAddDel::remove_all_columns()
@@ -1443,10 +1467,9 @@ DbAddDel::type_list_indexes DbAddDel::get_choice_index(const sharedptr<const Lay
const FieldFormatting& format = field->get_formatting_used();
- sharedptr<const Relationship> choice_relationship;
- Glib::ustring choice_field, choice_second;
bool choice_show_all = false;
- format.get_choices_related(choice_relationship, choice_field, choice_second, choice_show_all);
+ const sharedptr<const Relationship> choice_relationship =
+ format.get_choices_related_relationship(choice_show_all);
if(choice_relationship && !choice_show_all) //"Show All" choices don't use the ID field values.
{
if(choice_relationship->get_from_field() == from_key_name)
diff --git a/glom/utility_widgets/db_adddel/db_adddel.h b/glom/utility_widgets/db_adddel/db_adddel.h
index d453c83..e09521d 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.h
+++ b/glom/utility_widgets/db_adddel/db_adddel.h
@@ -390,7 +390,7 @@ private:
//TODO: Remove this and use AppGlom::get_application() instead?
Application* get_application();
- void set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first, const sharedptr<const LayoutItem_Field>& layout_choice_second, const Utils::type_list_values_with_second& list_values);
+ void set_cell_choices(CellRendererList* cell, const sharedptr<const LayoutItem_Field>& layout_choice_first, const sharedptr<const LayoutGroup>& layout_choice_extras, const Utils::type_list_values_with_second& list_values);
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 sharedptr<const LayoutItem_WithFormatting>& layout_item);
diff --git a/po/ChangeLog b/po/ChangeLog
index 075770d..b80a7b0 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -1,3 +1,9 @@
+2010-09-08 Murray Cumming <murrayc murrayc-desktop>
+
+ reviewed by: <delete if not using a buddy>
+
+ * POTFILES.in:
+
2009-09-03 Murray Cumming <murrayc murrayc-x61>
reviewed by: <delete if not using a buddy>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f0e47fd..12a4099 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -90,7 +90,7 @@ glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
glom/mode_design/layout/layout_item_dialogs/dialog_field_summary.cc
glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
-glom/mode_design/layout/layout_item_dialogs/dialog_groupby_secondaryfields.cc
+glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc
glom/mode_design/layout/layout_item_dialogs/dialog_groupby_sortfields.cc
glom/mode_design/layout/layout_item_dialogs/dialog_imageobject.cc
glom/mode_design/layout/layout_item_dialogs/dialog_notebook.cc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]