| 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 | ||
|---|---|---|
| 80 | 80 | REMOVE_DEPENDENCY, |
| 81 | 81 | SET_NAMED_PAIR, |
| 82 | 82 | CLEAR, |
| 83 | RESET, | |
| 83 | 84 | CHANGED, |
| 84 | 85 | LAST_SIGNAL |
| 85 | 86 | }; |
| ... | ... | |
| 96 | 97 | AdgEntity *entity); |
| 97 | 98 | static const AdgPair * _adg_named_pair (AdgModel *model, |
| 98 | 99 | const gchar *name); |
| 99 | static void _adg_clear (AdgModel *model); | |
| 100 | static void _adg_reset (AdgModel *model); | |
| 100 | 101 | static void _adg_set_named_pair (AdgModel *model, |
| 101 | 102 | const gchar *name, |
| 102 | 103 | const AdgPair *pair); |
| ... | ... | |
| 128 | 129 | klass->named_pair = _adg_named_pair; |
| 129 | 130 | klass->set_named_pair = _adg_set_named_pair; |
| 130 | 131 | klass->clear = NULL; |
| 132 | klass->reset = _adg_reset; | |
| 131 | 133 | klass->changed = _adg_changed; |
| 132 | 134 | |
| 133 | 135 | param = g_param_spec_object("dependency", |
| ... | ... | |
| 201 | 203 | * AdgModel::clear: |
| 202 | 204 | * @model: an #AdgModel |
| 203 | 205 | * |
| 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. | |
| 205 | 213 | **/ |
| 206 | 214 | _adg_signals[CLEAR] = |
| 207 | 215 | g_signal_new("clear", ADG_TYPE_MODEL, |
| 208 | 216 | G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE, |
| 209 | 217 | 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), | |
| 210 | 245 | NULL, NULL, |
| 211 | 246 | adg_marshal_VOID__VOID, |
| 212 | 247 | G_TYPE_NONE, 0); |
| ... | ... | |
| 241 | 276 | static void |
| 242 | 277 | _adg_dispose(GObject *object) |
| 243 | 278 | { |
| 244 | AdgModel *model; | |
| 245 | AdgModelPrivate *data; | |
| 246 | AdgEntity *entity; | |
| 279 | static gboolean is_disposed = FALSE; | |
| 247 | 280 | |
| 248 | model = (AdgModel *) object; | |
| 249 | data = model->data; | |
| 281 | if (G_UNLIKELY(!is_disposed)) { | |
| 282 | AdgModel *model; | |
| 283 | AdgModelPrivate *data; | |
| 284 | AdgEntity *entity; | |
| 250 | 285 | |
| 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; | |
| 258 | 288 | |
| 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 | } | |
| 261 | 299 | |
| 262 | 300 | if (_ADG_OLD_OBJECT_CLASS->dispose) |
| 263 | 301 | _ADG_OLD_OBJECT_CLASS->dispose(object); |
| ... | ... | |
| 492 | 530 | * @model: an #AdgModel |
| 493 | 531 | * |
| 494 | 532 | * <note><para> |
| 495 | * This function is only useful in entity implementations. | |
| 533 | * This function is only useful new model implementations. | |
| 496 | 534 | * </para></note> |
| 497 | 535 | * |
| 498 | 536 | * Emits the #AdgModel::clear signal on @model. |
| ... | ... | |
| 503 | 541 | g_return_if_fail(ADG_IS_MODEL(model)); |
| 504 | 542 | |
| 505 | 543 | 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 | **/ | |
| 552 | void | |
| 553 | adg_model_reset(AdgModel *model) | |
| 554 | { | |
| 555 | g_return_if_fail(ADG_IS_MODEL(model)); | |
| 556 | ||
| 557 | g_signal_emit(model, _adg_signals[RESET], 0); | |
| 506 | 558 | } |
| 507 | 559 | |
| 508 | 560 | /** |
| ... | ... | |
| 551 | 603 | node = g_slist_find(data->dependencies, entity); |
| 552 | 604 | |
| 553 | 605 | 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"), | |
| 557 | 608 | G_STRLOC, |
| 558 | 609 | g_type_name(G_OBJECT_TYPE(entity)), |
| 559 | 610 | g_type_name(G_OBJECT_TYPE(model))); |
| ... | ... | |
| 565 | 616 | } |
| 566 | 617 | |
| 567 | 618 | static void |
| 568 | _adg_clear(AdgModel *model) | |
| 619 | _adg_reset(AdgModel *model) | |
| 569 | 620 | { |
| 570 | 621 | AdgModelPrivate *data = model->data; |
| 571 | 622 | |
| 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 | } | |
| 574 | 629 | } |
| 575 | 630 | |
| 576 | 631 | static void |
| ... | ... | |
| 587 | 642 | if (pair == NULL) { |
| 588 | 643 | /* Delete mode: raise a warning if @name is not found */ |
| 589 | 644 | 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"), | |
| 591 | 646 | G_STRLOC, name); |
| 592 | 647 | |
| 593 | 648 | return; |
| 594 | 649 | } |
| 595 | 650 | |
| 596 | /* Insert/update mode */ | |
| 651 | /* Insert or update mode */ | |
| 597 | 652 | key = g_strdup(name); |
| 598 | 653 | value = adg_pair_dup(pair); |
| 599 | 654 | |
| src/adg/adg-model.h | ||
|---|---|---|
| 72 | 72 | const gchar *name, |
| 73 | 73 | const AdgPair *pair); |
| 74 | 74 | void (*clear) (AdgModel *model); |
| 75 | void (*reset) (AdgModel *model); | |
| 75 | 76 | void (*changed) (AdgModel *model); |
| 76 | 77 | }; |
| 77 | 78 | |
| ... | ... | |
| 100 | 101 | AdgNamedPairFunc callback, |
| 101 | 102 | gpointer user_data); |
| 102 | 103 | void adg_model_clear (AdgModel *model); |
| 104 | void adg_model_reset (AdgModel *model); | |
| 103 | 105 | void adg_model_changed (AdgModel *model); |
| 104 | 106 | |
| 105 | 107 | G_END_DECLS |
| 106 | 108 | |
