From b98105667427e4e5e506430469f1afa65552245c Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Fri, 10 Mar 2023 17:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86LayerStyleDialog=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E4=BA=86=E4=BF=AE=E6=94=B9=E6=8B=B7=E8=B4=9D=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MaterialStyle的拷贝有问题,导致编译报错 --- .../LayerStyleDialog.cpp | 20 ++++++++++++------- .../EditorWidgetComponent/LayerStyleDialog.h | 2 ++ .../src/Editor/LayerStyle.cpp | 20 ++++++++++++++----- .../src/Editor/LayerStyle.h | 9 ++++++--- .../src/Editor/RightBar/InfoDisplayWidget.cpp | 1 + 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp index e1f3129..ffc3899 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp @@ -18,10 +18,10 @@ LayerStyleDialog::LayerStyleDialog( if (existedStyle) { - this->layerStyle = existedStyle; + this->modifyingStyle = std::make_unique(existedStyle->clonePtr()); this->styleContainer = nullptr; - this->styleWidget = layerStyle->getInputWidget(); + this->styleWidget = modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); dialogLayout->addWidget(styleWidget); // do something @@ -41,9 +41,9 @@ LayerStyleDialog::LayerStyleDialog( if (!excludeStyleNames.contains(pair.first)) { typeSelector->addItem(pair.first); - if (!this->layerStyle) + if (!this->modifyingStyle) { - this->layerStyle = pair.second(); + this->modifyingStyle = std::move(pair.second()); } } } @@ -54,7 +54,7 @@ LayerStyleDialog::LayerStyleDialog( this->styleContainer = new QGridLayout(this); dialogLayout->addLayout(styleContainer); - this->styleWidget = this->layerStyle->getInputWidget(); + this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); this->styleContainer->addWidget(styleWidget); connect(typeSelector, QOverload::of(&QComboBox::currentIndexChanged), @@ -67,6 +67,12 @@ LayerStyleDialog::LayerStyleDialog( dialogLayout->addWidget(buttonBox); } +void LayerStyleDialog::accept() +{ + this->layerStyle = std::move(this->modifyingStyle); + QDialog::accept(); +} + void LayerStyleDialog::onStyleTypeSelectorChanged(int index) { if (this->styleWidget) @@ -75,8 +81,8 @@ void LayerStyleDialog::onStyleTypeSelectorChanged(int index) this->styleWidget->setParent(nullptr); delete styleWidget; } - this->layerStyle = std::move(LayerStyle::types[index].second()); - this->styleWidget = this->layerStyle->getInputWidget(); + this->modifyingStyle = std::move(LayerStyle::types[index].second()); + this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); this->styleContainer->addWidget(styleWidget, 0, 0, 1, 1); } diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h index d96d448..8246cca 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h @@ -9,6 +9,7 @@ class LayerStyleDialog : public QDialog private: QWidget* styleWidget; QGridLayout* styleContainer; + std::unique_ptr modifyingStyle; public: LayerStyleDialog( QWidget* parent = nullptr, @@ -17,5 +18,6 @@ public: std::shared_ptr layerStyle; private slots: void onStyleTypeSelectorChanged(int index); + void accept() override; }; diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index bd992d0..d4ba2ad 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -5,14 +5,14 @@ #include #include -const std::vector()>>> LayerStyle::types = { +const std::vector()>>> LayerStyle::types = { { QStringLiteral(""), - []() { return std::make_shared(); } + []() { return std::make_unique(); } }, { QStringLiteral(""), - []() { return std::make_shared(); } + []() { return std::make_unique(); } } }; @@ -45,7 +45,7 @@ QWidget* StrokeElementLayerStyle::getListDisplayWidget() const return w; } -StrokeElementLayerStyle::StrokeElementLayerStyle(StrokeElementLayerStyle& other) +StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& other) { materialStyles = std::vector>(other.materialStyles.size()); for (size_t i = 0; i < other.materialStyles.size(); i++) @@ -54,6 +54,11 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(StrokeElementLayerStyle& other) } } +std::shared_ptr StrokeElementLayerStyle::clonePtr() const +{ + return std::make_shared(StrokeElementLayerStyle(*this)); +} + std::vector FillElementLayerStyle::toBaseStyles() const { return std::vector(); @@ -83,7 +88,7 @@ QWidget* FillElementLayerStyle::getListDisplayWidget() const return w; } -FillElementLayerStyle::FillElementLayerStyle(FillElementLayerStyle& other) +FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other) { materialStyles = std::vector>(other.materialStyles.size()); for (size_t i = 0; i < other.materialStyles.size(); i++) @@ -91,3 +96,8 @@ FillElementLayerStyle::FillElementLayerStyle(FillElementLayerStyle& other) materialStyles[i] = std::make_shared(*other.materialStyles[i]); } } + +std::shared_ptr FillElementLayerStyle::clonePtr() const +{ + return std::make_shared(FillElementLayerStyle(*this)); +} diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index ca2b66e..4f10384 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -19,11 +19,12 @@ class LayerStyle { public: - const static std::vector()>>> types; + const static std::vector()>>> types; virtual QString getStyleName() const = 0; virtual QWidget* getInputWidget() const = 0; virtual QWidget* getListDisplayWidget() const = 0; virtual ~LayerStyle() {}; + virtual std::shared_ptr clonePtr() const = 0; }; class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle @@ -34,9 +35,10 @@ public: QWidget* getInputWidget() const override; QWidget* getListDisplayWidget() const override; StrokeElementLayerStyle() = default; - StrokeElementLayerStyle(StrokeElementLayerStyle& other); + StrokeElementLayerStyle(const StrokeElementLayerStyle& other); ~StrokeElementLayerStyle() = default; std::vector> materialStyles; + std::shared_ptr clonePtr() const override; }; class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle @@ -47,7 +49,8 @@ public: QWidget* getInputWidget() const override; QWidget* getListDisplayWidget() const override; FillElementLayerStyle() = default; - FillElementLayerStyle(FillElementLayerStyle& other); + FillElementLayerStyle(const FillElementLayerStyle& other); ~FillElementLayerStyle() = default; std::vector> materialStyles; + std::shared_ptr clonePtr() const override; }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 0e86147..f63ebed 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -198,6 +198,7 @@ void InfoDisplayWidget::generateLayerForm() if (dialog->layerStyle) { + (*styleIterator) = dialog->layerStyle; emit requireRefreshPreview(); emit requireSelfRefresh(); }