From e2a8d6e32f3d5bab6fa68ba42ec900d941c7b7c5 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 18 Mar 2007 16:58:41 +0000 Subject: [PATCH] Continuing RptReport. git-svn-id: svn+ssh://saetta.homelinux.org/svn/libreptool/trunk@5 3191ed1d-3fce-41bb-ab4a-0cebc0943b59 --- data/reptool.dtd | 16 +++++---- src/rptobject.c | 4 +-- src/rptobject.h | 2 +- src/rptobjecttext.c | 27 +++++++++------ src/rptobjecttext.h | 2 +- src/rptreport.c | 71 ++++++++++++++++++++++++++++++--------- tests/db_test.db | Bin 0 -> 2048 bytes tests/test_report_db.rpt | 14 ++++++++ 8 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 tests/db_test.db create mode 100644 tests/test_report_db.rpt diff --git a/data/reptool.dtd b/data/reptool.dtd index bba7fd0..b1f192b 100644 --- a/data/reptool.dtd +++ b/data/reptool.dtd @@ -114,25 +114,27 @@ @@ -148,11 +150,11 @@ diff --git a/src/rptobject.c b/src/rptobject.c index 2933ce2..938e9f5 100644 --- a/src/rptobject.c +++ b/src/rptobject.c @@ -113,13 +113,13 @@ rpt_object_init (RptObject *rpt_object) * Returns: the newly created #RptObject object. */ RptObject -*rpt_object_new (const gchar *name, RptPoint *position) +*rpt_object_new (const gchar *name, RptPoint position) { RptObject *rpt_object = RPT_OBJECT (g_object_new (rpt_object_get_type (), NULL));; g_object_set (rpt_object, "name", name, - "poisition", position, + "poisition", &position, NULL); return rpt_object; diff --git a/src/rptobject.h b/src/rptobject.h index 87f980d..fd52e56 100644 --- a/src/rptobject.h +++ b/src/rptobject.h @@ -55,7 +55,7 @@ struct _RptObjectClass GType rpt_object_get_type (void) G_GNUC_CONST; -RptObject *rpt_object_new (const gchar *name, RptPoint *position); +RptObject *rpt_object_new (const gchar *name, RptPoint position); void rpt_object_get_xml (RptObject *rptobj, xmlNode *xnode); diff --git a/src/rptobjecttext.c b/src/rptobjecttext.c index 1c6de9c..69d77a9 100644 --- a/src/rptobjecttext.c +++ b/src/rptobjecttext.c @@ -121,14 +121,21 @@ rpt_obj_text_init (RptObjText *rpt_obj_text) * Returns: the newly created #RptObject object. */ RptObject -*rpt_obj_text_new (const gchar *name, RptPoint *position) +*rpt_obj_text_new (const gchar *name, RptPoint position) { - RptObject *rpt_obj_text = RPT_OBJECT (g_object_new (rpt_obj_text_get_type (), NULL)); + RptObject *rpt_obj_text = NULL; + + gchar *name_ = g_strstrip (g_strdup (name)); - g_object_set (G_OBJECT (rpt_obj_text), - "name", name, - "position", position, - NULL); + if (strcmp (name_, "") != 0) + { + rpt_obj_text = RPT_OBJECT (g_object_new (rpt_obj_text_get_type (), NULL)); + + g_object_set (G_OBJECT (rpt_obj_text), + "name", name_, + "position", &position, + NULL); + } return rpt_obj_text; } @@ -145,15 +152,15 @@ RptObject gchar *name; RptObject *rpt_obj_text = NULL; - name = (gchar *)xmlGetProp (xnode, "name"); + name = g_strdup ((gchar *)xmlGetProp (xnode, "name")); if (name != NULL && strcmp (g_strstrip (name), "") != 0) { - RptPoint *position; + RptPoint position; RptObjTextPrivate *priv; - rpt_common_get_position (xnode, position); + rpt_common_get_position (xnode, &position); - rpt_obj_text = rpt_obj_text_new (name, position); + rpt_obj_text = rpt_obj_text_new ((const gchar *)name, position); if (rpt_obj_text != NULL) { diff --git a/src/rptobjecttext.h b/src/rptobjecttext.h index 723a990..52d346c 100644 --- a/src/rptobjecttext.h +++ b/src/rptobjecttext.h @@ -53,7 +53,7 @@ struct _RptObjTextClass GType rpt_obj_text_get_type (void) G_GNUC_CONST; -RptObject *rpt_obj_text_new (const gchar *name, RptPoint *position); +RptObject *rpt_obj_text_new (const gchar *name, RptPoint position); RptObject *rpt_obj_text_new_from_xml (xmlNode *xnode); void rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode); diff --git a/src/rptreport.c b/src/rptreport.c index b806ff3..d654ebc 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -59,13 +59,14 @@ static void rpt_report_get_property (GObject *object, GValue *value, GParamSpec *pspec); -static void rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset); +static void rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode); static RptObject *rpt_report_get_object_from_name (GList *list, const gchar *name); static xmlNode *rpt_report_rptprint_new_page (RptReport *rptreport, xmlNode *xroot); static void rpt_report_rptprint_body (RptReport *rptreport, - xmlNode *xpage); + xmlNode *xpage, + gdouble *cur_y); static void rpt_report_rptprint_parse_source (RptReport *rptreport, RptObject *rptobj, xmlNode *xnode); @@ -128,6 +129,10 @@ rpt_report_init (RptReport *rpt_report) { RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + priv->gda_client = NULL; + priv->gda_conn = NULL; + priv->gda_datamodel = NULL; + priv->page = (Page *)g_malloc0 (sizeof (Page)); priv->page->size = (RptSize *)g_malloc0 (sizeof (RptSize)); priv->page->size->width = 0.0; @@ -244,6 +249,7 @@ RptReport if (priv->gda_conn == NULL) { /* TO DO */ + g_warning ("Unable to establish the connection."); } else { @@ -273,7 +279,7 @@ RptReport xnodeset = xpresult->nodesetval; if (xnodeset->nodeNr == 1) { - rpt_report_xml_parse_body (rpt_report, xnodeset); + rpt_report_xml_parse_body (rpt_report, xnodeset->nodeTab[0]); } } } @@ -345,8 +351,9 @@ xmlDoc { xmlDoc *xdoc; xmlNode *xroot; - xmlNode *xnode; + xmlNode *xpage; gint pages; + gdouble cur_y = 0.0; RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rptreport); @@ -354,9 +361,31 @@ xmlDoc xroot = xmlNewNode (NULL, "reptool_report"); xmlDocSetRootElement (xdoc, xroot); - pages++; - xnode = rpt_report_rptprint_new_page (rptreport, xroot); - rpt_report_rptprint_body (rptreport, xnode); + if (priv->gda_datamodel != NULL) + { + gint row; + gint rows; + + rows = gda_data_model_get_n_rows (priv->gda_datamodel); + + for (row = 0; row < rows; row++) + { + if (row == 0 || cur_y > priv->page->size->height) + { + cur_y = 0.0; + pages++; + xpage = rpt_report_rptprint_new_page (rptreport, xroot); + } + + rpt_report_rptprint_body (rptreport, xpage, &cur_y); + } + } + else + { + pages++; + xpage = rpt_report_rptprint_new_page (rptreport, xroot); + rpt_report_rptprint_body (rptreport, xpage, &cur_y); + } return xdoc; } @@ -392,22 +421,22 @@ rpt_report_get_property (GObject *object, guint property_id, GValue *value, GPar } static void -rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset) +rpt_report_xml_parse_body (RptReport *rpt_report, xmlNode *xnode) { RptObject *rptobj; - gchar *objname; gchar *prop; - xmlNode *cur = xnodeset->nodeTab[0]; + gchar *objname; + xmlNode *cur; RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); - prop = xmlGetProp (cur, "height"); + prop = (gchar *)xmlGetProp (xnode, "height"); if (prop != NULL) { - priv->body->height = strtod (prop, NULL); + priv->body->height = strtod (g_strstrip (g_strdup (prop)), NULL); } - cur = cur->children; + cur = xnode->children; while (cur != NULL) { if (strcmp (cur->name, "text") == 0) @@ -415,7 +444,7 @@ rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset) rptobj = rpt_obj_text_new_from_xml (cur); if (rptobj != NULL) { - g_object_get (rptobj, "name", objname, NULL); + g_object_get (rptobj, "name", &objname, NULL); if (rpt_report_get_object_from_name (priv->body->objects, objname) == NULL) { @@ -424,6 +453,7 @@ rpt_report_xml_parse_body (RptReport *rpt_report, xmlNodeSetPtr xnodeset) else { /* TO DO */ + g_warning ("An object with name \"%s\" already exists.", objname); } } } @@ -450,7 +480,7 @@ static RptObject list = g_list_first (list); while (list != NULL) { - g_object_get ((RptObject *)list->data, "name", objname, NULL); + g_object_get ((RptObject *)list->data, "name", &objname, NULL); if (strcmp (name, objname) == 0) { obj = (RptObject *)list->data; @@ -479,11 +509,12 @@ static xmlNode } static void -rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage) +rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage, gdouble *cur_y) { GList *objects; xmlAttrPtr attr; xmlNode *xnode; + gchar *prop; RptObject *rptobj; @@ -502,6 +533,13 @@ rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage) xmlRemoveProp (attr); } + prop = (gchar *)xmlGetProp (xnode, "y"); + if (prop == NULL) + { + prop = g_strdup ("0.0"); + } + xmlSetProp (xnode, "y", g_strdup_printf ("%f", strtod (prop, NULL) + *cur_y)); + if (IS_RPT_OBJ_TEXT (rptobj)) { rpt_report_rptprint_parse_source (rptreport, rptobj, xnode); @@ -511,6 +549,7 @@ rpt_report_rptprint_body (RptReport *rptreport, xmlNode *xpage) objects = g_list_next (objects); } + *cur_y += priv->body->height; } static void diff --git a/tests/db_test.db b/tests/db_test.db new file mode 100644 index 0000000000000000000000000000000000000000..4c331e8f9990be508bbf9d003b927dc874a72448 GIT binary patch literal 2048 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCVBi8`WWWgIfG`XovteRbX_9F%jBC!z2IR8AxMsYpKrSncYs$+4 g + + + + + SQLite + URI=///home/andreaz/files/c/reptool/libreptool/tests/db_test.db + SELECT * FROM articles ORDER BY name + + + + + + -- 2.49.0