void SCgTupleArranger::startOperation() { // affect changes to bus SCgBus *bus = mTupleNode->bus(); Q_ASSERT(bus != 0); SCgBus *ghostBus = qgraphicsitem_cast<SCgBus*>(mGhosts[bus]); Q_ASSERT(ghostBus != 0); // map points into bus coordinates registerCommand(bus, ghostBus->points()); // affect pairs and objects foreach(SCgPair *pair, mBusPairs) { SCgObject *end = pair->endObject(); SCgObject *beg = pair->beginObject(); Q_ASSERT(end != 0 && beg != 0); SCgPair *ghostPair = qgraphicsitem_cast<SCgPair*>(mGhosts[pair]); Q_ASSERT(ghostPair != 0); registerCommand(pair, ghostPair->points()); if (beg->type() == SCgBus::Type) registerCommand(end, mGhosts[end]->pos()); else registerCommand(beg, mGhosts[beg]->pos()); }
void SCgHorizontalArranger::startOperation() { QList<SCgObject*> objects; foreach(QGraphicsItem* it, mView->scene()->selectedItems()) if(SCgObject::isSCgObjectType(it->type()) && it->type() != SCgPair::Type) objects.append(static_cast<SCgObject*>(it)); if(objects.isEmpty() || objects.size() == 1) { QMessageBox::information(0, qAppName(), tr("Nothing to align. Did you forget to select objects for alignment?")); return; } QList<SCgObject*>::const_iterator it; double averageY = 0; // Calculate average Y coordinate for (it = objects.begin(); it != objects.end(); ++it) averageY += (*it)->y(); averageY = averageY/objects.size(); // Set objects position for (it = objects.begin(); it != objects.end(); ++it) { if((*it)->type() == SCgBus::Type) { SCgBus* b = static_cast<SCgBus*>(*it); QVector<QPointF> points = b->mapToParent(b->points()); for(int i = 0; i < points.size(); ++i) points[i].setY(averageY); registerCommand(b, b->mapFromParent(points)); }else { QPointF p = (*it)->pos(); p.setY(averageY); registerCommand(*it, p); } } }
void SCgTupleArranger::startOperation() { // affect changes to bus SCgBus *bus = mTupleNode->bus(); Q_ASSERT(bus != 0); SCgBus *ghostBus = qgraphicsitem_cast<SCgBus*>(mGhosts[bus]); Q_ASSERT(ghostBus != 0); registerCommand(bus, ghostBus->points()); // affect pairs and objects foreach(SCgPair *pair, mBusPairs) { SCgObject *end = pair->getEndObject(); Q_ASSERT(end != 0); SCgObject *ghostEnd = mGhosts[end]; Q_ASSERT(ghostEnd != 0); SCgPair *ghostPair = qgraphicsitem_cast<SCgPair*>(mGhosts[pair]); Q_ASSERT(ghostPair != 0); registerCommand(pair, ghostPair->points()); registerCommand(end, ghostEnd->pos()); }