From 75d6f897415a1643b5d54a6becc518fae1572834 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 29 Aug 2011 15:15:03 +0200 Subject: [PATCH] Started implementation of RptReport::set_database_as_gtktreemodel. Initial refactoring. refs #35 --- src/parser.tab.c | 95 ++++++++++++++++----------------- src/parser.y | 9 ++-- src/rptreport.c | 122 +++++++++++++++++++++++++++++++------------ src/rptreport.h | 3 ++ src/rptreport_priv.h | 11 ++-- 5 files changed, 145 insertions(+), 95 deletions(-) diff --git a/src/parser.tab.c b/src/parser.tab.c index 5fc4689..47b25ac 100644 --- a/src/parser.tab.c +++ b/src/parser.tab.c @@ -79,7 +79,7 @@ #include "lexycal.yy.h" #include "rptreport_priv.h" -void yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s); +void yyerror (RptReport *rpt_report, gchar **ret, char const *s); /* Line 189 of yacc.c */ @@ -420,8 +420,8 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 32, 32, 33, 36, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49 + 0, 31, 31, 32, 35, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48 }; #endif @@ -554,7 +554,7 @@ do \ } \ else \ { \ - yyerror (rpt_report, row, ret, YY_("syntax error: cannot back up")); \ + yyerror (rpt_report, ret, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) @@ -634,7 +634,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, rpt_report, row, ret); \ + Type, Value, rpt_report, ret); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -648,22 +648,20 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, RptReport *rpt_report, gint row, gchar **ret) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, RptReport *rpt_report, gchar **ret) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep, rpt_report, row, ret) +yy_symbol_value_print (yyoutput, yytype, yyvaluep, rpt_report, ret) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; RptReport *rpt_report; - gint row; gchar **ret; #endif { if (!yyvaluep) return; YYUSE (rpt_report); - YYUSE (row); YYUSE (ret); # ifdef YYPRINT if (yytype < YYNTOKENS) @@ -686,15 +684,14 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, rpt_report, row, ret) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, RptReport *rpt_report, gint row, gchar **ret) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, RptReport *rpt_report, gchar **ret) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep, rpt_report, row, ret) +yy_symbol_print (yyoutput, yytype, yyvaluep, rpt_report, ret) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; RptReport *rpt_report; - gint row; gchar **ret; #endif { @@ -703,7 +700,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, rpt_report, row, ret) else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, rpt_report, row, ret); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, rpt_report, ret); YYFPRINTF (yyoutput, ")"); } @@ -746,14 +743,13 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule, RptReport *rpt_report, gint row, gchar **ret) +yy_reduce_print (YYSTYPE *yyvsp, int yyrule, RptReport *rpt_report, gchar **ret) #else static void -yy_reduce_print (yyvsp, yyrule, rpt_report, row, ret) +yy_reduce_print (yyvsp, yyrule, rpt_report, ret) YYSTYPE *yyvsp; int yyrule; RptReport *rpt_report; - gint row; gchar **ret; #endif { @@ -768,7 +764,7 @@ yy_reduce_print (yyvsp, yyrule, rpt_report, row, ret) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - , rpt_report, row, ret); + , rpt_report, ret); YYFPRINTF (stderr, "\n"); } } @@ -776,7 +772,7 @@ yy_reduce_print (yyvsp, yyrule, rpt_report, row, ret) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, Rule, rpt_report, row, ret); \ + yy_reduce_print (yyvsp, Rule, rpt_report, ret); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1027,21 +1023,19 @@ yysyntax_error (char *yyresult, int yystate, int yychar) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, RptReport *rpt_report, gint row, gchar **ret) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, RptReport *rpt_report, gchar **ret) #else static void -yydestruct (yymsg, yytype, yyvaluep, rpt_report, row, ret) +yydestruct (yymsg, yytype, yyvaluep, rpt_report, ret) const char *yymsg; int yytype; YYSTYPE *yyvaluep; RptReport *rpt_report; - gint row; gchar **ret; #endif { YYUSE (yyvaluep); YYUSE (rpt_report); - YYUSE (row); YYUSE (ret); if (!yymsg) @@ -1065,7 +1059,7 @@ int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus -int yyparse (RptReport *rpt_report, gint row, gchar **ret); +int yyparse (RptReport *rpt_report, gchar **ret); #else int yyparse (); #endif @@ -1101,12 +1095,11 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (RptReport *rpt_report, gint row, gchar **ret) +yyparse (RptReport *rpt_report, gchar **ret) #else int -yyparse (rpt_report, row, ret) +yyparse (rpt_report, ret) RptReport *rpt_report; - gint row; gchar **ret; #endif #endif @@ -1355,91 +1348,91 @@ yyreduce: case 4: /* Line 1455 of yacc.c */ -#line 36 "parser.y" +#line 35 "parser.y" { *ret = g_strdup ((yyvsp[(1) - (1)])); ;} break; case 5: /* Line 1455 of yacc.c */ -#line 39 "parser.y" +#line 38 "parser.y" { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 6: /* Line 1455 of yacc.c */ -#line 40 "parser.y" +#line 39 "parser.y" { (yyval) = (yyvsp[(1) - (1)]); ;} break; case 7: /* Line 1455 of yacc.c */ -#line 41 "parser.y" +#line 40 "parser.y" { (yyval) = g_strndup ((yyvsp[(1) - (1)]) + 1, strlen ((yyvsp[(1) - (1)])) - 2) ;} break; case 8: /* Line 1455 of yacc.c */ -#line 42 "parser.y" - { (yyval) = rpt_report_get_field (rpt_report, g_strndup ((yyvsp[(1) - (1)]) + 1, strlen ((yyvsp[(1) - (1)])) - 2), row); ;} +#line 41 "parser.y" + { (yyval) = rpt_report_get_field (rpt_report, g_strndup ((yyvsp[(1) - (1)]) + 1, strlen ((yyvsp[(1) - (1)])) - 2)); ;} break; case 9: /* Line 1455 of yacc.c */ -#line 43 "parser.y" - { (yyval) = rpt_report_get_special (rpt_report, (yyvsp[(1) - (1)]), row); ;} +#line 42 "parser.y" + { (yyval) = rpt_report_get_special (rpt_report, (yyvsp[(1) - (1)])); ;} break; case 10: /* Line 1455 of yacc.c */ -#line 44 "parser.y" +#line 43 "parser.y" { (yyval) = g_strdup_printf ("%f", strtod ((yyvsp[(1) - (3)]), NULL) + strtod ((yyvsp[(3) - (3)]), NULL)); ;} break; case 11: /* Line 1455 of yacc.c */ -#line 45 "parser.y" +#line 44 "parser.y" { (yyval) = g_strdup_printf ("%f", strtod ((yyvsp[(1) - (3)]), NULL) - strtod ((yyvsp[(3) - (3)]), NULL)); ;} break; case 12: /* Line 1455 of yacc.c */ -#line 46 "parser.y" +#line 45 "parser.y" { (yyval) = g_strdup_printf ("%f", strtod ((yyvsp[(1) - (3)]), NULL) * strtod ((yyvsp[(3) - (3)]), NULL)); ;} break; case 13: /* Line 1455 of yacc.c */ -#line 47 "parser.y" +#line 46 "parser.y" { (yyval) = g_strdup_printf ("%f", strtod ((yyvsp[(1) - (3)]), NULL) / strtod ((yyvsp[(3) - (3)]), NULL)); ;} break; case 14: /* Line 1455 of yacc.c */ -#line 48 "parser.y" +#line 47 "parser.y" { (yyval) = g_strconcat ((yyvsp[(1) - (3)]), (yyvsp[(3) - (3)]), NULL); ;} break; case 15: /* Line 1455 of yacc.c */ -#line 49 "parser.y" +#line 48 "parser.y" { (yyval) = (yyvsp[(2) - (3)]); ;} break; /* Line 1455 of yacc.c */ -#line 1443 "parser.tab.c" +#line 1436 "parser.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1474,7 +1467,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (rpt_report, row, ret, YY_("syntax error")); + yyerror (rpt_report, ret, YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -1498,11 +1491,11 @@ yyerrlab: if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (rpt_report, row, ret, yymsg); + yyerror (rpt_report, ret, yymsg); } else { - yyerror (rpt_report, row, ret, YY_("syntax error")); + yyerror (rpt_report, ret, YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -1526,7 +1519,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, rpt_report, row, ret); + yytoken, &yylval, rpt_report, ret); yychar = YYEMPTY; } } @@ -1582,7 +1575,7 @@ yyerrlab1: yydestruct ("Error: popping", - yystos[yystate], yyvsp, rpt_report, row, ret); + yystos[yystate], yyvsp, rpt_report, ret); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1617,7 +1610,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (rpt_report, row, ret, YY_("memory exhausted")); + yyerror (rpt_report, ret, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1625,7 +1618,7 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, rpt_report, row, ret); + yytoken, &yylval, rpt_report, ret); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1633,7 +1626,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, rpt_report, row, ret); + yystos[*yyssp], yyvsp, rpt_report, ret); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1651,12 +1644,12 @@ yyreturn: /* Line 1675 of yacc.c */ -#line 51 "parser.y" +#line 50 "parser.y" /* Called by yyparse on error. */ void -yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s) +yyerror (RptReport *rpt_report, gchar **ret, char const *s) { g_warning ("Bison error: %s", s); } diff --git a/src/parser.y b/src/parser.y index 8f14745..44985c6 100644 --- a/src/parser.y +++ b/src/parser.y @@ -8,7 +8,7 @@ #include "lexycal.yy.h" #include "rptreport_priv.h" -void yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s); +void yyerror (RptReport *rpt_report, gchar **ret, char const *s); %} %token INTEGER @@ -25,7 +25,6 @@ void yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s); %left '/' %parse-param {RptReport *rpt_report} -%parse-param {gint row} %parse-param {gchar **ret} %% /* Grammar rules and actions */ @@ -39,8 +38,8 @@ string: exp { *ret = g_strdup ($1); } exp: INTEGER { $$ = $1; } | FLOAT { $$ = $1; } | STRING { $$ = g_strndup ($1 + 1, strlen ($1) - 2) } - | FIELD { $$ = rpt_report_get_field (rpt_report, g_strndup ($1 + 1, strlen ($1) - 2), row); } - | SPECIAL { $$ = rpt_report_get_special (rpt_report, $1, row); } + | FIELD { $$ = rpt_report_get_field (rpt_report, g_strndup ($1 + 1, strlen ($1) - 2)); } + | SPECIAL { $$ = rpt_report_get_special (rpt_report, $1); } | exp '+' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) + strtod ($3, NULL)); } | exp '-' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) - strtod ($3, NULL)); } | exp '*' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) * strtod ($3, NULL)); } @@ -52,7 +51,7 @@ exp: INTEGER { $$ = $1; } /* Called by yyparse on error. */ void -yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s) +yyerror (RptReport *rpt_report, gchar **ret, char const *s) { g_warning ("Bison error: %s", s); } diff --git a/src/rptreport.c b/src/rptreport.c index 748c94e..5545421 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -49,6 +49,8 @@ typedef struct GdaConnection *gda_conn; GdaDataModel *gda_datamodel; + + GtkTreeModel *treemodel; } Database; typedef struct @@ -129,13 +131,11 @@ static xmlNode *rpt_report_rptprint_new_page (RptReport *rpt_report, static void rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur_y, - RptReportSection section, - gint row); + RptReportSection section); static void rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, - xmlNode *xnode, - gint row); + xmlNode *xnode); static void rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc); @@ -162,6 +162,8 @@ struct _RptReportPrivate Body *body; guint cur_page; + gint cur_row; + GtkTreeIter *cur_iter; }; G_DEFINE_TYPE (RptReport, rpt_report, G_TYPE_OBJECT) @@ -233,6 +235,9 @@ rpt_report_init (RptReport *rpt_report) priv->output_type = RPT_OUTPUT_PDF; priv->output_filename = g_strdup ("rptreport.pdf"); priv->copies = 1; + + priv->cur_row = -1; + priv->cur_iter = NULL; } /** @@ -650,6 +655,7 @@ rpt_report_set_database (RptReport *rpt_report, priv->db->sql = g_strstrip (g_strdup (sql)); priv->db->gda_conn = NULL; priv->db->gda_datamodel = NULL; + priv->db->treemodel = NULL; } /** @@ -670,13 +676,44 @@ rpt_report_set_database_from_datamodel (RptReport *rpt_report, GdaDataModel *dat { g_free (priv->db); } - priv->db = (Database *)g_malloc0 (sizeof (Database)); + priv->db = (Database *)g_new0 (Database, 1); priv->db->provider_id = NULL; priv->db->connection_string = NULL; priv->db->sql = NULL; priv->db->gda_conn = NULL; priv->db->gda_datamodel = data_model; + priv->db->treemodel = NULL; +} + +/** + * rpt_report_set_database_as_gtktreemodel: + * @rpt_report: an #RptReport object. + * @model: a #GtkTreeModel (for now only #GtkListStore is supported). + * + */ +void +rpt_report_set_database_as_gtktreemodel (RptReport *rpt_report, GtkTreeModel *model) +{ + g_return_if_fail (IS_RPT_REPORT (rpt_report)); + g_return_if_fail (GTK_IS_TREE_MODEL (rpt_report)); + + g_return_if_fail (GTK_IS_LIST_STORE (rpt_report)); + + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + + if (priv->db != NULL) + { + g_free (priv->db); + } + priv->db = (Database *)g_new0 (Database, 1); + + priv->db->provider_id = NULL; + priv->db->connection_string = NULL; + priv->db->sql = NULL; + priv->db->gda_conn = NULL; + priv->db->gda_datamodel = NULL; + priv->db->treemodel = model; } /** @@ -1343,9 +1380,9 @@ xmlDoc } rows = gda_data_model_get_n_rows (priv->db->gda_datamodel); - for (row = 0; row < rows; row++) { + priv->cur_row = row; if (row == 0 || priv->body->new_page_after || (priv->page_footer != NULL && (cur_y + priv->body->height > priv->page->size->height - priv->page->margin->bottom - priv->page_footer->height)) || @@ -1357,7 +1394,9 @@ xmlDoc priv->cur_page > 1) { cur_y = priv->page->size->height - priv->page->margin->bottom - priv->page_footer->height; - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1); + priv->cur_row = row - 1; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER); + priv->cur_row = row; } } @@ -1369,12 +1408,12 @@ xmlDoc if ((priv->cur_page == 1 && priv->page_header->first_page) || priv->cur_page > 1) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, row); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER); } } if (priv->cur_page == 1 && priv->report_header != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_HEADER, row); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_HEADER); if (priv->report_header->new_page_after) { cur_y = 0.0; @@ -1383,7 +1422,7 @@ xmlDoc } } - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY, row); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY); } if (priv->cur_page > 0 && priv->report_footer != NULL) @@ -1393,7 +1432,9 @@ xmlDoc { if (priv->page_header != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, row - 1); + priv->cur_row = row - 1; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER); + priv->cur_row = row; } cur_y = priv->page->margin->top; @@ -1402,19 +1443,27 @@ xmlDoc if (priv->cur_page > 0 && priv->page_footer != NULL) { cur_y = priv->page->size->height - priv->page->margin->bottom - priv->page_footer->height; - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1); + priv->cur_row = row - 1; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER); + priv->cur_row = row; } } - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_FOOTER, row - 1); + priv->cur_row = row - 1; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_FOOTER); + priv->cur_row = row; } if (priv->cur_page > 0 && priv->page_footer != NULL && priv->page_footer->last_page) { cur_y = priv->page->size->height - priv->page->margin->bottom - priv->page_footer->height; - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1); + priv->cur_row = row - 1; + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER); + priv->cur_row = row; } /* change @Pages */ rpt_report_change_specials (rpt_report, xdoc); + + priv->cur_row = -1; } else { @@ -1423,23 +1472,23 @@ xmlDoc if (priv->page_header != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER, -1); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_HEADER); } if (priv->report_header != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_HEADER, -1); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_HEADER); } - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY, -1); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_BODY); if (priv->report_footer != NULL) { - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_FOOTER, -1); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_REPORT_FOOTER); } if (priv->page_footer != NULL) { cur_y = priv->page->size->height - priv->page->margin->bottom - priv->page_footer->height; - rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, -1); + rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER); } } @@ -1583,7 +1632,7 @@ rpt_report_rptprint_page_add_object (xmlNode *xnodepage, RptObject *rpt_object) if (IS_RPT_OBJ_TEXT (rpt_object)) { - rpt_report_rptprint_parse_text_source (NULL, rpt_object, xnodeobj, -1); + rpt_report_rptprint_parse_text_source (NULL, rpt_object, xnodeobj); attr = xmlHasProp (xnodeobj, "source"); if (attr != NULL) { @@ -2226,7 +2275,10 @@ static xmlNode } static void -rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur_y, RptReportSection section, gint row) +rpt_report_rptprint_section (RptReport *rpt_report, + xmlNode *xpage, + gdouble *cur_y, + RptReportSection section) { GList *objects; xmlAttrPtr attr; @@ -2291,7 +2343,7 @@ rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur if (IS_RPT_OBJ_TEXT (rptobj)) { - rpt_report_rptprint_parse_text_source (rpt_report, rptobj, xnode, row); + rpt_report_rptprint_parse_text_source (rpt_report, rptobj, xnode); attr = xmlHasProp (xnode, "source"); if (attr != NULL) { @@ -2334,15 +2386,19 @@ rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur } static void -rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, xmlNode *xnode, gint row) +rpt_report_rptprint_parse_text_source (RptReport *rpt_report, + RptObject *rptobj, + xmlNode *xnode) { gchar *source; gchar *ret; + RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report); + g_object_get (G_OBJECT (rptobj), "source", &source, NULL); yy_scan_string (source); - yyparse (rpt_report, row, &ret); + yyparse (rpt_report, &ret); if (g_strstr_len (ret, -1, " ") != NULL) { @@ -2398,7 +2454,8 @@ rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc) } gchar -*rpt_report_get_field (RptReport *rpt_report, const gchar *field_name, gint row) +*rpt_report_get_field (RptReport *rpt_report, + const gchar *field_name) { GError *error; gint col; @@ -2412,10 +2469,10 @@ gchar if (col > -1) { - const GValue *gval; + GValue *gval; error = NULL; - gval = gda_data_model_get_value_at (priv->db->gda_datamodel, col, row, &error); + gval = (GValue *)gda_data_model_get_value_at (priv->db->gda_datamodel, col, priv->cur_row, &error); if (error != NULL) { g_warning ("Error on retrieving field «%s» value: %s.", @@ -2442,7 +2499,7 @@ gchar if (ret == NULL) { - ret = rpt_report_ask_field (rpt_report, field_name, row); + ret = rpt_report_ask_field (rpt_report, field_name); } if (ret == NULL) { @@ -2453,7 +2510,8 @@ gchar } gchar -*rpt_report_ask_field (RptReport *rpt_report, const gchar *field, gint row) +*rpt_report_ask_field (RptReport *rpt_report, + const gchar *field) { gchar *ret = NULL; @@ -2464,12 +2522,12 @@ gchar if (priv->db != NULL && priv->db->gda_datamodel != NULL) { g_signal_emit (rpt_report, klass->field_request_signal_id, - 0, field, priv->db->gda_datamodel, row, &ret); + 0, field, priv->db->gda_datamodel, priv->cur_row, &ret); } else { g_signal_emit (rpt_report, klass->field_request_signal_id, - 0, field, NULL, row, &ret); + 0, field, NULL, -1, &ret); } if (ret != NULL) { @@ -2554,7 +2612,7 @@ gchar } gchar -*rpt_report_get_special (RptReport *rpt_report, const gchar *special, gint row) +*rpt_report_get_special (RptReport *rpt_report, const gchar *special) { gchar *ret; gchar *real_special; diff --git a/src/rptreport.h b/src/rptreport.h index 69ab92a..9b27daa 100644 --- a/src/rptreport.h +++ b/src/rptreport.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -85,6 +86,8 @@ void rpt_report_set_database (RptReport *rpt_report, void rpt_report_set_database_from_datamodel (RptReport *rpt_report, GdaDataModel *data_model); +void rpt_report_set_database_as_gtktreemodel (RptReport *rpt_report, GtkTreeModel *model); + RptSize *rpt_report_get_page_size (RptReport *rpt_report); void rpt_report_set_page_size (RptReport *rpt_report, RptSize size); diff --git a/src/rptreport_priv.h b/src/rptreport_priv.h index 22e0c55..af36c3b 100644 --- a/src/rptreport_priv.h +++ b/src/rptreport_priv.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Andrea Zagli + * Copyright (C) 2007-2011 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,14 +28,11 @@ G_BEGIN_DECLS gchar *rpt_report_get_field (RptReport *rpt_report, - const gchar *field_name, - gint row); + const gchar *field_name); gchar *rpt_report_ask_field (RptReport *rpt_report, - const gchar *field, - gint row); + const gchar *field); gchar *rpt_report_get_special (RptReport *rpt_report, - const gchar *special, - gint row); + const gchar *special); G_END_DECLS -- 2.49.0