[AdgToyText] Refactored using maps
[adg.git] / adg / adg-model.c
blobe292a929f0a9edd89904a107ecbb3be4945104e6
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-model
23 * @short_description: The base class of the ADG model infrastructure
25 * A model is a conceptual representation of something. From an ADG
26 * user point of view, it is a collection of data and rules that
27 * defines how an object should be represented on a drawing.
29 * Because #AdgModel instances are only a conceptual idea, they are
30 * not renderable (that is, #AdgModel is not derived from #AdgEntity).
31 * Instead, it must be passed as subject to entities such as AdgStroke
32 * or AdgHatch.
33 **/
35 /**
36 * AdgModel:
38 * All fields are private and should not be used directly.
39 * Use its public methods instead.
40 **/
43 #include "adg-model.h"
44 #include "adg-model-private.h"
45 #include "adg-intl.h"
48 enum {
49 PROP_0
52 enum {
53 CHANGED,
54 LAST_SIGNAL
58 static void get_property (GObject *object,
59 guint prop_id,
60 GValue *value,
61 GParamSpec *pspec);
62 static void set_property (GObject *object,
63 guint prop_id,
64 const GValue *value,
65 GParamSpec *pspec);
66 static void changed (AdgModel *model);
68 static guint signals[LAST_SIGNAL] = { 0 };
71 G_DEFINE_ABSTRACT_TYPE(AdgModel, adg_model, G_TYPE_OBJECT);
74 static void
75 adg_model_class_init(AdgModelClass *klass)
77 GObjectClass *gobject_class;
79 gobject_class = (GObjectClass *) klass;
81 g_type_class_add_private(klass, sizeof(AdgModelPrivate));
83 gobject_class->get_property = get_property;
84 gobject_class->set_property = set_property;
86 klass->changed = changed;
88 /**
89 * AdgModel::changed:
90 * @model: an #AdgModel
92 * Notificates that the model has changed. By default, the model
93 * cache is invalidated.
94 **/
95 signals[CHANGED] = g_signal_new("changed", ADG_TYPE_MODEL,
96 G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE,
97 G_STRUCT_OFFSET(AdgModelClass, changed),
98 NULL, NULL,
99 g_cclosure_marshal_VOID__VOID,
100 G_TYPE_NONE, 0);
103 static void
104 adg_model_init(AdgModel *model)
106 AdgModelPrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(model, ADG_TYPE_MODEL,
107 AdgModelPrivate);
108 model->data = data;
111 static void
112 get_property(GObject *object,
113 guint prop_id, GValue *value, GParamSpec *pspec)
115 /* TODO: this is only a placeholder */
117 switch (prop_id) {
118 default:
119 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
120 break;
124 static void
125 set_property(GObject *object,
126 guint prop_id, const GValue *value, GParamSpec *pspec)
128 /* TODO: this is only a placeholder */
130 switch (prop_id) {
131 default:
132 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
133 break;
139 * adg_model_changed:
140 * @model: an #AdgModel
142 * Emits the "changed" signal on @model.
144 * This function is only useful in model implementations.
146 void
147 adg_model_changed(AdgModel *model)
149 g_return_if_fail(ADG_IS_MODEL(model));
151 g_signal_emit(model, signals[CHANGED], 0);
155 static void
156 changed(AdgModel *model)