@@ -213,20 +213,42 @@ void NetworkEditor::duplicateModule(const ModuleHandle& module)
213213
214214void NetworkEditor::connectNewModule (const ModuleHandle& moduleToConnectTo, const PortDescriptionInterface* portToConnect, const std::string& newModuleName)
215215{
216+ auto prop = sender ()->property (addNewModuleActionTypePropertyName ());
217+ qDebug () << sender ();
218+ qDebug () << " NetworkEditor SENDER PROPERTY:" << prop;
219+ qDebug () << sender ()->property (" inputPortToConnectPid" );
220+
216221 auto widget = findById (scene_->items (), moduleToConnectTo->get_id ());
217222 QPointF increment (0 , portToConnect->isInput () ? -110 : 110 );
218223 lastModulePosition_ = widget->scenePos () + increment;
219224
220- controller_->connectNewModule (portToConnect, newModuleName);
221- }
225+ qDebug () << " PORT CONNS:" << portToConnect->nconnections ();
222226
223- void NetworkEditor::insertNewModule (const SCIRun::Dataflow::Networks::ModuleHandle& moduleToConnectTo, const SCIRun::Dataflow::Networks::PortDescriptionInterface* outputPort, const SCIRun::Dataflow::Networks::PortDescriptionInterface* inputPort, const std::string& newModuleName)
224- {
225- auto widget = findById (scene_->items (), moduleToConnectTo->get_id ());
226- // QPointF increment(0, portToConnect->isInput() ? -110 : 110);
227- // lastModulePosition_ = widget->scenePos() + increment;
227+ PortDescriptionInterface* newConnectionInputPort = nullptr ;
228+ auto q = dynamic_cast <const PortWidget*>(portToConnect);
229+ if (q)
230+ {
231+ for (size_t i = 0 ; i < q->nconnections (); ++i)
232+ {
233+ auto cpi = q->connectedPorts ()[i];
234+ qDebug () << QString::fromStdString (cpi->id ().toString ());
235+ if (QString::fromStdString (cpi->id ().toString ()) == sender ()->property (" inputPortToConnectPid" ))
236+ newConnectionInputPort = cpi;
237+ }
238+ }
239+
240+ if (newConnectionInputPort)
241+ {
242+ qDebug () << " found port object to connect up with:" << newConnectionInputPort;
243+ }
244+ else
245+ {
246+ qDebug () << " Didn't find port object to connect up with, or this is just adding a new module, not inserting." ;
247+ }
228248
229- controller_->insertNewModule (outputPort, inputPort, newModuleName);
249+ controller_->connectNewModule (portToConnect, newModuleName);
250+
251+ // requestConnection(..., newConnectionInputPort);
230252}
231253
232254void NetworkEditor::replaceModuleWith (const ModuleHandle& moduleToReplace, const std::string& newModuleName)
@@ -407,7 +429,7 @@ void ZLevelManager::sendToBack()
407429
408430void ZLevelManager::setZValue (int z)
409431{
410- ModuleProxyWidget* node = selectedModuleProxy ();
432+ auto node = selectedModuleProxy ();
411433 if (node)
412434 {
413435 node->setZValue (z);
@@ -421,7 +443,7 @@ ModuleProxyWidget* getModuleProxy(QGraphicsItem* item)
421443
422444ModuleWidget* getModule (QGraphicsItem* item)
423445{
424- ModuleProxyWidget* proxy = getModuleProxy (item);
446+ auto proxy = getModuleProxy (item);
425447 if (proxy)
426448 return static_cast <ModuleWidget*>(proxy->widget ());
427449 return nullptr ;
@@ -443,7 +465,7 @@ void NetworkEditor::setVisibility(bool visible)
443465// TODO copy/paste
444466ModuleWidget* NetworkEditor::selectedModule () const
445467{
446- QList<QGraphicsItem*> items = scene_->selectedItems ();
468+ auto items = scene_->selectedItems ();
447469 if (items.count () == 1 )
448470 {
449471 return getModule (items.first ());
@@ -453,7 +475,7 @@ ModuleWidget* NetworkEditor::selectedModule() const
453475
454476ModuleProxyWidget* ZLevelManager::selectedModuleProxy () const
455477{
456- QList<QGraphicsItem*> items = scene_->selectedItems ();
478+ auto items = scene_->selectedItems ();
457479 if (items.count () == 1 )
458480 {
459481 return getModuleProxy (items.first ());
@@ -463,19 +485,19 @@ ModuleProxyWidget* ZLevelManager::selectedModuleProxy() const
463485
464486ConnectionLine* NetworkEditor::selectedLink () const
465487{
466- QList<QGraphicsItem*> items = scene_->selectedItems ();
488+ auto items = scene_->selectedItems ();
467489 if (items.count () == 1 )
468490 return dynamic_cast <ConnectionLine*>(items.first ());
469491 return nullptr ;
470492}
471493
472494NetworkEditor::ModulePair NetworkEditor::selectedModulePair () const
473495{
474- QList<QGraphicsItem*> items = scene_->selectedItems ();
496+ auto items = scene_->selectedItems ();
475497 if (items.count () == 2 )
476498 {
477- ModuleWidget* first = getModule (items.first ());
478- ModuleWidget* second = getModule (items.last ());
499+ auto first = getModule (items.first ());
500+ auto second = getModule (items.last ());
479501 if (first && second)
480502 return ModulePair (first, second);
481503 }
@@ -484,7 +506,7 @@ NetworkEditor::ModulePair NetworkEditor::selectedModulePair() const
484506
485507void NetworkEditor::del ()
486508{
487- QList<QGraphicsItem*> items = scene_->selectedItems ();
509+ auto items = scene_->selectedItems ();
488510 QMutableListIterator<QGraphicsItem*> i (items);
489511 while (i.hasNext ())
490512 {
@@ -514,7 +536,7 @@ void NetworkEditor::copy()
514536 {
515537 for (const auto & item : selected)
516538 {
517- if (ModuleProxyWidget* w = dynamic_cast <ModuleProxyWidget*>(item))
539+ if (auto w = dynamic_cast <ModuleProxyWidget*>(item))
518540 {
519541 if (w->getModuleWidget ()->getModuleId () == mod->get_id ().id_ )
520542 return true ;
@@ -554,7 +576,7 @@ void NetworkEditor::copy()
554576
555577void NetworkEditor::paste ()
556578{
557- QString str = QApplication::clipboard ()->text ();
579+ auto str = QApplication::clipboard ()->text ();
558580
559581 std::istringstream istr (str.toStdString ());
560582 try
@@ -628,7 +650,7 @@ void NetworkEditor::mouseMoveEvent(QMouseEvent *event)
628650 if (event->button () != Qt::LeftButton)
629651 Q_EMIT networkEditorMouseButtonPressed ();
630652
631- if (ConnectionLine* cL = getSingleConnectionSelected ())
653+ if (auto cL = getSingleConnectionSelected ())
632654 {
633655 if (event->buttons () & Qt::LeftButton)
634656 {
@@ -667,7 +689,7 @@ ConnectionLine* NetworkEditor::getSingleConnectionSelected()
667689
668690void NetworkEditor::unselectConnectionGroup ()
669691{
670- QList<QGraphicsItem*> items = scene_->selectedItems ();
692+ auto items = scene_->selectedItems ();
671693 if (items.count () == 3 )
672694 {
673695 int hasConnection = 0 ;
@@ -961,7 +983,7 @@ void NetworkEditor::loadNetwork(const NetworkFileHandle& xml)
961983
962984 Q_FOREACH (QGraphicsItem* item, scene_->items ())
963985 {
964- if (ModuleProxyWidget* w = dynamic_cast <ModuleProxyWidget*>(item))
986+ if (auto w = dynamic_cast <ModuleProxyWidget*>(item))
965987 {
966988 w->getModuleWidget ()->postLoadAction ();
967989 }
@@ -980,7 +1002,7 @@ void NetworkEditor::appendToNetwork(const NetworkFileHandle& xml)
9801002 Q_FOREACH (QGraphicsItem* item, scene_->items ())
9811003 {
9821004 if (!originalItems.contains (item))
983- if (ModuleProxyWidget* w = dynamic_cast <ModuleProxyWidget*>(item))
1005+ if (auto w = dynamic_cast <ModuleProxyWidget*>(item))
9841006 {
9851007 w->getModuleWidget ()->postLoadAction ();
9861008 }
0 commit comments