Skip to content
Snippets Groups Projects
Commit 049a6d8c authored by Mikhail Svechnikov's avatar Mikhail Svechnikov Committed by Wuttke, Joachim
Browse files

cleanup & use ActionFactory::createDuplicateAction

parent 55e1e551
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,21 @@ QAction* ActionFactory::createRemoveAction(QObject* parent, const QString& what, ...@@ -31,6 +31,21 @@ QAction* ActionFactory::createRemoveAction(QObject* parent, const QString& what,
return removeAction; return removeAction;
} }
QAction* ActionFactory::createDuplicateAction(QObject* parent, const QString& what,
std::function<void()> slot)
{
auto* duplicateAction = new QAction(parent);
duplicateAction->setText("Duplicate");
duplicateAction->setIcon(QIcon(":/images/content-copy.svg"));
duplicateAction->setIconText("Duplicate");
duplicateAction->setToolTip("Duplicate " + what);
if (slot)
QObject::connect(duplicateAction, &QAction::triggered, slot);
return duplicateAction;
}
QAction* ActionFactory::createShowInRealspaceAction(QObject* parent, const QString& what, QAction* ActionFactory::createShowInRealspaceAction(QObject* parent, const QString& what,
std::function<void()> slot) std::function<void()> slot)
{ {
......
...@@ -37,6 +37,12 @@ public: ...@@ -37,6 +37,12 @@ public:
//! If a slot is given, it will be connected to the "triggered" signal. //! If a slot is given, it will be connected to the "triggered" signal.
static QAction* createRemoveAction(QObject* parent, const QString& what, static QAction* createRemoveAction(QObject* parent, const QString& what,
std::function<void()> slot = nullptr); std::function<void()> slot = nullptr);
//! Create "duplicate" action.
//!
//! The "what" text will be used in the tooltip, appended to "Duplicate ".
//! If a slot is given, it will be connected to the "triggered" signal.
static QAction* createDuplicateAction(QObject* parent, const QString& what,
std::function<void()> slot = nullptr);
//! Create "show in Realspace" action. //! Create "show in Realspace" action.
//! //!
......
...@@ -83,12 +83,8 @@ LayerForm::LayerForm(QWidget* parent, LayerItem* layer, SampleEditorController* ...@@ -83,12 +83,8 @@ LayerForm::LayerForm(QWidget* parent, LayerItem* layer, SampleEditorController*
} }
// duplicate // duplicate
{ {
m_duplicateAction = new QAction(this); m_duplicateAction = ActionFactory::createDuplicateAction(
m_duplicateAction->setIcon(QIcon(":/images/content-copy.svg")); this, "layer", [this] { m_ec->duplicateLayerItem(m_layer); });
m_duplicateAction->setToolTip("Duplicate layer");
connect(m_duplicateAction, &QAction::triggered,
[this] { m_ec->duplicateLayerItem(m_layer); });
m_collapser->addAction(m_duplicateAction); m_collapser->addAction(m_duplicateAction);
} }
// remove // remove
......
...@@ -53,19 +53,25 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la ...@@ -53,19 +53,25 @@ ParticleLayoutForm::ParticleLayoutForm(LayerForm* parent, ParticleLayoutItem* la
m_structureEditingWidgets << btn; m_structureEditingWidgets << btn;
layouter.addStructureEditingRow(btn); layouter.addStructureEditingRow(btn);
m_removeAction = ActionFactory::createRemoveAction(
this, "particle layout", [=] { ec->removeLayoutItem(parent, layoutItem); });
auto* showInRealspaceAction = ActionFactory::createShowInRealspaceAction(
this, "particle layout", [=] { ec->requestViewInRealspace(layoutItem); });
m_collapser = GroupBoxCollapser::installIntoGroupBox(this); m_collapser = GroupBoxCollapser::installIntoGroupBox(this);
m_collapser->setExpanded(layoutItem->isExpandLayout()); m_collapser->setExpanded(layoutItem->isExpandLayout());
connect(m_collapser, &GroupBoxCollapser::toggled, this, connect(m_collapser, &GroupBoxCollapser::toggled, this,
[layoutItem](bool b) { layoutItem->setExpandLayout(b); }); [layoutItem](bool b) { layoutItem->setExpandLayout(b); });
m_collapser->addAction(showInRealspaceAction); // top right corner actions
m_collapser->addAction(m_removeAction); // show in real space
{
auto* showInRealspaceAction = ActionFactory::createShowInRealspaceAction(
this, "particle layout", [=] { ec->requestViewInRealspace(layoutItem); });
m_collapser->addAction(showInRealspaceAction);
}
// remove
{
m_removeAction = ActionFactory::createRemoveAction(
this, "particle layout", [=] { ec->removeLayoutItem(parent, layoutItem); });
m_collapser->addAction(m_removeAction);
}
m_layout = layouter.layout(); m_layout = layouter.layout();
updateDensityEnabling(); updateDensityEnabling();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment