Skip to content

Commit d7a9350

Browse files
committed
Working on subnet renaming
1 parent d3a1ab9 commit d7a9350

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

src/Interface/Application/NetworkEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ namespace Gui {
323323
void showSubnetChild(const QString& name);
324324
void addSubnetChild(const QString& name, SCIRun::Dataflow::Networks::ModuleHandle mod);
325325
void removeSubnetChild(const QString& name);
326+
void subnetMenuActionTriggered();
326327

327328
Q_SIGNALS:
328329
void connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId& id);
@@ -425,6 +426,7 @@ namespace Gui {
425426
std::vector<QGraphicsItem*> subnetItemsToMove();
426427
PortRewiringMap portRewiringMap_;
427428
QSet<QString> currentSubnetNames_;
429+
std::map<std::string, QString> subnetNameMap_;
428430

429431
template <typename Func>
430432
void tailRecurse(Func func)

src/Interface/Application/SCIRunMainWindow.cc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ void SCIRunMainWindow::renameSavedSubnetwork()
14151415
{
14161416
auto toRename = sender()->property("ID").toString();
14171417
bool ok;
1418-
auto text = QInputDialog::getText(this, tr("Rename subnet"), tr("Enter new subnet name:"), QLineEdit::Normal, savedSubnetworksNames_[toRename].toString(), &ok);
1418+
auto text = QInputDialog::getText(this, tr("Rename fragment"), tr("Enter new fragment name:"), QLineEdit::Normal, savedSubnetworksNames_[toRename].toString(), &ok);
14191419
if (ok && !text.isEmpty())
14201420
{
14211421
savedSubnetworksNames_[toRename] = text;
@@ -1805,18 +1805,47 @@ void SCIRunMainWindow::addModuleToWindowList(const QString& modId, bool hasUI)
18051805

18061806
if (modId.contains("Subnet"))
18071807
{
1808-
qDebug() << "do subnet stuff";
1808+
if (menuCurrentSubnets_->actions().isEmpty())
1809+
menuCurrentSubnets_->setEnabled(true);
1810+
1811+
auto subnetMenu = new QMenu(modId, this);
1812+
auto showAction = new QAction(subnetMenu);
1813+
showAction->setText("Show");
1814+
subnetMenu->addAction(showAction);
1815+
auto renameAction = new QAction(subnetMenu);
1816+
renameAction->setText("Rename...");
1817+
subnetMenu->addAction(renameAction);
1818+
1819+
connect(showAction, SIGNAL(triggered()), networkEditor_, SLOT(subnetMenuActionTriggered()));
1820+
connect(renameAction, SIGNAL(triggered()), networkEditor_, SLOT(subnetMenuActionTriggered()));
1821+
qDebug() << "add" << modId;
1822+
currentSubnetActions_.insert(modId, subnetMenu);
1823+
menuCurrentSubnets_->addMenu(subnetMenu);
18091824
}
18101825
}
18111826

18121827
void SCIRunMainWindow::removeModuleFromWindowList(const ModuleId& modId)
18131828
{
18141829
auto name = QString::fromStdString(modId.id_);
1830+
qDebug() << "remove" << name;
18151831
auto action = currentModuleActions_[name];
18161832
menuCurrent_->removeAction(action);
18171833
currentModuleActions_.remove(name);
18181834
if (menuCurrent_->actions().isEmpty())
18191835
menuCurrent_->setEnabled(false);
1836+
1837+
if (modId.id_.find("Subnet") != std::string::npos)
1838+
{
1839+
qDebug() << currentSubnetActions_;
1840+
auto subnet = currentSubnetActions_[name];
1841+
if (subnet)
1842+
subnet->setEnabled(false);
1843+
// //menuCurrentSubnets_->remove(subnet);
1844+
// currentSubnetActions_.remove(name);
1845+
// if (menuCurrentSubnets_->actions().isEmpty())
1846+
// menuCurrentSubnets_->setEnabled(false);
1847+
}
1848+
18201849
}
18211850

18221851
void SCIRunMainWindow::setupTagManagerWindow()

src/Interface/Application/SCIRunMainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public Q_SLOTS:
173173
int returnCode_ { 0 };
174174
QMap<QString,QMap<QString,QString>> styleSheetDetails_;
175175
QMap<QString, QAction*> currentModuleActions_;
176+
QMap<QString, QMenu*> currentSubnetActions_;
176177
boost::shared_ptr<class DialogErrorControl> dialogErrorControl_;
177178
boost::shared_ptr<class NetworkExecutionProgressBar> networkProgressBar_;
178179
boost::shared_ptr<class GuiActionProvenanceConverter> commandConverter_;

src/Interface/Application/SCIRunMainWindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@
254254
</widget>
255255
<addaction name="menuFile_"/>
256256
<addaction name="menuEdit"/>
257-
<addaction name="menuModules_"/>
258257
<addaction name="menuNetwork"/>
258+
<addaction name="menuModules_"/>
259259
<addaction name="menuSubnets_"/>
260260
<addaction name="menuToolkits_"/>
261261
<addaction name="menuWindow"/>

src/Interface/Application/Subnetworks.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ std::vector<QGraphicsItem*> NetworkEditor::subnetItemsToMove()
170170
void NetworkEditor::removeSubnetChild(const QString& name)
171171
{
172172
childrenNetworks_.erase(name);
173+
//TODO: erase from subnetNameMap_
173174
}
174175

175176
void NetworkEditor::addSubnetChild(const QString& name, ModuleHandle mod)
@@ -206,6 +207,41 @@ void NetworkEditor::showSubnetChild(const QString& name)
206207
}
207208
}
208209

210+
void NetworkEditor::subnetMenuActionTriggered()
211+
{
212+
auto action = qobject_cast<QAction*>(sender());
213+
auto subnetId = qobject_cast<QMenu*>(action->parent())->title();
214+
auto actionText = action->text();
215+
if ("Show" == actionText)
216+
{
217+
showSubnetChild(subnetNameMap_[subnetId.toStdString()]);
218+
}
219+
else if ("Rename..." == actionText)
220+
{
221+
bool ok;
222+
auto text = QInputDialog::getText(this, tr("Rename subnet"), tr("Enter new subnet name:"),
223+
QLineEdit::Normal, subnetNameMap_[subnetId.toStdString()], &ok);
224+
if (ok && !text.isEmpty())
225+
{
226+
qDebug() << "how to rename subnet";
227+
}
228+
229+
230+
}
231+
// Q_FOREACH(QGraphicsItem* item, scene_->items())
232+
// {
233+
// auto module = getModule(item);
234+
// if (module && module->getModuleId() == action->text().toStdString())
235+
// {
236+
// if (module->guiVisible())
237+
// module->hideUI();
238+
// else
239+
// module->showUI();
240+
// break;
241+
// }
242+
// }
243+
}
244+
209245
QRectF NetworkEditor::visibleRect() const
210246
{
211247
return mapToScene(rect()).boundingRect();
@@ -658,6 +694,7 @@ void NetworkEditor::makeSubnetworkFromComponents(const QString& name, const std:
658694
childrenNetworkItems_[name] = items;
659695

660696
addSubnetChild(name, subnetModule);
697+
subnetNameMap_[subnetModule->get_id()] = name;
661698

662699
Q_EMIT modified();
663700
Q_EMIT newModule(QString::fromStdString(subnetModule->get_id()), subnetModule->has_ui());

0 commit comments

Comments
 (0)