glom r1599 - in trunk: . glom/libglom/data_structure glom/libglom/data_structure/layout glom/mode_data



Author: murrayc
Date: Wed Apr 30 19:11:10 2008
New Revision: 1599
URL: http://svn.gnome.org/viewvc/glom?rev=1599&view=rev

Log:
2008-04-30  Murray Cumming  <murrayc murrayc com>

* glom/mode_data/notebook_data.cc: on_list_user_requested_details():
Do not call Box_Data_Details::refresh_data_from_database_with_primary_key() 
because on_switch_page_handler() does it later. This avoids an 
unnecessary extra refresh of the details view.

* glom/libglom/data_structure/layout/layoutitem_field.h:
Added predicate_LayoutItem_Field_IsSameField for use with std::find_if().
* glom/mode_data/box_data_details.cc: fill_from_database(): Do not add 
the primary key to the list twice, to avoid setting it twice, to avoid 
refreshing portals twice.

Modified:
   trunk/ChangeLog
   trunk/glom/libglom/data_structure/field.h
   trunk/glom/libglom/data_structure/layout/layoutitem_field.h
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/mode_data/notebook_data.cc

Modified: trunk/glom/libglom/data_structure/field.h
==============================================================================
--- trunk/glom/libglom/data_structure/field.h	(original)
+++ trunk/glom/libglom/data_structure/field.h	Wed Apr 30 19:11:10 2008
@@ -31,6 +31,9 @@
 namespace Glom
 {
 
+/** A predicate for use with std::find_if() to find a Field or LayoutItem which refers 
+ * to the same field, looking at just the name.
+ */
 template<class T_Element>
 class predicate_FieldHasName
 {

Modified: trunk/glom/libglom/data_structure/layout/layoutitem_field.h
==============================================================================
--- trunk/glom/libglom/data_structure/layout/layoutitem_field.h	(original)
+++ trunk/glom/libglom/data_structure/layout/layoutitem_field.h	Wed Apr 30 19:11:10 2008
@@ -30,7 +30,42 @@
 
 namespace Glom
 {
+  
+/** A predicate for use with std::find_if() to find a LayoutItem_Field which refers 
+ * to the same field, without comparing irrelevant stuff such as formatting.
+ */
+template<class T_Element>
+class predicate_LayoutItem_Field_IsSameField
+{
+public:
+  predicate_LayoutItem_Field_IsSameField(const sharedptr<const T_Element>& layout_item)
+  {
+    m_layout_item = layout_item;
+  }
+
+  virtual ~predicate_LayoutItem_Field_IsSameField()
+  {
+  }
+
+  bool operator() (const sharedptr<const T_Element>& element)
+  {
+    const bool result = (m_layout_item->get_name() == element->get_name());
+    
+    if(!result)
+      return false;
+    
+    //Compare the relationship and related relationshp:
+    sharedptr<const UsesRelationship> uses_a = m_layout_item;
+    sharedptr<const UsesRelationship> uses_b = element;
+    return (*uses_a == *uses_b);
+  }
+    
+protected:
+  sharedptr<const T_Element> m_layout_item;
+};
 
+/** A LayoutItem that shows the data from a table field.
+ */
 class LayoutItem_Field 
  : public LayoutItem,
    public UsesRelationship

Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc	(original)
+++ trunk/glom/mode_data/box_data_details.cc	Wed Apr 30 19:11:10 2008
@@ -294,8 +294,12 @@
         //Add extra possibly-non-visible columns that we need:
         sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
         layout_item->set_full_field_details(m_field_primary_key);
-        fieldsToGet.push_back(layout_item);
-
+        
+        if(std::find_if(fieldsToGet.begin(), fieldsToGet.end(), predicate_LayoutItem_Field_IsSameField<LayoutItem_Field>(layout_item)) == fieldsToGet.end())
+        {
+          fieldsToGet.push_back(layout_item);
+        }
+        
         //g_warning("primary_key name = %s", m_field_primary_key->get_name().c_str());
         const int index_primary_key = fieldsToGet.size() - 1;
 

Modified: trunk/glom/mode_data/notebook_data.cc
==============================================================================
--- trunk/glom/mode_data/notebook_data.cc	(original)
+++ trunk/glom/mode_data/notebook_data.cc	Wed Apr 30 19:11:10 2008
@@ -191,8 +191,7 @@
 
 void Notebook_Data::on_list_user_requested_details(const Gnome::Gda::Value& primary_key_value)
 {
-  //std::cout << "Notebook_Data::on_list_user_requested_details" << std::endl;
-  m_Box_Details.refresh_data_from_database_with_primary_key(primary_key_value);
+  //on_switch_page_handler() does this: m_Box_Details.refresh_data_from_database_with_primary_key(primary_key_value);
   set_current_page(m_iPage_Details);
 }
 
@@ -304,14 +303,14 @@
     if(box == &m_Box_List)
     {
       //std::cout << "debug: switching to list" << std::endl;
-      Gnome::Gda::Value primary_key_selected = m_Box_List.get_primary_key_value_selected();
+      const Gnome::Gda::Value primary_key_selected = m_Box_List.get_primary_key_value_selected();
       m_Box_List.refresh_data_from_database();
       m_Box_List.set_primary_key_value_selected(primary_key_selected);
     }
     else if(box == &m_Box_Details)
     {
       //std::cout << "debug: switching to details" << std::endl;
-      Gnome::Gda::Value primary_key_selected = m_Box_List.get_primary_key_value_selected();
+      const Gnome::Gda::Value primary_key_selected = m_Box_List.get_primary_key_value_selected();
       m_Box_Details.refresh_data_from_database_with_primary_key(primary_key_selected);
     }
   }



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