TaoZhang-Branch
karlis 2023-03-10 19:44:18 +08:00
parent b981056674
commit 3dd7fd7c0f
3 changed files with 15 additions and 14 deletions

View File

@ -33,6 +33,7 @@ PixelPath LayerWrapper::getCache()
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent) LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
{ {
this->parent = parent; this->parent = parent;
this->qTreeWidgetItem = new QTreeWidgetItem();
auto transformJson = json.value("transform").toObject(); auto transformJson = json.value("transform").toObject();
property.name = json.value("name").toString(); property.name = json.value("name").toString();
property.offset = {transformJson.value("offset").toObject().value("x").toDouble(), property.offset = {transformJson.value("offset").toObject().value("x").toDouble(),
@ -119,22 +120,22 @@ void LayerWrapper::setParent(FolderLayerWrapper* newParent)
void FolderLayerWrapper::removeAllChild() void FolderLayerWrapper::removeAllChild()
{ {
children.clear(); children.clear();
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
} }
void LayerWrapper::del() { void LayerWrapper::del() {
qDebug() << "LayerWrapper::del()"; qDebug() << "LayerWrapper::del()";
if (parent != nullptr){ if (parent != nullptr){
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem); parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
} }
} }
void LayerWrapper::delSelf() { void LayerWrapper::delSelf() {
qDebug() << "LayerWrapper::delSelf()"; qDebug() << "LayerWrapper::delSelf()";
if (parent != nullptr) { if (parent != nullptr) {
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem); parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
} }
} }
@ -154,7 +155,7 @@ void FolderLayerWrapper::delSelf() {
qDebug() << this; qDebug() << this;
for (auto& child : this->children) { for (auto& child : this->children) {
this->parent->addChild(child); this->parent->addChild(child);
this->parent->qTreeWidgetItem.addChild(&child.get()->qTreeWidgetItem); this->parent->qTreeWidgetItem->addChild(child.get()->qTreeWidgetItem);
child->setParent(this->parent); child->setParent(this->parent);
} }
while (!this->children.empty()) { while (!this->children.empty()) {
@ -166,18 +167,18 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem() QTreeWidgetItem* LayerWrapper::getQTreeItem()
{ {
this->qTreeWidgetItem.setText(0, this->property.name); this->qTreeWidgetItem->setText(0, this->property.name);
this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this)); this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
return &this->qTreeWidgetItem; return this->qTreeWidgetItem;
} }
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem() QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
{ {
while (this->qTreeWidgetItem.childCount() > 0) { while (this->qTreeWidgetItem->childCount() > 0) {
this->qTreeWidgetItem.removeChild(this->qTreeWidgetItem.child(0)); this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
} }
for (auto& child : this->children) { for (auto& child : this->children) {
this->qTreeWidgetItem.addChild(child->getQTreeItem()); this->qTreeWidgetItem->addChild(child->getQTreeItem());
} }
return LayerWrapper::getQTreeItem(); return LayerWrapper::getQTreeItem();
} }

View File

@ -33,7 +33,7 @@ class LayerWrapper
PixelPath cache; PixelPath cache;
public: public:
QTreeWidgetItem qTreeWidgetItem; QTreeWidgetItem* qTreeWidgetItem;
struct SimpleProperty struct SimpleProperty
{ {
QString name = ""; QString name = "";

View File

@ -51,7 +51,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
else else
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer); newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer)); folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem()); folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
qDebug() << jsonObj<<"----------------------"; qDebug() << jsonObj<<"----------------------";
this->refresh(); this->refresh();
emit requireRefreshPreview(); emit requireRefreshPreview();