Skip to content

Commit 53333a7

Browse files
authored
Merge branch 'master' into gcc6-2-fix
2 parents 765272e + f8d33c4 commit 53333a7

File tree

15 files changed

+103
-90
lines changed

15 files changed

+103
-90
lines changed

src/Dataflow/Engine/Controller/DynamicPortManager.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,11 @@ void DynamicPortManager::connectionAddedNeedToCloneAPort(const SCIRun::Dataflow:
4848
{
4949
if (enabled_)
5050
{
51-
//std::cout << "need to clone a port: " << ConnectionId::create(cd).id_ << std::endl;
52-
/// @todo: assumption: dynamic = input
5351
auto moduleIn = controller_->getNetwork()->lookupModule(cd.in_.moduleId_);
5452
if (moduleIn->getInputPort(cd.in_.portId_)->isDynamic())
5553
{
5654
ModuleBuilder builder;
5755
auto newPortId = builder.cloneInputPort(moduleIn, cd.in_.portId_);
58-
//std::cout << "SIGNALLING ADD: " << moduleIn->get_id() << " /// " << newPortId << std::endl;
5956
portAdded_(moduleIn->get_id(), newPortId);
6057
}
6158
}
@@ -65,16 +62,16 @@ void DynamicPortManager::connectionRemovedNeedToRemoveAPort(const SCIRun::Datafl
6562
{
6663
if (enabled_)
6764
{
68-
//std::cout << "need to remove a port: " << id.id_ << std::endl;
6965
auto desc = id.describe();
7066
auto moduleIn = controller_->getNetwork()->lookupModule(desc.in_.moduleId_);
71-
//std::cout << "REMOVE CHECKING: " << desc.in_.moduleId_ << " /// " << desc.in_.portId_ << std::endl;
72-
if (moduleIn->getInputPort(desc.in_.portId_)->isDynamic())
67+
if (moduleIn)
7368
{
74-
ModuleBuilder builder;
75-
builder.removeInputPort(moduleIn, desc.in_.portId_);
76-
//std::cout << "SIGNALLING REMOVE: " << moduleIn->get_id() << " /// " << desc.in_.portId_ << std::endl;
77-
portRemoved_(moduleIn->get_id(), desc.in_.portId_);
69+
if (moduleIn->getInputPort(desc.in_.portId_)->isDynamic())
70+
{
71+
ModuleBuilder builder;
72+
builder.removeInputPort(moduleIn, desc.in_.portId_);
73+
portRemoved_(moduleIn->get_id(), desc.in_.portId_);
74+
}
7875
}
7976
}
8077
}

src/Interface/Application/Connection.cc

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,28 +205,35 @@ namespace SCIRun
205205
{
206206
deleteAction_ = addAction(deleteAction);
207207
addWidgetToExecutionDisableList(deleteAction_);
208-
insertAction_ = addAction(insertModuleAction);
209-
addWidgetToExecutionDisableList(insertAction_);
210-
211-
212-
auto insertable = new QMenu;
213-
fillInsertModuleMenu(insertable, Application::Instance().controller()->getAllAvailableModuleDescriptions(), conn->connectedPorts().first, conn);
214-
insertAction_->setMenu(insertable);
215-
208+
if (!eitherPortDynamic(conn->connectedPorts()))
209+
{
210+
insertAction_ = addAction(insertModuleAction);
211+
addWidgetToExecutionDisableList(insertAction_);
212+
auto insertable = new QMenu;
213+
fillInsertModuleMenu(insertable, Application::Instance().controller()->getAllAvailableModuleDescriptions(), conn->connectedPorts().first, conn);
214+
insertAction_->setMenu(insertable);
215+
}
216216
disableAction_ = addAction(disableEnableAction);
217217
addWidgetToExecutionDisableList(disableAction_);
218218
notesAction_ = addAction(editNotesAction);
219219
}
220220
~ConnectionMenu()
221221
{
222222
removeWidgetFromExecutionDisableList(deleteAction_);
223-
removeWidgetFromExecutionDisableList(insertAction_);
223+
if (insertAction_)
224+
removeWidgetFromExecutionDisableList(insertAction_);
224225
removeWidgetFromExecutionDisableList(disableAction_);
225226
}
226-
QAction* notesAction_;
227-
QAction* deleteAction_;
228-
QAction* disableAction_;
229-
QAction* insertAction_;
227+
QAction* notesAction_{ nullptr };
228+
QAction* deleteAction_{ nullptr };
229+
QAction* disableAction_{ nullptr };
230+
QAction* insertAction_{ nullptr };
231+
232+
private:
233+
bool eitherPortDynamic(const std::pair<PortWidget*, PortWidget*>& ports) const
234+
{
235+
return ports.first->isDynamic() || ports.second->isDynamic();
236+
}
230237
};
231238
}
232239
}

