Ejemplo n.º 1
0
bool ClassInstanceData::change_rel(ToolCom * com, const char * args,
                                   bool isadd)
{
    com->get_unsigned(args); // 2

    BrowserRelation * r = (BrowserRelation *) com->get_id(args);
    BrowserClassInstance * other = (BrowserClassInstance *) com->get_id(args);

    if (r->deletedp() || other->deletedp()) {
        com->write_ack(FALSE);
        return FALSE;
    }

    RelationData * rd = (RelationData *) r->get_data();
    Q3ValueList<SlotRel>::Iterator it;

    for (it = relations.begin(); it != relations.end(); ++it) {
        const SlotRel & slot_rel = *it;

        if ((slot_rel.value == other) &&
            (r == ((slot_rel.is_a) ? rd->get_start() : rd->get_end())))
            break;
    }

    if (isadd) {
        if (it == relations.end()) {
            // not yet present
            QList<BrowserRelation *> l;

            cl->get_rels(((ClassInstanceData *)other->get_data())->cl, l);

            if ((! l.contains(r)) ||
                (!other->is_writable() && !root_permission())) {
                // illegal
                com->write_ack(FALSE);
                return FALSE;
            }

            // add it
            if (rd->is_a(r))
                add(other, rd);
            else
                ((ClassInstanceData *)other->get_data())
                ->add((BrowserClassInstance *) browser_node, rd);
        }
    }
    else if (it != relations.end()) {
        // remove it
        if (!other->is_writable() && !root_permission()) {
            // illegal
            com->write_ack(FALSE);
            return FALSE;
        }

        replace(other, rd, 0, (*it).is_a, 0);
    }

    return TRUE;
}