完善函数

dev-VirtualTexture
白封羽 2022-12-21 12:55:41 +08:00
parent 39602e091d
commit 5b5465103a
3 changed files with 28 additions and 6 deletions

View File

@ -4,6 +4,7 @@ EditorWidget::EditorWidget(QWidget *parent) : QWidget(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
previewWindow = ui.Preview; previewWindow = ui.Preview;
qDebug() << "123";
// test // test
QFile settingFile; QFile settingFile;
settingFile.setFileName("../data.json"); settingFile.setFileName("../data.json");

View File

@ -18,8 +18,9 @@ void FolderLayerWrapper::removeChild(LayerWrapper *child)
} }
} }
QPainterPath LayerWrapper::getCache() const QPainterPath LayerWrapper::getCache()
{ {
this->refresh();
return cache; return cache;
} }
// TODO: undone // TODO: undone
@ -49,11 +50,28 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
shared_ptr<LayerWrapper>(new LeafLayerWrapper(childJson.toObject(), elementManager, this))); shared_ptr<LayerWrapper>(new LeafLayerWrapper(childJson.toObject(), elementManager, this)));
} }
} }
#include <iostream>
LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent) LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent)
: LayerWrapper(json, parent) : LayerWrapper(json, parent)
{ {
qDebug() << json.value("name").toString();
int elementIndex = json.value("element").toInt(); int elementIndex = json.value("element").toInt();
wrappedElement = elementManager->getElementById(elementIndex); 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();
}

View File

@ -26,7 +26,8 @@ class LayerWrapper
QPainterPath cache; QPainterPath cache;
public: 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(QJsonObject json, LayerWrapper *parent);
LayerWrapper() = default; LayerWrapper() = default;
}; };
@ -37,6 +38,7 @@ class FolderLayerWrapper : public LayerWrapper
vector<shared_ptr<LayerWrapper>> children; vector<shared_ptr<LayerWrapper>> children;
public: public:
void refresh() override;
FolderLayerWrapper() = default; FolderLayerWrapper() = default;
FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent); FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent);
void addChild(LayerWrapper *child); void addChild(LayerWrapper *child);
@ -49,6 +51,7 @@ class LeafLayerWrapper : public LayerWrapper
GraphicElement *wrappedElement; GraphicElement *wrappedElement;
public: public:
void refresh() override;
LeafLayerWrapper() = default; LeafLayerWrapper() = default;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent); LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, LayerWrapper *parent);
}; };