From 5b5465103a06387c5586e58e93304a01401df1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B0=81=E7=BE=BD?= <2360164671@qq.com> Date: Wed, 21 Dec 2022 12:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidget.cpp | 5 ++-- .../src/Editor/LayerWrapper.cpp | 24 ++++++++++++++++--- .../src/Editor/LayerWrapper.h | 5 +++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp index 6d836ca..c61e341 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp @@ -4,17 +4,18 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); previewWindow = ui.Preview; + qDebug() << "123"; // test QFile settingFile; settingFile.setFileName("../data.json"); settingFile.open(QFile::ReadOnly); QByteArray setting = settingFile.readAll().trimmed(); QJsonParseError jError; - QJsonDocument jsonDoc(QJsonDocument::fromJson(setting,&jError)); + QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError)); qDebug() << jsonDoc.object().value("height").toDouble(); qDebug() << jError.errorString(); // end test - QJsonObject source=jsonDoc.object(); + QJsonObject source = jsonDoc.object(); elementManager = new ElementManager(source); layerManager = new LayerManager(source, elementManager); previewWindow->initialize(layerManager); diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 5d60a59..abd9c91 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -18,8 +18,9 @@ void FolderLayerWrapper::removeChild(LayerWrapper *child) } } -QPainterPath LayerWrapper::getCache() const +QPainterPath LayerWrapper::getCache() { + this->refresh(); return cache; } // TODO: undone @@ -49,11 +50,28 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element shared_ptr(new LeafLayerWrapper(childJson.toObject(), elementManager, this))); } } -#include + LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent) : LayerWrapper(json, parent) { - qDebug() << json.value("name").toString(); int elementIndex = json.value("element").toInt(); wrappedElement = elementManager->getElementById(elementIndex); } + +void LayerWrapper::refresh() +{ +} + +void FolderLayerWrapper::refresh() +{ + cache.clear(); + for (auto &child : children) + cache += child.get()->getCache(); +} + +void LeafLayerWrapper::refresh() +{ + cache.clear(); + if (wrappedElement != nullptr) + cache += wrappedElement->getPaintObject(); +} diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 1ad556b..77e7cfb 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -26,7 +26,8 @@ class LayerWrapper QPainterPath cache; public: - QPainterPath getCache() const; // invoke by manager, then invoke parent's applyStyles + virtual void refresh(); + QPainterPath getCache(); // invoke by manager, then invoke parent's applyStyles LayerWrapper(QJsonObject json, LayerWrapper *parent); LayerWrapper() = default; }; @@ -37,6 +38,7 @@ class FolderLayerWrapper : public LayerWrapper vector> children; public: + void refresh() override; FolderLayerWrapper() = default; FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent); void addChild(LayerWrapper *child); @@ -49,6 +51,7 @@ class LeafLayerWrapper : public LayerWrapper GraphicElement *wrappedElement; public: + void refresh() override; LeafLayerWrapper() = default; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent); };