[glom] ReportBuilder: Do not depend on Base_DB unnecessarily.



commit 8f2b46a7c1af5f79fee1dc2b2eb115cc92f8a22a
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Oct 17 18:51:03 2011 +0200

    ReportBuilder: Do not depend on Base_DB unnecessarily.
    
    * glom/report_builder.[h|cc]: Just add get/set_document() instead.

 ChangeLog              |    6 ++++++
 glom/report_builder.cc |   46 +++++++++++++++-------------------------------
 glom/report_builder.h  |   17 ++++++++++++++---
 3 files changed, 35 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3a77655..631dacc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-10-17  Murray Cumming  <murrayc murrayc com>
 
+	ReportBuilder: Do not depend on Base_DB unnecessarily.
+
+	* glom/report_builder.[h|cc]: Just add get/set_document() instead.
+
+2011-10-17  Murray Cumming  <murrayc murrayc com>
+
 	Move report building code around.
 
 	* glom/report_builder.[h|cc]: report_build(): Return the filepath,
diff --git a/glom/report_builder.cc b/glom/report_builder.cc
index 832e3a5..70436d0 100644
--- a/glom/report_builder.cc
+++ b/glom/report_builder.cc
@@ -21,11 +21,6 @@
 #include "report_builder.h"
 #include <libglom/utils.h>
 #include <libglom/data_structure/glomconversions.h>
-#include <libglom/data_structure/layout/report_parts/layoutitem_summary.h>
-#include <libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h>
-#include <libglom/data_structure/layout/report_parts/layoutitem_verticalgroup.h>
-#include <libglom/data_structure/layout/report_parts/layoutitem_header.h>
-#include <libglom/data_structure/layout/report_parts/layoutitem_footer.h>
 #include <libglom/db_utils.h>
 #include <glom/xsl_utils.h>
 #include <glibmm/i18n.h>
