From: Andrea Zagli Date: Sat, 28 Jan 2017 09:42:14 +0000 (+0100) Subject: Added functions ZakFormForm::get_elements and ::get_elements_by_type (closes #1105). X-Git-Tag: v0.1.0~8 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=780e00a364f9bb28da7d4168eb5702bb8bd8b464;p=zakform%2Flibzakform Added functions ZakFormForm::get_elements and ::get_elements_by_type (closes #1105). --- diff --git a/src/form.c b/src/form.c index a173097..f9d2c81 100644 --- a/src/form.c +++ b/src/form.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -58,7 +58,6 @@ static void zak_form_form_dispose (GObject *gobject); static void zak_form_form_finalize (GObject *gobject); static void zak_form_form_load_modules (ZakFormForm *zakform); -static GPtrArray *zak_form_form_get_elements (ZakFormForm *zakform); typedef struct { @@ -508,6 +507,50 @@ ZakFormElement return ret; } +/** + * zak_form_form_get_elements: + * @zakform: + * + * Returns: a #GPtrArray with the list of ZakFormElement's in the form. + */ +GPtrArray +*zak_form_form_get_elements (ZakFormForm *zakform) +{ + ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); + + return priv->ar_elements; +} + +/** + * zak_form_form_get_elements_by_type: + * @zakform: + * @type: + * + * Returns: a #GPtrArray with the list of ZakFormElement's in the form filtered by @type. + */ +GPtrArray +*zak_form_form_get_elements_by_type (ZakFormForm *zakform, GType type) +{ + GPtrArray *ar; + ZakFormElement *element; + + guint i; + + ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); + + ar = g_ptr_array_new (); + for (i = 0; i < priv->ar_elements->len; i++) + { + element = (ZakFormElement *)g_ptr_array_index (priv->ar_elements, i); + if (G_OBJECT_TYPE (element) == type) + { + g_ptr_array_add (ar, element); + } + } + + return ar; +} + /** * zak_form_form_add_validator: * @zakform: @@ -913,11 +956,3 @@ zak_form_form_load_modules (ZakFormForm* zakform) g_warning (_("Modules not supported by this operating system.")); } } - -static GPtrArray -*zak_form_form_get_elements (ZakFormForm *zakform) -{ - ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); - - return priv->ar_elements; -} diff --git a/src/form.h b/src/form.h index e97ca2a..88c4cfd 100644 --- a/src/form.h +++ b/src/form.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -50,6 +50,8 @@ gboolean zak_form_form_load_from_file (ZakFormForm *zakform, const gchar *filena gboolean zak_form_form_add_element (ZakFormForm *zakform, ZakFormElement *element); ZakFormElement *zak_form_form_get_element_by_id (ZakFormForm *zakform, const gchar *id); +GPtrArray *zak_form_form_get_elements (ZakFormForm *zakform); +GPtrArray *zak_form_form_get_elements_by_type (ZakFormForm *zakform, GType type); gboolean zak_form_form_add_validator (ZakFormForm *zakform, ZakFormValidator *validator);