From: Andrea Zagli Date: Mon, 4 Apr 2011 16:41:47 +0000 (+0200) Subject: Implemented min-value and max-value field's properties in X-Git-Tag: 0.1.6~2 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=e1ffea59d8ce9d7cde26d515e1dbeac7b267982f;p=libgtkform Implemented min-value and max-value field's properties in GtkFormFieldInteger and GtkFormFieldFloat. --- diff --git a/src/fielddatetime.c b/src/fielddatetime.c index 62a7e52..103782f 100644 --- a/src/fielddatetime.c +++ b/src/fielddatetime.c @@ -91,8 +91,8 @@ gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass) field_class->clear = gtk_form_field_datetime_clear; field_class->is_empty = gtk_form_field_datetime_is_empty; field_class->is_changed = gtk_form_field_datetime_is_changed; - field_class->is_valid = gtk_form_field_datetime_is_valid; field_class->set_as_origin = gtk_form_field_datetime_set_as_origin; + field_class->is_valid = gtk_form_field_datetime_is_valid; field_class->set_from_datamodel = gtk_form_field_datetime_set_from_datamodel; field_class->set_from_hashtable = gtk_form_field_datetime_set_from_hashtable; field_class->set_value = gtk_form_field_datetime_set_value; diff --git a/src/fieldfloat.c b/src/fieldfloat.c index 29c8854..d2c5bab 100644 --- a/src/fieldfloat.c +++ b/src/fieldfloat.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-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 @@ -76,6 +76,7 @@ gtk_form_field_float_class_init (GtkFormFieldFloatClass *klass) field_class->is_empty = gtk_form_field_float_is_empty; field_class->is_changed = gtk_form_field_float_is_changed; field_class->set_as_origin = gtk_form_field_float_set_as_origin; + field_class->is_valid = gtk_form_field_float_is_valid; field_class->set_from_datamodel = gtk_form_field_float_set_from_datamodel; field_class->set_from_hashtable = gtk_form_field_float_set_from_hashtable; field_class->set_value = gtk_form_field_float_set_value; @@ -314,6 +315,55 @@ gtk_form_field_float_set_as_origin (GtkFormField *field) priv->original_value = g_strtod (gtk_form_field_float_get_value_stringify (field), NULL); } +/** + * gtk_form_field_float_is_valid: + * @field: a #GtkFormField object. + * + */ +gboolean +gtk_form_field_float_is_valid (GtkFormField *field) +{ + gboolean ret; + + GtkFormFieldFloatPrivate *priv; + + gdouble value; + + gchar *min_value; + gchar *max_value; + + g_return_val_if_fail (IS_GTK_FORM_FIELD_FLOAT (field), FALSE); + + ret = TRUE; + + priv = GTK_FORM_FIELD_FLOAT_GET_PRIVATE (GTK_FORM_FIELD_FLOAT (field)); + + value = g_strtod (gtk_form_field_float_get_value_stringify (field), NULL); + + min_value = NULL; + max_value = NULL; + + g_object_get (G_OBJECT (field), + "min-value", &min_value, + "max-value", &max_value, + NULL); + + if (min_value != NULL + && g_strcmp0 (min_value, "") != 0) + { + ret = (g_strtod (min_value, NULL) <= value); + } + + if (ret + && max_value != NULL + && g_strcmp0 (max_value, "") != 0) + { + ret = (g_strtod (max_value, NULL) >= value); + } + + return ret; +} + /** * gtk_form_field_float_set_from_datamodel: * @field: a #GtkFormField object. diff --git a/src/fieldfloat.h b/src/fieldfloat.h index 6816ffb..fd21108 100644 --- a/src/fieldfloat.h +++ b/src/fieldfloat.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-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 @@ -64,6 +64,8 @@ gboolean gtk_form_field_float_is_empty (GtkFormField *field); gboolean gtk_form_field_float_is_changed (GtkFormField *field); void gtk_form_field_float_set_as_origin (GtkFormField *field); +gboolean gtk_form_field_float_is_valid (GtkFormField *field); + gboolean gtk_form_field_float_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row); gboolean gtk_form_field_float_set_from_hashtable (GtkFormField *field, GHashTable *hashtable); gboolean gtk_form_field_float_set_value (GtkFormField *field, GValue *gvalue); diff --git a/src/fieldinteger.c b/src/fieldinteger.c index e422e36..00c1260 100644 --- a/src/fieldinteger.c +++ b/src/fieldinteger.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-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 @@ -74,6 +74,7 @@ gtk_form_field_integer_class_init (GtkFormFieldIntegerClass *klass) field_class->is_empty = gtk_form_field_integer_is_empty; field_class->is_changed = gtk_form_field_integer_is_changed; field_class->set_as_origin = gtk_form_field_integer_set_as_origin; + field_class->is_valid = gtk_form_field_integer_is_valid; field_class->set_from_datamodel = gtk_form_field_integer_set_from_datamodel; field_class->set_from_hashtable = gtk_form_field_integer_set_from_hashtable; field_class->set_value = gtk_form_field_integer_set_value; @@ -275,6 +276,55 @@ gtk_form_field_integer_is_changed (GtkFormField *field) return ret; } +/** + * gtk_form_field_integer_is_valid: + * @field: a #GtkFormField object. + * + */ +gboolean +gtk_form_field_integer_is_valid (GtkFormField *field) +{ + gboolean ret; + + GtkFormFieldIntegerPrivate *priv; + + gint value; + + gchar *min_value; + gchar *max_value; + + g_return_val_if_fail (IS_GTK_FORM_FIELD_INTEGER (field), FALSE); + + ret = TRUE; + + priv = GTK_FORM_FIELD_INTEGER_GET_PRIVATE (GTK_FORM_FIELD_INTEGER (field)); + + value = strtol (gtk_form_field_integer_get_value_stringify (field), NULL, 10); + + min_value = NULL; + max_value = NULL; + + g_object_get (G_OBJECT (field), + "min-value", &min_value, + "max-value", &max_value, + NULL); + + if (min_value != NULL + && g_strcmp0 (min_value, "") != 0) + { + ret = (strtol (min_value, NULL, 10) <= value); + } + + if (ret + && max_value != NULL + && g_strcmp0 (max_value, "") != 0) + { + ret = (strtol (max_value, NULL, 10) >= value); + } + + return ret; +} + /** * gtk_form_field_integer_set_as_origin: * @field: a #GtkFormField object. diff --git a/src/fieldinteger.h b/src/fieldinteger.h index 3caa6de..8f635b8 100644 --- a/src/fieldinteger.h +++ b/src/fieldinteger.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-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 @@ -64,6 +64,8 @@ gboolean gtk_form_field_integer_is_empty (GtkFormField *field); gboolean gtk_form_field_integer_is_changed (GtkFormField *field); void gtk_form_field_integer_set_as_origin (GtkFormField *field); +gboolean gtk_form_field_integer_is_valid (GtkFormField *field); + gboolean gtk_form_field_integer_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row); gboolean gtk_form_field_integer_set_from_hashtable (GtkFormField *field, GHashTable *hashtable); gboolean gtk_form_field_integer_set_value (GtkFormField *field, GValue *gvalue); diff --git a/test/database.db b/test/database.db index 0c12002..8b04301 100644 Binary files a/test/database.db and b/test/database.db differ diff --git a/test/test_db.xml b/test/test_db.xml index 1c08013..1c234fd 100644 --- a/test/test_db.xml +++ b/test/test_db.xml @@ -19,6 +19,8 @@ + 1 + 20