]> git.sur5r.net Git - glabels/commitdiff
Optimized the handling of moved objects.
authorJim Evins <evins@snaught.com>
Tue, 7 Dec 2010 15:29:16 +0000 (10:29 -0500)
committerJim Evins <evins@snaught.com>
Tue, 7 Dec 2010 15:33:35 +0000 (10:33 -0500)
Created a separate "moved" signal for objects, so that we don't waste time
updating unrelated controls in the object editor.  This currently is most
visible with barcode objects.

src/label-object.c
src/label-object.h
src/label.c
src/object-editor.c

index d3ffe979a2225ce91eb081638ab378f48eadd837..8eb2aa7aa0be029cb04fb9b01b324c1b747092d3 100644 (file)
@@ -73,6 +73,7 @@ struct _glLabelObjectPrivate {
 
 enum {
         CHANGED,
+        MOVED,
         LAST_SIGNAL
 };
 
@@ -129,6 +130,16 @@ gl_label_object_class_init (glLabelObjectClass *class)
                              G_TYPE_NONE,
                              0);
 
+       signals[MOVED] =
+               g_signal_new ("moved",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (glLabelObjectClass, moved),
+                             NULL, NULL,
+                             gl_marshal_VOID__VOID,
+                             G_TYPE_NONE,
+                             0);
+
        gl_debug (DEBUG_LABEL, "END");
 }
 
@@ -388,9 +399,10 @@ gl_label_object_set_position (glLabelObject *object,
 
                object->priv->x = x;
                object->priv->y = y;
-       }
 
-        gl_label_object_emit_changed (object);
+                g_signal_emit (G_OBJECT(object), signals[MOVED], 0);
+
+       }
 
        gl_debug (DEBUG_LABEL, "END");
 }
@@ -422,9 +434,9 @@ gl_label_object_set_position_relative (glLabelObject *object,
                gl_debug (DEBUG_LABEL, "       x = %f, y= %f",
                          object->priv->x,
                          object->priv->y);
-       }
 
-        gl_label_object_emit_changed (object);
+                g_signal_emit (G_OBJECT(object), signals[MOVED], 0);
+       }
 
        gl_debug (DEBUG_LABEL, "END");
 }
index 5875f8e3102635c0e2f992eff6db7ac2502acd72..e2c43e0c1813440d026f545a92008d8f50cbd90f 100644 (file)
@@ -194,6 +194,9 @@ struct _glLabelObjectClass {
         void        (*changed) (glLabelObject *object,
                                 gpointer       user_data);
 
+        void        (*moved)   (glLabelObject *object,
+                                gpointer       user_data);
+
 };
 
 
index 37e0c6cf7d8e283983f39a4c61b19f94ad422a80..2fb3c7f68d97de8bdd8579981871ae5c70cd201e 100644 (file)
@@ -141,6 +141,9 @@ static void gl_label_finalize      (GObject *object);
 static void object_changed_cb      (glLabelObject *object,
                                     glLabel       *label);
 
+static void object_moved_cb        (glLabelObject *object,
+                                    glLabel       *label);
+
 static void do_modify              (glLabel       *label);
 
 static void begin_selection_op     (glLabel       *label);
@@ -518,6 +521,17 @@ object_changed_cb (glLabelObject *object,
 }
 
 
+/****************************************************************************/
+/* Object "moved" callback.                                                 */
+/****************************************************************************/
+static void
+object_moved_cb (glLabelObject *object,
+                 glLabel       *label)
+{
+        do_modify (label);
+}
+
+
 /****************************************************************************/
 /* Do modify.                                                               */
 /****************************************************************************/
