]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Added visible property to objects (closes #36).
authorAndrea Zagli <azagli@libero.it>
Mon, 31 Oct 2011 16:34:37 +0000 (17:34 +0100)
committerAndrea Zagli <azagli@libero.it>
Mon, 31 Oct 2011 16:34:37 +0000 (17:34 +0100)
data/reptool.dtd
data/reptool_report.dtd
src/rptobject.c
src/rptobject.h
src/rptobjectellipse.c
src/rptobjectimage.c
src/rptobjectline.c
src/rptobjectrect.c
src/rptobjecttext.c
src/rptprint.c
tests/test_rptreport.c

index ba0534a3e4e0a359a59f7fd77b91c48141c22772..862255b9a5778898716999f4561d7df922de8949 100644 (file)
@@ -3,9 +3,10 @@
 >
 
 <!ENTITY % object_commons_attrs
-  "name   CDATA #REQUIRED
-   x      CDATA #REQUIRED
-   y      CDATA #REQUIRED"
+  "name     CDATA #REQUIRED
+   x        CDATA #REQUIRED
+   y        CDATA #REQUIRED
+   visible  (y | n) #IMPLIED"
 >
 
 <!ENTITY % object_size_attrs
index 6a3f6339927f451bcd7176306c523a25929c6ee0..9dc9fd35596593002e319fa27934630d88b77e72 100644 (file)
@@ -4,7 +4,8 @@
 
 <!ENTITY % object_position_attrs
   "x        CDATA #REQUIRED
-   y        CDATA #REQUIRED"
+   y        CDATA #REQUIRED
+   visible  (y | n) #IMPLIED"
 >
 
 <!ENTITY % object_size_attrs
index 4ccf8fb104f9fa9f6877e22e416565cbb612f09d..f5396b2ce80e034cad0a52ed2bc5b2dfeff06ffa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2007-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
@@ -22,7 +22,8 @@ enum
 {
        PROP_0,
        PROP_NAME,
-       PROP_POSITION
+       PROP_POSITION,
+       PROP_VISIBLE
 };
 
 static void rpt_object_class_init (RptObjectClass *klass);
@@ -45,35 +46,10 @@ struct _RptObjectPrivate
        {
                gchar *name;
                RptPoint *position;
+               gboolean visibile;
        };
 
-GType
-rpt_object_get_type (void)
-{
-       static GType rpt_object_type = 0;
-
-       if (!rpt_object_type)
-               {
-                       static const GTypeInfo rpt_object_info =
-                       {
-                               sizeof (RptObjectClass),
-                               NULL,   /* base_init */
-                               NULL,   /* base_finalize */
-                               (GClassInitFunc) rpt_object_class_init,
-                               NULL,   /* class_finalize */
-                               NULL,   /* class_data */
-                               sizeof (RptObject),
-                               0,      /* n_preallocs */
-                               (GInstanceInitFunc) rpt_object_init,
-                               NULL
-                       };
-
-                       rpt_object_type = g_type_register_static (G_TYPE_OBJECT, "RptObject",
-                                                                 &rpt_object_info, 0);
-               }
-
-       return rpt_object_type;
-}
+G_DEFINE_TYPE (RptObject, rpt_object, G_TYPE_OBJECT)
 
 static void
 rpt_object_class_init (RptObjectClass *klass)
@@ -98,6 +74,12 @@ rpt_object_class_init (RptObjectClass *klass)
                                                               "Position",
                                                               "The object's position.",
                                                               G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_VISIBLE,
+                                        g_param_spec_boolean ("visible",
+                                                              "Visibility",
+                                                              "The object's visibility.",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE));
 }
 
 static void
