BlockView cosmetics, more enums, fixed right-click on bus point/segment move
This commit is contained in:
@@ -13,6 +13,14 @@
|
||||
const QString _BlockView_Mime_ = "_BlockView_copypaste_";
|
||||
|
||||
|
||||
template <typename T> QSet<T> QList2QSet(const QList<T> & l) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
return QSet<T>(l.begin(), l.end());
|
||||
#else
|
||||
return QSet<T>::fromList(l);
|
||||
#endif
|
||||
}
|
||||
|
||||
BlockView::BlockView(QWidget * parent): QGraphicsView(parent), tmp_bus(true) {
|
||||
_init();
|
||||
}
|
||||
@@ -33,7 +41,7 @@ void BlockView::_init() {
|
||||
qRegisterMetaType<BlockBusItem*>();
|
||||
grid_visible = grid_snap = pm_connect = navigation = m_connect = m_trace_with_buses = prev_tcb = minimap = true;
|
||||
mm_drag = moved = new_branch = new_bus = mm_cancel = iconnect = mm_copy = m_pin_mc = mm_thumb = move_bus_point = wheel_zoom = false;
|
||||
match_bus = bus_from = 0;
|
||||
match_bus = bus_from = cur_bus = 0;
|
||||
mm_ci = 0;
|
||||
hpin = 0;
|
||||
ghost_ = 0;
|
||||
@@ -164,12 +172,12 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
case QEvent::GraphicsSceneMouseDoubleClick:
|
||||
mil = scene_->items(scene_point);
|
||||
foreach (QGraphicsItem * i, mil) {
|
||||
if (i->data(1006) == "item") {
|
||||
if (i->data(bvidType).toInt() == bvitBlock) {
|
||||
//emit blockDoubleClicked((BlockItem * )i);
|
||||
QMetaObject::invokeMethod(this, "blockDoubleClicked", Qt::QueuedConnection, Q_ARG(BlockItem * , (BlockItem*)i));
|
||||
return true;
|
||||
}
|
||||
if (i->data(1005) == "connection") {
|
||||
if (i->data(bvidType).toInt() == bvitBus) {
|
||||
if (qgraphicsitem_cast<BlockBusItem*>(i)->isBusSelected()) {
|
||||
//emit busDoubleClicked(qgraphicsitem_cast<BlockBusItem*>(i));
|
||||
QMetaObject::invokeMethod(this, "busDoubleClicked", Qt::QueuedConnection, Q_ARG(BlockBusItem * , (BlockBusItem*)i));
|
||||
@@ -183,7 +191,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mil = scene_->items(scene_point);
|
||||
mm_ci = (mil.isEmpty() ? 0 : mil.front());
|
||||
if (mm_ci != 0) {
|
||||
while (mm_ci->data(1005).toString() == "connection") {
|
||||
while (mm_ci->data(bvidType).toInt() == bvitBus) {
|
||||
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci))
|
||||
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci)->isBusSelected())
|
||||
break;
|
||||
@@ -199,13 +207,12 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
break;*/
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
if (mm_ci != 0) {
|
||||
if (mm_ci->data(1008).toBool()) {
|
||||
if (mm_ci->data(bvidInvalidItem).toBool()) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
//if (mm_ci->data(1007).toBool()) break;
|
||||
//if (mm_ci->data(bvidItemSelection).toBool()) break;
|
||||
}
|
||||
//qDebug() << "press";
|
||||
if (me->buttons().testFlag(Qt::LeftButton)) btncnt++;
|
||||
if (me->buttons().testFlag(Qt::RightButton)) btncnt++;
|
||||
if (me->buttons().testFlag(Qt::MidButton)) btncnt++;
|
||||
@@ -218,34 +225,41 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
block_emit_selection = true;
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
i->setSelected(i->data(1000).toBool());
|
||||
i->setSelected(i->data(bvidSelected).toBool());
|
||||
block_emit_selection = false;
|
||||
emit selectionChanged();
|
||||
}
|
||||
if (mm_copy && mm_cancel) {
|
||||
deleteCopyTemp();
|
||||
mm_copy = moved = false;
|
||||
unsetCursor();
|
||||
if (mm_cancel) {
|
||||
if (cur_bus) {
|
||||
cur_bus->pol = cur_bus->bpol;
|
||||
cur_bus->prepareGeometryChange();
|
||||
cur_bus = 0;
|
||||
}
|
||||
if (mm_copy) {
|
||||
deleteCopyTemp();
|
||||
mm_copy = moved = false;
|
||||
unsetCursor();
|
||||
}
|
||||
if (new_bus) {
|
||||
new_bus = false;
|
||||
unmarkPins(true);
|
||||
reconnectAll();
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
if (new_branch) {
|
||||
new_branch = false;
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
if (moved) {
|
||||
moved = false;
|
||||
restoreSelState();
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (new_bus && mm_cancel) {
|
||||
new_bus = false;
|
||||
unmarkPins(true);
|
||||
reconnectAll();
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
if (new_branch && mm_cancel) {
|
||||
new_branch = false;
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
if (moved && mm_cancel) {
|
||||
moved = false;
|
||||
restoreSelState();
|
||||
hideTmpBuses();
|
||||
m_trace_with_buses = prev_tcb;
|
||||
}
|
||||
if (mm_cancel) return true;
|
||||
mm_mods = me->modifiers();
|
||||
mm_drag = moved = false;
|
||||
screen_point = me->screenPos();
|
||||
@@ -260,7 +274,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
while (!mil.isEmpty()) {
|
||||
mm_ci = mil.front();
|
||||
if (mm_ci->data(bvidDTHandle).toBool()) return QGraphicsView::eventFilter(o, e);
|
||||
if (mm_ci->data(1008).toBool() || mm_ci->data(1007).toBool()) {
|
||||
if (mm_ci->data(bvidInvalidItem).toBool() || mm_ci->data(bvidItemSelection).toBool()) {
|
||||
mil.pop_front();
|
||||
} else break;
|
||||
}
|
||||
@@ -268,7 +282,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mm_ci = 0;
|
||||
return true;
|
||||
}
|
||||
while (mm_ci->data(1005).toString() == "connection") {
|
||||
while (mm_ci->data(bvidType).toInt() == bvitBus) {
|
||||
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci))
|
||||
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci)->isBusSelected())
|
||||
break;
|
||||
@@ -280,21 +294,21 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mm_ci->data(1003).toBool()) {
|
||||
if (mm_ci->data(bvidVisualizeSelection).toBool()) {
|
||||
if (mil.size() > 1) {
|
||||
mm_ci = mil[1];
|
||||
mil.pop_front();
|
||||
if (mm_ci->data(1003).toBool())
|
||||
if (mm_ci->data(bvidVisualizeSelection).toBool())
|
||||
if (mil.size() > 1)
|
||||
mm_ci = mil[1];
|
||||
} else
|
||||
mm_ci = 0;
|
||||
}
|
||||
if (mm_ci->data(1002).toBool()) {
|
||||
if (mm_ci->data(bvidMoveParent).toBool()) {
|
||||
QGraphicsItem * ti = mm_ci;
|
||||
while (mm_ci->parentItem() != 0)
|
||||
mm_ci = mm_ci->parentItem();
|
||||
if (!ti->data(1010).toString().isEmpty()) { // text item, check for rect
|
||||
if (!ti->data(bvidDecorText).toString().isEmpty()) { // text item, check for rect
|
||||
BlockItem * bi = qgraphicsitem_cast<BlockItem*>(mm_ci);
|
||||
if (bi) {
|
||||
if (!bi->sceneRect().contains(scene_point)) {
|
||||
@@ -306,7 +320,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
return true;
|
||||
}
|
||||
if (mm_ci) {
|
||||
if (mm_ci->data(1004) == "pin" && m_connect) {
|
||||
if ((mm_ci->data(bvidType).toInt() == bvitPin) && m_connect) {
|
||||
if (qgraphicsitem_cast<BlockItemPin*>(mm_ci)->state() == BlockItemPin::Hover) {
|
||||
trace_from = mm_ci->scenePos();
|
||||
qgraphicsitem_cast<BlockItemPin*>(mm_ci)->clearStateStack();
|
||||
@@ -344,11 +358,11 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
ghost_->setPos(quantize(me->scenePos(), grid_step));
|
||||
}*/
|
||||
if (mm_ci)
|
||||
if (mm_ci->data(1008).toBool()) {
|
||||
if (mm_ci->data(bvidInvalidItem).toBool()) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
if (mm_ci->data(1007).toBool()) break;
|
||||
if (mm_ci->data(bvidItemSelection).toBool()) break;
|
||||
if (mm_ci->data(bvidDTHandle).toBool()) break;
|
||||
if (mm_cancel) return true;
|
||||
if (me->buttons().testFlag(Qt::LeftButton)) {
|
||||
@@ -362,7 +376,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
mil = scene_->items(me->scenePos());
|
||||
hpin = 0;
|
||||
foreach (QGraphicsItem * i, mil)
|
||||
if (i->data(1004) == "pin") {
|
||||
if (i->data(bvidType).toInt() == bvitPin) {
|
||||
hpin = qgraphicsitem_cast<BlockItemPin*>(i);
|
||||
break;
|
||||
}
|
||||
@@ -391,7 +405,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
if (fmm_drag) {
|
||||
fmm_drag = false;
|
||||
if (mm_ci) {
|
||||
if ((mm_ci->data(1006) == "item")) {
|
||||
if (mm_ci->data(bvidType).toInt() == bvitBlock) {
|
||||
if (!mm_ci->isSelected() && sel_items.isEmpty()) {
|
||||
clearSelection();
|
||||
mm_ci->setSelected(true);
|
||||
@@ -407,7 +421,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
deleteCopyTemp();
|
||||
QList<BlockItem * > bi;
|
||||
foreach (QGraphicsItem * i, sel_items) {
|
||||
if (i->data(1006) == "item") {
|
||||
if (i->data(bvidType).toInt() == bvitBlock) {
|
||||
//qDebug() << "copy";
|
||||
bi << qgraphicsitem_cast<BlockItem*>(i);
|
||||
BlockItem * ti = bi.back()->copy();
|
||||
@@ -492,7 +506,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
if (mm_ci)
|
||||
if (mm_ci->data(1100).toBool())
|
||||
if (mm_ci->data(bvidBlockDecor).toBool())
|
||||
return true;
|
||||
}
|
||||
if (me->modifiers().testFlag(Qt::ControlModifier) && me->buttons() != 0 && mm_ci == 0)
|
||||
@@ -510,11 +524,11 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
return true;
|
||||
}
|
||||
if (mm_ci)
|
||||
if (mm_ci->data(1008).toBool()) {
|
||||
if (mm_ci->data(bvidInvalidItem).toBool()) {
|
||||
mm_ci = 0;
|
||||
break;
|
||||
}
|
||||
if (mm_ci->data(1007).toBool()) break;
|
||||
if (mm_ci->data(bvidItemSelection).toBool()) break;
|
||||
if (mm_copy) {
|
||||
QList<QGraphicsItem*> ai;
|
||||
blockSignals(true);
|
||||
@@ -522,7 +536,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
QList<BlockItem*> ci;
|
||||
QList<BlockBusItem*> bi;
|
||||
foreach (QGraphicsItem * b, sel_items)
|
||||
if (b->data(1006) == "item") {
|
||||
if (b->data(bvidType).toInt() == bvitBlock) {
|
||||
ci << qgraphicsitem_cast<BlockItem*>(b);
|
||||
ai << qgraphicsitem_cast<QGraphicsItem*>(b);
|
||||
}
|
||||
@@ -544,7 +558,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
if (moved && pm_connect) {
|
||||
QList<QGraphicsItem*> ci;
|
||||
foreach (QGraphicsItem * b, sel_items)
|
||||
if (b->data(1006) == "item")
|
||||
if (b->data(bvidType).toInt() == bvitBlock)
|
||||
ci << b;
|
||||
simplifyBuses();
|
||||
emitActionEvent(BlockItemBase::BlockMove, ci);
|
||||
@@ -591,7 +605,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
} else {
|
||||
if (mm_ci != 0) {
|
||||
if (me->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
if (mm_ci->data(1006) == "item")
|
||||
if (mm_ci->data(bvidType).toInt() == bvitBlock)
|
||||
mm_ci->setSelected(!mm_ci->isSelected());
|
||||
} else
|
||||
mm_ci->setSelected(true);
|
||||
@@ -642,12 +656,20 @@ void BlockView::timerEvent(QTimerEvent * e) {
|
||||
void BlockView::wheelEvent(QWheelEvent * e) {
|
||||
if (!navigation) return;
|
||||
if (wheel_zoom || e->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
double scl = 1. - e->angleDelta().y() / 500.;
|
||||
#else
|
||||
double scl = 1. - e->delta() / 500.;
|
||||
#endif
|
||||
if (!is_nav_anim || (nav_anim.state() != QPropertyAnimation::Running))
|
||||
nav_target = _nav();
|
||||
QRectF r = nav_target;
|
||||
double vw = viewport()->width(), vh = viewport()->height();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
double cx = double(e->position().x()) / vw, cy = double(e->position().y()) / vh;
|
||||
#else
|
||||
double cx = double(e->pos().x()) / vw, cy = double(e->pos().y()) / vh;
|
||||
#endif
|
||||
double pw = r.width(), ph = r.height();
|
||||
r.setWidth(r.width() * scl);
|
||||
r.setHeight(r.width() * vh / vw);
|
||||
@@ -950,7 +972,7 @@ void BlockView::clearSelection() {
|
||||
void BlockView::addItem(QGraphicsItem * item, bool emit_action) {
|
||||
scene_->addItem(item);
|
||||
applyGridStep();
|
||||
if (item->data(1005) == "connection") {
|
||||
if (item->data(bvidType).toInt() == bvitBus) {
|
||||
loadBus(qgraphicsitem_cast<BlockBusItem*>(item));
|
||||
((BlockBusItem*)item)->setSquareNodes(square_node);
|
||||
connect((BlockBusItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBus(QObject*)), Qt::UniqueConnection);
|
||||
@@ -958,14 +980,14 @@ void BlockView::addItem(QGraphicsItem * item, bool emit_action) {
|
||||
emit connectionsChanged();
|
||||
return;
|
||||
}
|
||||
if (item->data(1006) == "item") {
|
||||
if (item->data(bvidType).toInt() == bvitBlock) {
|
||||
connect((BlockItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBlock(QObject*)), Qt::UniqueConnection);
|
||||
connect((BlockItem*)item, SIGNAL(blockHoverEnter(BlockItem*)), this, SIGNAL(blockHoverEnter(BlockItem*)), Qt::UniqueConnection);
|
||||
connect((BlockItem*)item, SIGNAL(blockHoverLeave(BlockItem*)), this, SIGNAL(blockHoverLeave(BlockItem*)), Qt::UniqueConnection);
|
||||
if (emit_action) emitActionEvent(BlockItemBase::BlockAdd, QList<QGraphicsItem*>() << item);
|
||||
return;
|
||||
}
|
||||
item->setData(1009, "decor");
|
||||
item->setData(bvidType, bvitDecor);
|
||||
}
|
||||
|
||||
|
||||
@@ -973,7 +995,7 @@ QList<BlockBusItem * > BlockView::buses() const {
|
||||
QList<BlockBusItem * > ret;
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1005) == "connection")
|
||||
if (i->data(bvidType).toInt() == bvitBus)
|
||||
if (!copy_buses.contains((BlockBusItem*)i))
|
||||
ret << qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
return ret;
|
||||
@@ -1002,7 +1024,7 @@ QList<BlockItem * > BlockView::blocks() const {
|
||||
QList<BlockItem * > ret;
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1006) == "item")
|
||||
if (i->data(bvidType).toInt() == bvitBlock)
|
||||
ret << qgraphicsitem_cast<BlockItem*>(i);
|
||||
return ret;
|
||||
}
|
||||
@@ -1011,7 +1033,7 @@ QList<BlockItem * > BlockView::blocks() const {
|
||||
QList<QGraphicsItem * > BlockView::decors() const {
|
||||
QList<QGraphicsItem*> ret, gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if ((i->data(1009) == "decor") && !i->data(1008).toBool() && !i->data(1007).toBool() && (i->parentItem() == 0)
|
||||
if ((i->data(bvidType).toInt() == bvitDecor) && !i->data(bvidInvalidItem).toBool() && !i->data(bvidItemSelection).toBool() && (i->parentItem() == 0)
|
||||
&& (i != &sel_rect) && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i))
|
||||
ret << i;
|
||||
return ret;
|
||||
@@ -1027,7 +1049,8 @@ BlockBusItem * BlockView::connectionBus(BlockItem * b0, BlockItem * b1) const {
|
||||
|
||||
QList<BlockBusItem * > BlockView::connectionBuses(BlockItem * b0, BlockItem * b1) const {
|
||||
if (!b0 || !b1) return QList<BlockBusItem * >();
|
||||
QSet<BlockBusItem * > bs0 = b0->connectedBuses().toSet(), bs1 = b1->connectedBuses().toSet();
|
||||
QSet<BlockBusItem * > bs0 = QList2QSet(b0->connectedBuses()),
|
||||
bs1 = QList2QSet(b1->connectedBuses());
|
||||
return (bs0 & bs1).values();
|
||||
}
|
||||
|
||||
@@ -1037,7 +1060,7 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
|
||||
if (p0 == p1) return false;
|
||||
if (p0->busType() != p1->busType()) return false;
|
||||
QList<BlockBusItem * > bl0 = p0->connectedBuses(), bl1 = p1->connectedBuses();
|
||||
if (!(bl0.toSet() & bl1.toSet()).isEmpty()) return true;
|
||||
if (!(QList2QSet(bl0) & QList2QSet(bl1)).isEmpty()) return true;
|
||||
BlockBusItem * nb = new BlockBusItem();
|
||||
nb->setBusType(p0->busType());
|
||||
//nb->setEndpointsNumber(3);
|
||||
@@ -1165,7 +1188,7 @@ QRectF BlockView::itemsBoundingRect() const {
|
||||
QRectF ret;
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->isVisible() && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i)) {
|
||||
if (!(i->data(1007).toBool()) && !i->data(1008).toBool()) {
|
||||
if (!(i->data(bvidItemSelection).toBool()) && !i->data(bvidInvalidItem).toBool()) {
|
||||
QRectF br = i->mapRectToScene(i->boundingRect());
|
||||
if (br.width() <= 1 || br.height() <= 1) continue;
|
||||
if (f) ret = br;
|
||||
@@ -1179,11 +1202,11 @@ QRectF BlockView::itemsBoundingRect() const {
|
||||
|
||||
void BlockView::restoreSelState() {
|
||||
foreach (QGraphicsItem * i, sel_items) {
|
||||
i->setPos(i->data(1001).toPointF());
|
||||
i->setPos(i->data(bvidItemPos).toPointF());
|
||||
}
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1005) == "connection") {
|
||||
if (i->data(bvidType).toInt() == bvitBus) {
|
||||
BlockBusItem * bi = qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
bi->pol = bi->bpol;
|
||||
bi->prepareGeometryChange();
|
||||
@@ -1195,9 +1218,9 @@ void BlockView::saveSelState() {
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
sel_items = scene_->selectedItems();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
i->setData(1000, i->isSelected());
|
||||
i->setData(1001, i->pos());
|
||||
if (i->data(1005) == "connection")
|
||||
i->setData(bvidSelected, i->isSelected());
|
||||
i->setData(bvidItemPos, i->pos());
|
||||
if (i->data(bvidType).toInt() == bvitBus)
|
||||
qgraphicsitem_cast<BlockBusItem*>(i)->bpol = qgraphicsitem_cast<BlockBusItem*>(i)->pol;
|
||||
}
|
||||
}
|
||||
@@ -1226,7 +1249,7 @@ void BlockView::applySelRect(QGraphicsSceneMouseEvent * me) {
|
||||
if (!add) clearSelection();
|
||||
else {
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
i->setSelected(i->data(1000).toBool());
|
||||
i->setSelected(i->data(bvidSelected).toBool());
|
||||
}
|
||||
foreach (QGraphicsItem * i, ci) {
|
||||
i->setSelected(!i->isSelected());
|
||||
@@ -1262,7 +1285,7 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
|
||||
wavetrace.fill(BlockViewWavetrace::Empty);
|
||||
QList<QGraphicsItem*> gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1006) == "item") {
|
||||
if (i->data(bvidType).toInt() == bvitBlock) {
|
||||
QRect ir = i->mapRectToScene(i->boundingRect()).toRect().normalized();
|
||||
wavetrace.fill(QRect(ir.topLeft() / grid_step + dp, ir.bottomRight() / grid_step + dp), BlockViewWavetrace::Blocked);
|
||||
QVector<BlockItemPin * > pins = qgraphicsitem_cast<BlockItem * >(i)->pins();
|
||||
@@ -1273,7 +1296,7 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
|
||||
}
|
||||
if (m_trace_with_buses) {
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1005) == "connection") {
|
||||
if (i->data(bvidType).toInt() == bvitBus) {
|
||||
BlockBusItem * b = qgraphicsitem_cast<BlockBusItem * >(i);
|
||||
if (!b) continue;
|
||||
for (int s = 0; s < b->segments.size(); ++s) {
|
||||
@@ -1322,7 +1345,7 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
|
||||
void BlockView::clearBusStates() {
|
||||
QList<QGraphicsItem * > gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1005) == "connection") {
|
||||
if (i->data(bvidType).toInt() == bvitBus) {
|
||||
BlockBusItem * b = qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
b->clearBusState();
|
||||
// if (i != bus_from && i != match_bus)
|
||||
@@ -1344,9 +1367,9 @@ void BlockView::matchBus() {
|
||||
point = tmp_bus.pol.back();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i != bus_from) {
|
||||
if (i->data(1005) == "connection")
|
||||
if (i->data(bvidType).toInt() == bvitBus)
|
||||
buses << qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
if (i->data(1006) == "item")
|
||||
if (i->data(bvidType).toInt() == bvitBlock)
|
||||
blockl << qgraphicsitem_cast<BlockItem*>(i);
|
||||
}
|
||||
}
|
||||
@@ -1435,7 +1458,7 @@ void BlockView::markPins(int bus_type) {
|
||||
unhoverPins();
|
||||
QList<QGraphicsItem * > gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1004) == "pin") {
|
||||
if (i->data(bvidType).toInt() == bvitPin) {
|
||||
BlockItemPin * p = qgraphicsitem_cast<BlockItemPin*>(i);
|
||||
p->saveState();
|
||||
if (m_pin_mc) {
|
||||
@@ -1458,7 +1481,7 @@ void BlockView::unmarkPins(bool to_normal) {
|
||||
unhoverPins();
|
||||
QList<QGraphicsItem * > gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1004) == "pin") {
|
||||
if (i->data(bvidType).toInt() == bvitPin) {
|
||||
qgraphicsitem_cast<BlockItemPin*>(i)->restoreState();
|
||||
if (to_normal)
|
||||
while (qgraphicsitem_cast<BlockItemPin*>(i)->restoreState());
|
||||
@@ -1477,7 +1500,7 @@ void BlockView::unhoverPins(BlockItemPin* excl_pin) {
|
||||
QList<QGraphicsItem * > gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (excl_pin == ((BlockItemPin*)i)) continue;
|
||||
if (i->data(1004) == "pin") {
|
||||
if (i->data(bvidType).toInt() == bvitPin) {
|
||||
((BlockItemPin*)i)->enlargePin(false);
|
||||
}
|
||||
}
|
||||
@@ -1498,10 +1521,10 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
|
||||
QList<BlockBusItem * > buses;
|
||||
//qDebug() << "move" << dp;
|
||||
foreach (QGraphicsItem * i, items)
|
||||
if (i->data(1006) == "item" && i->flags().testFlag(QGraphicsItem::ItemIsMovable))
|
||||
if ((i->data(bvidType).toInt() == bvitBlock) && i->flags().testFlag(QGraphicsItem::ItemIsMovable))
|
||||
pins << qgraphicsitem_cast<BlockItem*>(i)->pins();
|
||||
foreach (QGraphicsItem * i, gi)
|
||||
if (i->data(1005) == "connection")
|
||||
if (i->data(bvidType).toInt() == bvitBus)
|
||||
buses << qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
foreach (BlockBusItem * b, buses) {
|
||||
QList<BlockItemPin * > bpins = b->connections_.values();
|
||||
@@ -1555,10 +1578,10 @@ QList<BlockBusItem * > BlockView::internalBuses(const QList<BlockItem * > & item
|
||||
QList<BlockBusItem * > ret;
|
||||
if (items.isEmpty()) return ret;
|
||||
QList<BlockBusItem * > sbl = buses();
|
||||
QSet<BlockItem * > sis = QSet<BlockItem * >::fromList(items);
|
||||
QSet<BlockItem * > sis = QList2QSet(items);
|
||||
foreach (BlockBusItem * bi, sbl) {
|
||||
if (bi->connectedBlocks().isEmpty()) continue;
|
||||
QSet<BlockItem * > bis = QSet<BlockItem * >::fromList(bi->connectedBlocks());
|
||||
QSet<BlockItem * > bis = QList2QSet(bi->connectedBlocks());
|
||||
if ((bis - sis).isEmpty())
|
||||
ret << bi;
|
||||
}
|
||||
@@ -1604,7 +1627,7 @@ QList<BlockItemPin * > BlockView::nearPins(BlockItemPin * pin, Qt::KeyboardModif
|
||||
|
||||
BlockItemPin * BlockView::getPin(const QList<QGraphicsItem *> & list) const {
|
||||
foreach (QGraphicsItem * i, list) {
|
||||
if (i->data(1004) == "pin")
|
||||
if (i->data(bvidType).toInt() == bvitPin)
|
||||
return qgraphicsitem_cast<BlockItemPin*>(i);
|
||||
}
|
||||
return 0;
|
||||
@@ -1638,7 +1661,7 @@ QList<BlockItem * > BlockView::selectedBlocks() const {
|
||||
QList<BlockItem * > ret;
|
||||
QList<QGraphicsItem * > sil = scene()->selectedItems();
|
||||
foreach (QGraphicsItem * b, sil)
|
||||
if (b->data(1006) == "item")
|
||||
if (b->data(bvidType).toInt() == bvitBlock)
|
||||
ret << qgraphicsitem_cast<BlockItem*>(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1833,7 +1856,7 @@ void BlockView::removedBlock(QObject * o) {
|
||||
void BlockView::removeJunk() {
|
||||
QList<QGraphicsItem * > gi = scene_->items();
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1005) != "connection") continue;
|
||||
if (i->data(bvidType).toInt() != bvitBus) continue;
|
||||
BlockBusItem * b = qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
if (b->pol.size() <= 1) {
|
||||
b->deleteLater();
|
||||
@@ -1892,9 +1915,9 @@ void BlockView::reconnectAll() {
|
||||
QList<BlockItemPin * > pins;
|
||||
QList<BlockBusItem * > buses;
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1004) == "pin")
|
||||
if (i->data(bvidType).toInt() == bvitPin)
|
||||
pins << qgraphicsitem_cast<BlockItemPin*>(i);
|
||||
if (i->data(1005) == "connection")
|
||||
if (i->data(bvidType).toInt() == bvitBus)
|
||||
buses << qgraphicsitem_cast<BlockBusItem*>(i);
|
||||
}
|
||||
foreach (BlockItemPin * p, pins) {
|
||||
@@ -2043,9 +2066,9 @@ void BlockView::removeSelected() {
|
||||
if (i->connectedBlocks().isEmpty())
|
||||
dbuses << i;
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1006) == "item")
|
||||
if (i->data(bvidType).toInt() == bvitBlock)
|
||||
ai << qgraphicsitem_cast<QGraphicsItem*>(i);
|
||||
if ((i->data(1006) == "item") || (i->data(1005) == "connection") || (i->data(1009) == "decor")) {
|
||||
if ((i->data(bvidType).toInt() == bvitBlock) || (i->data(bvidType).toInt() == bvitBus) || (i->data(bvidType).toInt() == bvitDecor)) {
|
||||
scene_->sendEvent(i, new QGraphicsSceneEvent(QEvent::Close));
|
||||
delete i;
|
||||
}
|
||||
@@ -2068,11 +2091,11 @@ void BlockView::removeAll() {
|
||||
QList<QGraphicsItem*> gi = scene_->items(), ai;
|
||||
blockSignals(true);
|
||||
foreach (QGraphicsItem * i, gi) {
|
||||
if (i->data(1006) == "item")
|
||||
if (i->data(bvidType).toInt() == bvitBlock)
|
||||
ai << qgraphicsitem_cast<QGraphicsItem*>(i);
|
||||
if ((i->data(1006) == "item") || (i->data(1005) == "connection") || (i->data(1009) == "decor")) {
|
||||
if ((i != &sel_rect) && (i != &tmp_bus) && (i->parentItem() == 0) && !(i->data(1008).toBool()) && !(i->data(1007).toBool())) {
|
||||
//qDebug() << "delete" << i->data(1004);
|
||||
if ((i->data(bvidType).toInt() == bvitBlock) || (i->data(bvidType).toInt() == bvitBus) || (i->data(bvidType).toInt() == bvitDecor)) {
|
||||
if ((i != &sel_rect) && (i != &tmp_bus) && (i->parentItem() == 0) && !(i->data(bvidInvalidItem).toBool()) && !(i->data(bvidItemSelection).toBool())) {
|
||||
//qDebug() << "delete" << i->data(1005).toInt();
|
||||
scene_->sendEvent(i, new QGraphicsSceneEvent(QEvent::Close));
|
||||
delete i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user