[glom] Dialog_FieldDefinition: Show self-triggering lookups as grayed-out.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Dialog_FieldDefinition: Show self-triggering lookups as grayed-out.
- Date: Thu, 10 Sep 2015 13:41:56 +0000 (UTC)
commit c54711d6559da6bf350e6f9a47b320572c96bde9
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Sep 10 15:33:42 2015 +0200
Dialog_FieldDefinition: Show self-triggering lookups as grayed-out.
This gives the user some clue. I would like to explain why it
is grayed out, in a tooltip, but I don't think GTK+ allows that.
Bug #754641 (m.rick.mac)
glom/libglom/document/document.cc | 22 ----------------
glom/libglom/document/document.h | 7 -----
glom/mode_design/fields/dialog_fielddefinition.cc | 4 +-
glom/mode_design/layout/combobox_relationship.cc | 28 +++++++++++++++++++++
glom/mode_design/layout/combobox_relationship.h | 4 +++
5 files changed, 34 insertions(+), 31 deletions(-)
---
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 91b8230..c15b4b5 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -625,11 +625,6 @@ 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
{
- 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();
@@ -645,23 +640,6 @@ Document::type_vec_relationships Document::get_relationships_excluding_triggered
}
}
- if(!excluding_triggered_by_field.empty())
- {
- //Remove self-lookups:
- auto iter = result.begin();
- while(iter != result.end())
- {
- const auto& rel = *iter;
- if(rel && (rel->get_from_field()) == excluding_triggered_by_field)
- {
- iter = result.erase(iter);
- }
- else {
- ++iter;
- }
- }
- }
-
return result;
}
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 72acae8..6769863 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -189,13 +189,6 @@ public:
*/
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 cf15b56..31539fd 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -177,8 +177,8 @@ void Dialog_FieldDefinition::set_field(const std::shared_ptr<const Field>& field
{
//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);
+ const auto vecRelationships = document->get_relationships(table_name);
+ m_pCombo_LookupRelationship->set_relationships_excluding_triggered_by(vecRelationships,
m_Field->get_name());
}
std::shared_ptr<Relationship> lookup_relationship;
diff --git a/glom/mode_design/layout/combobox_relationship.cc
b/glom/mode_design/layout/combobox_relationship.cc
index 231c4ae..88e09af 100644
--- a/glom/mode_design/layout/combobox_relationship.cc
+++ b/glom/mode_design/layout/combobox_relationship.cc
@@ -186,7 +186,13 @@ void ComboBox_Relationship::set_relationships(Document* document, const Glib::us
void ComboBox_Relationship::set_relationships(const type_vec_relationships& relationships)
{
+ set_relationships_excluding_triggered_by(relationships, Glib::ustring());
+}
+
+void ComboBox_Relationship::set_relationships_excluding_triggered_by(const type_vec_relationships&
relationships, const Glib::ustring& excluding_triggered_by_field)
+{
m_model->clear();
+ m_excluding_triggered_by_field = excluding_triggered_by_field;
set_display_parent_table(Glib::ustring(), Glib::ustring());
@@ -213,10 +219,19 @@ void ComboBox_Relationship::on_cell_data_name(const Gtk::TreeModel::const_iterat
}
*/
+bool ComboBox_Relationship::get_cell_is_sensitive(const std::shared_ptr<const Relationship>& relationship)
const
+{
+ if(m_excluding_triggered_by_field.empty())
+ return true;
+
+ return relationship->get_from_field() != m_excluding_triggered_by_field;
+}
+
void ComboBox_Relationship::on_cell_data_title(const Gtk::TreeModel::const_iterator& iter)
{
Gtk::TreeModel::Row row = *iter;
Glib::ustring title;
+ bool sensitive = true;
std::shared_ptr<Relationship> relationship = row[m_model_columns.m_relationship];
if(relationship)
{
@@ -226,10 +241,16 @@ void ComboBox_Relationship::on_cell_data_title(const Gtk::TreeModel::const_itera
//related relationship:
std::shared_ptr<Relationship> parent_relationship = (*iterParent)[m_model_columns.m_relationship];
if(parent_relationship)
+ {
title = item_get_title_or_name(parent_relationship) + "::" + item_get_title_or_name(relationship);
+ sensitive = get_cell_is_sensitive(parent_relationship);
+ }
}
else
+ {
title = item_get_title_or_name(relationship);
+ sensitive = get_cell_is_sensitive(relationship);
+ }
}
else if(get_has_parent_table())
{
@@ -241,6 +262,7 @@ void ComboBox_Relationship::on_cell_data_title(const Gtk::TreeModel::const_itera
}
m_renderer_title->property_text() = title;
+ m_renderer_title->property_sensitive() = sensitive;
}
bool ComboBox_Relationship::on_row_separator(const Glib::RefPtr<Gtk::TreeModel>& /* model */, const
Gtk::TreeModel::const_iterator& iter)
@@ -254,6 +276,7 @@ void ComboBox_Relationship::on_cell_data_fromfield(const Gtk::TreeModel::const_i
{
Gtk::TreeModel::Row row = *iter;
Glib::ustring text;
+ bool sensitive = true;
std::shared_ptr<Relationship> relationship = row[m_model_columns.m_relationship];
if(relationship && relationship->get_has_fields())
{
@@ -262,15 +285,20 @@ void ComboBox_Relationship::on_cell_data_fromfield(const Gtk::TreeModel::const_i
{
std::shared_ptr<Relationship> parent_relationship = (*iterParent)[m_model_columns.m_relationship];
if(parent_relationship)
+ {
text = Glib::ustring::compose(_(" Via: %1::%2"), item_get_title(parent_relationship),
relationship->get_from_field());
+ sensitive = get_cell_is_sensitive(parent_relationship);
+ }
}
else
{
text = Glib::ustring::compose(_(" Via: %1"), relationship->get_to_field());
+ sensitive = get_cell_is_sensitive(relationship);
}
}
m_renderer_fromfield->property_text() = text;
+ m_renderer_fromfield->property_sensitive() = sensitive;
}
void ComboBox_Relationship::set_display_parent_table(const Glib::ustring& table_name, const Glib::ustring&
table_title)
diff --git a/glom/mode_design/layout/combobox_relationship.h b/glom/mode_design/layout/combobox_relationship.h
index 76b3ebb..13731d3 100644
--- a/glom/mode_design/layout/combobox_relationship.h
+++ b/glom/mode_design/layout/combobox_relationship.h
@@ -41,6 +41,8 @@ public:
typedef std::vector< std::shared_ptr<Relationship> > type_vec_relationships;
void set_relationships(const type_vec_relationships& relationship);
+ void set_relationships_excluding_triggered_by(const type_vec_relationships& relationship, const
Glib::ustring& excluding_triggered_by_field);
+
void set_relationships(Document* document, const Glib::ustring parent_table_name, bool
show_related_relationships = false, bool show_parent_table = true);
void set_selected_relationship(const std::shared_ptr<const Relationship>& relationship);
@@ -64,6 +66,7 @@ private:
void on_cell_data_fromfield(const Gtk::TreeModel::const_iterator& iter);
bool on_row_separator(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::const_iterator&
iter);
+ bool get_cell_is_sensitive(const std::shared_ptr<const Relationship>& relationship) const;
bool get_has_parent_table() const;
//Tree model columns:
@@ -86,6 +89,7 @@ private:
Gtk::CellRendererText* m_renderer_fromfield;
Glib::ustring m_extra_table_name, m_extra_table_title;
+ Glib::ustring m_excluding_triggered_by_field;
};
} //namespace Glom
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]