[glom] Dialog_FieldDefinition: Don't offer a self-triggering lookup.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Dialog_FieldDefinition: Don't offer a self-triggering lookup.
- Date: Mon, 7 Sep 2015 14:49:05 +0000 (UTC)
commit 5629610aced8ce202d92a7259abd8e76f332ce47
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Sep 7 16:45:51 2015 +0200
Dialog_FieldDefinition: Don't offer a self-triggering lookup.
Document: Add get_relationships_excluding_triggered_by().
Dialog_FieldDefinition::set_field(): Use it to avoid offering
a relationship in the list of lookup relationships if the
relationship has the actual field as its from field, because
that would be a self-triggering relationship (endless).
Ideally, we would have some way to show the user why they don't
see the relationship in the list, but at least we will prevent
them from doing this.
The previous commit checks for this too.
Bug #754641 (m.rick.mac)
glom/libglom/document/document.cc | 42 +++++++++++++++-----
glom/libglom/document/document.h | 11 +++++
glom/mode_design/fields/dialog_fielddefinition.cc | 4 +-
3 files changed, 45 insertions(+), 12 deletions(-)
---
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index b82d622..91b8230 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -625,24 +625,44 @@ std::shared_ptr<Relationship> Document::get_relationship(const Glib::ustring& ta
Document::type_vec_relationships Document::get_relationships(const Glib::ustring& table_name, bool
plus_system_prefs) const
{
- const std::shared_ptr<const DocumentTableInfo> info = get_table_info(table_name);
- if(info)
+ return get_relationships_excluding_triggered_by(table_name, Glib::ustring(), plus_system_prefs);
+}
+
+Document::type_vec_relationships Document::get_relationships_excluding_triggered_by(const Glib::ustring&
table_name, const Glib::ustring& excluding_triggered_by_field, bool plus_system_prefs) const
+{
+ const auto info = get_table_info(table_name);
+ if(!info)
+ return type_vec_relationships();
+
+ auto result = info->m_relationships;
+
+ //Add the system properties if necessary:
+ if(plus_system_prefs)
{
- auto result = info->m_relationships;
+ if(find_if_same_name(result, GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES) == result.end())
+ {
+ result.push_back(create_relationship_system_preferences(table_name));
+ }
+ }
- //Add the system properties if necessary:
- if(plus_system_prefs)
+ if(!excluding_triggered_by_field.empty())
+ {
+ //Remove self-lookups:
+ auto iter = result.begin();
+ while(iter != result.end())
{
- if(find_if_same_name(result, GLOM_RELATIONSHIP_NAME_SYSTEM_PROPERTIES) == result.end())
+ const auto& rel = *iter;
+ if(rel && (rel->get_from_field()) == excluding_triggered_by_field)
{
- result.push_back(create_relationship_system_preferences(table_name));
+ iter = result.erase(iter);
+ }
+ else {
+ ++iter;
}
}
-
- return result;
}
- else
- return type_vec_relationships();
+
+ return result;
}
void Document::set_relationships(const Glib::ustring& table_name, const type_vec_relationships&
vecRelationships) //TODO_shared_relationships
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 05bd723..72acae8 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -184,7 +184,18 @@ public:
std::vector<Glib::ustring> get_translation_available_locales() const;
typedef std::vector< std::shared_ptr<Relationship> > type_vec_relationships;
+
+ /** Get relationships used by this table.
+ */
type_vec_relationships get_relationships(const Glib::ustring& table_name, bool plus_system_prefs = false)
const;
+
+
+ /** Get relationships used by this table,
+ * excluding relationships whose from_field is the @a excluding_triggered_by_field field,
+ * to prevent self-triggering lookups.
+ */
+ type_vec_relationships get_relationships_excluding_triggered_by(const Glib::ustring& table_name, const
Glib::ustring& excluding_triggered_by_field, bool plus_system_prefs = false) const;
+
void set_relationships(const Glib::ustring& table_name, const type_vec_relationships& vecRelationships);
std::shared_ptr<Relationship> get_relationship(const Glib::ustring& table_name, const Glib::ustring&
relationship_name) const;
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc
b/glom/mode_design/fields/dialog_fielddefinition.cc
index 1d0367f..cf15b56 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -175,7 +175,9 @@ void Dialog_FieldDefinition::set_field(const std::shared_ptr<const Field>& field
Document* document = dynamic_cast<Document*>(get_document());
if(document)
{
- const auto vecRelationships = document->get_relationships(table_name);
+ //Get the relationships used by this table, excluding relationships triggered
+ //by this field itself (to avoid circular self-lookups):
+ const auto vecRelationships = document->get_relationships_excluding_triggered_by(table_name,
m_Field->get_name());
m_pCombo_LookupRelationship->set_relationships(vecRelationships);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]