CompositionEditor::CompositionEditor(Composition &composition, Library &library, QWidget *parent) : QSplitter{Qt::Horizontal, parent}, draw{composition, this}, componentModel{QtListFactory::createComponentList(library.getComponents(), this)}, instances{QtListFactory::createInstanceList(composition.getInstances(), componentModel, this)}, connections{QtListFactory::createConnectionList(composition.getConnections(), this)} { this->addWidget(&draw); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(new QLabel("Instances")); layout->addWidget(&instanceView); layout->addWidget(new QLabel("Connections")); layout->addWidget(&connectionView); QWidget *rightPanel = new QWidget(); rightPanel->setLayout(layout); this->addWidget(rightPanel); instanceView.setItemDelegateForColumn(QtNameTypeItem<IComponentInstance>::TYPE_INDEX, new ComboboxItemDelegate(modelFromTypeIndex<IComponentInstance>)); //FIXME memory leak instanceView.setModel(instances); connectionView.setModel(connections); connect(&draw, SIGNAL(addInstance(Point,Composition&)), this, SIGNAL(addInstance(Point,Composition&))); }
void RizzlyPrint::visit(const Composition &composition) { for (const auto *inst : composition.getInstances()) { inst->accept(*this); } for (const auto *con : composition.getConnections()) { con->accept(*this); } }
void CompositionTest::delete_selfInstance_port_removes_dependant_connections() { Component *comp1 = ComponentFactory::produce("comp1", {"in"}, {"out"}); Composition *composition = new Composition(new CompositionInstance(comp1)); comp1->setImplementation(composition); const auto inst = composition->getSelfInstance(); auto portIn = inst->getPorts()[0]; auto portOut = inst->getPorts()[1]; auto connection = ConnectionFactory::produce(portIn, portOut); composition->getConnections().add(connection); ComponentPort *port = comp1->getPorts()[0]; CPPUNIT_ASSERT_EQUAL(size_t(1), composition->getConnections().size()); comp1->getPorts().remove(port); CPPUNIT_ASSERT_EQUAL(size_t(0), composition->getConnections().size()); ComponentFactory::dispose(comp1); }
void CompositionTest::deleteInstancePort_removes_dependant_connections() { Component *comp1 = ComponentFactory::produce("comp1", {"in"}, {"out"}); Composition *composition = new Composition(new CompositionInstanceMock()); Instance *inst = InstanceFactory::produce(comp1, "inst", Point(0,0)); composition->getInstances().add(inst); InstancePort *portOut = inst->getPort("out"); InstancePort *portIn = inst->getPort("in"); Connection *connection = ConnectionFactory::produce(portOut, portIn); composition->getConnections().add(connection); ComponentPort *port = comp1->getPorts()[0]; CPPUNIT_ASSERT_EQUAL(size_t(1), composition->getConnections().size()); comp1->getPorts().remove(port); CPPUNIT_ASSERT_EQUAL(size_t(0), composition->getConnections().size()); CompositionFactory::dispose(composition); ComponentFactory::dispose(comp1); }
void RizzlyPrintTest::connection() { std::stringstream ss; RizzlyPrint printer(ss); Component *component = ComponentFactory::produce("Component", {"a"}, {"b"}); Instance *instance = InstanceFactory::produce(component, "inst", Point(0,0)); Connection *connection = ConnectionFactory::produce(instance->getPorts().front(), instance->getPorts().back()); Composition *composition = new Composition(new CompositionInstanceMock()); composition->getInstances().add(instance); composition->getConnections().add(connection); printer.print(*composition); std::vector<std::string> listing = asList(ss); CPPUNIT_ASSERT_EQUAL(size_t(2), listing.size()); CPPUNIT_ASSERT_EQUAL(std::string("inst: Component;"), listing[0]); CPPUNIT_ASSERT_EQUAL(std::string("inst.a -> inst.b;"), listing[1]); CompositionFactory::dispose(composition); ComponentFactory::dispose(component); }