src/Interface/Application/ModuleProxyWidget.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,6 @@ bool ModuleProxyWidget::isSubwidget(QWidget* alienWidget) const
369369
qobject_cast<QProgressBar*>(alienWidget);
370370
}
371371

372-
void ModuleProxyWidget::menuFunction()
373-
{
374-
module_->menuFunction();
375-
}
376-
377372
void ModuleProxyWidget::highlightIfSelected()
378373
{
379374
if (!isSelected_ && isSelected())

src/Interface/Application/ModuleProxyWidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ namespace SCIRun
5252
void createStartupNote();
5353
void adjustHeight(int delta);
5454
void adjustWidth(int delta);
55-
void menuFunction();
5655

5756
//TODO: move to utility
5857
static void ensureItemVisible(QGraphicsItem* item);

src/Interface/Application/ModuleWidget.cc

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace Gui {
7474
<< new QAction("Help", parent)
7575
<< new QAction("Edit Notes...", parent)
7676
<< new QAction("Duplicate", parent)
77-
<< new QAction("Replace With", parent)
77+
<< new QAction("Replace With...", parent)
7878
//<< disabled(new QAction("Ignore*", parent))
7979
<< new QAction("Show Log", parent)
8080
//<< disabled(new QAction("Make Sub-Network", parent)) // Issue #287
@@ -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),
@@ -527,20 +528,39 @@ void ModuleWidget::setupModuleActions()
527528
|| theModule_->get_id().name_ == "Subnet")
528529
actionsMenu_->getMenu()->removeAction(actionsMenu_->getAction("Duplicate"));
529530
if (theModule_->get_id().name_ == "Subnet")
530-
actionsMenu_->getMenu()->removeAction(actionsMenu_->getAction("Replace With"));
531+
actionsMenu_->getMenu()->removeAction(actionsMenu_->getAction("Replace With..."));
531532

532533
connectNoteEditorToAction(actionsMenu_->getAction("Notes"));
533534
connectUpdateNote(this);
534535
}
535536

536537
void ModuleWidget::postLoadAction()
537538
{
538-
auto replaceWith = actionsMenu_->getAction("Replace With");
539-
auto menu = new QMenu(this);
540-
replaceWith->setMenu(menu);
541-
fillReplaceWithMenu();
542-
connect(this, SIGNAL(connectionAdded(const SCIRun::Dataflow::Networks::ConnectionDescription&)), this, SLOT(fillReplaceWithMenu()));
543-
connect(this, SIGNAL(connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId&)), this, SLOT(fillReplaceWithMenu()));
539+
auto replaceWith = actionsMenu_->getAction("Replace With...");
540+
if (replaceWith)
541+
connect(replaceWith, SIGNAL(triggered()), this, SLOT(showReplaceWithWidget()));
542+
}
543+
544+
void ModuleWidget::showReplaceWithWidget()
545+
{
546+
#ifndef __APPLE__
547+
replaceWithDialog_ = new QDialog;
548+
replaceWithDialog_->setWindowTitle("Replace a module");
549+
auto layout = new QHBoxLayout;
550+
layout->addWidget(new QLabel("Replace " + name_ + " with:"));
551+
auto button = new QPushButton("Choose a compatible module");
552+
auto menu = new QMenu;
553+
button->setMenu(menu);
554+
fillReplaceWithMenu(menu);
555+
layout->addWidget(button);
556+
auto cancel = new QPushButton("Cancel");
557+
connect(cancel, SIGNAL(clicked()), replaceWithDialog_, SLOT(reject()));
558+
layout->addWidget(cancel);
559+
replaceWithDialog_->setLayout(layout);
560+
replaceWithDialog_->exec();
561+
#else
562+
QMessageBox::information(nullptr, "Replace with disabled", "The replace with command is disabled on OSX until the Qt 5 upgrade is complete.");
563+
#endif
544564
}
545565

546566
bool ModuleWidget::guiVisible() const
@@ -550,35 +570,25 @@ bool ModuleWidget::guiVisible() const
550570
return false;
551571
}
552572

553-
void ModuleWidget::fillReplaceWithMenu()
573+
void ModuleWidget::fillReplaceWithMenu(QMenu* menu)
554574
{
555575
if (deleting_ || networkBeingCleared_)
556576
return;
557577

558-
auto menu = getReplaceWithMenu();
559578
menu->clear();
560579
LOG_DEBUG("Filling menu for " << theModule_->get_module_name() << std::endl);
561580
auto replacements = Application::Instance().controller()->possibleReplacements(this->theModule_);
562581
auto isReplacement = [&](const ModuleDescription& md) { return replacements.find(md.lookupInfo_) != replacements.end(); };
563582
fillMenuWithFilteredModuleActions(menu, Application::Instance().controller()->getAllAvailableModuleDescriptions(),
564583
isReplacement,
565584
[=](QAction* action) { QObject::connect(action, SIGNAL(triggered()), this, SLOT(replaceModuleWith())); },
566-
fullWidgetDisplay_->getModuleActionButton());
567-
}
568-
569-
void ModuleWidget::menuFunction()
570-
{
571-
// fullWidgetDisplay_->getModuleActionButton()->setMenu(nullptr);
572-
// actionsMenu_.reset();
573-
}
574-
575-
QMenu* ModuleWidget::getReplaceWithMenu()
576-
{
577-
return actionsMenu_->getAction("Replace With")->menu();
585+
replaceWithDialog_);
578586
}
579587

