[glom] Document::set_tables(): Check for an actual change.



commit c9a9185a8de8e94e25ce40c553b26d3b53f43d8d
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Nov 19 11:38:24 2013 +0100

    Document::set_tables(): Check for an actual change.
    
    * glom/libglom/data_structure/tableinfo.h(): Add operator==()
      and operator!=().
    * glom/libglom/document/document.cc(): set_tables(): Check for a
      change before re-setting this and marking
      the document as modified.

 glom/libglom/data_structure/tableinfo.cc |   13 +++++++++++++
 glom/libglom/data_structure/tableinfo.h  |    3 +++
 glom/libglom/document/document.cc        |    7 +++++--
 3 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/glom/libglom/data_structure/tableinfo.cc b/glom/libglom/data_structure/tableinfo.cc
index 313a2d0..48cae40 100644
--- a/glom/libglom/data_structure/tableinfo.cc
+++ b/glom/libglom/data_structure/tableinfo.cc
@@ -49,6 +49,19 @@ TableInfo& TableInfo::operator=(const TableInfo& src)
   return *this;
 }
 
+bool TableInfo::operator==(const TableInfo& src) const
+{
+  return TranslatableItem::operator==(src) &&
+    HasTitleSingular::operator==(src) && 
+    (m_hidden == src.m_hidden) &&
+    (m_default == src.m_default);
+}
+
+bool TableInfo::operator!=(const TableInfo& src) const
+{
+  return !operator==(src);
+}
+
 bool TableInfo::get_hidden() const
 {
   return m_hidden;
diff --git a/glom/libglom/data_structure/tableinfo.h b/glom/libglom/data_structure/tableinfo.h
index 9705393..fcff322 100644
--- a/glom/libglom/data_structure/tableinfo.h
+++ b/glom/libglom/data_structure/tableinfo.h
@@ -36,6 +36,9 @@ public:
   TableInfo(const TableInfo& src);
   TableInfo& operator=(const TableInfo& src);
 
+  bool operator==(const TableInfo& src) const;
+  bool operator!=(const TableInfo& src) const;
+
   /** Returns true if this table should not be shown in the list of tables when in operator mode.
    */
   bool get_hidden() const;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 712bdda..2fadd61 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1304,9 +1304,12 @@ void Document::set_tables(const type_listTableInfo& tables)
     if(iterfind != tables.end())
     {
       sharedptr<TableInfo> infoFound = *iterfind;
-      *info = *infoFound; //TODO: Check that it has really changed, to avoid calling set_modified() 
unnecessarily?
+      if(infoFound && (*infoFound != *info))
+      {
+        *info = *infoFound;
 
-      something_changed = true;
+        something_changed = true;
+      }
     }
   }
 


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