@@ -121,8 +121,9 @@ namespace SCIRun {
121121 class PortActionsMenu : public QMenu
122122 {
123123 public:
124- explicit PortActionsMenu (PortWidget* parent) : QMenu(" Actions" , parent), faves_(nullptr )
124+ explicit PortActionsMenu (PortWidget* parent) : QMenu(" Actions" , parent), parent_(parent), faves_(nullptr )
125125 {
126+ #if SCIRUN4_CODE_TO_BE_ENABLED_LATER
126127 QList<QAction*> actions;
127128 if (!parent->isInput ())
128129 {
@@ -137,23 +138,58 @@ namespace SCIRun {
137138 actions.append (separatorAction (parent));
138139 }
139140 addActions (actions);
141+ #endif
140142
141- auto m = new QMenu (" Connect Module" , parent);
143+ base_ = new QMenu (" Connect Module" , parent);
142144 faves_ = new QMenu (" Favorites" , parent);
143- m->addMenu (faves_);
144- compatibleModuleActions_ = fillConnectToEmptyPortMenu (m, Application::Instance ().controller ()->getAllAvailableModuleDescriptions (), parent);
145- addMenu (m);
145+ base_->addMenu (faves_);
146+ compatibleModuleActions_ = fillConnectToEmptyPortMenu (base_, Application::Instance ().controller ()->getAllAvailableModuleDescriptions (), parent);
147+
148+ connectModuleAction_ = addAction (" Connect Module..." );
149+ connect (connectModuleAction_, SIGNAL (triggered ()), parent, SLOT (pickConnectModule ()));
146150 }
151+
147152 void filterFavorites ()
148153 {
149154 faves_->clear ();
150155 for (const auto & action : compatibleModuleActions_)
151156 if (SCIRunMainWindow::Instance ()->isInFavorites (action->text ())) // TODO: break out predicate
152157 faves_->addAction (action);
153158 }
159+
160+ QStringList compatibleModules () const
161+ {
162+ QStringList qsl;
163+ Q_FOREACH (QAction* q, compatibleModuleActions_)
164+ qsl.append (q->text ());
165+ qsl.sort ();
166+ return qsl;
167+ }
168+
169+ void portPicked (const QString& module )
170+ {
171+ auto actionIter = std::find_if (compatibleModuleActions_.begin (), compatibleModuleActions_.end (), [&module ](QAction* a) { return a->text () == module ; });
172+ if (actionIter != compatibleModuleActions_.end ())
173+ {
174+ (*actionIter)->trigger ();
175+ }
176+ else
177+ qDebug () << " action not found:" << compatibleModules ();
178+ }
179+
180+ virtual void showEvent (QShowEvent* event) override
181+ {
182+ QPoint p = pos ();
183+ QRect geo = parent_->geometry ();
184+ move (p.x () + geo.width () - geometry ().width (), p.y ());
185+ }
186+
154187 private:
188+ PortWidget* parent_;
189+ QMenu* base_;
155190 QMenu* faves_;
156191 QList<QAction*> compatibleModuleActions_;
192+ QAction* connectModuleAction_;
157193 };
158194 }}
159195
@@ -312,6 +348,20 @@ void PortWidget::doMouseRelease(Qt::MouseButton button, const QPointF& pos, Qt::
312348 }
313349}
314350
351+ void PortWidget::pickConnectModule ()
352+ {
353+ QInputDialog qid;
354+ qid.setWindowTitle (" Connect new module here" );
355+ qid.setLabelText (" New module to connect:" );
356+ qid.setComboBoxItems (menu_->compatibleModules ());
357+ qid.setOption (QInputDialog::UseListViewForComboBoxItems, true );
358+ auto ok = qid.exec ();
359+ if (ok == QDialog::Accepted)
360+ {
361+ menu_->portPicked (qid.textValue ());
362+ }
363+ }
364+
315365size_t PortWidget::getIndex () const
316366{
317367 return index_;
0 commit comments