Skip to content

Commit

Permalink
scene: Add Scene::netlistChanged() signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Tectu committed Sep 28, 2023
1 parent c53cb12 commit d15a63d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions demo/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ MainWindow::MainWindow(QWidget *parent)
break;
}
});
connect(_scene, &QSchematic::Scene::netlistChanged, [](){
qDebug() << "Netlist changed";
});

// View
_view = new QSchematic::View(this);
Expand Down
22 changes: 21 additions & 1 deletion qschematic/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ Scene::clearIsDirty()
{
if (_undoStack)
_undoStack->setClean();

emit netlistChanged();
}

void
Expand Down Expand Up @@ -293,6 +295,7 @@ Scene::addItem(const std::shared_ptr<Items::Item>& item)

// Let the world know
emit itemAdded(item);
emit netlistChanged();

return true;
}
Expand Down Expand Up @@ -322,6 +325,7 @@ Scene::removeItem(const std::shared_ptr<Items::Item> item)

// Let the world know
emit itemRemoved(item);
emit netlistChanged();

// NOTE: In order to keep items alive through this entire event loop round,
// otherwise crashes because Qt messes with items even after they're removed
Expand Down Expand Up @@ -1015,7 +1019,7 @@ Scene::renderCachedBackground()
}

void
Scene::updateNodeConnections(const Items::Node* node) const
Scene::updateNodeConnections(const Items::Node* node)
{
// Check if a connector lays on a wirepoint
for (auto& connector : node->connectors()) {
Expand Down Expand Up @@ -1060,6 +1064,8 @@ Scene::updateNodeConnections(const Items::Node* node) const
}
}
}

emit netlistChanged();
}

void
Expand Down Expand Up @@ -1090,6 +1096,8 @@ Scene::wirePointMoved(wire& rawWire, int index)
m_wire_manager->attach_wire_to_connector(&rawWire, index, connector.get());
}
}

emit netlistChanged();
}

void
Expand All @@ -1107,6 +1115,8 @@ Scene::generateConnections()
if (wire)
m_wire_manager->attach_wire_to_connector(wire.get(), connector.get());
}

emit netlistChanged();
}

/**
Expand All @@ -1124,6 +1134,8 @@ Scene::finishCurrentWire()
_newWire->simplify();
// _newWire->updatePosition();
_newWire.reset();

emit netlistChanged();
}

std::shared_ptr<Items::Wire>
Expand Down Expand Up @@ -1218,6 +1230,8 @@ Scene::removeLastWirePoint()
_newWire->move_point_to(_newWire->pointsAbsolute().count() - 1, mousePos);
}
}

emit netlistChanged();
}

/**
Expand Down Expand Up @@ -1267,6 +1281,8 @@ Scene::removeUnconnectedWires()
// Remove the wires that have to be removed
for (const auto& wire : wiresToRemove)
_undoStack->push(new Commands::ItemRemove(this, wire));

emit netlistChanged();
}

bool
Expand All @@ -1283,6 +1299,8 @@ Scene::addWire(const std::shared_ptr<Items::Wire>& wire)
return false;
}

emit netlistChanged();

return true;
}

Expand All @@ -1298,5 +1316,7 @@ Scene::removeWire(const std::shared_ptr<Items::Wire>& wire)
m_wire_manager->detach_wire(connector.get());
}

emit netlistChanged();

return m_wire_manager->remove_wire(wire);
}
11 changes: 10 additions & 1 deletion qschematic/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ namespace QSchematic
void itemRemoved(std::shared_ptr<Items::Item> item);
void itemHighlighted(const std::shared_ptr<const Items::Item>& item);

/**
* Signal to indicate that the netlist has likely changed.
*
* @note It is not guaranteed that the netlist actually changed. It's just likely.
*/
// ToDo: We're currently firing this signal too many times.
void
netlistChanged();

protected:
Settings _settings;

Expand Down Expand Up @@ -228,7 +237,7 @@ namespace QSchematic
private:
void renderCachedBackground();
void setupNewItem(Items::Item& item);
void updateNodeConnections(const Items::Node* node) const;
void updateNodeConnections(const Items::Node* node);
void generateConnections();
void finishCurrentWire();

Expand Down

0 comments on commit d15a63d

Please sign in to comment.