Fix bug where undoing+redoing AddWire multiple times crashes
This commit is contained in:
parent
de9e38ddf7
commit
9414c8c426
@ -35,8 +35,8 @@ void CircuitBuffer::addFromScene(const QList<Part*> &parts, const QList<Wire*>&
|
||||
}
|
||||
for(auto wire : wires)
|
||||
{
|
||||
auto wireInputPart = (Part*)wire->m_connectorInput->parentItem();
|
||||
auto wireOutputPart = (Part*)wire->m_connectorOutput->parentItem();
|
||||
auto wireInputPart = wire->m_connectorInput->parentPart();
|
||||
auto wireOutputPart = wire->m_connectorOutput->parentPart();
|
||||
|
||||
// Create wireData
|
||||
WireData wireData;
|
||||
|
@ -17,6 +17,11 @@ Connector::Connector(Scene* scene, Part *parentPart, ConnectorType::ConnectorTyp
|
||||
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
|
||||
}
|
||||
|
||||
Part* Connector::parentPart()
|
||||
{
|
||||
return (Part*)parentItem();
|
||||
}
|
||||
|
||||
QRectF Connector::boundingRect() const
|
||||
{
|
||||
if(m_connectorType == ConnectorType::Output)
|
||||
|
@ -9,7 +9,7 @@ class Part;
|
||||
class Wire;
|
||||
class Scene;
|
||||
|
||||
class Connector : public QGraphicsItem
|
||||
class Connector : private QGraphicsItem
|
||||
{
|
||||
public:
|
||||
friend class Scene;
|
||||
@ -24,6 +24,8 @@ public:
|
||||
|
||||
Connector(Scene* scene, Part *parentPart, ConnectorType::ConnectorType side);
|
||||
|
||||
Part* parentPart();
|
||||
|
||||
QRectF boundingRect() const override; // For drawing
|
||||
QPainterPath shape() const override; // For selection ("Hitbox")
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
@ -52,8 +52,8 @@ bool FileHandler::save(QString filename)
|
||||
fOut << "[wires]\n";
|
||||
for(auto wire : m_logic->m_wires)
|
||||
{
|
||||
auto wireInputPart = (Part*)wire->m_connectorInput->parentItem();
|
||||
auto wireOutputPart = (Part*)wire->m_connectorOutput->parentItem();
|
||||
auto wireInputPart = wire->m_connectorInput->parentPart();
|
||||
auto wireOutputPart = wire->m_connectorOutput->parentPart();
|
||||
|
||||
fOut << wireInputPart << " " << wireInputPart->m_outputs.indexOf(wire->m_connectorInput) << " " << wireOutputPart << " " << wireOutputPart->m_inputs.indexOf(wire->m_connectorOutput) << "\n";
|
||||
}
|
||||
|
10
Part.cpp
10
Part.cpp
@ -34,6 +34,16 @@ PartType::PartType Part::partType()
|
||||
return m_partType;
|
||||
}
|
||||
|
||||
QPointF Part::getPos() const
|
||||
{
|
||||
return pos();
|
||||
}
|
||||
|
||||
void Part::setPos(QPointF pos)
|
||||
{
|
||||
QGraphicsItem::setPos(pos);
|
||||
}
|
||||
|
||||
void Part::addInputs(int amount)
|
||||
{
|
||||
for(int i = 0; i < amount; i++)
|
||||
|
6
Part.h
6
Part.h
@ -9,7 +9,7 @@
|
||||
class Connector;
|
||||
class Logic;
|
||||
|
||||
class Part : public QGraphicsItem
|
||||
class Part : protected QGraphicsItem
|
||||
{
|
||||
public:
|
||||
friend class Connector;
|
||||
@ -17,6 +17,7 @@ public:
|
||||
friend class Logic;
|
||||
friend class AddPart;
|
||||
friend class RemoveParts;
|
||||
friend class AddWire;
|
||||
friend class RemoveWire;
|
||||
friend class CopyParts;
|
||||
|
||||
@ -45,6 +46,9 @@ public:
|
||||
|
||||
PartType::PartType partType();
|
||||
|
||||
QPointF getPos() const;
|
||||
void setPos(QPointF pos);
|
||||
|
||||
void addInputs(int amount);
|
||||
void addOutputs(int amount);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user