]> saetta.ns0.it Git - libgtkform/commitdiff
Implemented min-value and max-value field's properties in
authorAndrea Zagli <azagli@libero.it>
Mon, 4 Apr 2011 16:41:47 +0000 (18:41 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 4 Apr 2011 16:41:47 +0000 (18:41 +0200)
GtkFormFieldInteger and GtkFormFieldFloat.

src/fielddatetime.c
src/fieldfloat.c
src/fieldfloat.h
src/fieldinteger.c
src/fieldinteger.h
test/database.db
test/test_db.xml

index 62a7e52fc0fdc6e351096a3ffb55187b4a5fdf3c..103782f49ecd0d56b430982e666525bd8ff8938b 100644 (file)
@@ -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;
index 29c8854667356261584274a9973a34023194c831..d2c5baba60961d2de0a542055a3dbed55606e02b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * 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.
index 6816ffbeae1b71c21575f81febc9469b787b1eaf..fd211083b89f340f1bee0c6d8a3b8cb232beb94d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * 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);
index e422e36a9e3af289c089b9a5c8cd068e49395f01..00c12601f7b2adc8f03612b3f7902324f7b5b21e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * 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.
index 3caa6de3407789efa762a386fb64931b19d3b226..8f635b8dc577fbd4cd7b8ff4f4568051b5006eeb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * 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);
index 0c1200262f9d9a52b7ff505f2a366adc70d67fca..8b04301b2e4008704f8113f444c51dd3d3e829e1 100644 (file)
Binary files a/test/database.db and b/test/database.db differ
index 1c08013c041c069dc9c1a2280ceba3d831c2fe66..1c234fd1829659caf2c084a16b006876cdbf5c58 100644 (file)
@@ -19,6 +19,8 @@
 
        <widget type="spin" name="spn_age" label="label4">
                <field type="integer" name="age">
+                       <min-value>1</min-value>
+                       <max-value>20</max-value>
                </field>
        </widget>