[glom] ComboGlom::set_value(): Do not cause a change to be signalled.



commit f6538b6964e279af6778336ac23aef1e65ec2fb2
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 9 23:10:17 2011 +0200

    ComboGlom::set_value(): Do not cause a change to be signalled.
    
    * glom/mode_data/datawidget/combo.[h|cc]: Prevent unsuitable signal
    emissions when setting the value programatically.

 ChangeLog                          |    7 +++++++
 glom/mode_data/datawidget/combo.cc |   12 +++++++++++-
 glom/mode_data/datawidget/combo.h  |    3 +++
 3 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f24d56f..3595fa0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-09-09  Murray Cumming  <murrayc murrayc com>
 
+	ComboGlom::set_value(): Do not cause a change to be signalled.
+
+	* glom/mode_data/datawidget/combo.[h|cc]: Prevent unsuitable signal 
+	emissions when setting the value programatically.
+
+2011-09-09  Murray Cumming  <murrayc murrayc com>
+
 	Do not create XML documents containing form feeds.
 
 	* glom/libglom/utils.[h|cc]: Added string_clean_for_xml(), though it is 
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 7f07788..46caf52 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -43,7 +43,8 @@ namespace DataWidgetChildren
 
 ComboGlom::ComboGlom(bool has_entry)
 : Gtk::ComboBox(has_entry),
-  ComboChoicesWithTreeModel()
+  ComboChoicesWithTreeModel(),
+  m_ignore_changed(false)
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
@@ -207,6 +208,10 @@ void ComboGlom::set_value(const Gnome::Gda::Value& value)
     return;
   }
 
+  //Avoid emiting the edited signal just because of these calls:
+  const bool old_ignore = m_ignore_changed;
+  m_ignore_changed = true;
+
   bool found = false;
   for(Gtk::TreeModel::iterator iter = model->children().begin(); iter != model->children().end(); ++iter)
   {
@@ -228,6 +233,8 @@ void ComboGlom::set_value(const Gnome::Gda::Value& value)
     unset_active();
   }
 
+  m_ignore_changed = old_ignore;
+
   //Show a different color if the value is numeric, if that's specified:
   if(layout_item->get_glom_type() == Field::TYPE_NUMERIC)
   {
@@ -318,6 +325,9 @@ void ComboGlom::on_changed()
   //Call base class:
   Gtk::ComboBox::on_changed();
 
+  if(m_ignore_changed)
+    return;
+
   //This signal is emitted for every key press, but sometimes it's just to say that the active item has changed to "no active item",
   //if the text is not in the dropdown list:
   Gtk::TreeModel::iterator iter = get_active();
diff --git a/glom/mode_data/datawidget/combo.h b/glom/mode_data/datawidget/combo.h
index 06f0612..8f25991 100644
--- a/glom/mode_data/datawidget/combo.h
+++ b/glom/mode_data/datawidget/combo.h
@@ -79,6 +79,9 @@ private:
 
   Gnome::Gda::Value m_old_value; //TODO: Only useful for navigation, which currently has no implementation.
   //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
+
+  //Prevent us from emitting signals just because set_value() was called:
+  bool m_ignore_changed;
 };
 
 } //namespace DataWidetChildren



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]