QVariant QVariantTree::internalDelTreeValue(const QVariant& root, const QVariantList& address, bool* isValid) const { QVariant result = root; bool trueValid = true; if (address.isEmpty()) result.clear(); // if no address -> invalid else if (address.count() == 1) { QVariantTreeElementContainer* containerType = containerOf(result.type()); if (containerType == NULL) trueValid = false; else result = containerType->delItem(result, address.first()); } else { QVariantTreeElementContainer* containerType = containerOf(result.type()); if (containerType && containerType->keys(result).contains(address.first())) { result = containerType->item(result, address.first()); result = internalDelTreeValue(result, address.mid(1)); result = containerType->setItem(root, address.first(), result); } else trueValid = false; } if (isValid) *isValid = trueValid; return result; }
QVariantList QVariantTree::itemContainerKeys() const { Q_ASSERT(nodeIsContainer()); QVariantTreeElementContainer* containerType = containerOf(nodeType()); Q_ASSERT_X(containerType != 0, "QVariantTree", "cannot find container of type"); return containerType->keys(nodeValue()); }
QVariant QVariantTree::internalSetTreeValue(const QVariant& root, const QVariantList& address, const QVariant& value, bool* isValid) const { QVariant result = root; bool trueValid = true; if (address.isEmpty()) result = value; else { QVariantTreeElementContainer* containerType = containerOf(result.type()); if (containerType && containerType->keys(result).contains(address.first())) { result = containerType->item(result, address.first()); result = internalSetTreeValue(result, address.mid(1), value); result = containerType->setItem(root, address.first(), result); } else trueValid = false; } if (isValid) *isValid = trueValid; return result; }
QVariant QVariantTree::getTreeValue(const QVariant& root, const QVariantList& address, bool* isValid) const { QVariant result = root; int indexAddress = 0; bool trueValid = true; while (trueValid && indexAddress < address.count()) { QVariantTreeElementContainer* containerType = NULL; QVariant key = address.value(indexAddress++); trueValid = typeIsContainer(result.type()) && (containerType = containerOf(result.type())) && containerType->keys(result).contains(key); if (trueValid) result = containerType->item(result, key); } if (isValid) *isValid = trueValid; if (trueValid == false) result.clear(); return result; }
QVariant QVariantTree::getItemContainer(const QVariant& key, const QVariant& defaultValue) const { Q_ASSERT(nodeIsContainer()); QVariantTreeElementContainer* containerType = containerOf(nodeType()); Q_ASSERT_X(containerType != 0, "QVariantTree", "cannot find container of type"); return containerType->item(nodeValue(), key, defaultValue); }
void QVariantTree::delItemContainer(const QVariant& key) { Q_ASSERT(nodeIsContainer()); QVariantTreeElementContainer* containerType = containerOf(nodeType()); Q_ASSERT_X(containerType != 0, "QVariantTree", "cannot find container of type"); QVariantList collItemAddress = _address; collItemAddress << QVariant(key); _root = internalDelTreeValue(_root, collItemAddress); }
void delEventTable(EventTable *et, const char *name, void (*callback)(void *)) { Node *head = (Node *)g_hash_table_lookup(et, name); Event *event; Node *curr; Node *p; forEachNodes(head, curr, p) { event = containerOf(curr, Event, node); if (event->callback == callback) { delNode(curr); xfree(event); break; } }