From: Andrea Zagli Date: Sun, 28 Mar 2021 07:22:42 +0000 (+0200) Subject: Added function GdaExGrid::html_get_header (and test). X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=d721c335d4724c637ca6cdc89a9f7dde9a5d10b3;p=libgdaexgrid Added function GdaExGrid::html_get_header (and test). --- diff --git a/.gitignore b/.gitignore index afcfcc0..b859a1c 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ Rules-quot tests/grid tests/grid_from_xml tests/grid_tree +tests/grid_html_from_xml test-driver *.gir *.typelib \ No newline at end of file diff --git a/src/grid.c b/src/grid.c index a98027c..4f32f93 100644 --- a/src/grid.c +++ b/src/grid.c @@ -1065,6 +1065,48 @@ gdaex_grid_fill_from_sqlbuilder (GdaExGrid *grid, GdaEx *gdaex, GdaExSqlBuilder return gdaex_grid_fill_from_sqlbuilder_with_missing_func (grid, gdaex, builder, NULL, NULL, error); } + +/** + * gdaex_grid_html_get_header: + * @grid: a #GdaExGrid object. + * + * Returns: the table header (only the tr tag). + */ +gchar +*gdaex_grid_html_get_header (GdaExGrid *grid) +{ + GdaExGridPrivate *priv; + + GdaExGridColumn *gcolumn; + + guint col; + + GString *str; + + gchar *ret; + + g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL); + + priv = gdaex_grid_get_instance_private (grid); + + str = g_string_new ("\n"); + + for (col = 0; col < priv->columns->len; col++) + { + gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col); + g_string_append_printf (str, + "\t%s\n", + gdaex_grid_column_get_title (gcolumn)); + } + + g_string_append (str, "\n"); + + ret = g_strdup (str->str); + g_string_free (str, TRUE); + + return ret; +} + /* PRIVATE */ static void gdaex_grid_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) diff --git a/src/grid.h b/src/grid.h index 1040621..2b8257e 100644 --- a/src/grid.h +++ b/src/grid.h @@ -1,7 +1,7 @@ /* * grid.h * - * Copyright (C) 2010-2020 Andrea Zagli + * Copyright (C) 2010-2021 Andrea Zagli * * This file is part of libgdaexgrid. * @@ -115,6 +115,9 @@ gboolean gdaex_grid_fill_from_datamodel (GdaExGrid *grid, GdaDataModel *dm, GErr gboolean gdaex_grid_fill_from_sqlbuilder (GdaExGrid *grid, GdaEx *gdaex, GdaExSqlBuilder *builder, GError **error); +gchar *gdaex_grid_html_get_header (GdaExGrid *grid); + + G_END_DECLS #endif /* __GDAEX_GRID_H__ */ diff --git a/tests/Makefile.am b/tests/Makefile.am index d028fb8..46a4613 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,7 +16,8 @@ endif noinst_PROGRAMS = \ grid \ grid_from_xml \ - grid_tree + grid_tree \ + grid_html_from_xml LDADD = $(top_builddir)/src/libgdaexgrid.la diff --git a/tests/grid_html_from_xml.c b/tests/grid_html_from_xml.c new file mode 100644 index 0000000..6387584 --- /dev/null +++ b/tests/grid_html_from_xml.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 Andrea Zagli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include + +#include "grid.h" +#include "gridcolumn.h" + +int +main (int argc, char **argv) +{ + GdaEx *gdaex; + + GdaExGrid *grid; + + gtk_init (&argc, &argv); + + gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=grid.db", TESTSDIR)); + if (gdaex == NULL) + { + g_error ("Unable to connect to the db."); + } + + grid = gdaex_grid_new_from_file (argv[1]); + + g_printf ("%s\n\n", gdaex_grid_html_get_header (grid)); + + return 0; +}