@@ -335,6 +335,7 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, ModuleHandle
335335 theModule_(theModule),
336336 previousModuleState_(UNSET),
337337 moduleId_(id(theModule)),
338+ name_(name),
338339 dialog_(nullptr ),
339340 dockable_(nullptr ),
340341 dialogErrorControl_(dialogErrorControl),
@@ -536,35 +537,26 @@ void ModuleWidget::setupModuleActions()
536537void ModuleWidget::postLoadAction ()
537538{
538539 auto replaceWith = actionsMenu_->getAction (" Replace With..." );
539- connect (replaceWith, SIGNAL (triggered ()), this , SLOT (showReplaceWithWidget ()));
540- replaceWithWidget_ = new QPushButton (this );
541- auto menu = new QMenu (this );
542- replaceWithWidget_->setMenu (menu);
543- fillReplaceWithMenu ();
544- connect (this , SIGNAL (connectionAdded (const SCIRun::Dataflow::Networks::ConnectionDescription&)), this , SLOT (fillReplaceWithMenu ()));
545- connect (this , SIGNAL (connectionDeleted (const SCIRun::Dataflow::Networks::ConnectionId&)), this , SLOT (fillReplaceWithMenu ()));
540+ if (replaceWith)
541+ connect (replaceWith, SIGNAL (triggered ()), this , SLOT (showReplaceWithWidget ()));
546542}
547543
548544void ModuleWidget::showReplaceWithWidget ()
549545{
550- qDebug () << __FUNCTION__;
551- /* QMessageBox msgBox;
552- QPushButton *connectButton = msgBox.addButton("Replacement", QMessageBox::ActionRole);
553- qDebug() << replaceWithWidget_->menu()->actions().size();
554- connectButton->setMenu(replaceWithWidget_->menu());
555- QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
556- msgBox.setText("Press button to replace.");
557-
558- QDialog dialog;
559- auto l = new QHBoxLayout;
560- auto b = new QPushButton("Replacement");
561- auto menu = new QMenu(this);
562- b->setMenu(menu);
563- fillReplaceWithMenuImpl(menu);
564- l->addWidget(b);
565- dialog.setLayout(l);
566- dialog.exec();
567- */
546+ replaceWithDialog_ = new QDialog;
547+ replaceWithDialog_->setWindowTitle (" Replace a module" );
548+ auto layout = new QHBoxLayout;
549+ layout->addWidget (new QLabel (" Replace " + name_ + " with:" ));
550+ auto button = new QPushButton (" Choose a compatible module" );
551+ auto menu = new QMenu;
552+ button->setMenu (menu);
553+ fillReplaceWithMenu (menu);
554+ layout->addWidget (button);
555+ auto cancel = new QPushButton (" Cancel" );
556+ connect (cancel, SIGNAL (clicked ()), replaceWithDialog_, SLOT (reject ()));
557+ layout->addWidget (cancel);
558+ replaceWithDialog_->setLayout (layout);
559+ replaceWithDialog_->exec ();
568560}
569561
570562bool ModuleWidget::guiVisible () const
@@ -574,15 +566,7 @@ bool ModuleWidget::guiVisible() const
574566 return false ;
575567}
576568
577- void ModuleWidget::fillReplaceWithMenu ()
578- {
579- if (deleting_ || networkBeingCleared_)
580- return ;
581-
582- fillReplaceWithMenuImpl (getReplaceWithMenu ());
583- }
584-
585- void ModuleWidget::fillReplaceWithMenuImpl (QMenu* menu)
569+ void ModuleWidget::fillReplaceWithMenu (QMenu* menu)
586570{
587571 if (deleting_ || networkBeingCleared_)
588572 return ;
@@ -594,22 +578,12 @@ void ModuleWidget::fillReplaceWithMenuImpl(QMenu* menu)
594578 fillMenuWithFilteredModuleActions (menu, Application::Instance ().controller ()->getAllAvailableModuleDescriptions (),
595579 isReplacement,
596580 [=](QAction* action) { QObject::connect (action, SIGNAL (triggered ()), this , SLOT (replaceModuleWith ())); },
597- fullWidgetDisplay_->getModuleActionButton ());
598- }
599-
600- void ModuleWidget::menuFunction ()
601- {
602- // fullWidgetDisplay_->getModuleActionButton()->setMenu(nullptr);
603- // actionsMenu_.reset();
604- }
605-
606- QMenu* ModuleWidget::getReplaceWithMenu ()
607- {
608- return replaceWithWidget_->menu ();
581+ replaceWithDialog_);
609582}
610583
611584void ModuleWidget::replaceModuleWith ()
612585{
586+ delete replaceWithDialog_;
613587 auto action = qobject_cast<QAction*>(sender ());
614588 auto moduleToReplace = action->text ();
615589 Q_EMIT replaceModuleWith (theModule_, moduleToReplace.toStdString ());
@@ -998,7 +972,6 @@ ModuleWidget::NetworkClearingScope::~NetworkClearingScope()
998972ModuleWidget::~ModuleWidget ()
999973{
1000974 disconnect (this , SIGNAL (dynamicPortChanged (const std::string&, bool )), this , SLOT (updateDialogForDynamicPortChange (const std::string&, bool )));
1001- disconnect (this , SIGNAL (connectionDeleted (const SCIRun::Dataflow::Networks::ConnectionId&)), this , SLOT (fillReplaceWithMenu ()));
1002975
1003976 if (!theModule_->isStoppable ())
1004977 {
0 commit comments