@@ -105,7 +87,9 @@ rpt_object_init (RptObject *rpt_object)
 {
        RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
 
+       priv->name = NULL;
        priv->position = NULL;
+       priv->visibile = TRUE;
 }
 
 /**
@@ -142,20 +126,40 @@ rpt_object_get_xml (RptObject *rpt_object, xmlNode *xnode)
                        RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
                
                        xmlSetProp (xnode, "name", priv->name);
+
                        if (priv->position != NULL)
                                {
                                        rpt_common_set_position (xnode, priv->position);
                                }
 
+                       xmlSetProp (xnode, "visible", priv->visibile ? "y" : "n");
+
                        RPT_OBJECT_GET_CLASS (rpt_object)->get_xml (rpt_object, xnode);
                }
 }
 
+/**
+ * rpt_object_set_from_xml:
+ * @rpt_object:
+ * @xnode:
+ *
+ */
+void
+rpt_object_set_from_xml (RptObject *rpt_object, xmlNode *xnode)
+{
+       gchar *prop;
+
+       g_return_if_fail (IS_RPT_OBJECT (rpt_object));
+
+       prop = (gchar *)xmlGetProp (xnode, "visible");
+       g_object_set (rpt_object, "visible", g_strcmp0 (prop, "y") == 0, NULL);
+       if (prop != NULL) xmlFree (prop);
+}
+
 static void
 rpt_object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        RptObject *rpt_object = RPT_OBJECT (object);
-
        RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
 
        switch (property_id)
