完善函数

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,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);

View File

@ -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<LayerWrapper>(new LeafLayerWrapper(childJson.toObject(), elementManager, this)));
}
}
#include <iostream>
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();
}

View File

@ -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<shared_ptr<LayerWrapper>> 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);
};