ADG

Sign in or create your account | Project List | Help

ADG Commit Details

Date:2010-07-02 22:39:17 (2 months 2 days ago)
Author:Nicola Fontana
Commit:1ffa27ff0ee1259b9c6efeba5728f2362441c5cd
Message:[AdgModel] Added "reset" signal


New signal to reset the model to the initial state. Actually, it
basically removes all the named pairs. Now it is possible to redefine
the model with optional parts: the named pairs are cleared, hence the
eventual entities bound to those pairs are not rendered.

The issue #44 is basically resolved with this commit but will be closed
as soon as the optional rendering of parts will be included in the demo.
Files: src/adg/adg-model.c (10 diffs)
src/adg/adg-model.h (2 diffs)

Change Details

src/adg/adg-model.c
8080    REMOVE_DEPENDENCY,
8181    SET_NAMED_PAIR,
8282    CLEAR,
83    RESET,
8384    CHANGED,
8485    LAST_SIGNAL
8586};
...... 
9697                                                 AdgEntity *entity);
9798static const AdgPair * _adg_named_pair (AdgModel *model,
9899                                                 const gchar *name);
99static void _adg_clear (AdgModel *model);
100static void _adg_reset (AdgModel *model);
100101static void _adg_set_named_pair (AdgModel *model,
101102                                                 const gchar *name,
102103                                                 const AdgPair *pair);
...... 
128129    klass->named_pair = _adg_named_pair;
129130    klass->set_named_pair = _adg_set_named_pair;
130131    klass->clear = NULL;
132    klass->reset = _adg_reset;
131133    klass->changed = _adg_changed;
132134
133135    param = g_param_spec_object("dependency",
...... 
201203     * AdgModel::clear:
202204     * @model: an #AdgModel
203205     *
204     * Removes any cached information from @model.
206     * <note><para>
207     * This signal is only useful in model implementations.
208     * </para></note>
209     *
210     * Removes any information from @model cached by the implementation
211     * code. Useful to force a recomputation of the cache when something
212     * in the model has changed.
205213     **/
206214    _adg_signals[CLEAR] =
207215        g_signal_new("clear", ADG_TYPE_MODEL,
208216                     G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE,
209217                     G_STRUCT_OFFSET(AdgModelClass, clear),
218                     NULL, NULL,
219                     adg_marshal_VOID__VOID,
220                     G_TYPE_NONE, 0);
221
222    /**
223     * AdgModel::reset:
224     * @model: an #AdgModel
225     *
226     * Resets the state of @model by destroying any named pair
227     * associated to it. This step also involves the emission of the
228     * AdgModel:clear signal.
229     *
230     * This signal is intended to be used while redefining the model.
231     * A typical usage would be on these terms:
232     *
233     * |[
234     * adg_model_reset(model);
235     * // Definition of model. This also requires the redefinition of
236     * // the named pairs because the old ones have been destroyed.
237     * ...
238     * adg_model_changed(model);
239     * ]|
240     **/
241    _adg_signals[RESET] =
242        g_signal_new("reset", ADG_TYPE_MODEL,
243                     G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE,
244                     G_STRUCT_OFFSET(AdgModelClass, reset),
210245                     NULL, NULL,
211246                     adg_marshal_VOID__VOID,
212247                     G_TYPE_NONE, 0);
...... 
241276static void
242277_adg_dispose(GObject *object)
243278{
244    AdgModel *model;
245    AdgModelPrivate *data;
246    AdgEntity *entity;
279    static gboolean is_disposed = FALSE;
247280
248    model = (AdgModel *) object;
249    data = model->data;
281    if (G_UNLIKELY(!is_disposed)) {
282        AdgModel *model;
283        AdgModelPrivate *data;
284        AdgEntity *entity;
250285
251    /* Remove all the dependencies from the model: this will emit
252     * a "remove-dependency" signal for every dependency, dropping
253     * all references from those entities to this model */
254    while (data->dependencies != NULL) {
255        entity = (AdgEntity *) data->dependencies->data;
256        adg_model_remove_dependency(model, entity);
257    }
286        model = (AdgModel *) object;
287        data = model->data;
258288
259    if (data->named_pairs)
260        _adg_clear(model);
289        /* Remove all the dependencies: this will emit a
290         * "remove-dependency" signal for every dependency, dropping
291         * all references from entities to this model */
292        while (data->dependencies != NULL) {
293            entity = (AdgEntity *) data->dependencies->data;
294            adg_model_remove_dependency(model, entity);
295        }
296
297        g_signal_emit(model, _adg_signals[RESET], 0);
298    }
261299
262300    if (_ADG_OLD_OBJECT_CLASS->dispose)
263301        _ADG_OLD_OBJECT_CLASS->dispose(object);
...... 
492530 * @model: an #AdgModel
493531 *
494532 * <note><para>
495 * This function is only useful in entity implementations.
533 * This function is only useful new model implementations.
496534 * </para></note>
497535 *
498536 * Emits the #AdgModel::clear signal on @model.
...... 
503541    g_return_if_fail(ADG_IS_MODEL(model));
504542
505543    g_signal_emit(model, _adg_signals[CLEAR], 0);
544}
545
546/**
547 * adg_model_reset:
548 * @model: an #AdgModel
549 *
550 * Emits the #AdgModel::reset signal on @model.
551 **/
552void
553adg_model_reset(AdgModel *model)
554{
555    g_return_if_fail(ADG_IS_MODEL(model));
556
557    g_signal_emit(model, _adg_signals[RESET], 0);
506558}
507559
508560/**
...... 
551603    node = g_slist_find(data->dependencies, entity);
552604
553605    if (node == NULL) {
554        g_warning("%s: attempting to remove the dependency on an entity "
555                  "with type %s from a model of type %s, but the entity "
556                  "is yet not present",
606        g_warning(_("%s: attempting to remove the nonexistent dependency "
607                    "on the entity with type %s from a model of type %s"),
557608                  G_STRLOC,
558609                  g_type_name(G_OBJECT_TYPE(entity)),
559610                  g_type_name(G_OBJECT_TYPE(model)));
...... 
565616}
566617
567618static void
568_adg_clear(AdgModel *model)
619_adg_reset(AdgModel *model)
569620{
570621    AdgModelPrivate *data = model->data;
571622
572    g_hash_table_destroy(data->named_pairs);
573    data->named_pairs = NULL;
623    adg_model_clear(model);
624
625    if (data->named_pairs) {
626        g_hash_table_destroy(data->named_pairs);
627        data->named_pairs = NULL;
628    }
574629}
575630
576631static void
...... 
587642    if (pair == NULL) {
588643        /* Delete mode: raise a warning if @name is not found */
589644        if (*hash == NULL || !g_hash_table_remove(*hash, name))
590            g_warning("%s: attempting to remove inexistent `%s' named pair",
645            g_warning(_("%s: attempting to remove nonexistent `%s' named pair"),
591646                      G_STRLOC, name);
592647
593648        return;
594649    }
595650
596    /* Insert/update mode */
651    /* Insert or update mode */
597652    key = g_strdup(name);
598653    value = adg_pair_dup(pair);
599654
src/adg/adg-model.h
7272                                                 const gchar *name,
7373                                                 const AdgPair *pair);
7474    void (*clear) (AdgModel *model);
75    void (*reset) (AdgModel *model);
7576    void (*changed) (AdgModel *model);
7677};
7778
...... 
100101                                                 AdgNamedPairFunc callback,
101102                                                 gpointer user_data);
102103void adg_model_clear (AdgModel *model);
104void adg_model_reset (AdgModel *model);
103105void adg_model_changed (AdgModel *model);
104106
105107G_END_DECLS
106108

Archive Download the corresponding diff file