示例#1
0
Cell* Cell::copy(Cell *cell)
{
    Cell *c = 0;
    if(!cell)
        c = new Cell();
    else
        c = cell;

    c->setStitch(stitch());
    c->setBgColor(bgColor());
    c->setColor(c->color());
    c->setTransformOriginPoint(transformOriginPoint());
    c->setRotation(0);
    c->setTransform(QTransform());
	c->setTransformations(ChartItemTools::cloneGraphicsTransformations(this));
	foreach (QGraphicsTransform* t, transformations())
		t->setParent(parentObject());

    return c;
}
示例#2
0
template<class Transformation> void Object<Transformation>::setClean(std::vector<std::reference_wrapper<Object<Transformation>>> objects) {
    /* Remove all clean objects from the list */
    auto firstClean = std::remove_if(objects.begin(), objects.end(), [](Object<Transformation>& o) { return !o.isDirty(); });
    objects.erase(firstClean, objects.end());

    /* No dirty objects left, done */
    if(objects.empty()) return;

    /* Add non-clean parents to the list. Mark each added object as visited, so
       they aren't added more than once */
    for(std::size_t end = objects.size(), i = 0; i != end; ++i) {
        Object<Transformation>& o = objects[i];
        o.flags |= Flag::Visited;

        Object<Transformation>* parent = o.parent();
        while(parent && !(parent->flags & Flag::Visited) && parent->isDirty()) {
            objects.push_back(*parent);
            parent = parent->parent();
        }
    }

    /* Cleanup all marks */
    for(auto o: objects) o.get().flags &= ~Flag::Visited;

    /* Compute absolute transformations */
    Scene<Transformation>* scene = objects[0].get().scene();
    CORRADE_ASSERT(scene, "Object::setClean(): objects must be part of some scene", );
    std::vector<typename Transformation::DataType> transformations(scene->transformations(objects));

    /* Go through all objects and clean them */
    for(std::size_t i = 0; i != objects.size(); ++i) {
        /* The object might be duplicated in the list, don't clean it more than once */
        if(!objects[i].get().isDirty()) continue;

        objects[i].get().setCleanInternal(transformations[i]);
        CORRADE_ASSERT(!objects[i].get().isDirty(), "SceneGraph::Object::setClean(): original implementation was not called", );
    }
}