完善函数
parent
39602e091d
commit
5b5465103a
|
@ -4,17 +4,18 @@ 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");
|
||||||
settingFile.open(QFile::ReadOnly);
|
settingFile.open(QFile::ReadOnly);
|
||||||
QByteArray setting = settingFile.readAll().trimmed();
|
QByteArray setting = settingFile.readAll().trimmed();
|
||||||
QJsonParseError jError;
|
QJsonParseError jError;
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting,&jError));
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(setting, &jError));
|
||||||
qDebug() << jsonDoc.object().value("height").toDouble();
|
qDebug() << jsonDoc.object().value("height").toDouble();
|
||||||
qDebug() << jError.errorString();
|
qDebug() << jError.errorString();
|
||||||
// end test
|
// end test
|
||||||
QJsonObject source=jsonDoc.object();
|
QJsonObject source = jsonDoc.object();
|
||||||
elementManager = new ElementManager(source);
|
elementManager = new ElementManager(source);
|
||||||
layerManager = new LayerManager(source, elementManager);
|
layerManager = new LayerManager(source, elementManager);
|
||||||
previewWindow->initialize(layerManager);
|
previewWindow->initialize(layerManager);
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue