[glom] Move some Report code around.



commit aae40ab17b6ebba9bbf82b7430e58e5da799a0fe
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Oct 17 17:54:04 2011 +0200

    Move some Report code around.
    
    * glom/mode_data/box_data_manyrecords.cc: print_layout():
    Move the report creation to ReportBuilder.
    * glom/report_builder.[h|cc]: Added create_standard_list_report().
    * glom/xsl_utils.cc: Do not output all the XSL and HTML to std::cout,
    but do output the temporary file name of the generated HTML file.

 ChangeLog                              |   10 ++++++++
 glom/mode_data/box_data_manyrecords.cc |   16 ++----------
 glom/report_builder.cc                 |   40 ++++++++++++++++++++++++++++++++
 glom/report_builder.h                  |    4 ++-
 glom/xsl_utils.cc                      |   14 +++++-----
 5 files changed, 63 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e43c4ff..601f968 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2011-10-17  Murray Cumming  <murrayc murrayc com>
 
+	Move some Report code around.
+
+	* glom/mode_data/box_data_manyrecords.cc: print_layout():
+	Move the report creation to ReportBuilder.
+	* glom/report_builder.[h|cc]: Added create_standard_list_report().
+	* glom/xsl_utils.cc: Do not output all the XSL and HTML to std::cout,
+	but do output the temporary file name of the generated HTML file.
+
+2011-10-17  Murray Cumming  <murrayc murrayc com>
+
 	XSLT file: Minor fixes.
 
 	* xslt/print_report_to_html.xsl: Change xsl::version to version, which
diff --git a/glom/mode_data/box_data_manyrecords.cc b/glom/mode_data/box_data_manyrecords.cc
index ddb0972..6f56f08 100644
--- a/glom/mode_data/box_data_manyrecords.cc
+++ b/glom/mode_data/box_data_manyrecords.cc
@@ -78,21 +78,11 @@ void Box_Data_ManyRecords::print_layout()
   else
   {
     //Create a simple report on the fly:
-    sharedptr<Report> report_temp(new Report());
-    report_temp->set_name("list");
-    //Translators: This is a noun. It is the title of a report.
-    report_temp->set_title(_("List"));
-
-    //Add all the fields from the layout:
-    for(type_vecConstLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
-    {
-      sharedptr<const LayoutItem> item = *iter;
-      sharedptr<LayoutItem> unconst = sharedptr<LayoutItem>::cast_const(item); //TODO: Avoid this?
-      report_temp->m_layout_group->add_item(unconst);
-    }
+    Document* document = get_document();
+    sharedptr<Report> report_temp = ReportBuilder::create_standard_list_report(document, m_table_name);
 
     ReportBuilder report_builder;
-    report_builder.set_document(get_document());
+    report_builder.set_document(document);
     report_builder.report_build(m_found_set, report_temp, get_app_window());
   }
 }
diff --git a/glom/report_builder.cc b/glom/report_builder.cc
index d544600..b80fa60 100644
--- a/glom/report_builder.cc
+++ b/glom/report_builder.cc
@@ -28,6 +28,7 @@
 #include <libglom/data_structure/layout/report_parts/layoutitem_footer.h>
 #include <libglom/db_utils.h>
 #include <glom/xsl_utils.h>
+#include <glibmm/i18n.h>
 
 namespace Glom
 {
@@ -578,5 +579,44 @@ void ReportBuilder::report_build(const FoundSet& found_set, const sharedptr<cons
   GlomXslUtils::transform_and_open(*pDocument, "print_report_to_html.xsl", parent_window);
 }
 
+static void fill_standard_list_report_fill(const sharedptr<Report>& report, const sharedptr<const LayoutGroup>& layout_group)
+{
+  if(!report)
+    return;
+
+  if(!layout_group)
+    return;
+
+  for(LayoutGroup::type_list_items::const_iterator iter = layout_group->m_list_items.begin(); iter != layout_group->m_list_items.end(); ++iter)
+  {
+    const sharedptr<const LayoutItem> item = *iter;
+    if(!item)
+      continue;
+
+    const sharedptr<LayoutItem> unconst = sharedptr<LayoutItem>::cast_const(item); //TODO: Avoid this?
+    report->m_layout_group->add_item(unconst);
+  }
+}
+
+
+sharedptr<Report> ReportBuilder::create_standard_list_report(const Document* document, const Glib::ustring& table_name)
+{
+  sharedptr<Report> result(new Report());
+  result->set_name("list");
+  //Translators: This is a noun. It is the title of a report.
+  result->set_title(_("List"));
+
+  const Document::type_list_layout_groups layout_groups = 
+    document->get_data_layout_groups("list", table_name); //TODO: layout_platform.
+  for(Document::type_list_layout_groups::const_iterator iter = layout_groups.begin(); iter != layout_groups.end(); ++iter)
+  {
+    const sharedptr<const LayoutGroup> group = *iter;
+    if(group)
+      fill_standard_list_report_fill(result, group);
+  }
+
+  return result;
+}
+
 
 } //namespace Glom
diff --git a/glom/report_builder.h b/glom/report_builder.h
index 2173bc8..49a6a0c 100644
--- a/glom/report_builder.h
+++ b/glom/report_builder.h
@@ -34,10 +34,12 @@ public:
   ReportBuilder();
   virtual ~ReportBuilder();
 
+  static sharedptr<Report> create_standard_list_report(const Document* document, const Glib::ustring& table_name);
+
   //void set_report(const Glib::ustring& table_name, const sharedptr<const Report>& report);
   //sharedptr<Report> get_report();
 
- void report_build(const FoundSet& found_set, const sharedptr<const Report>& report, Gtk::Window* parent_window = 0);
+  void report_build(const FoundSet& found_set, const sharedptr<const Report>& report, Gtk::Window* parent_window = 0);
 
  
 
diff --git a/glom/xsl_utils.cc b/glom/xsl_utils.cc
index e94abb7..69aa56e 100644
--- a/glom/xsl_utils.cc
+++ b/glom/xsl_utils.cc
@@ -69,12 +69,12 @@ void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const
 {
   //Use libxslt to convert the XML to HTML:
   const Glib::ustring result = xslt_process(xml_document, get_xslt_file(xsl_file_path));
-  std::cout << "After xslt: " << result << std::endl;
+  //std::cout << "After xslt: " << result << std::endl;
 
   //Save it to a temporary file and show it in a browser:
   const Glib::ustring temp_path = Glib::build_filename(
     Glib::get_tmp_dir(), "glom_printout.html");
-  //std::cout << "temp_path=" << temp_path << std::endl;
+  std::cout << "temp_path=" << temp_path << std::endl;
 
   Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(temp_path);
   Glib::RefPtr<Gio::FileOutputStream> stream;
@@ -139,11 +139,11 @@ void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const
 Glib::ustring GlomXslUtils::xslt_process(const xmlpp::Document& xml_document, const std::string& filepath_xslt)
 {
   //Debug output:
-  std::cout << "XML before XSLT processing: " << std::endl;
-  std::cout << "  ";
-  xmlpp::Document& nonconst = const_cast<xmlpp::Document&>(xml_document);
-  nonconst.write_to_stream_formatted(std::cout);
-  std::cout << std::endl;
+  //std::cout << "XML before XSLT processing: " << std::endl;
+  //std::cout << "  ";
+  //xmlpp::Document& nonconst = const_cast<xmlpp::Document&>(xml_document);
+  //nonconst.write_to_stream_formatted(std::cout);
+  //std::cout << std::endl;
 
   Glib::ustring  result;
 



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