@@ -168,6 +172,10 @@ rpt_object_set_property (GObject *object, guint property_id, const GValue *value
                                priv->position = g_memdup (g_value_get_pointer (value), sizeof (RptPoint));
                                break;
 
+                       case PROP_VISIBLE:
+                               priv->visibile = g_value_get_boolean (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -178,7 +186,6 @@ static void
 rpt_object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        RptObject *rpt_object = RPT_OBJECT (object);
-
        RptObjectPrivate *priv = RPT_OBJECT_GET_PRIVATE (rpt_object);
 
        switch (property_id)
@@ -191,6 +198,10 @@ rpt_object_get_property (GObject *object, guint property_id, GValue *value, GPar
                                g_value_set_pointer (value, g_memdup (priv->position, sizeof (RptPoint)));
                                break;
 
+                       case PROP_VISIBLE:
+                               g_value_set_boolean (value, priv->visibile);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index 5a3533ad35aa6f8f5d4cad2dcfdbb846d4d8fdc5..d604f99cf7023e3e5c2a4bc77e85db4091e91278 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ * Copyright (C) 2007-2011 Andrea Zagli <azagli@inwind.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -58,6 +58,7 @@ GType rpt_object_get_type (void) G_GNUC_CONST;
 RptObject *rpt_object_new (const gchar *name, RptPoint position);
 
 void rpt_object_get_xml (RptObject *rpt_object, xmlNode *xnode);
+void rpt_object_set_from_xml (RptObject *rpt_object, xmlNode *xnode);
 
 
 G_END_DECLS
index 08b046424309b9854471e45d5d874a90b569de59..42a5ebd40c222d552b8c09efab1bff2715ac3e12 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2007-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
@@ -150,6 +150,8 @@ RptObject
                                        RptSize *size;
                                        RptStroke *stroke;
 
+                                       rpt_object_set_from_xml (RPT_OBJECT (rpt_obj_ellipse), xnode);
+
                                        priv = RPT_OBJ_ELLIPSE_GET_PRIVATE (rpt_obj_ellipse);
 
                                        size = rpt_common_get_size (xnode);
index c9f0b8817262e8332affbe81739a0aea6073d090..c2a3224bd3e4682b244f1cacbd9dc54c96ad7aab 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2007-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
@@ -192,6 +192,8 @@ RptObject
                                {
                                        priv = RPT_OBJ_IMAGE_GET_PRIVATE (rpt_obj_image);
 
+                                       rpt_object_set_from_xml (RPT_OBJECT (rpt_obj_image), xnode);
+
                                        priv->size = rpt_common_get_size (xnode);
                                        priv->rotation = rpt_common_get_rotation (xnode);
                                        priv->border = rpt_common_get_border (xnode);
index f734592ebef18e3f784aedfe22cfa7dc17039a82..86d641f50300ef02bbedbc304101b7c704bd6d33 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2007-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
@@ -174,6 +174,8 @@ RptObject
 
                        if (rpt_obj_line != NULL)
                                {
+                                       rpt_object_set_from_xml (RPT_OBJECT (rpt_obj_line), xnode);
+
                                        priv = RPT_OBJ_LINE_GET_PRIVATE (rpt_obj_line);
 
                                        priv->size = rpt_common_get_size (xnode);
index 81db44dd2603d7a67f6fa3a908f0cf12c8022488..57092170ad37cfb77c9e63ef5e9783e19a7f7b61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2007-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
@@ -160,6 +160,8 @@ RptObject
                                        RptRotation *rotation;
                                        RptStroke *stroke;
 
+                                       rpt_object_set_from_xml (RPT_OBJECT (rpt_obj_rect), xnode);
+
                                        priv = RPT_OBJ_RECT_GET_PRIVATE (rpt_obj_rect);
 
                                        size = rpt_common_get_size (xnode);
index d1eaf57d509ce37f6df124c9d9c42dcd905175bd..640cc1db21df7dbf6f694c2d1eac5d6b914bfd36 100644 (file)
@@ -235,6 +235,8 @@ RptObject
                                {
                                        gchar *prop;
 
+                                       rpt_object_set_from_xml (RPT_OBJECT (rpt_obj_text), xnode);
+
                                        priv = RPT_OBJ_TEXT_GET_PRIVATE (rpt_obj_text);
 
                                        priv->size = rpt_common_get_size (xnode);
index 89a3e6dfb7c4a198ce69d014b978842ac5d2eaaa..f7de3150d1aefdb90d6e6380ff2f0dcaebd7df55 100644 (file)
@@ -708,6 +708,8 @@ rpt_print_get_xml_page_attributes (RptPrint *rpt_print, xmlNode *xml_page)
 static void
 rpt_print_page (RptPrint *rpt_print, xmlNode *xnode)
 {
+       gchar *prop;
+
        RptPrintPrivate *priv = RPT_PRINT_GET_PRIVATE (rpt_print);
 
        xmlNode *cur = xnode->children;
@@ -731,28 +733,38 @@ rpt_print_page (RptPrint *rpt_print, xmlNode *xnode)
                {
                        if (!xmlNodeIsText (cur))
                                {
-                                       cairo_save (priv->cr);
-                                       if (g_strcmp0 (cur->name, "text") == 0)
-                                               {
-                                                       rpt_print_text_xml (rpt_print, cur);
-                                               }
-                                       else if (g_strcmp0 (cur->name, "line") == 0)
-                                               {
-                                                       rpt_print_line_xml (rpt_print, cur);
-                                               }
-                                       else if (g_strcmp0 (cur->name, "rect") == 0)
-                                               {
-                                                       rpt_print_rect_xml (rpt_print, cur);
-                                               }
-                                       else if (g_strcmp0 (cur->name, "ellipse") == 0)
+                                       prop = (gchar *)xmlGetProp (cur, "visible");
+                                       if (prop != NULL
+                                           && strcmp (g_strstrip (prop), "y") == 0)
                                                {
-                                                       rpt_print_ellipse_xml (rpt_print, cur);
+                                                       cairo_save (priv->cr);
+                                                       if (g_strcmp0 (cur->name, "text") == 0)
+                                                               {
+                                                                       rpt_print_text_xml (rpt_print, cur);
+                                                               }
+                                                       else if (g_strcmp0 (cur->name, "line") == 0)
+                                                               {
+                                                                       rpt_print_line_xml (rpt_print, cur);
+                                                               }
+                                                       else if (g_strcmp0 (cur->name, "rect") == 0)
+                                                               {
+                                                                       rpt_print_rect_xml (rpt_print, cur);
+                                                               }
+                                                       else if (g_strcmp0 (cur->name, "ellipse") == 0)
+                                                               {
+                                                                       rpt_print_ellipse_xml (rpt_print, cur);
+                                                               }
+                                                       else if (g_strcmp0 (cur->name, "image") == 0)
+                                                               {
+                                                                       rpt_print_image_xml (rpt_print, cur);
+                                                               }
+                                                       cairo_restore (priv->cr);
                                                }
-                                       else if (g_strcmp0 (cur->name, "image") == 0)
+
+                                       if (prop != NULL)
                                                {
-                                                       rpt_print_image_xml (rpt_print, cur);
+                                                       xmlFree (prop);
                                                }
-                                       cairo_restore (priv->cr);
                                }
 
                        cur = cur->next;
index 035ad3ae72d7cb6aa8c9c62ffa9faacbf55c9bec..cb9066c0aebef56aae32af86dc6ab3b811abafeb 100644 (file)
@@ -75,6 +75,10 @@ main (int argc, char **argv)
                                        rpt_print_set_output_filename (rptp, "test.pdf");
                                        rpt_print_print (rptp, NULL);
                                }
+                       else
+                               {
+                                       g_warning ("Error on creating RptPrint.");
+                               }
                }
 
        return 0;