@@ -34,6 +29,7 @@ namespace Glom
 {
 
 ReportBuilder::ReportBuilder()
+: m_document(0)
 {
 }
 
@@ -41,7 +37,6 @@ ReportBuilder::~ReportBuilder()
 {
 }
 
-
 void ReportBuilder::report_build_headerfooter(const FoundSet& found_set, xmlpp::Element& parent_node, const sharedptr<LayoutGroup>& group)
 {
   //Add XML node:
@@ -197,7 +192,7 @@ void ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
       guint rows_count = datamodel->get_n_rows();
       for(guint row = 0; row < rows_count; ++row)
       {
-        const Gnome::Gda::Value group_value = datamodel->get_value_at(0 /* col*/, row);
+        const Gnome::Gda::Value group_value = datamodel->get_value_at(0 /* col*/, row); //TODO: Catch exceptions.
 
 
         //Add XML node:
@@ -399,13 +394,13 @@ void ReportBuilder::report_build_records_field(const FoundSet& found_set, xmlpp:
     if(!datamodel)
       return;
 
-    value = datamodel->get_value_at(colField, row);
+    value = datamodel->get_value_at(colField, row); //TODO: Catch exceptions.
     colField = 0;
     row = 0;
   }
   else
   {
-    value = datamodel->get_value_at(colField, row);
+    value = datamodel->get_value_at(colField, row); //TODO: Catch exceptions.
   }
 
   nodeField->set_attribute("title", field->get_title_or_name()); //Not always used, but useful.
@@ -553,27 +548,7 @@ std::string ReportBuilder::report_build(const FoundSet& found_set, const sharedp
   if(!itemsToGet_TopLevel.empty())
   {
     xmlpp::Element* nodeGroupBy = nodeParent->add_child("ungrouped_records");
-
-    // TODO: I am not sure where an exception could be thrown here. It seems
-    // not to be in glom, otherwise the code wouldn't compile with
-    // -fno-exceptions. If it's in a library, it does not seem to take an
-    // additional error paramater for that. armin.
-    try
-    {
-      report_build_records(found_set, *nodeGroupBy, itemsToGet_TopLevel);
-    }
-    catch(const Glib::Exception& ex)
-    {
-      //Handle database errors here rather than crashing the whole application:
-      handle_error(ex);
-      return std::string();
-    }
-    catch(const std::exception& ex)
-    {
-      //Handle database errors here rather than crashing the whole application:
-      handle_error(ex);
-      return std::string();
-    }
+    report_build_records(found_set, *nodeGroupBy, itemsToGet_TopLevel);
   }
 
   return GlomXslUtils::transform(*pDocument, "print_report_to_html.xsl");
@@ -598,7 +573,6 @@ static void fill_standard_list_report_fill(const sharedptr<Report>& report, cons
   }
 }
 
-
 sharedptr<Report> ReportBuilder::create_standard_list_report(const Document* document, const Glib::ustring& table_name)
 {
   sharedptr<Report> result(new Report());
@@ -618,5 +592,15 @@ sharedptr<Report> ReportBuilder::create_standard_list_report(const Document* doc
   return result;
 }
 
+void ReportBuilder::set_document(Document* document)
+{
+  m_document = document;
+}
+
+Document* ReportBuilder::get_document()
+{
+  return m_document;
+}
+
 
 } //namespace Glom
diff --git a/glom/report_builder.h b/glom/report_builder.h
index 00e02b3..253b5c4 100644
--- a/glom/report_builder.h
+++ b/glom/report_builder.h
@@ -21,14 +21,18 @@
 #ifndef GLOM_REPORT_BUILDER_H
 #define GLOM_REPORT_BUILDER_H
 
-#include <glom/base_db.h>
 #include <libglom/data_structure/report.h>
-#include <libglom/sharedptr.h>
+#include <libglom/document/document.h>
+#include <libglom/data_structure/layout/report_parts/layoutitem_summary.h>
+#include <libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h>
+#include <libglom/data_structure/layout/report_parts/layoutitem_verticalgroup.h>
+#include <libglom/data_structure/layout/report_parts/layoutitem_header.h>
+#include <libglom/data_structure/layout/report_parts/layoutitem_footer.h>
 
 namespace Glom
 {
 
-class ReportBuilder : public Base_DB
+class ReportBuilder
 {
 public:
   ReportBuilder();
@@ -36,6 +40,8 @@ public:
 
   static sharedptr<Report> create_standard_list_report(const Document* document, const Glib::ustring& table_name);
 
+  void set_document(Document* document);
+
   //void set_report(const Glib::ustring& table_name, const sharedptr<const Report>& report);
   //sharedptr<Report> get_report();
 
@@ -52,6 +58,7 @@ private:
   void report_build_headerfooter(const FoundSet& found_set, xmlpp::Element& parent_node, const sharedptr<LayoutGroup>& group);
 
   typedef std::vector< sharedptr<LayoutItem> > type_vecLayoutItems;
+  typedef std::vector< sharedptr<LayoutItem_Field> > type_vecLayoutFields;
 
   void report_build_records(const FoundSet& found_set, xmlpp::Element& parent_node, const type_vecLayoutItems& items, bool one_record_only = false);
   void report_build_records_get_fields(const FoundSet& found_set, const sharedptr<LayoutGroup>& group, type_vecLayoutFields& items);
@@ -59,6 +66,10 @@ private:
   void report_build_records_text(const FoundSet& found_set, xmlpp::Element& nodeParent, const sharedptr<const LayoutItem_Text>& textobject, bool vertical = false);
   void report_build_records_image(const FoundSet& found_set, xmlpp::Element& nodeParent, const sharedptr<const LayoutItem_Image>& imageobject, bool vertical = false);
   void report_build_records_vertical_group(const FoundSet& found_set, xmlpp::Element& vertical_group_node, const sharedptr<LayoutItem_VerticalGroup>& group, const Glib::RefPtr<Gnome::Gda::DataModel>& datamodel, guint row, guint& field_index);
+
+  Document* get_document();
+
+  Document* m_document;
 };
 
 } //namespace Glom



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