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

add duplicateLayerItem()

parent 15bce2ba
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,8 @@ LayerForm::LayerForm(QWidget* parent, LayerItem* layer, SampleEditorController* ...@@ -86,7 +86,8 @@ LayerForm::LayerForm(QWidget* parent, LayerItem* layer, SampleEditorController*
m_duplicateAction = new QAction(this); m_duplicateAction = new QAction(this);
m_duplicateAction->setIcon(QIcon(":/images/content-copy.svg")); m_duplicateAction->setIcon(QIcon(":/images/content-copy.svg"));
m_duplicateAction->setToolTip("Duplicate layer"); m_duplicateAction->setToolTip("Duplicate layer");
connect(m_duplicateAction, &QAction::triggered, []() { qInfo() << "Duplicate layer"; }); connect(m_duplicateAction, &QAction::triggered,
[this] { m_ec->duplicateLayerItem(m_layer); });
m_collapser->addAction(m_duplicateAction); m_collapser->addAction(m_duplicateAction);
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "GUI/Model/Sample/ParticleItem.h" #include "GUI/Model/Sample/ParticleItem.h"
#include "GUI/Model/Sample/ParticleLayoutItem.h" #include "GUI/Model/Sample/ParticleLayoutItem.h"
#include "GUI/Model/Sample/SampleItem.h" #include "GUI/Model/Sample/SampleItem.h"
#include "GUI/Support/XML/Backup.h"
#include "GUI/View/Numeric/DoubleSpinBox.h" #include "GUI/View/Numeric/DoubleSpinBox.h"
#include "GUI/View/SampleDesigner/CompoundForm.h" #include "GUI/View/SampleDesigner/CompoundForm.h"
#include "GUI/View/SampleDesigner/CoreAndShellForm.h" #include "GUI/View/SampleDesigner/CoreAndShellForm.h"
...@@ -67,15 +68,14 @@ void SampleEditorController::addLayerItem(LayerItem* before) ...@@ -67,15 +68,14 @@ void SampleEditorController::addLayerItem(LayerItem* before)
m_undoStack.push(new CommandAddLayer(this, newIndex)); m_undoStack.push(new CommandAddLayer(this, newIndex));
} }
void SampleEditorController::addLayerItemFromUndo(int atIndex) QColor SampleEditorController::findColor(int atIndex)
{ {
// -- find a color for the new layer QColor result;
QColor color;
auto unusedColors = LayerEditorUtil::predefinedLayerColors(); auto unusedColors = LayerEditorUtil::predefinedLayerColors();
for (auto* l : m_sampleItem->layerItems()) for (auto* l : m_sampleItem->layerItems())
unusedColors.removeAll(l->color()); unusedColors.removeAll(l->color());
if (!unusedColors.isEmpty()) if (!unusedColors.isEmpty())
color = unusedColors.first(); result = unusedColors.first();
else { else {
// search for a color which has been used the less, and which is not the same as in the // search for a color which has been used the less, and which is not the same as in the
// layers above and below // layers above and below
...@@ -97,16 +97,15 @@ void SampleEditorController::addLayerItemFromUndo(int atIndex) ...@@ -97,16 +97,15 @@ void SampleEditorController::addLayerItemFromUndo(int atIndex)
for (const auto& col : sortedByUsage) for (const auto& col : sortedByUsage)
if (col != above && col != below) { if (col != above && col != below) {
color = col; result = col;
break; break;
} }
} }
return result;
}
// - create new layer void SampleEditorController::onLayerAdded(LayerItem* layer)
LayerItem* layer = m_sampleItem->createLayerItemAt(atIndex); {
layer->setMaterial(materialModel()->defaultMaterialItem());
layer->setColor(color);
ASSERT(m_sampleForm); ASSERT(m_sampleForm);
m_sampleForm->onLayerAdded(layer); m_sampleForm->onLayerAdded(layer);
m_sampleForm->updateUnits(); m_sampleForm->updateUnits();
...@@ -119,6 +118,29 @@ void SampleEditorController::addLayerItemFromUndo(int atIndex) ...@@ -119,6 +118,29 @@ void SampleEditorController::addLayerItemFromUndo(int atIndex)
c->expand(); c->expand();
} }
void SampleEditorController::addLayerItemFromUndo(int atIndex)
{
QColor color = findColor(atIndex); // before adding layer
LayerItem* layer = m_sampleItem->createLayerItemAt(atIndex);
layer->setMaterial(materialModel()->defaultMaterialItem());
layer->setColor(color);
onLayerAdded(layer);
}
void SampleEditorController::duplicateLayerItem(const LayerItem* layerItem)
{
int at_index = m_sampleItem->layerItems().indexOf(layerItem) + 1;
QColor color = findColor(at_index); // before adding layer
LayerItem* new_layer = m_sampleItem->createLayerItemAt(at_index);
GUI::Util::copyContents(layerItem, new_layer);
new_layer->setColor(color);
onLayerAdded(new_layer);
}
void SampleEditorController::addLayoutItem(LayerForm* layerItemWidget) void SampleEditorController::addLayoutItem(LayerForm* layerItemWidget)
{ {
auto* newLayoutItem = layerItemWidget->layerItem()->addLayoutItem(); auto* newLayoutItem = layerItemWidget->layerItem()->addLayoutItem();
......
...@@ -72,7 +72,10 @@ public: ...@@ -72,7 +72,10 @@ public:
ProjectDocument* projectDocument() const; ProjectDocument* projectDocument() const;
void addLayerItem(LayerItem* before); void addLayerItem(LayerItem* before);
QColor findColor(int atIndex);
void onLayerAdded(LayerItem* layer);
void addLayerItemFromUndo(int atIndex); void addLayerItemFromUndo(int atIndex);
void duplicateLayerItem(const LayerItem* layerItem);
void removeLayerItem(LayerItem* layerItem); void removeLayerItem(LayerItem* layerItem);
void removeLayerItemFromUndo(int atIndex); void removeLayerItemFromUndo(int atIndex);
void addLayoutItem(LayerForm* layerItem); void addLayoutItem(LayerForm* layerItem);
......
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