Skip to content

Commit 21dd1f9

Browse files
committed
Refactor
1 parent 36491d5 commit 21dd1f9

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

src/Interface/Application/Port.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,20 @@ class OutputPortWidget : public PortWidget
261261
QWidget* parent = nullptr);
262262
};
263263

264+
struct SubnetPortWidgetCtorArgs
265+
{
266+
QString name;
267+
QColor color;
268+
std::string datatype;
269+
boost::function<boost::shared_ptr<ConnectionFactory>()> connectionFactory;
270+
boost::function<boost::shared_ptr<ClosestPortFinder>()> closestPortFinder;
271+
Dataflow::Networks::PortDescriptionInterface* realPort;
272+
};
273+
264274
class SubnetInputPortWidget : public InputPortWidget
265275
{
266276
public:
267-
SubnetInputPortWidget(const QString& name, const QColor& color, const std::string& datatype,
268-
boost::function<boost::shared_ptr<ConnectionFactory>()> connectionFactory,
269-
boost::function<boost::shared_ptr<ClosestPortFinder>()> closestPortFinder,
270-
Dataflow::Networks::PortDescriptionInterface* realPort,
271-
QWidget* parent = nullptr);
277+
SubnetInputPortWidget(const SubnetPortWidgetCtorArgs& args, QWidget* parent = nullptr);
272278
virtual Dataflow::Networks::PortDescriptionInterface* getRealPort() override { return realPort_; }
273279
private:
274280
Dataflow::Networks::PortDescriptionInterface* realPort_;
@@ -277,11 +283,7 @@ class SubnetInputPortWidget : public InputPortWidget
277283
class SubnetOutputPortWidget : public OutputPortWidget
278284
{
279285
public:
280-
SubnetOutputPortWidget(const QString& name, const QColor& color, const std::string& datatype,
281-
boost::function<boost::shared_ptr<ConnectionFactory>()> connectionFactory,
282-
boost::function<boost::shared_ptr<ClosestPortFinder>()> closestPortFinder,
283-
Dataflow::Networks::PortDescriptionInterface* realPort,
284-
QWidget* parent = nullptr);
286+
SubnetOutputPortWidget(const SubnetPortWidgetCtorArgs& args, QWidget* parent = nullptr);
285287
virtual Dataflow::Networks::PortDescriptionInterface* getRealPort() override { return realPort_; }
286288
private:
287289
Dataflow::Networks::PortDescriptionInterface* realPort_;

src/Interface/Application/Subnetworks.cc

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ editor_(editor), name_(name), subnetModuleId_(subnetModuleId)
9292
WidgetStyleMixin::toolbarStyle(subnetBar);
9393
subnetBar->setObjectName("SubnetToolbar");
9494
SCIRunMainWindow::Instance()->addNetworkActionsToBar(subnetBar);
95+
subnetBar->setIconSize(QSize(20, 20));
9596
vbox->setMenuBar(subnetBar);
9697

9798
saveAsTemplatePushButton_->hide();
@@ -230,20 +231,18 @@ void NetworkEditor::setupPortHolder(const std::vector<SharedPointer<PortDescript
230231
int offset = 12;
231232
for (const auto& port : ports)
232233
{
234+
SubnetPortWidgetCtorArgs args { QString::fromStdString(port->get_portname()),
235+
to_color(PortColorLookup::toColor(port->get_typename()), 230), port->get_typename(),
236+
[this](){ return boost::make_shared<ConnectionFactory>([this]() { return scene_; }); },
237+
[this](){ return boost::make_shared<ClosestPortFinder>([this]() { return scene_; }); },
238+
port.get()};
239+
233240
PortWidget* portRepl;
234-
if (name == "Outputs")
235-
portRepl = new SubnetInputPortWidget(QString::fromStdString(port->get_portname()),
236-
to_color(PortColorLookup::toColor(port->get_typename()), 230), port->get_typename(),
237-
[this](){ return boost::make_shared<ConnectionFactory>([this]() { return scene_; }); },
238-
[this](){ return boost::make_shared<ClosestPortFinder>([this]() { return scene_; }); },
239-
port.get());
241+
if (name == "Outputs") // flip input and output designation here.
242+
portRepl = new SubnetInputPortWidget(args);
240243
else // Inputs
241-
portRepl = new SubnetOutputPortWidget(QString::fromStdString(port->get_portname()),
242-
to_color(PortColorLookup::toColor(port->get_typename()), 230), port->get_typename(),
243-
[this](){ return boost::make_shared<ConnectionFactory>([this]() { return scene_; }); },
244-
[this](){ return boost::make_shared<ClosestPortFinder>([this]() { return scene_; }); },
245-
port.get()
246-
);
244+
portRepl = new SubnetOutputPortWidget(args);
245+
247246
layout->addWidget(portRepl);
248247
portRepl->setSceneFunc([this]() { return scene_; });
249248
portRepl->setPositionObject(boost::make_shared<LambdaPositionProvider>([proxy, offset]() { return proxy->pos() + QPointF(offset, 0); }));
@@ -264,24 +263,15 @@ void NetworkEditor::setupPortHolder(const std::vector<SharedPointer<PortDescript
264263
proxy->setPos(position(visibleRect()));
265264
}
266265

267-
SubnetInputPortWidget::SubnetInputPortWidget(const QString& name, const QColor& color, const std::string& datatype,
268-
boost::function<boost::shared_ptr<ConnectionFactory>()> connectionFactory,
269-
boost::function<boost::shared_ptr<ClosestPortFinder>()> closestPortFinder,
270-
PortDescriptionInterface* realPort,
271-
QWidget* parent)
272-
: InputPortWidget(name, color, datatype, ModuleId(), PortId(), 0, true, connectionFactory, closestPortFinder, {}, parent), realPort_(realPort)
273-
266+
SubnetInputPortWidget::SubnetInputPortWidget(const SubnetPortWidgetCtorArgs& args, QWidget* parent)
267+
: InputPortWidget(args.name, args.color, args.datatype, {}, PortId(), 0, true, args.connectionFactory, args.closestPortFinder, {}, parent), realPort_(args.realPort)
274268
{
275269

276270
}
277271

278272

279-
SubnetOutputPortWidget::SubnetOutputPortWidget(const QString& name, const QColor& color, const std::string& datatype,
280-
boost::function<boost::shared_ptr<ConnectionFactory>()> connectionFactory,
281-
boost::function<boost::shared_ptr<ClosestPortFinder>()> closestPortFinder,
282-
PortDescriptionInterface* realPort,
283-
QWidget* parent)
284-
: OutputPortWidget(name, color, datatype, ModuleId(), PortId(), 0, true, connectionFactory, closestPortFinder, {}, parent), realPort_(realPort)
273+
SubnetOutputPortWidget::SubnetOutputPortWidget(const SubnetPortWidgetCtorArgs& args, QWidget* parent)
274+
: OutputPortWidget(args.name, args.color, args.datatype, {}, PortId(), 0, true, args.connectionFactory, args.closestPortFinder, {}, parent), realPort_(args.realPort)
285275
{
286276

287277
}

0 commit comments

Comments
 (0)