580588
void ModuleWidget::replaceModuleWith()
581589
{
590+
delete replaceWithDialog_;
591+
replaceWithDialog_ = nullptr;
582592
auto action = qobject_cast<QAction*>(sender());
583593
auto moduleToReplace = action->text();
584594
Q_EMIT replaceModuleWith(theModule_, moduleToReplace.toStdString());
@@ -967,7 +977,6 @@ ModuleWidget::NetworkClearingScope::~NetworkClearingScope()
967977
ModuleWidget::~ModuleWidget()
968978
{
969979
disconnect(this, SIGNAL(dynamicPortChanged(const std::string&, bool)), this, SLOT(updateDialogForDynamicPortChange(const std::string&, bool)));
970-
disconnect(this, SIGNAL(connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId&)), this, SLOT(fillReplaceWithMenu()));
971980

972981
if (!theModule_->isStoppable())
973982
{

src/Interface/Application/ModuleWidget.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ class ModuleWidget : public QStackedWidget,
151151
int portSpacing() const;
152152
void setPortSpacing(bool highlighted);
153153

154-
virtual boost::signals2::connection connectExecuteBegins(const SCIRun::Dataflow::Networks::ExecuteBeginsSignalType::slot_type& subscriber) override final;
155-
virtual boost::signals2::connection connectExecuteEnds(const SCIRun::Dataflow::Networks::ExecuteEndsSignalType::slot_type& subscriber) override final;
156-
virtual boost::signals2::connection connectErrorListener(const SCIRun::Dataflow::Networks::ErrorSignalType::slot_type& subscriber) override final;
154+
boost::signals2::connection connectExecuteBegins(const SCIRun::Dataflow::Networks::ExecuteBeginsSignalType::slot_type& subscriber) override final;
155+
boost::signals2::connection connectExecuteEnds(const SCIRun::Dataflow::Networks::ExecuteEndsSignalType::slot_type& subscriber) override final;
156+
boost::signals2::connection connectErrorListener(const SCIRun::Dataflow::Networks::ErrorSignalType::slot_type& subscriber) override final;
157157

158158
void updateNoteFromFile(const Note& note);
159159

@@ -174,7 +174,7 @@ class ModuleWidget : public QStackedWidget,
174174
void setupPortSceneCollaborator(QGraphicsProxyWidget* proxy);
175175

176176
public Q_SLOTS:
177-
virtual bool executeWithSignals() override;
177+
bool executeWithSignals() override;
178178
void toggleOptionsDialog();
179179
void setLogButtonColor(const QColor& color);
180180
void resetLogButtonColor();
@@ -194,7 +194,6 @@ public Q_SLOTS:
194194
void updateMetadata(bool active);
195195
void updatePortSpacing(bool highlighted);
196196
void replaceMe();
197-
void menuFunction();
198197
Q_SIGNALS:
199198
void removeModule(const SCIRun::Dataflow::Networks::ModuleId& moduleId);
200199
void interrupt(const SCIRun::Dataflow::Networks::ModuleId& moduleId);
@@ -234,14 +233,14 @@ private Q_SLOTS:
234233
void executeTriggeredProgrammatically(bool upstream);
235234
void stopButtonPushed();
236235
void colorOptionsButton(bool visible);
237-
void fillReplaceWithMenu();
238236
void replaceModuleWith();
239237
void updateDialogForDynamicPortChange(const std::string& portName, bool adding);
240238
void handleDialogFatalError(const QString& message);
241239
void changeExecuteButtonToPlay();
242240
void changeExecuteButtonToStop();
243241
void updateDockWidgetProperties(bool isFloating);
244242
void incomingConnectionStateChanged(bool disabled, int index);
243+
void showReplaceWithWidget();
245244
protected:
246245
virtual void enterEvent(QEvent* event) override;
247246
virtual void leaveEvent(QEvent* event) override;
@@ -253,6 +252,7 @@ private Q_SLOTS:
253252
bool executedOnce_, skipExecuteDueToFatalError_, disabled_;
254253
std::atomic<bool> errored_;
255254
int previousPageIndex_ {0};
255+
QDialog* replaceWithDialog_{ nullptr };
256256

257257
SCIRun::Dataflow::Networks::ModuleHandle theModule_;
258258
std::atomic<int> previousModuleState_;
@@ -264,6 +264,7 @@ private Q_SLOTS:
264264
void setupDisplayConnections(ModuleWidgetDisplayBase* display);
265265
void resizeBasedOnModuleName(ModuleWidgetDisplayBase* display, int index);
266266
std::string moduleId_;
267+
QString name_;
267268
class ModuleDialogGeneric* dialog_;
268269
QDockWidget* dockable_;
269270
void makeOptionsDialog();
@@ -274,9 +275,9 @@ private Q_SLOTS:
274275
void adjustDockState(bool dockEnabled);
275276
Qt::DockWidgetArea allowedDockArea() const;
276277
void printInputPorts(const SCIRun::Dataflow::Networks::ModuleInfoProvider& moduleInfoProvider) const;
277-
QMenu* getReplaceWithMenu();
278278
void setInputPortSpacing(bool highlighted);
279279
void setOutputPortSpacing(bool highlighted);
280+
void fillReplaceWithMenu(QMenu* menu);
280281

281282
class ModuleLogWindow* logWindow_;
282283
boost::scoped_ptr<class ModuleActionsMenu> actionsMenu_;

src/Interface/Application/NetworkEditor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void NetworkEditor::replaceModuleWith(const ModuleHandle& moduleToReplace, const
276276
InEditingContext iec(this);
277277

278278
auto oldModule = findById(scene_->items(), moduleToReplace->get_id());
279-
lastModulePosition_ = oldModule->scenePos();
279+
lastModulePosition_ = oldModule->scenePos() - QPointF(15, 15);;
280280
controller_->addModule(newModuleName);
281281

282282
// connect up same ports

src/Interface/Application/NetworkEditor.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ namespace Gui {
269269
using ConnectorFunc = std::function<void(NetworkEditor*)>;
270270
static void setConnectorFunc(ConnectorFunc func) { connectorFunc_ = func; }
271271

272+
struct InEditingContext
273+
{
274+
explicit InEditingContext(NetworkEditor* ed)
275+
{
276+
inEditingContext_ = ed;
277+
}
278+
~InEditingContext()
279+
{
280+
inEditingContext_ = nullptr;
281+
}
282+
};
272283
protected:
273284
void dropEvent(QDropEvent* event) override;
274285
void dragEnterEvent(QDragEnterEvent* event) override;
@@ -438,17 +449,7 @@ namespace Gui {
438449
}
439450

440451
static NetworkEditor* inEditingContext_;
441-
struct InEditingContext
442-
{
443-
explicit InEditingContext(NetworkEditor* ed)
444-
{
445-
inEditingContext_ = ed;
446-
}
447-
~InEditingContext()
448-
{
449-
inEditingContext_ = nullptr;
450-
}
451-
};
452+
452453
static ConnectorFunc connectorFunc_;
453454
static std::function<QPointF(const QRectF&)> topSubnetPortHolderPositioner_;
454455
static std::function<QPointF(const QRectF&)> bottomSubnetPortHolderPositioner_;

0 commit comments

Comments
 (0)