diff --git a/qad_blockview/blockbusitem.cpp b/qad_blockview/blockbusitem.cpp index b7a36c0..0dcc423 100644 --- a/qad_blockview/blockbusitem.cpp +++ b/qad_blockview/blockbusitem.cpp @@ -218,7 +218,7 @@ void BlockBusItem::simplify(bool full) { else sp[i] = pol[segments[segs[i]].first]; } QLineF l0(sp[0], cp), l1(cp, sp[1]); - if (l0.angle() != l1.angle()) continue; + if (qAbs(l0.angle() - l1.angle()) > 0.1) continue; if (segments[s0].first == p) { if (segments[s1].first == p) segments[s0].first = segments[s1].second; else segments[s0].first = segments[s1].first; @@ -313,6 +313,22 @@ BlockBusItem * BlockBusItem::copy() const { } +void BlockBusItem::saveState() { + segments_s = segments; + ends_ind_s = ends_ind; + ends_s = ends; + pol_s = pol; +} + + +void BlockBusItem::restoreState() { + segments = segments_s; + ends_ind = ends_ind_s; + ends = ends_s; + pol = pol_s; +} + + void BlockBusItem::updateGeometry() { ends = endpoints(); ends_ind.clear(); @@ -359,21 +375,25 @@ QVector BlockBusItem::endpoints() const { } -QVector BlockBusItem::endpointLine(int ep) const { +QVector BlockBusItem::endpointLine(int ep, double angle) const { QVector ret; int seg = -1; int np = segmentPointPair(ep, &seg), pp = np; if (ep < 0 || np < 0) return ret; if (pol[np] == pol[ep]) return ret; - QPointF sp = pol[np] - pol[ep]; - bool sdir = (qAbs(sp.x()) >= qAbs(sp.y())); + //QPointF sp = pol[np] - pol[ep]; + QLineF l(pol[ep], pol[np]); + //qDebug() << "first" << l.angle() << angle << (l.angle() != angle); + if (qAbs(l.angle() - angle) > 0.1) return ret; + //qDebug() << "check next" << segments.size(); for (int i = 0; i < segments.size(); ++i) { + //qDebug() << i << np << pointSegmentsCount(np); if (np < 0) break; if (pointSegmentsCount(np) != 2) break; if (i > 0) { - sp = pol[np] - pol[pp]; - bool idir = (qAbs(sp.x()) >= qAbs(sp.y())); - if (sdir != idir) break; + QLineF l(pol[pp], pol[np]); + //qDebug() << i << l.angle() << angle; + if (qAbs(l.angle() - angle) > 0.1) break; } ret << np; pp = np; diff --git a/qad_blockview/blockbusitem.h b/qad_blockview/blockbusitem.h index 4f337ee..2552418 100644 --- a/qad_blockview/blockbusitem.h +++ b/qad_blockview/blockbusitem.h @@ -62,6 +62,9 @@ public: QByteArray save() const; void load(const QByteArray & data); BlockBusItem * copy() const; + + void saveState(); + void restoreState(); enum {Type = UserType + 2}; @@ -72,7 +75,7 @@ protected: void checkDelete(); void emitAction(BlockItemBase::Action a); QVector endpoints() const; - QVector endpointLine(int ep) const; + QVector endpointLine(int ep, double angle) const; int pointSegmentsCount(int point, QList * segs = 0) const; int neighborSegmentPoint(int point, int * seg) const; int type() const {return Type;} @@ -90,11 +93,11 @@ protected: QPen p_, ph, pu, pa, pr, pn; QBrush b_, bh, bu, ba, br; QString tt, bus_name; - QList > segments, ends_ind; + QList > segments, ends_ind, segments_s, ends_ind_s; QMap connections_; - QVector ends; + QVector ends, ends_s; QImage im_bus, im_end; - QPolygonF pol, bpol; + QPolygonF pol, bpol, pol_s; Qt::KeyboardModifiers mm_mods; bool temp_; double pen_width, grid_step; diff --git a/qad_blockview/blockview.cpp b/qad_blockview/blockview.cpp index 2f3e959..92b7ac2 100644 --- a/qad_blockview/blockview.cpp +++ b/qad_blockview/blockview.cpp @@ -316,8 +316,10 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) { if (mm_cancel) return true; if (me->buttons().testFlag(Qt::LeftButton)) { if (!mm_drag) { - if ((screen_point - me->screenPos()).manhattanLength() >= QApplication::startDragDistance()) + if ((screen_point - me->screenPos()).manhattanLength() >= QApplication::startDragDistance()) { mm_drag = fmm_drag = true; + saveBusesState(); + } } else { if (tmp_bus.isVisible()) { mil = scene_->items(me->scenePos()); @@ -956,6 +958,20 @@ void BlockView::saveSelState() { } +void BlockView::saveBusesState() { + QList bl = buses(); + foreach (BlockBusItem * b, bl) + b->saveState(); +} + + +void BlockView::restoreBusesState() { + QList bl = buses(); + foreach (BlockBusItem * b, bl) + b->restoreState(); +} + + void BlockView::applySelRect(QGraphicsSceneMouseEvent * me) { QList ci = sel_rect.collidingItems(Qt::IntersectsItemBoundingRect); QList gi = scene_->items(); @@ -1218,7 +1234,7 @@ void BlockView::moveBuses(const QList & items, QPointF dp) { QList gi = scene_->items(); QVector pins; QList buses; - //qDebug() << "move"; + //qDebug() << "move" << dp; foreach (QGraphicsItem * i, items) if (i->data(1006) == "item" && i->flags().testFlag(QGraphicsItem::ItemIsMovable)) pins << qgraphicsitem_cast(i)->pins(); @@ -1255,9 +1271,15 @@ void BlockView::moveBuses(const QList & items, QPointF dp) { } }*/ QPointF pdp = dp; - if (p->alignment() == Qt::AlignTop || p->alignment() == Qt::AlignBottom) pdp.setY(0.); - if (p->alignment() == Qt::AlignLeft || p->alignment() == Qt::AlignRight) pdp.setX(0.); - QVector epl = b->endpointLine(ends[i]); + double ang = 0.; + switch (p->alignment()) { + case Qt::AlignRight : pdp.setX(0.); ang = 0.; break; + case Qt::AlignTop : pdp.setY(0.); ang = 90.; break; + case Qt::AlignLeft : pdp.setX(0.); ang = 180.; break; + case Qt::AlignBottom: pdp.setY(0.); ang = 270.; break; + default: break; + } + QVector epl = b->endpointLine(ends[i], ang); foreach (int e, epl) b->movePoint(e, pdp); b->movePoint(ends[i], dp); diff --git a/qad_blockview/blockview.h b/qad_blockview/blockview.h index cb07e9c..db0078a 100644 --- a/qad_blockview/blockview.h +++ b/qad_blockview/blockview.h @@ -90,6 +90,8 @@ protected: void thumbShow(); void restoreSelState(); void saveSelState(); + void saveBusesState(); + void restoreBusesState(); void applySelRect(QGraphicsSceneMouseEvent * me); void applyGridStep(); void trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem * bus); diff --git a/qad_widgets/session_manager.cpp b/qad_widgets/session_manager.cpp index 9210d6e..23e2706 100644 --- a/qad_widgets/session_manager.cpp +++ b/qad_widgets/session_manager.cpp @@ -87,16 +87,24 @@ void SessionManager::load(bool onlyMainwindow) { checks[i].second->setChecked(sr.getValue(checks[i].first, checks[i].second->isChecked())); for (int i = 0; i < lines.size(); ++i) lines[i].second->setText(sr.getValue(lines[i].first, lines[i].second->text())); - for (int i = 0; i < combos.size(); ++i) - combos[i].second->setCurrentIndex(sr.getValue(combos[i].first, combos[i].second->currentIndex())); + for (int i = 0; i < combos.size(); ++i) { + QComboBox * c = combos[i].second; + int v = sr.getValue(combos[i].first, c->currentIndex()); + if (v >= 0 && v < c->count()) + c->setCurrentIndex(v); + } for (int i = 0; i < dspins.size(); ++i) dspins[i].second->setValue(sr.getValue(dspins[i].first, dspins[i].second->value())); for (int i = 0; i < spins.size(); ++i) spins[i].second->setValue(sr.getValue(spins[i].first, spins[i].second->value())); for (int i = 0; i < spinsliders.size(); ++i) spinsliders[i].second->setValue(sr.getValue(spinsliders[i].first, spinsliders[i].second->value())); - for (int i = 0; i < tabs.size(); ++i) - tabs[i].second->setCurrentIndex(sr.getValue(tabs[i].first, tabs[i].second->currentIndex())); + for (int i = 0; i < tabs.size(); ++i) { + QTabWidget * t = tabs[i].second; + int v = sr.getValue(tabs[i].first, t->currentIndex()); + if (v >= 0 && v < t->count()) + t->setCurrentIndex(v); + } for (int i = 0; i < actions.size(); ++i) actions[i].second->setChecked(sr.getValue(actions[i].first, actions[i].second->isChecked())); for (int i = 0; i < stringlists.size(); ++i)