@@ -771,6 +785,8 @@ gl_label_add_object (glLabel       *label,
 
         g_signal_connect (G_OBJECT (object), "changed",
                           G_CALLBACK (object_changed_cb), label);
+        g_signal_connect (G_OBJECT (object), "moved",
+                          G_CALLBACK (object_moved_cb), label);
 
         do_modify (label);
 
@@ -794,6 +810,8 @@ gl_label_delete_object (glLabel       *label,
 
         g_signal_handlers_disconnect_by_func (G_OBJECT (object),
                                               G_CALLBACK (object_changed_cb), label);
+        g_signal_handlers_disconnect_by_func (G_OBJECT (object),
+                                              G_CALLBACK (object_moved_cb), label);
         g_object_unref (object);
 
         do_modify (label);
index e302ac5ab6770de862b46b0ee489ed9dabf4589a..0901cdda7c2a77db942df1af0b24fb99feb386db 100644 (file)
@@ -87,6 +87,9 @@ static void set_key_names                       (glObjectEditor       *editor,
 static void object_changed_cb                   (glLabelObject        *object,
                                                  glObjectEditor       *editor);
 
+static void object_moved_cb                     (glLabelObject        *object,
+                                                 glObjectEditor       *editor);
+
 
 
 /*****************************************************************************/
@@ -198,6 +201,8 @@ gl_object_editor_finalize (GObject *object)
         {
                 g_signal_handlers_disconnect_by_func (G_OBJECT(editor->priv->object),
                                                       object_changed_cb, editor);
+                g_signal_handlers_disconnect_by_func (G_OBJECT(editor->priv->object),
+                                                      object_moved_cb, editor);
                 g_object_unref (editor->priv->object);
         }
 
@@ -291,6 +296,8 @@ set_object (glObjectEditor  *editor,
         {
                 g_signal_handlers_disconnect_by_func (G_OBJECT(editor->priv->object),
                                                       object_changed_cb, editor);
+                g_signal_handlers_disconnect_by_func (G_OBJECT(editor->priv->object),
+                                                      object_moved_cb, editor);
                 g_object_unref (editor->priv->object);
         }
 
@@ -442,10 +449,13 @@ set_object (glObjectEditor  *editor,
                         gtk_notebook_set_current_page (GTK_NOTEBOOK (editor->priv->notebook), 0);
                 }
 
+                object_moved_cb (object, editor);
                 object_changed_cb (object, editor);
 
                 g_signal_connect (G_OBJECT (object), "changed",
                                   G_CALLBACK (object_changed_cb), editor);
+                g_signal_connect (G_OBJECT (object), "moved",
+                                  G_CALLBACK (object_moved_cb), editor);
         }
         else
         {
@@ -728,7 +738,6 @@ static void
 object_changed_cb (glLabelObject  *object,
                    glObjectEditor *editor)
 {
-        gdouble              x, y;
         gdouble              w, h;
         glColorNode         *line_color_node;
         gdouble              line_width;
@@ -755,9 +764,6 @@ object_changed_cb (glLabelObject  *object,
         gl_debug (DEBUG_EDITOR, "BEGIN");
 
 
-        gl_label_object_get_position (object, &x, &y);
-        gl_object_editor_set_position (editor, x, y);
-
         label = gl_label_object_get_parent (object);
         merge = gl_label_get_merge (label);
 
@@ -871,6 +877,24 @@ object_changed_cb (glLabelObject  *object,
 }
 
 
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. object "moved" callback.                                         */
+/*---------------------------------------------------------------------------*/
+static void
+object_moved_cb (glLabelObject  *object,
+                 glObjectEditor *editor)
+{
+        gdouble              x, y;
+
+        gl_debug (DEBUG_EDITOR, "BEGIN");
+
+        gl_label_object_get_position (object, &x, &y);
+        gl_object_editor_set_position (editor, x, y);
+
+        gl_debug (DEBUG_EDITOR, "END");
+}
+
+
 /*****************************************************************************/
 /* Object editor "changed" callback.                                         */
 /*****************************************************************************/
@@ -905,6 +929,7 @@ gl_object_editor_changed_cb (glObjectEditor *editor)
 
 
         g_signal_handlers_block_by_func (G_OBJECT (object), object_changed_cb, editor);
+        g_signal_handlers_block_by_func (G_OBJECT (object), object_moved_cb, editor);
 
 
         gl_object_editor_get_position (editor, &x, &y);
@@ -1017,6 +1042,7 @@ gl_object_editor_changed_cb (glObjectEditor *editor)
 
 
         g_signal_handlers_unblock_by_func (G_OBJECT (object), object_changed_cb, editor);
+        g_signal_handlers_unblock_by_func (G_OBJECT (object), object_moved_cb, editor);
 
         gl_debug (DEBUG_EDITOR, "END");
 }