[glom/glom-1-18] Fields: Adapt choices fields when changing field names.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-18] Fields: Adapt choices fields when changing field names.
- Date: Fri, 7 Oct 2011 07:57:49 +0000 (UTC)
commit a288dd6f7000b5f8335c13198a728abffb8c7b4e
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Oct 7 09:44:02 2011 +0200
Fields: Adapt choices fields when changing field names.
* glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
Added change_field_item_name().
* glom/libglom/data_structure/layout/layoutgroup.cc: change_field_item_name():
Change the formatting too, by calling the new method.
* glom/libglom/document/document.cc: change_field_name(): Change the default
formatting of fields too.
Bug #661075
ChangeLog | 12 +++++++++
.../data_structure/layout/fieldformatting.cc | 27 ++++++++++++++++++++
.../data_structure/layout/fieldformatting.h | 7 +++++
glom/libglom/data_structure/layout/layoutgroup.cc | 15 ++++++++++-
glom/libglom/document/document.cc | 16 +++++++++--
5 files changed, 73 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d20958..58b74cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-10-07 Murray Cumming <murrayc murrayc com>
+
+ Fields: Adapt choices fields when changing field names.
+
+ * glom/libglom/data_structure/layout/fieldformatting.[h|cc]:
+ Added change_field_item_name().
+ * glom/libglom/data_structure/layout/layoutgroup.cc: change_field_item_name():
+ Change the formatting too, by calling the new method.
+ * glom/libglom/document/document.cc: change_field_name(): Change the default
+ formatting of fields too.
+ Bug #661075
+
2011-10-06 Murray Cumming <murrayc murrayc com>
TreeModelDb: fill_values_if_necessary(): Avoid a crash.
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index bb081db..c616f3d 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -300,4 +300,31 @@ void FieldFormatting::change_field_name(const Glib::ustring& table_name, const G
}
}
+bool FieldFormatting::change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name_old, const Glib::ustring& field_name_new)
+{
+ if(!m_choices_related_field)
+ return false; //Nothing changed.
+
+ sharedptr<const Relationship> relationship = get_relationship();
+
+ const Glib::ustring field_table =
+ m_choices_related_field->get_table_used( relationship->get_to_table() );
+
+ if((field_table == table_name) &&
+ (m_choices_related_field->get_name() == field_name_old))
+ {
+ //Change it:
+ m_choices_related_field->set_name(field_name_new);
+ return true; //something changed.
+ }
+
+ if(m_choices_extra_layout_group)
+ {
+ m_choices_extra_layout_group->change_field_item_name(table_name,
+ field_name_old, field_name_new);
+ }
+
+ return false; //Nothing changed.
+}
+
} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index b9e5a55..151ed54 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -152,6 +152,13 @@ public:
NumericFormat m_numeric_format; //Only used for numeric fields.
+ /** Adapt to a change of field name,
+ * so this Formatting does not refer to any field that no longer exists.
+ *
+ * @result true if something was changed.
+ */
+ bool change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name_old, const Glib::ustring& field_name_new);
+
private:
type_list_values m_choices_custom_list; //A drop-down list of possible values for the field.
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc b/glom/libglom/data_structure/layout/layoutgroup.cc
index 9e37b24..80f3bc4 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -310,7 +310,10 @@ void LayoutGroup::change_field_item_name(const Glib::ustring& table_name, const
for(LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin(); iterItem != m_list_items.end(); ++iterItem)
{
sharedptr<LayoutItem> item = *iterItem;
- sharedptr<LayoutItem_Field> field_item = sharedptr<LayoutItem_Field>::cast_dynamic(item);
+ sharedptr<LayoutItem_Field> field_item =
+ sharedptr<LayoutItem_Field>::cast_dynamic(item);
+
+ //Field layout items:
if(field_item)
{
if(field_item->get_has_relationship_name()) //If it's a related table (this would be a self-relationship)
@@ -335,6 +338,16 @@ void LayoutGroup::change_field_item_name(const Glib::ustring& table_name, const
}
else
{
+ //Formatting:
+ sharedptr<LayoutItem_WithFormatting> with_formatting =
+ sharedptr<LayoutItem_WithFormatting>::cast_dynamic(item);
+ if(with_formatting)
+ {
+ FieldFormatting& formatting = with_formatting->m_formatting;
+ formatting.change_field_item_name(table_name, field_name, field_name_new);
+ }
+
+ //Recurse into sub-groups:
sharedptr<LayoutGroup> sub_group = sharedptr<LayoutGroup>::cast_dynamic(item);
if(sub_group)
sub_group->change_field_item_name(table_name, field_name, field_name_new);
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 37091ec..6e208b2 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -887,7 +887,6 @@ sharedptr<Field> Document::get_field(const Glib::ustring& table_name, const Glib
return sharedptr<Field>();
}
-
void Document::change_field_name(const Glib::ustring& table_name, const Glib::ustring& strFieldNameOld, const Glib::ustring& strFieldNameNew)
{
type_tables::iterator iterFindTable = m_tables.find(table_name);
@@ -902,11 +901,23 @@ void Document::change_field_name(const Glib::ustring& table_name, const Glib::us
(*iterFind)->set_name(strFieldNameNew);
}
-
//Find any relationships, layouts, or formatting that use this field
//Look at each table:
for(type_tables::iterator iter = m_tables.begin(); iter != m_tables.end(); ++iter)
{
+ //Fields:
+ type_vec_fields& vecFields = iter->second.m_fields;
+ for(type_vec_fields::iterator iterField = vecFields.begin(); iterField != vecFields.end(); ++iterField)
+ {
+ sharedptr<Field> field = *iterField;
+ if(!field)
+ continue;
+
+ //Formatting:
+ FieldFormatting& formatting = field->m_default_formatting;
+ formatting.change_field_item_name(table_name, strFieldNameOld, strFieldNameNew);
+ }
+
//Look at each relationship in the table:
for(type_vec_relationships::iterator iterRels = iter->second.m_relationships.begin(); iterRels != iter->second.m_relationships.end(); ++iterRels)
{
@@ -943,7 +954,6 @@ void Document::change_field_name(const Glib::ustring& table_name, const Glib::us
//Look at each layout:
for(DocumentTableInfo::type_layouts::iterator iterLayouts = iter->second.m_layouts.begin(); iterLayouts != iter->second.m_layouts.end(); ++iterLayouts)
{
-
//Look at each group:
for(type_list_layout_groups::iterator iterGroup = iterLayouts->m_layout_groups.begin(); iterGroup != iterLayouts->m_layout_groups.end(); ++iterGroup)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]